1 /* 2 * Copyright (C) 2022 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 17 #ifndef CHRE_UTIL_PIGWEED_RPC_HELPER_H_ 18 #define CHRE_UTIL_PIGWEED_RPC_HELPER_H_ 19 20 #include <cstdint> 21 22 #include "chre/util/pigweed/rpc_common.h" 23 #include "chre_api/chre.h" 24 25 namespace chre { 26 27 /** 28 * Returns whether the endpoint matches. 29 * 30 * Only the lower 16 bits are considered. 31 * 32 * @param expectedId Expected channel ID. 33 * @param actualId Actual channel ID. 34 * @return whether the nanoapp IDs match (lower 16b). 35 */ 36 bool rpcEndpointsMatch(uint32_t expectedId, uint32_t actualId); 37 /** 38 * Validates that the host client sending the message matches the expected 39 * channel ID. 40 * 41 * @param msg Message received from the host client. 42 * @param channelId Channel ID extracted from the received packet. 43 * @return Whether the IDs match. 44 */ 45 bool validateHostChannelId(const chreMessageFromHostData *msg, 46 uint32_t channelId); 47 48 /** 49 * Validates that the nanoapp sending the message matches the expected 50 * channel ID. 51 * 52 * @param senderInstanceId ID of the nanoapp sending the message. 53 * @param channelId Channel ID extracted from the received packet. 54 * @return Whether the IDs match. 55 */ 56 bool validateNanoappChannelId(uint32_t nappId, uint32_t channelId); 57 58 } // namespace chre 59 60 #endif // CHRE_UTIL_PIGWEED_RPC_HELPER_H_ 61