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 #ifndef CHPP_WIFI_TYPES_H_
17 #define CHPP_WIFI_TYPES_H_
18 
19 // This file was automatically generated by chre_api_to_chpp.py
20 // Date: 2021-05-24 15:46:25 UTC
21 // Source: chre_api/include/chre_api/chre/wifi.h @ commit 833a6241
22 
23 // DO NOT modify this file directly, as those changes will be lost the next
24 // time the script is executed
25 
26 #include <stdbool.h>
27 #include <stddef.h>
28 #include <stdint.h>
29 
30 #include "chpp/app.h"
31 #include "chpp/common/common_types.h"
32 #include "chpp/macros.h"
33 #include "chre_api/chre/version.h"
34 #include "chre_api/chre/wifi.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 CHPP_PACKED_START
41 
42 //! See {@link chreWifiLci} for details
43 struct ChppWifiLci {
44   int64_t latitude;
45   int64_t longitude;
46   int32_t altitude;
47   uint8_t latitudeUncertainty;
48   uint8_t longitudeUncertainty;
49   uint8_t altitudeType;
50   uint8_t altitudeUncertainty;
51 } CHPP_PACKED_ATTR;
52 
53 //! See {@link chreWifiRangingResult} for details
54 struct ChppWifiRangingResult {
55   uint64_t timestamp;
56   uint8_t macAddress[6];
57   uint8_t status;
58   int8_t rssi;
59   uint32_t distance;
60   uint32_t distanceStdDev;
61   struct ChppWifiLci lci;
62   uint8_t flags;
63   uint8_t reserved[7];  // Input ignored; always set to 0
64 } CHPP_PACKED_ATTR;
65 
66 //! See {@link chreWifiRangingEvent} for details
67 struct ChppWifiRangingEvent {
68   uint8_t
69       version;  // Input ignored; always set to CHRE_WIFI_RANGING_EVENT_VERSION
70   uint8_t resultCount;
71   uint8_t reserved[2];  // Input ignored; always set to 0
72   struct ChppOffset
73       results;  // References resultCount instances of struct ChppOffset
74 } CHPP_PACKED_ATTR;
75 
76 //! See {@link chreWifiRangingTarget} for details
77 struct ChppWifiRangingTarget {
78   uint8_t macAddress[6];
79   uint32_t primaryChannel;
80   uint32_t centerFreqPrimary;
81   uint32_t centerFreqSecondary;
82   uint8_t channelWidth;
83   uint8_t reserved[3];  // Input ignored; always set to 0
84 } CHPP_PACKED_ATTR;
85 
86 //! See {@link chreWifiRangingParams} for details
87 struct ChppWifiRangingParams {
88   uint8_t targetListLen;
89   struct ChppOffset
90       targetList;  // References targetListLen instances of struct ChppOffset
91 } CHPP_PACKED_ATTR;
92 
93 //! See {@link chreWifiScanResult} for details
94 struct ChppWifiScanResult {
95   uint32_t ageMs;
96   uint16_t capabilityInfo;
97   uint8_t ssidLen;
98   uint8_t ssid[32];
99   uint8_t bssid[6];
100   uint8_t flags;
101   int8_t rssi;
102   uint8_t band;
103   uint32_t primaryChannel;
104   uint32_t centerFreqPrimary;
105   uint32_t centerFreqSecondary;
106   uint8_t channelWidth;
107   uint8_t securityMode;
108   uint8_t radioChain;
109   int8_t rssiChain0;
110   int8_t rssiChain1;
111   uint8_t reserved[7];  // Input ignored; always set to 0
112 } CHPP_PACKED_ATTR;
113 
114 //! See {@link chreWifiScanEvent} for details
115 struct ChppWifiScanEvent {
116   uint8_t version;  // Input ignored; always set to CHRE_WIFI_SCAN_EVENT_VERSION
117   uint8_t resultCount;
118   uint8_t resultTotal;
119   uint8_t eventIndex;
120   uint8_t scanType;
121   uint8_t ssidSetSize;
122   uint16_t scannedFreqListLen;
123   uint64_t referenceTime;
124   struct ChppOffset scannedFreqList;  // References scannedFreqListLen instances
125                                       // of struct ChppOffset
126   struct ChppOffset
127       results;  // References resultCount instances of struct ChppOffset
128   uint8_t radioChainPref;
129 } CHPP_PACKED_ATTR;
130 
131 //! See {@link chreWifiSsidListItem} for details
132 struct ChppWifiSsidListItem {
133   uint8_t ssidLen;
134   uint8_t ssid[32];
135 } CHPP_PACKED_ATTR;
136 
137 //! See {@link chreWifiScanParams} for details
138 struct ChppWifiScanParams {
139   uint8_t scanType;
140   uint32_t maxScanAgeMs;
141   uint16_t frequencyListLen;
142   struct ChppOffset frequencyList;  // References frequencyListLen instances of
143                                     // struct ChppOffset
144   uint8_t ssidListLen;
145   struct ChppOffset
146       ssidList;  // References ssidListLen instances of struct ChppOffset
147   uint8_t radioChainPref;
148   uint8_t channelSet;
149 } CHPP_PACKED_ATTR;
150 
151 //! CHPP app header plus struct ChppWifiScanEventWithHeader
152 struct ChppWifiScanEventWithHeader {
153   struct ChppAppHeader header;
154   struct ChppWifiScanEvent payload;
155 } CHPP_PACKED_ATTR;
156 
157 //! CHPP app header plus struct ChppWifiScanParamsWithHeader
158 struct ChppWifiScanParamsWithHeader {
159   struct ChppAppHeader header;
160   struct ChppWifiScanParams payload;
161 } CHPP_PACKED_ATTR;
162 
163 //! CHPP app header plus struct ChppWifiRangingEventWithHeader
164 struct ChppWifiRangingEventWithHeader {
165   struct ChppAppHeader header;
166   struct ChppWifiRangingEvent payload;
167 } CHPP_PACKED_ATTR;
168 
169 //! CHPP app header plus struct ChppWifiRangingParamsWithHeader
170 struct ChppWifiRangingParamsWithHeader {
171   struct ChppAppHeader header;
172   struct ChppWifiRangingParams payload;
173 } CHPP_PACKED_ATTR;
174 
175 CHPP_PACKED_END
176 
177 // Encoding functions (CHRE --> CHPP)
178 
179 /**
180  * Converts from given CHRE structure to serialized CHPP type.
181  *
182  * @param in Fully-formed CHRE structure.
183  * @param out Upon success, will point to a buffer allocated with chppMalloc().
184  * It is the responsibility of the caller to set the values of the CHPP app
185  * layer header, and to free the buffer when it is no longer needed via
186  * chppFree() or CHPP_FREE_AND_NULLIFY().
187  * @param outSize Upon success, will be set to the size of the output buffer, in
188  * bytes.
189  *
190  * @return true on success, false if memory allocation failed.
191  */
192 bool chppWifiScanEventFromChre(const struct chreWifiScanEvent *in,
193                                struct ChppWifiScanEventWithHeader **out,
194                                size_t *outSize);
195 
196 /**
197  * Converts from given CHRE structure to serialized CHPP type.
198  *
199  * @param in Fully-formed CHRE structure.
200  * @param out Upon success, will point to a buffer allocated with chppMalloc().
201  * It is the responsibility of the caller to set the values of the CHPP app
202  * layer header, and to free the buffer when it is no longer needed via
203  * chppFree() or CHPP_FREE_AND_NULLIFY().
204  * @param outSize Upon success, will be set to the size of the output buffer, in
205  * bytes.
206  *
207  * @return true on success, false if memory allocation failed.
208  */
209 bool chppWifiScanParamsFromChre(const struct chreWifiScanParams *in,
210                                 struct ChppWifiScanParamsWithHeader **out,
211                                 size_t *outSize);
212 
213 /**
214  * Converts from given CHRE structure to serialized CHPP type.
215  *
216  * @param in Fully-formed CHRE structure.
217  * @param out Upon success, will point to a buffer allocated with chppMalloc().
218  * It is the responsibility of the caller to set the values of the CHPP app
219  * layer header, and to free the buffer when it is no longer needed via
220  * chppFree() or CHPP_FREE_AND_NULLIFY().
221  * @param outSize Upon success, will be set to the size of the output buffer, in
222  * bytes.
223  *
224  * @return true on success, false if memory allocation failed.
225  */
226 bool chppWifiRangingEventFromChre(const struct chreWifiRangingEvent *in,
227                                   struct ChppWifiRangingEventWithHeader **out,
228                                   size_t *outSize);
229 
230 /**
231  * Converts from given CHRE structure to serialized CHPP type.
232  *
233  * @param in Fully-formed CHRE structure.
234  * @param out Upon success, will point to a buffer allocated with chppMalloc().
235  * It is the responsibility of the caller to set the values of the CHPP app
236  * layer header, and to free the buffer when it is no longer needed via
237  * chppFree() or CHPP_FREE_AND_NULLIFY().
238  * @param outSize Upon success, will be set to the size of the output buffer, in
239  * bytes.
240  *
241  * @return true on success, false if memory allocation failed.
242  */
243 bool chppWifiRangingParamsFromChre(const struct chreWifiRangingParams *in,
244                                    struct ChppWifiRangingParamsWithHeader **out,
245                                    size_t *outSize);
246 
247 // Decoding functions (CHPP --> CHRE)
248 
249 /**
250  * Converts from serialized CHPP structure to a CHRE type.
251  *
252  * @param in Fully-formed CHPP structure.
253  * @param in Size of the CHPP structure in bytes.
254  *
255  * @return If successful, a pointer to a CHRE structure allocated with
256  * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
257  * to free the buffer when it is no longer needed via chppFree() or
258  * CHPP_FREE_AND_NULLIFY().
259  */
260 struct chreWifiScanEvent *chppWifiScanEventToChre(
261     const struct ChppWifiScanEvent *in, size_t inSize);
262 
263 /**
264  * Converts from serialized CHPP structure to a CHRE type.
265  *
266  * @param in Fully-formed CHPP structure.
267  * @param in Size of the CHPP structure in bytes.
268  *
269  * @return If successful, a pointer to a CHRE structure allocated with
270  * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
271  * to free the buffer when it is no longer needed via chppFree() or
272  * CHPP_FREE_AND_NULLIFY().
273  */
274 struct chreWifiScanParams *chppWifiScanParamsToChre(
275     const struct ChppWifiScanParams *in, size_t inSize);
276 
277 /**
278  * Converts from serialized CHPP structure to a CHRE type.
279  *
280  * @param in Fully-formed CHPP structure.
281  * @param in Size of the CHPP structure in bytes.
282  *
283  * @return If successful, a pointer to a CHRE structure allocated with
284  * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
285  * to free the buffer when it is no longer needed via chppFree() or
286  * CHPP_FREE_AND_NULLIFY().
287  */
288 struct chreWifiRangingEvent *chppWifiRangingEventToChre(
289     const struct ChppWifiRangingEvent *in, size_t inSize);
290 
291 /**
292  * Converts from serialized CHPP structure to a CHRE type.
293  *
294  * @param in Fully-formed CHPP structure.
295  * @param in Size of the CHPP structure in bytes.
296  *
297  * @return If successful, a pointer to a CHRE structure allocated with
298  * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
299  * to free the buffer when it is no longer needed via chppFree() or
300  * CHPP_FREE_AND_NULLIFY().
301  */
302 struct chreWifiRangingParams *chppWifiRangingParamsToChre(
303     const struct ChppWifiRangingParams *in, size_t inSize);
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 
309 #endif  // CHPP_WIFI_TYPES_H_
310