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 17 #ifndef CHPP_CLIENT_DISCOVERY_H_ 18 #define CHPP_CLIENT_DISCOVERY_H_ 19 20 #include <stdbool.h> 21 #include <stddef.h> 22 #include <stdint.h> 23 24 #include "chpp/app.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /************************************************ 31 * Public functions 32 ***********************************************/ 33 34 /** 35 * CHPP discovery state initialization that should be called on CHPP startup. It 36 * may be called during transient internal resets, but is a no-op. 37 */ 38 void chppDiscoveryInit(struct ChppAppState *context); 39 40 /** 41 * CHPP discovery state de-initialization that should be called during shutdown. 42 */ 43 void chppDiscoveryDeinit(struct ChppAppState *context); 44 45 /** 46 * A method that can be invoked to block until the CHPP discovery sequence 47 * completes. This can be useful to wait until CHPP client invocations can 48 * succeed. 49 * 50 * @param context The non-null pointer to the ChppAppState of this instance. 51 * @param timeoutMs The timeout in milliseconds. 52 * 53 * @return False if timed out waiting for discovery completion. 54 */ 55 bool chppWaitForDiscoveryComplete(struct ChppAppState *context, 56 uint64_t timeoutMs); 57 58 /** 59 * Dispatches an Rx Datagram from the transport layer that is determined to be 60 * for the CHPP Discovery Client. 61 * 62 * @param context Maintains status for each app layer instance. 63 * @param buf Input (request) datagram. Cannot be null. 64 * @param len Length of input data in bytes. 65 */ 66 bool chppDispatchDiscoveryServiceResponse(struct ChppAppState *context, 67 const uint8_t *buf, size_t len); 68 69 /** 70 * Initiates a CHPP service discovery from the client side, in order to send a 71 * CHPP_DISCOVERY_COMMAND_DISCOVER_ALL client request to a server. It is 72 * expected that this function be called upon initialization, after sending or 73 * receiving a reset-ack. 74 * 75 * @param context Maintains status for each app layer instance. 76 */ 77 void chppInitiateDiscovery(struct ChppAppState *context); 78 79 /** 80 * Checks if all discovery clients have been matched with a remote service. 81 * 82 * @param context Maintains status for each app layer instance. 83 * 84 * @return true if all registered clients have been matched by a discovered 85 * service. 86 */ 87 bool chppAreAllClientsMatched(struct ChppAppState *context); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif // CHPP_CLIENT_DISCOVERY_H_ 94