blob: 649c1eeb8eaf3a4a6498d81232b36cbf014add9d [file] [log] [blame]
Steven Moreland5553ac42020-11-11 02:14:45 +00001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18namespace android {
19
20#pragma clang diagnostic push
21#pragma clang diagnostic error "-Wpadded"
22
Steven Moreland659416d2021-05-11 00:47:50 +000023constexpr int32_t RPC_SESSION_ID_NEW = -1;
24
25enum : uint8_t {
26 RPC_CONNECTION_OPTION_REVERSE = 0x1,
27};
28
29struct RpcConnectionHeader {
30 int32_t sessionId;
31 uint8_t options;
32 uint8_t reserved[3];
33};
34
Steven Moreland5553ac42020-11-11 02:14:45 +000035enum : uint32_t {
36 /**
37 * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected
38 */
39 RPC_COMMAND_TRANSACT = 0,
40 /**
41 * follows is RpcWireReply
42 */
43 RPC_COMMAND_REPLY,
44 /**
45 * follows is RpcWireAddress
46 *
47 * note - this in the protocol directly instead of as a 'special
48 * transaction' in order to keep it as lightweight as possible (we don't
49 * want to create a 'Parcel' object for every decref)
50 */
51 RPC_COMMAND_DEC_STRONG,
52};
53
54/**
55 * These commands are used when the address in an RpcWireTransaction is zero'd
56 * out (no address). This allows the transact/reply flow to be used for
57 * additional server commands, without making the protocol for
58 * transactions/replies more complicated.
59 */
60enum : uint32_t {
61 RPC_SPECIAL_TRANSACT_GET_ROOT = 0,
Steven Morelandf137de92021-04-24 01:54:26 +000062 RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1,
Steven Morelandbdb53ab2021-05-05 17:57:41 +000063 RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2,
Steven Moreland5553ac42020-11-11 02:14:45 +000064};
65
Steven Moreland5553ac42020-11-11 02:14:45 +000066// serialization is like:
67// |RpcWireHeader|struct desginated by 'command'| (over and over again)
68
69struct RpcWireHeader {
70 uint32_t command; // RPC_COMMAND_*
71 uint32_t bodySize;
72
73 uint32_t reserved[2];
74};
75
76struct RpcWireAddress {
77 uint8_t address[32];
78};
79
80struct RpcWireTransaction {
81 RpcWireAddress address;
82 uint32_t code;
83 uint32_t flags;
84
85 uint64_t asyncNumber;
86
87 uint32_t reserved[4];
88
89 uint8_t data[0];
90};
91
92struct RpcWireReply {
93 int32_t status; // transact return
94 uint8_t data[0];
95};
96
97#pragma clang diagnostic pop
98
99} // namespace android