blob: fbcfac61e29a53a813ec3b3f1bb57e2a1af56aaa [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 Moreland826367f2021-09-10 14:05:31 -070023constexpr uint8_t RPC_CONNECTION_OPTION_INCOMING = 0x1; // default is outgoing
Steven Moreland659416d2021-05-11 00:47:50 +000024
Steven Moreland01a6bad2021-06-11 00:59:20 +000025constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_CREATED = 1 << 0; // distinguish from '0' address
26constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_FOR_SERVER = 1 << 1;
27
28struct RpcWireAddress {
29 uint64_t options;
30 uint8_t address[32];
31};
Steven Moreland14cd3fe2021-09-02 16:18:14 -070032static_assert(sizeof(RpcWireAddress) == 40);
Steven Moreland01a6bad2021-06-11 00:59:20 +000033
Steven Morelandc88b7fc2021-06-10 00:40:39 +000034/**
35 * This is sent to an RpcServer in order to request a new connection is created,
36 * either as part of a new session or an existing session
37 */
Steven Moreland659416d2021-05-11 00:47:50 +000038struct RpcConnectionHeader {
Steven Morelandbf57bce2021-07-26 15:26:12 -070039 uint32_t version; // maximum supported by caller
Steven Moreland659416d2021-05-11 00:47:50 +000040 uint8_t options;
Steven Moreland826367f2021-09-10 14:05:31 -070041 uint8_t reservered[9];
42 // Follows is sessionIdSize bytes.
43 // if size is 0, this is requesting a new session.
44 uint16_t sessionIdSize;
Steven Morelandbf57bce2021-07-26 15:26:12 -070045};
Steven Moreland826367f2021-09-10 14:05:31 -070046static_assert(sizeof(RpcConnectionHeader) == 16);
Steven Morelandbf57bce2021-07-26 15:26:12 -070047
48/**
49 * In response to an RpcConnectionHeader which corresponds to a new session,
50 * this returns information to the server.
51 */
52struct RpcNewSessionResponse {
53 uint32_t version; // maximum supported by callee <= maximum supported by caller
54 uint8_t reserved[4];
Steven Moreland659416d2021-05-11 00:47:50 +000055};
Steven Moreland14cd3fe2021-09-02 16:18:14 -070056static_assert(sizeof(RpcNewSessionResponse) == 8);
Steven Moreland659416d2021-05-11 00:47:50 +000057
Steven Morelandc88b7fc2021-06-10 00:40:39 +000058#define RPC_CONNECTION_INIT_OKAY "cci"
59
60/**
61 * Whenever a client connection is setup, this is sent as the initial
62 * transaction. The main use of this is in order to control the timing for when
Steven Moreland1b304292021-07-15 22:59:34 +000063 * an incoming connection is setup.
Steven Morelandc88b7fc2021-06-10 00:40:39 +000064 */
Steven Moreland19fc9f72021-06-10 03:57:30 +000065struct RpcOutgoingConnectionInit {
Steven Morelandc88b7fc2021-06-10 00:40:39 +000066 char msg[4];
67 uint8_t reserved[4];
68};
Steven Moreland14cd3fe2021-09-02 16:18:14 -070069static_assert(sizeof(RpcOutgoingConnectionInit) == 8);
Steven Morelandc88b7fc2021-06-10 00:40:39 +000070
Steven Moreland5553ac42020-11-11 02:14:45 +000071enum : uint32_t {
72 /**
73 * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected
74 */
75 RPC_COMMAND_TRANSACT = 0,
76 /**
77 * follows is RpcWireReply
78 */
79 RPC_COMMAND_REPLY,
80 /**
81 * follows is RpcWireAddress
82 *
83 * note - this in the protocol directly instead of as a 'special
84 * transaction' in order to keep it as lightweight as possible (we don't
85 * want to create a 'Parcel' object for every decref)
86 */
87 RPC_COMMAND_DEC_STRONG,
88};
89
90/**
91 * These commands are used when the address in an RpcWireTransaction is zero'd
92 * out (no address). This allows the transact/reply flow to be used for
93 * additional server commands, without making the protocol for
94 * transactions/replies more complicated.
95 */
96enum : uint32_t {
97 RPC_SPECIAL_TRANSACT_GET_ROOT = 0,
Steven Morelandf137de92021-04-24 01:54:26 +000098 RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1,
Steven Morelandbdb53ab2021-05-05 17:57:41 +000099 RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2,
Steven Moreland5553ac42020-11-11 02:14:45 +0000100};
101
Steven Moreland5553ac42020-11-11 02:14:45 +0000102// serialization is like:
103// |RpcWireHeader|struct desginated by 'command'| (over and over again)
104
105struct RpcWireHeader {
106 uint32_t command; // RPC_COMMAND_*
107 uint32_t bodySize;
108
109 uint32_t reserved[2];
110};
Steven Moreland14cd3fe2021-09-02 16:18:14 -0700111static_assert(sizeof(RpcWireHeader) == 16);
Steven Moreland5553ac42020-11-11 02:14:45 +0000112
Steven Moreland5553ac42020-11-11 02:14:45 +0000113struct RpcWireTransaction {
114 RpcWireAddress address;
115 uint32_t code;
116 uint32_t flags;
117
118 uint64_t asyncNumber;
119
120 uint32_t reserved[4];
121
Devin Moore139913a2021-08-13 19:59:16 +0000122 uint8_t data[];
Steven Moreland5553ac42020-11-11 02:14:45 +0000123};
Steven Moreland14cd3fe2021-09-02 16:18:14 -0700124static_assert(sizeof(RpcWireTransaction) == 72);
Steven Moreland5553ac42020-11-11 02:14:45 +0000125
126struct RpcWireReply {
127 int32_t status; // transact return
Devin Moore139913a2021-08-13 19:59:16 +0000128 uint8_t data[];
Steven Moreland5553ac42020-11-11 02:14:45 +0000129};
Steven Moreland14cd3fe2021-09-02 16:18:14 -0700130static_assert(sizeof(RpcWireReply) == 4);
Steven Moreland5553ac42020-11-11 02:14:45 +0000131
132#pragma clang diagnostic pop
133
134} // namespace android