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 { |
| 24 | RPC_CONNECTION_OPTION_REVERSE = 0x1, |
| 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 | }; |
| 34 | |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 35 | /** |
| 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 Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 39 | struct RpcConnectionHeader { |
Steven Moreland | 01a6bad | 2021-06-11 00:59:20 +0000 | [diff] [blame^] | 40 | RpcWireAddress sessionId; |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 41 | uint8_t options; |
Steven Moreland | 01a6bad | 2021-06-11 00:59:20 +0000 | [diff] [blame^] | 42 | uint8_t reserved[7]; |
Steven Moreland | 659416d | 2021-05-11 00:47:50 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 45 | #define RPC_CONNECTION_INIT_OKAY "cci" |
| 46 | |
| 47 | /** |
| 48 | * Whenever a client connection is setup, this is sent as the initial |
| 49 | * transaction. The main use of this is in order to control the timing for when |
| 50 | * a reverse connection is setup. |
| 51 | */ |
Steven Moreland | 19fc9f7 | 2021-06-10 03:57:30 +0000 | [diff] [blame] | 52 | struct RpcOutgoingConnectionInit { |
Steven Moreland | c88b7fc | 2021-06-10 00:40:39 +0000 | [diff] [blame] | 53 | char msg[4]; |
| 54 | uint8_t reserved[4]; |
| 55 | }; |
| 56 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 57 | enum : uint32_t { |
| 58 | /** |
| 59 | * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected |
| 60 | */ |
| 61 | RPC_COMMAND_TRANSACT = 0, |
| 62 | /** |
| 63 | * follows is RpcWireReply |
| 64 | */ |
| 65 | RPC_COMMAND_REPLY, |
| 66 | /** |
| 67 | * follows is RpcWireAddress |
| 68 | * |
| 69 | * note - this in the protocol directly instead of as a 'special |
| 70 | * transaction' in order to keep it as lightweight as possible (we don't |
| 71 | * want to create a 'Parcel' object for every decref) |
| 72 | */ |
| 73 | RPC_COMMAND_DEC_STRONG, |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * These commands are used when the address in an RpcWireTransaction is zero'd |
| 78 | * out (no address). This allows the transact/reply flow to be used for |
| 79 | * additional server commands, without making the protocol for |
| 80 | * transactions/replies more complicated. |
| 81 | */ |
| 82 | enum : uint32_t { |
| 83 | RPC_SPECIAL_TRANSACT_GET_ROOT = 0, |
Steven Moreland | f137de9 | 2021-04-24 01:54:26 +0000 | [diff] [blame] | 84 | RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1, |
Steven Moreland | bdb53ab | 2021-05-05 17:57:41 +0000 | [diff] [blame] | 85 | RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2, |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 88 | // serialization is like: |
| 89 | // |RpcWireHeader|struct desginated by 'command'| (over and over again) |
| 90 | |
| 91 | struct RpcWireHeader { |
| 92 | uint32_t command; // RPC_COMMAND_* |
| 93 | uint32_t bodySize; |
| 94 | |
| 95 | uint32_t reserved[2]; |
| 96 | }; |
| 97 | |
Steven Moreland | 5553ac4 | 2020-11-11 02:14:45 +0000 | [diff] [blame] | 98 | struct RpcWireTransaction { |
| 99 | RpcWireAddress address; |
| 100 | uint32_t code; |
| 101 | uint32_t flags; |
| 102 | |
| 103 | uint64_t asyncNumber; |
| 104 | |
| 105 | uint32_t reserved[4]; |
| 106 | |
| 107 | uint8_t data[0]; |
| 108 | }; |
| 109 | |
| 110 | struct RpcWireReply { |
| 111 | int32_t status; // transact return |
| 112 | uint8_t data[0]; |
| 113 | }; |
| 114 | |
| 115 | #pragma clang diagnostic pop |
| 116 | |
| 117 | } // namespace android |