blob: c73d8c2bd82fb516dfb49c34f3a3729a5f15ff8c [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 +000023enum : uint8_t {
Steven Moreland1b304292021-07-15 22:59:34 +000024 RPC_CONNECTION_OPTION_INCOMING = 0x1, // default is outgoing
Steven Moreland659416d2021-05-11 00:47:50 +000025};
26
Steven Moreland01a6bad2021-06-11 00:59:20 +000027constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_CREATED = 1 << 0; // distinguish from '0' address
28constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_FOR_SERVER = 1 << 1;
29
30struct RpcWireAddress {
31 uint64_t options;
32 uint8_t address[32];
33};
34
Steven Morelandc88b7fc2021-06-10 00:40:39 +000035/**
36 * This is sent to an RpcServer in order to request a new connection is created,
37 * either as part of a new session or an existing session
38 */
Steven Moreland659416d2021-05-11 00:47:50 +000039struct RpcConnectionHeader {
Steven Morelandbf57bce2021-07-26 15:26:12 -070040 uint32_t version; // maximum supported by caller
41 uint8_t reserver0[4];
Steven Moreland01a6bad2021-06-11 00:59:20 +000042 RpcWireAddress sessionId;
Steven Moreland659416d2021-05-11 00:47:50 +000043 uint8_t options;
Steven Morelandbf57bce2021-07-26 15:26:12 -070044 uint8_t reserved1[7];
45};
46
47/**
48 * In response to an RpcConnectionHeader which corresponds to a new session,
49 * this returns information to the server.
50 */
51struct RpcNewSessionResponse {
52 uint32_t version; // maximum supported by callee <= maximum supported by caller
53 uint8_t reserved[4];
Steven Moreland659416d2021-05-11 00:47:50 +000054};
55
Steven Morelandc88b7fc2021-06-10 00:40:39 +000056#define RPC_CONNECTION_INIT_OKAY "cci"
57
58/**
59 * Whenever a client connection is setup, this is sent as the initial
60 * transaction. The main use of this is in order to control the timing for when
Steven Moreland1b304292021-07-15 22:59:34 +000061 * an incoming connection is setup.
Steven Morelandc88b7fc2021-06-10 00:40:39 +000062 */
Steven Moreland19fc9f72021-06-10 03:57:30 +000063struct RpcOutgoingConnectionInit {
Steven Morelandc88b7fc2021-06-10 00:40:39 +000064 char msg[4];
65 uint8_t reserved[4];
66};
67
Steven Moreland5553ac42020-11-11 02:14:45 +000068enum : uint32_t {
69 /**
70 * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected
71 */
72 RPC_COMMAND_TRANSACT = 0,
73 /**
74 * follows is RpcWireReply
75 */
76 RPC_COMMAND_REPLY,
77 /**
78 * follows is RpcWireAddress
79 *
80 * note - this in the protocol directly instead of as a 'special
81 * transaction' in order to keep it as lightweight as possible (we don't
82 * want to create a 'Parcel' object for every decref)
83 */
84 RPC_COMMAND_DEC_STRONG,
85};
86
87/**
88 * These commands are used when the address in an RpcWireTransaction is zero'd
89 * out (no address). This allows the transact/reply flow to be used for
90 * additional server commands, without making the protocol for
91 * transactions/replies more complicated.
92 */
93enum : uint32_t {
94 RPC_SPECIAL_TRANSACT_GET_ROOT = 0,
Steven Morelandf137de92021-04-24 01:54:26 +000095 RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1,
Steven Morelandbdb53ab2021-05-05 17:57:41 +000096 RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2,
Steven Moreland5553ac42020-11-11 02:14:45 +000097};
98
Steven Moreland5553ac42020-11-11 02:14:45 +000099// serialization is like:
100// |RpcWireHeader|struct desginated by 'command'| (over and over again)
101
102struct RpcWireHeader {
103 uint32_t command; // RPC_COMMAND_*
104 uint32_t bodySize;
105
106 uint32_t reserved[2];
107};
108
Steven Moreland5553ac42020-11-11 02:14:45 +0000109struct RpcWireTransaction {
110 RpcWireAddress address;
111 uint32_t code;
112 uint32_t flags;
113
114 uint64_t asyncNumber;
115
116 uint32_t reserved[4];
117
Devin Moore139913a2021-08-13 19:59:16 +0000118 uint8_t data[];
Steven Moreland5553ac42020-11-11 02:14:45 +0000119};
120
121struct RpcWireReply {
122 int32_t status; // transact return
Devin Moore139913a2021-08-13 19:59:16 +0000123 uint8_t data[];
Steven Moreland5553ac42020-11-11 02:14:45 +0000124};
125
126#pragma clang diagnostic pop
127
128} // namespace android