Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | namespace android { |
| 19 | |
| 20 | #pragma clang diagnostic push |
| 21 | #pragma clang diagnostic error "-Wpadded" |
| 22 | |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 23 | enum : uint8_t { |
Steven Moreland | 1b30429 | 2021-07-15 22:59:34 +0000 | [diff] [blame] | 24 | RPC_CONNECTION_OPTION_INCOMING = 0x1, // default is outgoing |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
Steven Moreland | 01a6bad | 2021-06-11 00:59:20 +0000 | [diff] [blame] | 27 | constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_CREATED = 1 << 0; // distinguish from '0' address |
| 28 | constexpr uint64_t RPC_WIRE_ADDRESS_OPTION_FOR_SERVER = 1 << 1; |
| 29 | |
| 30 | struct RpcWireAddress { |
| 31 | uint64_t options; |
| 32 | uint8_t address[32]; |
| 33 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 34 | static_assert(sizeof(RpcWireAddress) == 40); |
Steven Moreland | 01a6bad | 2021-06-11 00:59:20 +0000 | [diff] [blame] | 35 | |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 36 | /** |
| 37 | * This is sent to an RpcServer in order to request a new connection is created, |
| 38 | * either as part of a new session or an existing session |
| 39 | */ |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 40 | struct RpcConnectionHeader { |
Steven Moreland | bf57bce | 2021-07-26 15:26:12 -0700 | [diff] [blame] | 41 | uint32_t version; // maximum supported by caller |
| 42 | uint8_t reserver0[4]; |
Steven Moreland | 01a6bad | 2021-06-11 00:59:20 +0000 | [diff] [blame] | 43 | RpcWireAddress sessionId; |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 44 | uint8_t options; |
Steven Moreland | bf57bce | 2021-07-26 15:26:12 -0700 | [diff] [blame] | 45 | uint8_t reserved1[7]; |
| 46 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 47 | static_assert(sizeof(RpcConnectionHeader) == 56); |
Steven Moreland | bf57bce | 2021-07-26 15:26:12 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * In response to an RpcConnectionHeader which corresponds to a new session, |
| 51 | * this returns information to the server. |
| 52 | */ |
| 53 | struct RpcNewSessionResponse { |
| 54 | uint32_t version; // maximum supported by callee <= maximum supported by caller |
| 55 | uint8_t reserved[4]; |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 56 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 57 | static_assert(sizeof(RpcNewSessionResponse) == 8); |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 58 | |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 59 | #define RPC_CONNECTION_INIT_OKAY "cci" |
| 60 | |
| 61 | /** |
| 62 | * Whenever a client connection is setup, this is sent as the initial |
| 63 | * transaction. The main use of this is in order to control the timing for when |
Steven Moreland | 1b30429 | 2021-07-15 22:59:34 +0000 | [diff] [blame] | 64 | * an incoming connection is setup. |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 65 | */ |
Steven Moreland | 19fc9f7 | 2021-06-10 03:57:30 +0000 | [diff] [blame] | 66 | struct RpcOutgoingConnectionInit { |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 67 | char msg[4]; |
| 68 | uint8_t reserved[4]; |
| 69 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 70 | static_assert(sizeof(RpcOutgoingConnectionInit) == 8); |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 71 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 72 | enum : uint32_t { |
| 73 | /** |
| 74 | * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected |
| 75 | */ |
| 76 | RPC_COMMAND_TRANSACT = 0, |
| 77 | /** |
| 78 | * follows is RpcWireReply |
| 79 | */ |
| 80 | RPC_COMMAND_REPLY, |
| 81 | /** |
| 82 | * follows is RpcWireAddress |
| 83 | * |
| 84 | * note - this in the protocol directly instead of as a 'special |
| 85 | * transaction' in order to keep it as lightweight as possible (we don't |
| 86 | * want to create a 'Parcel' object for every decref) |
| 87 | */ |
| 88 | RPC_COMMAND_DEC_STRONG, |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * These commands are used when the address in an RpcWireTransaction is zero'd |
| 93 | * out (no address). This allows the transact/reply flow to be used for |
| 94 | * additional server commands, without making the protocol for |
| 95 | * transactions/replies more complicated. |
| 96 | */ |
| 97 | enum : uint32_t { |
| 98 | RPC_SPECIAL_TRANSACT_GET_ROOT = 0, |
Steven Moreland | f137de9 | 2021-04-24 01:54:26 +0000 | [diff] [blame] | 99 | RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1, |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 100 | RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2, |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 103 | // serialization is like: |
| 104 | // |RpcWireHeader|struct desginated by 'command'| (over and over again) |
| 105 | |
| 106 | struct RpcWireHeader { |
| 107 | uint32_t command; // RPC_COMMAND_* |
| 108 | uint32_t bodySize; |
| 109 | |
| 110 | uint32_t reserved[2]; |
| 111 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 112 | static_assert(sizeof(RpcWireHeader) == 16); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 113 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 114 | struct RpcWireTransaction { |
| 115 | RpcWireAddress address; |
| 116 | uint32_t code; |
| 117 | uint32_t flags; |
| 118 | |
| 119 | uint64_t asyncNumber; |
| 120 | |
| 121 | uint32_t reserved[4]; |
| 122 | |
Devin Moore | 139913a | 2021-08-13 19:59:16 +0000 | [diff] [blame] | 123 | uint8_t data[]; |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 124 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 125 | static_assert(sizeof(RpcWireTransaction) == 72); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 126 | |
| 127 | struct RpcWireReply { |
| 128 | int32_t status; // transact return |
Devin Moore | 139913a | 2021-08-13 19:59:16 +0000 | [diff] [blame] | 129 | uint8_t data[]; |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 130 | }; |
Steven Moreland | 14cd3fe | 2021-09-02 16:18:14 -0700 | [diff] [blame^] | 131 | static_assert(sizeof(RpcWireReply) == 4); |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 132 | |
| 133 | #pragma clang diagnostic pop |
| 134 | |
| 135 | } // namespace android |