blob: 4bd8e36aade4b18a86f5e07a2382c37f1e760545 [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
Steven Morelandc88b7fc2021-06-10 00:40:39 +000029/**
30 * This is sent to an RpcServer in order to request a new connection is created,
31 * either as part of a new session or an existing session
32 */
Steven Moreland659416d2021-05-11 00:47:50 +000033struct RpcConnectionHeader {
34 int32_t sessionId;
35 uint8_t options;
36 uint8_t reserved[3];
37};
38
Steven Morelandc88b7fc2021-06-10 00:40:39 +000039#define RPC_CONNECTION_INIT_OKAY "cci"
40
41/**
42 * Whenever a client connection is setup, this is sent as the initial
43 * transaction. The main use of this is in order to control the timing for when
44 * a reverse connection is setup.
45 */
Steven Moreland19fc9f72021-06-10 03:57:30 +000046struct RpcOutgoingConnectionInit {
Steven Morelandc88b7fc2021-06-10 00:40:39 +000047 char msg[4];
48 uint8_t reserved[4];
49};
50
Steven Moreland5553ac42020-11-11 02:14:45 +000051enum : uint32_t {
52 /**
53 * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected
54 */
55 RPC_COMMAND_TRANSACT = 0,
56 /**
57 * follows is RpcWireReply
58 */
59 RPC_COMMAND_REPLY,
60 /**
61 * follows is RpcWireAddress
62 *
63 * note - this in the protocol directly instead of as a 'special
64 * transaction' in order to keep it as lightweight as possible (we don't
65 * want to create a 'Parcel' object for every decref)
66 */
67 RPC_COMMAND_DEC_STRONG,
68};
69
70/**
71 * These commands are used when the address in an RpcWireTransaction is zero'd
72 * out (no address). This allows the transact/reply flow to be used for
73 * additional server commands, without making the protocol for
74 * transactions/replies more complicated.
75 */
76enum : uint32_t {
77 RPC_SPECIAL_TRANSACT_GET_ROOT = 0,
Steven Morelandf137de92021-04-24 01:54:26 +000078 RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1,
Steven Morelandbdb53ab2021-05-05 17:57:41 +000079 RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2,
Steven Moreland5553ac42020-11-11 02:14:45 +000080};
81
Steven Moreland5553ac42020-11-11 02:14:45 +000082// serialization is like:
83// |RpcWireHeader|struct desginated by 'command'| (over and over again)
84
85struct RpcWireHeader {
86 uint32_t command; // RPC_COMMAND_*
87 uint32_t bodySize;
88
89 uint32_t reserved[2];
90};
91
Steven Moreland91538242021-06-10 23:35:35 +000092constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_CREATED = 1 << 0; // distinguish from '0' address
93constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_FOR_SERVER = 1 << 1;
94
Steven Moreland5553ac42020-11-11 02:14:45 +000095struct RpcWireAddress {
Steven Moreland91538242021-06-10 23:35:35 +000096 uint64_t options;
Steven Moreland5553ac42020-11-11 02:14:45 +000097 uint8_t address[32];
98};
99
100struct RpcWireTransaction {
101 RpcWireAddress address;
102 uint32_t code;
103 uint32_t flags;
104
105 uint64_t asyncNumber;
106
107 uint32_t reserved[4];
108
109 uint8_t data[0];
110};
111
112struct RpcWireReply {
113 int32_t status; // transact return
114 uint8_t data[0];
115};
116
117#pragma clang diagnostic pop
118
119} // namespace android