• 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 // This file was automatically generated by chre_api_to_chpp.py
18 // Date: 2022-02-03 23:05:31 UTC
19 // Source: chre_api/include/chre_api/chre/wifi.h @ commit b5a92e457
20 
21 // DO NOT modify this file directly, as those changes will be lost the next
22 // time the script is executed
23 
24 #include "chpp/common/wifi_types.h"
25 #include "chpp/macros.h"
26 #include "chpp/memory.h"
27 
28 #include <stddef.h>
29 #include <stdint.h>
30 #include <string.h>
31 
32 // Encoding (CHRE --> CHPP) size functions
33 
34 //! @return number of bytes required to represent the given
35 //! chreWifiScanEvent along with the CHPP header as
36 //! struct ChppWifiScanEventWithHeader
chppWifiSizeOfScanEventFromChre(const struct chreWifiScanEvent * scanEvent)37 static size_t chppWifiSizeOfScanEventFromChre(
38     const struct chreWifiScanEvent *scanEvent) {
39   size_t encodedSize = sizeof(struct ChppWifiScanEventWithHeader);
40   encodedSize += scanEvent->scannedFreqListLen * sizeof(uint32_t);
41   encodedSize += scanEvent->resultCount * sizeof(struct ChppWifiScanResult);
42   return encodedSize;
43 }
44 
45 //! @return number of bytes required to represent the given
46 //! chreWifiScanParams along with the CHPP header as
47 //! struct ChppWifiScanParamsWithHeader
chppWifiSizeOfScanParamsFromChre(const struct chreWifiScanParams * scanParams)48 static size_t chppWifiSizeOfScanParamsFromChre(
49     const struct chreWifiScanParams *scanParams) {
50   size_t encodedSize = sizeof(struct ChppWifiScanParamsWithHeader);
51   encodedSize += scanParams->frequencyListLen * sizeof(uint32_t);
52   encodedSize += scanParams->ssidListLen * sizeof(struct ChppWifiSsidListItem);
53   return encodedSize;
54 }
55 
56 //! @return number of bytes required to represent the given
57 //! chreWifiRangingEvent along with the CHPP header as
58 //! struct ChppWifiRangingEventWithHeader
chppWifiSizeOfRangingEventFromChre(const struct chreWifiRangingEvent * rangingEvent)59 static size_t chppWifiSizeOfRangingEventFromChre(
60     const struct chreWifiRangingEvent *rangingEvent) {
61   size_t encodedSize = sizeof(struct ChppWifiRangingEventWithHeader);
62   encodedSize +=
63       rangingEvent->resultCount * sizeof(struct ChppWifiRangingResult);
64   return encodedSize;
65 }
66 
67 //! @return number of bytes required to represent the given
68 //! chreWifiRangingParams along with the CHPP header as
69 //! struct ChppWifiRangingParamsWithHeader
chppWifiSizeOfRangingParamsFromChre(const struct chreWifiRangingParams * rangingParams)70 static size_t chppWifiSizeOfRangingParamsFromChre(
71     const struct chreWifiRangingParams *rangingParams) {
72   size_t encodedSize = sizeof(struct ChppWifiRangingParamsWithHeader);
73   encodedSize +=
74       rangingParams->targetListLen * sizeof(struct ChppWifiRangingTarget);
75   return encodedSize;
76 }
77 
78 //! @return number of bytes required to represent the given
79 //! chreWifiNanSubscribeConfig along with the CHPP header as
80 //! struct ChppWifiNanSubscribeConfigWithHeader
chppWifiSizeOfNanSubscribeConfigFromChre(const struct chreWifiNanSubscribeConfig * nanSubscribeConfig)81 static size_t chppWifiSizeOfNanSubscribeConfigFromChre(
82     const struct chreWifiNanSubscribeConfig *nanSubscribeConfig) {
83   size_t encodedSize = sizeof(struct ChppWifiNanSubscribeConfigWithHeader);
84   if (nanSubscribeConfig->service != NULL) {
85     encodedSize += strlen(nanSubscribeConfig->service) + 1;
86   }
87   encodedSize += nanSubscribeConfig->serviceSpecificInfoSize * sizeof(uint8_t);
88   encodedSize += nanSubscribeConfig->matchFilterLength * sizeof(uint8_t);
89   return encodedSize;
90 }
91 
92 //! @return number of bytes required to represent the given
93 //! chreWifiNanDiscoveryEvent along with the CHPP header as
94 //! struct ChppWifiNanDiscoveryEventWithHeader
chppWifiSizeOfNanDiscoveryEventFromChre(const struct chreWifiNanDiscoveryEvent * nanDiscoveryEvent)95 static size_t chppWifiSizeOfNanDiscoveryEventFromChre(
96     const struct chreWifiNanDiscoveryEvent *nanDiscoveryEvent) {
97   size_t encodedSize = sizeof(struct ChppWifiNanDiscoveryEventWithHeader);
98   encodedSize += nanDiscoveryEvent->serviceSpecificInfoSize * sizeof(uint8_t);
99   return encodedSize;
100 }
101 
102 // Encoding (CHRE --> CHPP) conversion functions
103 
chppWifiConvertScanResultFromChre(const struct chreWifiScanResult * in,struct ChppWifiScanResult * out)104 static void chppWifiConvertScanResultFromChre(
105     const struct chreWifiScanResult *in, struct ChppWifiScanResult *out) {
106   out->ageMs = in->ageMs;
107   out->capabilityInfo = in->capabilityInfo;
108   out->ssidLen = in->ssidLen;
109   memcpy(out->ssid, in->ssid, sizeof(out->ssid));
110   memcpy(out->bssid, in->bssid, sizeof(out->bssid));
111   out->flags = in->flags;
112   out->rssi = in->rssi;
113   out->band = in->band;
114   out->primaryChannel = in->primaryChannel;
115   out->centerFreqPrimary = in->centerFreqPrimary;
116   out->centerFreqSecondary = in->centerFreqSecondary;
117   out->channelWidth = in->channelWidth;
118   out->securityMode = in->securityMode;
119   out->radioChain = in->radioChain;
120   out->rssiChain0 = in->rssiChain0;
121   out->rssiChain1 = in->rssiChain1;
122   memset(&out->reserved, 0, sizeof(out->reserved));
123 }
124 
chppWifiConvertScanEventFromChre(const struct chreWifiScanEvent * in,struct ChppWifiScanEvent * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)125 static void chppWifiConvertScanEventFromChre(const struct chreWifiScanEvent *in,
126                                              struct ChppWifiScanEvent *out,
127                                              uint8_t *payload,
128                                              size_t payloadSize,
129                                              uint16_t *vlaOffset) {
130   out->version = CHRE_WIFI_SCAN_EVENT_VERSION;
131   out->resultCount = in->resultCount;
132   out->resultTotal = in->resultTotal;
133   out->eventIndex = in->eventIndex;
134   out->scanType = in->scanType;
135   out->ssidSetSize = in->ssidSetSize;
136   out->scannedFreqListLen = in->scannedFreqListLen;
137   out->referenceTime = in->referenceTime;
138   out->scannedFreqList.length =
139       (uint16_t)(in->scannedFreqListLen * sizeof(uint32_t));
140   CHPP_ASSERT((size_t)(*vlaOffset + out->scannedFreqList.length) <=
141               payloadSize);
142   if (out->scannedFreqList.length > 0 &&
143       *vlaOffset + out->scannedFreqList.length <= payloadSize) {
144     memcpy(&payload[*vlaOffset], in->scannedFreqList,
145            in->scannedFreqListLen * sizeof(uint32_t));
146     out->scannedFreqList.offset = *vlaOffset;
147     *vlaOffset += out->scannedFreqList.length;
148   } else {
149     out->scannedFreqList.offset = 0;
150   }
151 
152   struct ChppWifiScanResult *results =
153       (struct ChppWifiScanResult *)&payload[*vlaOffset];
154   out->results.length =
155       (uint16_t)(in->resultCount * sizeof(struct ChppWifiScanResult));
156   CHPP_ASSERT((size_t)(*vlaOffset + out->results.length) <= payloadSize);
157   if (out->results.length > 0 &&
158       *vlaOffset + out->results.length <= payloadSize) {
159     for (size_t i = 0; i < in->resultCount; i++) {
160       chppWifiConvertScanResultFromChre(&in->results[i], &results[i]);
161     }
162     out->results.offset = *vlaOffset;
163     *vlaOffset += out->results.length;
164   } else {
165     out->results.offset = 0;
166   }
167   out->radioChainPref = in->radioChainPref;
168 }
169 
chppWifiConvertSsidListItemFromChre(const struct chreWifiSsidListItem * in,struct ChppWifiSsidListItem * out)170 static void chppWifiConvertSsidListItemFromChre(
171     const struct chreWifiSsidListItem *in, struct ChppWifiSsidListItem *out) {
172   out->ssidLen = in->ssidLen;
173   memcpy(out->ssid, in->ssid, sizeof(out->ssid));
174 }
175 
chppWifiConvertScanParamsFromChre(const struct chreWifiScanParams * in,struct ChppWifiScanParams * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)176 static void chppWifiConvertScanParamsFromChre(
177     const struct chreWifiScanParams *in, struct ChppWifiScanParams *out,
178     uint8_t *payload, size_t payloadSize, uint16_t *vlaOffset) {
179   out->scanType = in->scanType;
180   out->maxScanAgeMs = in->maxScanAgeMs;
181   out->frequencyListLen = in->frequencyListLen;
182   out->frequencyList.length =
183       (uint16_t)(in->frequencyListLen * sizeof(uint32_t));
184   CHPP_ASSERT((size_t)(*vlaOffset + out->frequencyList.length) <= payloadSize);
185   if (out->frequencyList.length > 0 &&
186       *vlaOffset + out->frequencyList.length <= payloadSize) {
187     memcpy(&payload[*vlaOffset], in->frequencyList,
188            in->frequencyListLen * sizeof(uint32_t));
189     out->frequencyList.offset = *vlaOffset;
190     *vlaOffset += out->frequencyList.length;
191   } else {
192     out->frequencyList.offset = 0;
193   }
194   out->ssidListLen = in->ssidListLen;
195 
196   struct ChppWifiSsidListItem *ssidList =
197       (struct ChppWifiSsidListItem *)&payload[*vlaOffset];
198   out->ssidList.length =
199       (uint16_t)(in->ssidListLen * sizeof(struct ChppWifiSsidListItem));
200   CHPP_ASSERT((size_t)(*vlaOffset + out->ssidList.length) <= payloadSize);
201   if (out->ssidList.length > 0 &&
202       *vlaOffset + out->ssidList.length <= payloadSize) {
203     for (size_t i = 0; i < in->ssidListLen; i++) {
204       chppWifiConvertSsidListItemFromChre(&in->ssidList[i], &ssidList[i]);
205     }
206     out->ssidList.offset = *vlaOffset;
207     *vlaOffset += out->ssidList.length;
208   } else {
209     out->ssidList.offset = 0;
210   }
211   out->radioChainPref = in->radioChainPref;
212   out->channelSet = in->channelSet;
213 }
214 
chppWifiConvertLciFromChre(const struct chreWifiLci * in,struct ChppWifiLci * out)215 static void chppWifiConvertLciFromChre(const struct chreWifiLci *in,
216                                        struct ChppWifiLci *out) {
217   out->latitude = in->latitude;
218   out->longitude = in->longitude;
219   out->altitude = in->altitude;
220   out->latitudeUncertainty = in->latitudeUncertainty;
221   out->longitudeUncertainty = in->longitudeUncertainty;
222   out->altitudeType = in->altitudeType;
223   out->altitudeUncertainty = in->altitudeUncertainty;
224 }
225 
chppWifiConvertRangingResultFromChre(const struct chreWifiRangingResult * in,struct ChppWifiRangingResult * out)226 static void chppWifiConvertRangingResultFromChre(
227     const struct chreWifiRangingResult *in, struct ChppWifiRangingResult *out) {
228   out->timestamp = in->timestamp;
229   memcpy(out->macAddress, in->macAddress, sizeof(out->macAddress));
230   out->status = in->status;
231   out->rssi = in->rssi;
232   out->distance = in->distance;
233   out->distanceStdDev = in->distanceStdDev;
234   chppWifiConvertLciFromChre(&in->lci, &out->lci);
235   out->flags = in->flags;
236   memset(&out->reserved, 0, sizeof(out->reserved));
237 }
238 
chppWifiConvertRangingEventFromChre(const struct chreWifiRangingEvent * in,struct ChppWifiRangingEvent * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)239 static void chppWifiConvertRangingEventFromChre(
240     const struct chreWifiRangingEvent *in, struct ChppWifiRangingEvent *out,
241     uint8_t *payload, size_t payloadSize, uint16_t *vlaOffset) {
242   out->version = CHRE_WIFI_RANGING_EVENT_VERSION;
243   out->resultCount = in->resultCount;
244   memset(&out->reserved, 0, sizeof(out->reserved));
245 
246   struct ChppWifiRangingResult *results =
247       (struct ChppWifiRangingResult *)&payload[*vlaOffset];
248   out->results.length =
249       (uint16_t)(in->resultCount * sizeof(struct ChppWifiRangingResult));
250   CHPP_ASSERT((size_t)(*vlaOffset + out->results.length) <= payloadSize);
251   if (out->results.length > 0 &&
252       *vlaOffset + out->results.length <= payloadSize) {
253     for (size_t i = 0; i < in->resultCount; i++) {
254       chppWifiConvertRangingResultFromChre(&in->results[i], &results[i]);
255     }
256     out->results.offset = *vlaOffset;
257     *vlaOffset += out->results.length;
258   } else {
259     out->results.offset = 0;
260   }
261 }
262 
chppWifiConvertRangingTargetFromChre(const struct chreWifiRangingTarget * in,struct ChppWifiRangingTarget * out)263 static void chppWifiConvertRangingTargetFromChre(
264     const struct chreWifiRangingTarget *in, struct ChppWifiRangingTarget *out) {
265   memcpy(out->macAddress, in->macAddress, sizeof(out->macAddress));
266   out->primaryChannel = in->primaryChannel;
267   out->centerFreqPrimary = in->centerFreqPrimary;
268   out->centerFreqSecondary = in->centerFreqSecondary;
269   out->channelWidth = in->channelWidth;
270   memset(&out->reserved, 0, sizeof(out->reserved));
271 }
272 
chppWifiConvertRangingParamsFromChre(const struct chreWifiRangingParams * in,struct ChppWifiRangingParams * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)273 static void chppWifiConvertRangingParamsFromChre(
274     const struct chreWifiRangingParams *in, struct ChppWifiRangingParams *out,
275     uint8_t *payload, size_t payloadSize, uint16_t *vlaOffset) {
276   out->targetListLen = in->targetListLen;
277 
278   struct ChppWifiRangingTarget *targetList =
279       (struct ChppWifiRangingTarget *)&payload[*vlaOffset];
280   out->targetList.length =
281       (uint16_t)(in->targetListLen * sizeof(struct ChppWifiRangingTarget));
282   CHPP_ASSERT((size_t)(*vlaOffset + out->targetList.length) <= payloadSize);
283   if (out->targetList.length > 0 &&
284       *vlaOffset + out->targetList.length <= payloadSize) {
285     for (size_t i = 0; i < in->targetListLen; i++) {
286       chppWifiConvertRangingTargetFromChre(&in->targetList[i], &targetList[i]);
287     }
288     out->targetList.offset = *vlaOffset;
289     *vlaOffset += out->targetList.length;
290   } else {
291     out->targetList.offset = 0;
292   }
293 }
294 
chppWifiConvertNanSubscribeConfigFromChre(const struct chreWifiNanSubscribeConfig * in,struct ChppWifiNanSubscribeConfig * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)295 static void chppWifiConvertNanSubscribeConfigFromChre(
296     const struct chreWifiNanSubscribeConfig *in,
297     struct ChppWifiNanSubscribeConfig *out, uint8_t *payload,
298     size_t payloadSize, uint16_t *vlaOffset) {
299   out->subscribeType = in->subscribeType;
300   if (in->service != NULL) {
301     size_t strSize = strlen(in->service) + 1;
302     memcpy(&payload[*vlaOffset], in->service, strSize);
303     out->service.length = (uint16_t)(strSize);
304     out->service.offset = *vlaOffset;
305     *vlaOffset += out->service.length;
306   } else {
307     out->service.length = 0;
308     out->service.offset = 0;
309   }
310 
311   out->serviceSpecificInfo.length =
312       (uint16_t)(in->serviceSpecificInfoSize * sizeof(uint8_t));
313   CHPP_ASSERT((size_t)(*vlaOffset + out->serviceSpecificInfo.length) <=
314               payloadSize);
315   if (out->serviceSpecificInfo.length > 0 &&
316       *vlaOffset + out->serviceSpecificInfo.length <= payloadSize) {
317     memcpy(&payload[*vlaOffset], in->serviceSpecificInfo,
318            in->serviceSpecificInfoSize * sizeof(uint8_t));
319     out->serviceSpecificInfo.offset = *vlaOffset;
320     *vlaOffset += out->serviceSpecificInfo.length;
321   } else {
322     out->serviceSpecificInfo.offset = 0;
323   }
324   out->serviceSpecificInfoSize = in->serviceSpecificInfoSize;
325   out->matchFilter.length = (uint16_t)(in->matchFilterLength * sizeof(uint8_t));
326   CHPP_ASSERT((size_t)(*vlaOffset + out->matchFilter.length) <= payloadSize);
327   if (out->matchFilter.length > 0 &&
328       *vlaOffset + out->matchFilter.length <= payloadSize) {
329     memcpy(&payload[*vlaOffset], in->matchFilter,
330            in->matchFilterLength * sizeof(uint8_t));
331     out->matchFilter.offset = *vlaOffset;
332     *vlaOffset += out->matchFilter.length;
333   } else {
334     out->matchFilter.offset = 0;
335   }
336   out->matchFilterLength = in->matchFilterLength;
337 }
338 
chppWifiConvertNanDiscoveryEventFromChre(const struct chreWifiNanDiscoveryEvent * in,struct ChppWifiNanDiscoveryEvent * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)339 static void chppWifiConvertNanDiscoveryEventFromChre(
340     const struct chreWifiNanDiscoveryEvent *in,
341     struct ChppWifiNanDiscoveryEvent *out, uint8_t *payload, size_t payloadSize,
342     uint16_t *vlaOffset) {
343   out->subscribeId = in->subscribeId;
344   out->publishId = in->publishId;
345   memcpy(out->publisherAddress, in->publisherAddress,
346          sizeof(out->publisherAddress));
347   out->serviceSpecificInfo.length =
348       (uint16_t)(in->serviceSpecificInfoSize * sizeof(uint8_t));
349   CHPP_ASSERT((size_t)(*vlaOffset + out->serviceSpecificInfo.length) <=
350               payloadSize);
351   if (out->serviceSpecificInfo.length > 0 &&
352       *vlaOffset + out->serviceSpecificInfo.length <= payloadSize) {
353     memcpy(&payload[*vlaOffset], in->serviceSpecificInfo,
354            in->serviceSpecificInfoSize * sizeof(uint8_t));
355     out->serviceSpecificInfo.offset = *vlaOffset;
356     *vlaOffset += out->serviceSpecificInfo.length;
357   } else {
358     out->serviceSpecificInfo.offset = 0;
359   }
360   out->serviceSpecificInfoSize = in->serviceSpecificInfoSize;
361 }
362 
chppWifiConvertNanSessionLostEventFromChre(const struct chreWifiNanSessionLostEvent * in,struct ChppWifiNanSessionLostEvent * out)363 static void chppWifiConvertNanSessionLostEventFromChre(
364     const struct chreWifiNanSessionLostEvent *in,
365     struct ChppWifiNanSessionLostEvent *out) {
366   out->id = in->id;
367   out->peerId = in->peerId;
368 }
369 
chppWifiConvertNanSessionTerminatedEventFromChre(const struct chreWifiNanSessionTerminatedEvent * in,struct ChppWifiNanSessionTerminatedEvent * out)370 static void chppWifiConvertNanSessionTerminatedEventFromChre(
371     const struct chreWifiNanSessionTerminatedEvent *in,
372     struct ChppWifiNanSessionTerminatedEvent *out) {
373   out->id = in->id;
374   out->reason = in->reason;
375   memcpy(out->reserved, in->reserved, sizeof(out->reserved));
376 }
377 
chppWifiConvertNanRangingParamsFromChre(const struct chreWifiNanRangingParams * in,struct ChppWifiNanRangingParams * out)378 static void chppWifiConvertNanRangingParamsFromChre(
379     const struct chreWifiNanRangingParams *in,
380     struct ChppWifiNanRangingParams *out) {
381   memcpy(out->macAddress, in->macAddress, sizeof(out->macAddress));
382 }
383 
384 // Encoding (CHRE --> CHPP) top-level functions
385 
chppWifiScanEventFromChre(const struct chreWifiScanEvent * in,struct ChppWifiScanEventWithHeader ** out,size_t * outSize)386 bool chppWifiScanEventFromChre(const struct chreWifiScanEvent *in,
387                                struct ChppWifiScanEventWithHeader **out,
388                                size_t *outSize) {
389   CHPP_NOT_NULL(out);
390   CHPP_NOT_NULL(outSize);
391 
392   size_t payloadSize = chppWifiSizeOfScanEventFromChre(in);
393   *out = chppMalloc(payloadSize);
394   if (*out != NULL) {
395     uint8_t *payload = (uint8_t *)&(*out)->payload;
396     uint16_t vlaOffset = sizeof(struct ChppWifiScanEvent);
397     chppWifiConvertScanEventFromChre(in, &(*out)->payload, payload, payloadSize,
398                                      &vlaOffset);
399     *outSize = payloadSize;
400     return true;
401   }
402   return false;
403 }
404 
chppWifiScanParamsFromChre(const struct chreWifiScanParams * in,struct ChppWifiScanParamsWithHeader ** out,size_t * outSize)405 bool chppWifiScanParamsFromChre(const struct chreWifiScanParams *in,
406                                 struct ChppWifiScanParamsWithHeader **out,
407                                 size_t *outSize) {
408   CHPP_NOT_NULL(out);
409   CHPP_NOT_NULL(outSize);
410 
411   size_t payloadSize = chppWifiSizeOfScanParamsFromChre(in);
412   *out = chppMalloc(payloadSize);
413   if (*out != NULL) {
414     uint8_t *payload = (uint8_t *)&(*out)->payload;
415     uint16_t vlaOffset = sizeof(struct ChppWifiScanParams);
416     chppWifiConvertScanParamsFromChre(in, &(*out)->payload, payload,
417                                       payloadSize, &vlaOffset);
418     *outSize = payloadSize;
419     return true;
420   }
421   return false;
422 }
423 
chppWifiRangingEventFromChre(const struct chreWifiRangingEvent * in,struct ChppWifiRangingEventWithHeader ** out,size_t * outSize)424 bool chppWifiRangingEventFromChre(const struct chreWifiRangingEvent *in,
425                                   struct ChppWifiRangingEventWithHeader **out,
426                                   size_t *outSize) {
427   CHPP_NOT_NULL(out);
428   CHPP_NOT_NULL(outSize);
429 
430   size_t payloadSize = chppWifiSizeOfRangingEventFromChre(in);
431   *out = chppMalloc(payloadSize);
432   if (*out != NULL) {
433     uint8_t *payload = (uint8_t *)&(*out)->payload;
434     uint16_t vlaOffset = sizeof(struct ChppWifiRangingEvent);
435     chppWifiConvertRangingEventFromChre(in, &(*out)->payload, payload,
436                                         payloadSize, &vlaOffset);
437     *outSize = payloadSize;
438     return true;
439   }
440   return false;
441 }
442 
chppWifiRangingParamsFromChre(const struct chreWifiRangingParams * in,struct ChppWifiRangingParamsWithHeader ** out,size_t * outSize)443 bool chppWifiRangingParamsFromChre(const struct chreWifiRangingParams *in,
444                                    struct ChppWifiRangingParamsWithHeader **out,
445                                    size_t *outSize) {
446   CHPP_NOT_NULL(out);
447   CHPP_NOT_NULL(outSize);
448 
449   size_t payloadSize = chppWifiSizeOfRangingParamsFromChre(in);
450   *out = chppMalloc(payloadSize);
451   if (*out != NULL) {
452     uint8_t *payload = (uint8_t *)&(*out)->payload;
453     uint16_t vlaOffset = sizeof(struct ChppWifiRangingParams);
454     chppWifiConvertRangingParamsFromChre(in, &(*out)->payload, payload,
455                                          payloadSize, &vlaOffset);
456     *outSize = payloadSize;
457     return true;
458   }
459   return false;
460 }
461 
chppWifiNanSubscribeConfigFromChre(const struct chreWifiNanSubscribeConfig * in,struct ChppWifiNanSubscribeConfigWithHeader ** out,size_t * outSize)462 bool chppWifiNanSubscribeConfigFromChre(
463     const struct chreWifiNanSubscribeConfig *in,
464     struct ChppWifiNanSubscribeConfigWithHeader **out, size_t *outSize) {
465   CHPP_NOT_NULL(out);
466   CHPP_NOT_NULL(outSize);
467 
468   size_t payloadSize = chppWifiSizeOfNanSubscribeConfigFromChre(in);
469   *out = chppMalloc(payloadSize);
470   if (*out != NULL) {
471     uint8_t *payload = (uint8_t *)&(*out)->payload;
472     uint16_t vlaOffset = sizeof(struct ChppWifiNanSubscribeConfig);
473     chppWifiConvertNanSubscribeConfigFromChre(in, &(*out)->payload, payload,
474                                               payloadSize, &vlaOffset);
475     *outSize = payloadSize;
476     return true;
477   }
478   return false;
479 }
480 
chppWifiNanDiscoveryEventFromChre(const struct chreWifiNanDiscoveryEvent * in,struct ChppWifiNanDiscoveryEventWithHeader ** out,size_t * outSize)481 bool chppWifiNanDiscoveryEventFromChre(
482     const struct chreWifiNanDiscoveryEvent *in,
483     struct ChppWifiNanDiscoveryEventWithHeader **out, size_t *outSize) {
484   CHPP_NOT_NULL(out);
485   CHPP_NOT_NULL(outSize);
486 
487   size_t payloadSize = chppWifiSizeOfNanDiscoveryEventFromChre(in);
488   *out = chppMalloc(payloadSize);
489   if (*out != NULL) {
490     uint8_t *payload = (uint8_t *)&(*out)->payload;
491     uint16_t vlaOffset = sizeof(struct ChppWifiNanDiscoveryEvent);
492     chppWifiConvertNanDiscoveryEventFromChre(in, &(*out)->payload, payload,
493                                              payloadSize, &vlaOffset);
494     *outSize = payloadSize;
495     return true;
496   }
497   return false;
498 }
499 
chppWifiNanSessionLostEventFromChre(const struct chreWifiNanSessionLostEvent * in,struct ChppWifiNanSessionLostEventWithHeader ** out,size_t * outSize)500 bool chppWifiNanSessionLostEventFromChre(
501     const struct chreWifiNanSessionLostEvent *in,
502     struct ChppWifiNanSessionLostEventWithHeader **out, size_t *outSize) {
503   CHPP_NOT_NULL(out);
504   CHPP_NOT_NULL(outSize);
505 
506   size_t payloadSize = sizeof(struct ChppWifiNanSessionLostEventWithHeader);
507   *out = chppMalloc(payloadSize);
508   if (*out != NULL) {
509     chppWifiConvertNanSessionLostEventFromChre(in, &(*out)->payload);
510     *outSize = payloadSize;
511     return true;
512   }
513   return false;
514 }
515 
chppWifiNanSessionTerminatedEventFromChre(const struct chreWifiNanSessionTerminatedEvent * in,struct ChppWifiNanSessionTerminatedEventWithHeader ** out,size_t * outSize)516 bool chppWifiNanSessionTerminatedEventFromChre(
517     const struct chreWifiNanSessionTerminatedEvent *in,
518     struct ChppWifiNanSessionTerminatedEventWithHeader **out, size_t *outSize) {
519   CHPP_NOT_NULL(out);
520   CHPP_NOT_NULL(outSize);
521 
522   size_t payloadSize =
523       sizeof(struct ChppWifiNanSessionTerminatedEventWithHeader);
524   *out = chppMalloc(payloadSize);
525   if (*out != NULL) {
526     chppWifiConvertNanSessionTerminatedEventFromChre(in, &(*out)->payload);
527     *outSize = payloadSize;
528     return true;
529   }
530   return false;
531 }
532 
chppWifiNanRangingParamsFromChre(const struct chreWifiNanRangingParams * in,struct ChppWifiNanRangingParamsWithHeader ** out,size_t * outSize)533 bool chppWifiNanRangingParamsFromChre(
534     const struct chreWifiNanRangingParams *in,
535     struct ChppWifiNanRangingParamsWithHeader **out, size_t *outSize) {
536   CHPP_NOT_NULL(out);
537   CHPP_NOT_NULL(outSize);
538 
539   size_t payloadSize = sizeof(struct ChppWifiNanRangingParamsWithHeader);
540   *out = chppMalloc(payloadSize);
541   if (*out != NULL) {
542     chppWifiConvertNanRangingParamsFromChre(in, &(*out)->payload);
543     *outSize = payloadSize;
544     return true;
545   }
546   return false;
547 }
548 
549 // Decoding (CHPP --> CHRE) conversion functions
550 
chppWifiConvertScanResultToChre(const struct ChppWifiScanResult * in,struct chreWifiScanResult * out)551 static bool chppWifiConvertScanResultToChre(const struct ChppWifiScanResult *in,
552                                             struct chreWifiScanResult *out) {
553   out->ageMs = in->ageMs;
554   out->capabilityInfo = in->capabilityInfo;
555   out->ssidLen = in->ssidLen;
556   memcpy(out->ssid, in->ssid, sizeof(out->ssid));
557   memcpy(out->bssid, in->bssid, sizeof(out->bssid));
558   out->flags = in->flags;
559   out->rssi = in->rssi;
560   out->band = in->band;
561   out->primaryChannel = in->primaryChannel;
562   out->centerFreqPrimary = in->centerFreqPrimary;
563   out->centerFreqSecondary = in->centerFreqSecondary;
564   out->channelWidth = in->channelWidth;
565   out->securityMode = in->securityMode;
566   out->radioChain = in->radioChain;
567   out->rssiChain0 = in->rssiChain0;
568   out->rssiChain1 = in->rssiChain1;
569   memset(&out->reserved, 0, sizeof(out->reserved));
570 
571   return true;
572 }
573 
chppWifiConvertScanEventToChre(const struct ChppWifiScanEvent * in,struct chreWifiScanEvent * out,size_t inSize)574 static bool chppWifiConvertScanEventToChre(const struct ChppWifiScanEvent *in,
575                                            struct chreWifiScanEvent *out,
576                                            size_t inSize) {
577   out->version = CHRE_WIFI_SCAN_EVENT_VERSION;
578   out->resultCount = in->resultCount;
579   out->resultTotal = in->resultTotal;
580   out->eventIndex = in->eventIndex;
581   out->scanType = in->scanType;
582   out->ssidSetSize = in->ssidSetSize;
583   out->scannedFreqListLen = in->scannedFreqListLen;
584   out->referenceTime = in->referenceTime;
585 
586   if (in->scannedFreqList.length == 0) {
587     out->scannedFreqList = NULL;
588   } else {
589     if (in->scannedFreqList.offset + in->scannedFreqList.length > inSize ||
590         in->scannedFreqList.length !=
591             in->scannedFreqListLen * sizeof(uint32_t)) {
592       return false;
593     }
594 
595     uint32_t *scannedFreqListOut =
596         chppMalloc(in->scannedFreqListLen * sizeof(uint32_t));
597     if (scannedFreqListOut == NULL) {
598       return false;
599     }
600 
601     memcpy(scannedFreqListOut,
602            &((const uint8_t *)in)[in->scannedFreqList.offset],
603            in->scannedFreqListLen * sizeof(uint32_t));
604     out->scannedFreqList = scannedFreqListOut;
605   }
606 
607   if (in->results.length == 0) {
608     out->results = NULL;
609   } else {
610     if (in->results.offset + in->results.length > inSize ||
611         in->results.length !=
612             in->resultCount * sizeof(struct ChppWifiScanResult)) {
613       return false;
614     }
615 
616     const struct ChppWifiScanResult *resultsIn =
617         (const struct ChppWifiScanResult *)&(
618             (const uint8_t *)in)[in->results.offset];
619 
620     struct chreWifiScanResult *resultsOut =
621         chppMalloc(in->resultCount * sizeof(struct chreWifiScanResult));
622     if (resultsOut == NULL) {
623       return false;
624     }
625 
626     for (size_t i = 0; i < in->resultCount; i++) {
627       if (!chppWifiConvertScanResultToChre(&resultsIn[i], &resultsOut[i])) {
628         return false;
629       }
630     }
631     out->results = resultsOut;
632   }
633 
634   out->radioChainPref = in->radioChainPref;
635 
636   return true;
637 }
638 
chppWifiConvertSsidListItemToChre(const struct ChppWifiSsidListItem * in,struct chreWifiSsidListItem * out)639 static bool chppWifiConvertSsidListItemToChre(
640     const struct ChppWifiSsidListItem *in, struct chreWifiSsidListItem *out) {
641   out->ssidLen = in->ssidLen;
642   memcpy(out->ssid, in->ssid, sizeof(out->ssid));
643 
644   return true;
645 }
646 
chppWifiConvertScanParamsToChre(const struct ChppWifiScanParams * in,struct chreWifiScanParams * out,size_t inSize)647 static bool chppWifiConvertScanParamsToChre(const struct ChppWifiScanParams *in,
648                                             struct chreWifiScanParams *out,
649                                             size_t inSize) {
650   out->scanType = in->scanType;
651   out->maxScanAgeMs = in->maxScanAgeMs;
652   out->frequencyListLen = in->frequencyListLen;
653 
654   if (in->frequencyList.length == 0) {
655     out->frequencyList = NULL;
656   } else {
657     if (in->frequencyList.offset + in->frequencyList.length > inSize ||
658         in->frequencyList.length != in->frequencyListLen * sizeof(uint32_t)) {
659       return false;
660     }
661 
662     uint32_t *frequencyListOut =
663         chppMalloc(in->frequencyListLen * sizeof(uint32_t));
664     if (frequencyListOut == NULL) {
665       return false;
666     }
667 
668     memcpy(frequencyListOut, &((const uint8_t *)in)[in->frequencyList.offset],
669            in->frequencyListLen * sizeof(uint32_t));
670     out->frequencyList = frequencyListOut;
671   }
672 
673   out->ssidListLen = in->ssidListLen;
674 
675   if (in->ssidList.length == 0) {
676     out->ssidList = NULL;
677   } else {
678     if (in->ssidList.offset + in->ssidList.length > inSize ||
679         in->ssidList.length !=
680             in->ssidListLen * sizeof(struct ChppWifiSsidListItem)) {
681       return false;
682     }
683 
684     const struct ChppWifiSsidListItem *ssidListIn =
685         (const struct ChppWifiSsidListItem *)&(
686             (const uint8_t *)in)[in->ssidList.offset];
687 
688     struct chreWifiSsidListItem *ssidListOut =
689         chppMalloc(in->ssidListLen * sizeof(struct chreWifiSsidListItem));
690     if (ssidListOut == NULL) {
691       return false;
692     }
693 
694     for (size_t i = 0; i < in->ssidListLen; i++) {
695       if (!chppWifiConvertSsidListItemToChre(&ssidListIn[i], &ssidListOut[i])) {
696         return false;
697       }
698     }
699     out->ssidList = ssidListOut;
700   }
701 
702   out->radioChainPref = in->radioChainPref;
703   out->channelSet = in->channelSet;
704 
705   return true;
706 }
707 
chppWifiConvertLciToChre(const struct ChppWifiLci * in,struct chreWifiLci * out)708 static bool chppWifiConvertLciToChre(const struct ChppWifiLci *in,
709                                      struct chreWifiLci *out) {
710   out->latitude = in->latitude;
711   out->longitude = in->longitude;
712   out->altitude = in->altitude;
713   out->latitudeUncertainty = in->latitudeUncertainty;
714   out->longitudeUncertainty = in->longitudeUncertainty;
715   out->altitudeType = in->altitudeType;
716   out->altitudeUncertainty = in->altitudeUncertainty;
717 
718   return true;
719 }
720 
chppWifiConvertRangingResultToChre(const struct ChppWifiRangingResult * in,struct chreWifiRangingResult * out)721 static bool chppWifiConvertRangingResultToChre(
722     const struct ChppWifiRangingResult *in, struct chreWifiRangingResult *out) {
723   out->timestamp = in->timestamp;
724   memcpy(out->macAddress, in->macAddress, sizeof(out->macAddress));
725   out->status = in->status;
726   out->rssi = in->rssi;
727   out->distance = in->distance;
728   out->distanceStdDev = in->distanceStdDev;
729   if (!chppWifiConvertLciToChre(&in->lci, &out->lci)) {
730     return false;
731   }
732   out->flags = in->flags;
733   memset(&out->reserved, 0, sizeof(out->reserved));
734 
735   return true;
736 }
737 
chppWifiConvertRangingEventToChre(const struct ChppWifiRangingEvent * in,struct chreWifiRangingEvent * out,size_t inSize)738 static bool chppWifiConvertRangingEventToChre(
739     const struct ChppWifiRangingEvent *in, struct chreWifiRangingEvent *out,
740     size_t inSize) {
741   out->version = CHRE_WIFI_RANGING_EVENT_VERSION;
742   out->resultCount = in->resultCount;
743   memset(&out->reserved, 0, sizeof(out->reserved));
744 
745   if (in->results.length == 0) {
746     out->results = NULL;
747   } else {
748     if (in->results.offset + in->results.length > inSize ||
749         in->results.length !=
750             in->resultCount * sizeof(struct ChppWifiRangingResult)) {
751       return false;
752     }
753 
754     const struct ChppWifiRangingResult *resultsIn =
755         (const struct ChppWifiRangingResult *)&(
756             (const uint8_t *)in)[in->results.offset];
757 
758     struct chreWifiRangingResult *resultsOut =
759         chppMalloc(in->resultCount * sizeof(struct chreWifiRangingResult));
760     if (resultsOut == NULL) {
761       return false;
762     }
763 
764     for (size_t i = 0; i < in->resultCount; i++) {
765       if (!chppWifiConvertRangingResultToChre(&resultsIn[i], &resultsOut[i])) {
766         return false;
767       }
768     }
769     out->results = resultsOut;
770   }
771 
772   return true;
773 }
774 
chppWifiConvertRangingTargetToChre(const struct ChppWifiRangingTarget * in,struct chreWifiRangingTarget * out)775 static bool chppWifiConvertRangingTargetToChre(
776     const struct ChppWifiRangingTarget *in, struct chreWifiRangingTarget *out) {
777   memcpy(out->macAddress, in->macAddress, sizeof(out->macAddress));
778   out->primaryChannel = in->primaryChannel;
779   out->centerFreqPrimary = in->centerFreqPrimary;
780   out->centerFreqSecondary = in->centerFreqSecondary;
781   out->channelWidth = in->channelWidth;
782   memset(&out->reserved, 0, sizeof(out->reserved));
783 
784   return true;
785 }
786 
chppWifiConvertRangingParamsToChre(const struct ChppWifiRangingParams * in,struct chreWifiRangingParams * out,size_t inSize)787 static bool chppWifiConvertRangingParamsToChre(
788     const struct ChppWifiRangingParams *in, struct chreWifiRangingParams *out,
789     size_t inSize) {
790   out->targetListLen = in->targetListLen;
791 
792   if (in->targetList.length == 0) {
793     out->targetList = NULL;
794   } else {
795     if (in->targetList.offset + in->targetList.length > inSize ||
796         in->targetList.length !=
797             in->targetListLen * sizeof(struct ChppWifiRangingTarget)) {
798       return false;
799     }
800 
801     const struct ChppWifiRangingTarget *targetListIn =
802         (const struct ChppWifiRangingTarget *)&(
803             (const uint8_t *)in)[in->targetList.offset];
804 
805     struct chreWifiRangingTarget *targetListOut =
806         chppMalloc(in->targetListLen * sizeof(struct chreWifiRangingTarget));
807     if (targetListOut == NULL) {
808       return false;
809     }
810 
811     for (size_t i = 0; i < in->targetListLen; i++) {
812       if (!chppWifiConvertRangingTargetToChre(&targetListIn[i],
813                                               &targetListOut[i])) {
814         return false;
815       }
816     }
817     out->targetList = targetListOut;
818   }
819 
820   return true;
821 }
822 
chppWifiConvertNanSubscribeConfigToChre(const struct ChppWifiNanSubscribeConfig * in,struct chreWifiNanSubscribeConfig * out,size_t inSize)823 static bool chppWifiConvertNanSubscribeConfigToChre(
824     const struct ChppWifiNanSubscribeConfig *in,
825     struct chreWifiNanSubscribeConfig *out, size_t inSize) {
826   out->subscribeType = in->subscribeType;
827 
828   if (in->service.length == 0) {
829     out->service = NULL;
830   } else {
831     char *serviceOut = chppMalloc(in->service.length);
832     if (serviceOut == NULL) {
833       return false;
834     }
835 
836     memcpy(serviceOut, &((const uint8_t *)in)[in->service.offset],
837            in->service.length);
838     out->service = serviceOut;
839   }
840 
841   if (in->serviceSpecificInfo.length == 0) {
842     out->serviceSpecificInfo = NULL;
843   } else {
844     if (in->serviceSpecificInfo.offset + in->serviceSpecificInfo.length >
845             inSize ||
846         in->serviceSpecificInfo.length !=
847             in->serviceSpecificInfoSize * sizeof(uint8_t)) {
848       return false;
849     }
850 
851     uint8_t *serviceSpecificInfoOut =
852         chppMalloc(in->serviceSpecificInfoSize * sizeof(uint8_t));
853     if (serviceSpecificInfoOut == NULL) {
854       return false;
855     }
856 
857     memcpy(serviceSpecificInfoOut,
858            &((const uint8_t *)in)[in->serviceSpecificInfo.offset],
859            in->serviceSpecificInfoSize * sizeof(uint8_t));
860     out->serviceSpecificInfo = serviceSpecificInfoOut;
861   }
862 
863   out->serviceSpecificInfoSize = in->serviceSpecificInfoSize;
864 
865   if (in->matchFilter.length == 0) {
866     out->matchFilter = NULL;
867   } else {
868     if (in->matchFilter.offset + in->matchFilter.length > inSize ||
869         in->matchFilter.length != in->matchFilterLength * sizeof(uint8_t)) {
870       return false;
871     }
872 
873     uint8_t *matchFilterOut =
874         chppMalloc(in->matchFilterLength * sizeof(uint8_t));
875     if (matchFilterOut == NULL) {
876       return false;
877     }
878 
879     memcpy(matchFilterOut, &((const uint8_t *)in)[in->matchFilter.offset],
880            in->matchFilterLength * sizeof(uint8_t));
881     out->matchFilter = matchFilterOut;
882   }
883 
884   out->matchFilterLength = in->matchFilterLength;
885 
886   return true;
887 }
888 
chppWifiConvertNanDiscoveryEventToChre(const struct ChppWifiNanDiscoveryEvent * in,struct chreWifiNanDiscoveryEvent * out,size_t inSize)889 static bool chppWifiConvertNanDiscoveryEventToChre(
890     const struct ChppWifiNanDiscoveryEvent *in,
891     struct chreWifiNanDiscoveryEvent *out, size_t inSize) {
892   out->subscribeId = in->subscribeId;
893   out->publishId = in->publishId;
894   memcpy(out->publisherAddress, in->publisherAddress,
895          sizeof(out->publisherAddress));
896 
897   if (in->serviceSpecificInfo.length == 0) {
898     out->serviceSpecificInfo = NULL;
899   } else {
900     if (in->serviceSpecificInfo.offset + in->serviceSpecificInfo.length >
901             inSize ||
902         in->serviceSpecificInfo.length !=
903             in->serviceSpecificInfoSize * sizeof(uint8_t)) {
904       return false;
905     }
906 
907     uint8_t *serviceSpecificInfoOut =
908         chppMalloc(in->serviceSpecificInfoSize * sizeof(uint8_t));
909     if (serviceSpecificInfoOut == NULL) {
910       return false;
911     }
912 
913     memcpy(serviceSpecificInfoOut,
914            &((const uint8_t *)in)[in->serviceSpecificInfo.offset],
915            in->serviceSpecificInfoSize * sizeof(uint8_t));
916     out->serviceSpecificInfo = serviceSpecificInfoOut;
917   }
918 
919   out->serviceSpecificInfoSize = in->serviceSpecificInfoSize;
920 
921   return true;
922 }
923 
chppWifiConvertNanSessionLostEventToChre(const struct ChppWifiNanSessionLostEvent * in,struct chreWifiNanSessionLostEvent * out)924 static bool chppWifiConvertNanSessionLostEventToChre(
925     const struct ChppWifiNanSessionLostEvent *in,
926     struct chreWifiNanSessionLostEvent *out) {
927   out->id = in->id;
928   out->peerId = in->peerId;
929 
930   return true;
931 }
932 
chppWifiConvertNanSessionTerminatedEventToChre(const struct ChppWifiNanSessionTerminatedEvent * in,struct chreWifiNanSessionTerminatedEvent * out)933 static bool chppWifiConvertNanSessionTerminatedEventToChre(
934     const struct ChppWifiNanSessionTerminatedEvent *in,
935     struct chreWifiNanSessionTerminatedEvent *out) {
936   out->id = in->id;
937   out->reason = in->reason;
938   memcpy(out->reserved, in->reserved, sizeof(out->reserved));
939 
940   return true;
941 }
942 
chppWifiConvertNanRangingParamsToChre(const struct ChppWifiNanRangingParams * in,struct chreWifiNanRangingParams * out)943 static bool chppWifiConvertNanRangingParamsToChre(
944     const struct ChppWifiNanRangingParams *in,
945     struct chreWifiNanRangingParams *out) {
946   memcpy(out->macAddress, in->macAddress, sizeof(out->macAddress));
947 
948   return true;
949 }
950 
951 // Decoding (CHPP --> CHRE) top-level functions
952 
chppWifiScanEventToChre(const struct ChppWifiScanEvent * in,size_t inSize)953 struct chreWifiScanEvent *chppWifiScanEventToChre(
954     const struct ChppWifiScanEvent *in, size_t inSize) {
955   struct chreWifiScanEvent *out = NULL;
956 
957   if (inSize >= sizeof(struct ChppWifiScanEvent)) {
958     out = chppMalloc(sizeof(struct chreWifiScanEvent));
959     if (out != NULL) {
960       if (!chppWifiConvertScanEventToChre(in, out, inSize)) {
961         CHPP_FREE_AND_NULLIFY(out);
962       }
963     }
964   }
965 
966   return out;
967 }
chppWifiScanParamsToChre(const struct ChppWifiScanParams * in,size_t inSize)968 struct chreWifiScanParams *chppWifiScanParamsToChre(
969     const struct ChppWifiScanParams *in, size_t inSize) {
970   struct chreWifiScanParams *out = NULL;
971 
972   if (inSize >= sizeof(struct ChppWifiScanParams)) {
973     out = chppMalloc(sizeof(struct chreWifiScanParams));
974     if (out != NULL) {
975       if (!chppWifiConvertScanParamsToChre(in, out, inSize)) {
976         CHPP_FREE_AND_NULLIFY(out);
977       }
978     }
979   }
980 
981   return out;
982 }
chppWifiRangingEventToChre(const struct ChppWifiRangingEvent * in,size_t inSize)983 struct chreWifiRangingEvent *chppWifiRangingEventToChre(
984     const struct ChppWifiRangingEvent *in, size_t inSize) {
985   struct chreWifiRangingEvent *out = NULL;
986 
987   if (inSize >= sizeof(struct ChppWifiRangingEvent)) {
988     out = chppMalloc(sizeof(struct chreWifiRangingEvent));
989     if (out != NULL) {
990       if (!chppWifiConvertRangingEventToChre(in, out, inSize)) {
991         CHPP_FREE_AND_NULLIFY(out);
992       }
993     }
994   }
995 
996   return out;
997 }
chppWifiRangingParamsToChre(const struct ChppWifiRangingParams * in,size_t inSize)998 struct chreWifiRangingParams *chppWifiRangingParamsToChre(
999     const struct ChppWifiRangingParams *in, size_t inSize) {
1000   struct chreWifiRangingParams *out = NULL;
1001 
1002   if (inSize >= sizeof(struct ChppWifiRangingParams)) {
1003     out = chppMalloc(sizeof(struct chreWifiRangingParams));
1004     if (out != NULL) {
1005       if (!chppWifiConvertRangingParamsToChre(in, out, inSize)) {
1006         CHPP_FREE_AND_NULLIFY(out);
1007       }
1008     }
1009   }
1010 
1011   return out;
1012 }
chppWifiNanSubscribeConfigToChre(const struct ChppWifiNanSubscribeConfig * in,size_t inSize)1013 struct chreWifiNanSubscribeConfig *chppWifiNanSubscribeConfigToChre(
1014     const struct ChppWifiNanSubscribeConfig *in, size_t inSize) {
1015   struct chreWifiNanSubscribeConfig *out = NULL;
1016 
1017   if (inSize >= sizeof(struct ChppWifiNanSubscribeConfig)) {
1018     out = chppMalloc(sizeof(struct chreWifiNanSubscribeConfig));
1019     if (out != NULL) {
1020       if (!chppWifiConvertNanSubscribeConfigToChre(in, out, inSize)) {
1021         CHPP_FREE_AND_NULLIFY(out);
1022       }
1023     }
1024   }
1025 
1026   return out;
1027 }
chppWifiNanDiscoveryEventToChre(const struct ChppWifiNanDiscoveryEvent * in,size_t inSize)1028 struct chreWifiNanDiscoveryEvent *chppWifiNanDiscoveryEventToChre(
1029     const struct ChppWifiNanDiscoveryEvent *in, size_t inSize) {
1030   struct chreWifiNanDiscoveryEvent *out = NULL;
1031 
1032   if (inSize >= sizeof(struct ChppWifiNanDiscoveryEvent)) {
1033     out = chppMalloc(sizeof(struct chreWifiNanDiscoveryEvent));
1034     if (out != NULL) {
1035       if (!chppWifiConvertNanDiscoveryEventToChre(in, out, inSize)) {
1036         CHPP_FREE_AND_NULLIFY(out);
1037       }
1038     }
1039   }
1040 
1041   return out;
1042 }
chppWifiNanSessionLostEventToChre(const struct ChppWifiNanSessionLostEvent * in,size_t inSize)1043 struct chreWifiNanSessionLostEvent *chppWifiNanSessionLostEventToChre(
1044     const struct ChppWifiNanSessionLostEvent *in, size_t inSize) {
1045   struct chreWifiNanSessionLostEvent *out = NULL;
1046 
1047   if (inSize >= sizeof(struct ChppWifiNanSessionLostEvent)) {
1048     out = chppMalloc(sizeof(struct chreWifiNanSessionLostEvent));
1049     if (out != NULL) {
1050       if (!chppWifiConvertNanSessionLostEventToChre(in, out)) {
1051         CHPP_FREE_AND_NULLIFY(out);
1052       }
1053     }
1054   }
1055 
1056   return out;
1057 }
1058 struct chreWifiNanSessionTerminatedEvent *
chppWifiNanSessionTerminatedEventToChre(const struct ChppWifiNanSessionTerminatedEvent * in,size_t inSize)1059 chppWifiNanSessionTerminatedEventToChre(
1060     const struct ChppWifiNanSessionTerminatedEvent *in, size_t inSize) {
1061   struct chreWifiNanSessionTerminatedEvent *out = NULL;
1062 
1063   if (inSize >= sizeof(struct ChppWifiNanSessionTerminatedEvent)) {
1064     out = chppMalloc(sizeof(struct chreWifiNanSessionTerminatedEvent));
1065     if (out != NULL) {
1066       if (!chppWifiConvertNanSessionTerminatedEventToChre(in, out)) {
1067         CHPP_FREE_AND_NULLIFY(out);
1068       }
1069     }
1070   }
1071 
1072   return out;
1073 }
chppWifiNanRangingParamsToChre(const struct ChppWifiNanRangingParams * in,size_t inSize)1074 struct chreWifiNanRangingParams *chppWifiNanRangingParamsToChre(
1075     const struct ChppWifiNanRangingParams *in, size_t inSize) {
1076   struct chreWifiNanRangingParams *out = NULL;
1077 
1078   if (inSize >= sizeof(struct ChppWifiNanRangingParams)) {
1079     out = chppMalloc(sizeof(struct chreWifiNanRangingParams));
1080     if (out != NULL) {
1081       if (!chppWifiConvertNanRangingParamsToChre(in, out)) {
1082         CHPP_FREE_AND_NULLIFY(out);
1083       }
1084     }
1085   }
1086 
1087   return out;
1088 }
1089