• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * @param appState Application layer state.
39  */
40 void chppDiscoveryInit(struct ChppAppState *appState);
41 
42 /**
43  * CHPP discovery state de-initialization that should be called during shutdown.
44  *
45  * @param appState Application layer state.
46  */
47 void chppDiscoveryDeinit(struct ChppAppState *appState);
48 
49 /**
50  * A method that can be invoked to block until the CHPP discovery sequence
51  * completes. This can be useful to wait until CHPP client invocations can
52  * succeed.
53  *
54  * @param appState Application layer state.
55  * @param timeoutMs The timeout in milliseconds.
56  *
57  * @return False if timed out waiting for discovery completion.
58  */
59 bool chppWaitForDiscoveryComplete(struct ChppAppState *appState,
60                                   uint64_t timeoutMs);
61 
62 /**
63  * Dispatches an Rx Datagram from the transport layer that is determined to be
64  * for the CHPP Discovery Client.
65  *
66  * @param appState Application layer state.
67  * @param buf Input (request) datagram. Cannot be null.
68  * @param len Length of input data in bytes.
69  */
70 bool chppDispatchDiscoveryServiceResponse(struct ChppAppState *appState,
71                                           const uint8_t *buf, size_t len);
72 
73 /**
74  * Initiates a CHPP service discovery from the client side, in order to send a
75  * CHPP_DISCOVERY_COMMAND_DISCOVER_ALL client request to a server. It is
76  * expected that this function be called upon initialization, after sending or
77  * receiving a reset-ack.
78  *
79  * @param appState Application layer state.
80  */
81 void chppInitiateDiscovery(struct ChppAppState *appState);
82 
83 /**
84  * Checks if all discovery clients have been matched with a remote service.
85  *
86  * @param appState Application layer state.
87  *
88  * @return true if all registered clients have been matched by a discovered
89  * service.
90  */
91 bool chppAreAllClientsMatched(struct ChppAppState *appState);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif  // CHPP_CLIENT_DISCOVERY_H_
98