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:30 UTC
19 // Source: chre_api/include/chre_api/chre/wwan.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/wwan_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 //! chreWwanCellInfoResult along with the CHPP header as
36 //! struct ChppWwanCellInfoResultWithHeader
chppWwanSizeOfCellInfoResultFromChre(const struct chreWwanCellInfoResult * cellInfoResult)37 static size_t chppWwanSizeOfCellInfoResultFromChre(
38 const struct chreWwanCellInfoResult *cellInfoResult) {
39 size_t encodedSize = sizeof(struct ChppWwanCellInfoResultWithHeader);
40 encodedSize +=
41 cellInfoResult->cellInfoCount * sizeof(struct ChppWwanCellInfo);
42 return encodedSize;
43 }
44
45 // Encoding (CHRE --> CHPP) conversion functions
46
chppWwanConvertCellIdentityCdmaFromChre(const struct chreWwanCellIdentityCdma * in,struct ChppWwanCellIdentityCdma * out)47 static void chppWwanConvertCellIdentityCdmaFromChre(
48 const struct chreWwanCellIdentityCdma *in,
49 struct ChppWwanCellIdentityCdma *out) {
50 out->networkId = in->networkId;
51 out->systemId = in->systemId;
52 out->basestationId = in->basestationId;
53 out->longitude = in->longitude;
54 out->latitude = in->latitude;
55 }
56
chppWwanConvertSignalStrengthCdmaFromChre(const struct chreWwanSignalStrengthCdma * in,struct ChppWwanSignalStrengthCdma * out)57 static void chppWwanConvertSignalStrengthCdmaFromChre(
58 const struct chreWwanSignalStrengthCdma *in,
59 struct ChppWwanSignalStrengthCdma *out) {
60 out->dbm = in->dbm;
61 out->ecio = in->ecio;
62 }
63
chppWwanConvertSignalStrengthEvdoFromChre(const struct chreWwanSignalStrengthEvdo * in,struct ChppWwanSignalStrengthEvdo * out)64 static void chppWwanConvertSignalStrengthEvdoFromChre(
65 const struct chreWwanSignalStrengthEvdo *in,
66 struct ChppWwanSignalStrengthEvdo *out) {
67 out->dbm = in->dbm;
68 out->ecio = in->ecio;
69 out->signalNoiseRatio = in->signalNoiseRatio;
70 }
71
chppWwanConvertCellInfoCdmaFromChre(const struct chreWwanCellInfoCdma * in,struct ChppWwanCellInfoCdma * out)72 static void chppWwanConvertCellInfoCdmaFromChre(
73 const struct chreWwanCellInfoCdma *in, struct ChppWwanCellInfoCdma *out) {
74 chppWwanConvertCellIdentityCdmaFromChre(&in->cellIdentityCdma,
75 &out->cellIdentityCdma);
76 chppWwanConvertSignalStrengthCdmaFromChre(&in->signalStrengthCdma,
77 &out->signalStrengthCdma);
78 chppWwanConvertSignalStrengthEvdoFromChre(&in->signalStrengthEvdo,
79 &out->signalStrengthEvdo);
80 }
81
chppWwanConvertCellIdentityGsmFromChre(const struct chreWwanCellIdentityGsm * in,struct ChppWwanCellIdentityGsm * out)82 static void chppWwanConvertCellIdentityGsmFromChre(
83 const struct chreWwanCellIdentityGsm *in,
84 struct ChppWwanCellIdentityGsm *out) {
85 out->mcc = in->mcc;
86 out->mnc = in->mnc;
87 out->lac = in->lac;
88 out->cid = in->cid;
89 out->arfcn = in->arfcn;
90 out->bsic = in->bsic;
91 memset(&out->reserved, 0, sizeof(out->reserved));
92 }
93
chppWwanConvertSignalStrengthGsmFromChre(const struct chreWwanSignalStrengthGsm * in,struct ChppWwanSignalStrengthGsm * out)94 static void chppWwanConvertSignalStrengthGsmFromChre(
95 const struct chreWwanSignalStrengthGsm *in,
96 struct ChppWwanSignalStrengthGsm *out) {
97 out->signalStrength = in->signalStrength;
98 out->bitErrorRate = in->bitErrorRate;
99 out->timingAdvance = in->timingAdvance;
100 }
101
chppWwanConvertCellInfoGsmFromChre(const struct chreWwanCellInfoGsm * in,struct ChppWwanCellInfoGsm * out)102 static void chppWwanConvertCellInfoGsmFromChre(
103 const struct chreWwanCellInfoGsm *in, struct ChppWwanCellInfoGsm *out) {
104 chppWwanConvertCellIdentityGsmFromChre(&in->cellIdentityGsm,
105 &out->cellIdentityGsm);
106 chppWwanConvertSignalStrengthGsmFromChre(&in->signalStrengthGsm,
107 &out->signalStrengthGsm);
108 }
109
chppWwanConvertCellIdentityLteFromChre(const struct chreWwanCellIdentityLte * in,struct ChppWwanCellIdentityLte * out)110 static void chppWwanConvertCellIdentityLteFromChre(
111 const struct chreWwanCellIdentityLte *in,
112 struct ChppWwanCellIdentityLte *out) {
113 out->mcc = in->mcc;
114 out->mnc = in->mnc;
115 out->ci = in->ci;
116 out->pci = in->pci;
117 out->tac = in->tac;
118 out->earfcn = in->earfcn;
119 }
120
chppWwanConvertSignalStrengthLteFromChre(const struct chreWwanSignalStrengthLte * in,struct ChppWwanSignalStrengthLte * out)121 static void chppWwanConvertSignalStrengthLteFromChre(
122 const struct chreWwanSignalStrengthLte *in,
123 struct ChppWwanSignalStrengthLte *out) {
124 out->signalStrength = in->signalStrength;
125 out->rsrp = in->rsrp;
126 out->rsrq = in->rsrq;
127 out->rssnr = in->rssnr;
128 out->cqi = in->cqi;
129 out->timingAdvance = in->timingAdvance;
130 }
131
chppWwanConvertCellInfoLteFromChre(const struct chreWwanCellInfoLte * in,struct ChppWwanCellInfoLte * out)132 static void chppWwanConvertCellInfoLteFromChre(
133 const struct chreWwanCellInfoLte *in, struct ChppWwanCellInfoLte *out) {
134 chppWwanConvertCellIdentityLteFromChre(&in->cellIdentityLte,
135 &out->cellIdentityLte);
136 chppWwanConvertSignalStrengthLteFromChre(&in->signalStrengthLte,
137 &out->signalStrengthLte);
138 }
139
chppWwanConvertCellIdentityNrFromChre(const struct chreWwanCellIdentityNr * in,struct ChppWwanCellIdentityNr * out)140 static void chppWwanConvertCellIdentityNrFromChre(
141 const struct chreWwanCellIdentityNr *in,
142 struct ChppWwanCellIdentityNr *out) {
143 out->mcc = in->mcc;
144 out->mnc = in->mnc;
145 out->nci0 = in->nci0;
146 out->nci1 = in->nci1;
147 out->pci = in->pci;
148 out->tac = in->tac;
149 out->nrarfcn = in->nrarfcn;
150 }
151
chppWwanConvertSignalStrengthNrFromChre(const struct chreWwanSignalStrengthNr * in,struct ChppWwanSignalStrengthNr * out)152 static void chppWwanConvertSignalStrengthNrFromChre(
153 const struct chreWwanSignalStrengthNr *in,
154 struct ChppWwanSignalStrengthNr *out) {
155 out->ssRsrp = in->ssRsrp;
156 out->ssRsrq = in->ssRsrq;
157 out->ssSinr = in->ssSinr;
158 out->csiRsrp = in->csiRsrp;
159 out->csiRsrq = in->csiRsrq;
160 out->csiSinr = in->csiSinr;
161 }
162
chppWwanConvertCellInfoNrFromChre(const struct chreWwanCellInfoNr * in,struct ChppWwanCellInfoNr * out)163 static void chppWwanConvertCellInfoNrFromChre(
164 const struct chreWwanCellInfoNr *in, struct ChppWwanCellInfoNr *out) {
165 chppWwanConvertCellIdentityNrFromChre(&in->cellIdentityNr,
166 &out->cellIdentityNr);
167 chppWwanConvertSignalStrengthNrFromChre(&in->signalStrengthNr,
168 &out->signalStrengthNr);
169 }
170
chppWwanConvertCellIdentityTdscdmaFromChre(const struct chreWwanCellIdentityTdscdma * in,struct ChppWwanCellIdentityTdscdma * out)171 static void chppWwanConvertCellIdentityTdscdmaFromChre(
172 const struct chreWwanCellIdentityTdscdma *in,
173 struct ChppWwanCellIdentityTdscdma *out) {
174 out->mcc = in->mcc;
175 out->mnc = in->mnc;
176 out->lac = in->lac;
177 out->cid = in->cid;
178 out->cpid = in->cpid;
179 }
180
chppWwanConvertSignalStrengthTdscdmaFromChre(const struct chreWwanSignalStrengthTdscdma * in,struct ChppWwanSignalStrengthTdscdma * out)181 static void chppWwanConvertSignalStrengthTdscdmaFromChre(
182 const struct chreWwanSignalStrengthTdscdma *in,
183 struct ChppWwanSignalStrengthTdscdma *out) {
184 out->rscp = in->rscp;
185 }
186
chppWwanConvertCellInfoTdscdmaFromChre(const struct chreWwanCellInfoTdscdma * in,struct ChppWwanCellInfoTdscdma * out)187 static void chppWwanConvertCellInfoTdscdmaFromChre(
188 const struct chreWwanCellInfoTdscdma *in,
189 struct ChppWwanCellInfoTdscdma *out) {
190 chppWwanConvertCellIdentityTdscdmaFromChre(&in->cellIdentityTdscdma,
191 &out->cellIdentityTdscdma);
192 chppWwanConvertSignalStrengthTdscdmaFromChre(&in->signalStrengthTdscdma,
193 &out->signalStrengthTdscdma);
194 }
195
chppWwanConvertCellIdentityWcdmaFromChre(const struct chreWwanCellIdentityWcdma * in,struct ChppWwanCellIdentityWcdma * out)196 static void chppWwanConvertCellIdentityWcdmaFromChre(
197 const struct chreWwanCellIdentityWcdma *in,
198 struct ChppWwanCellIdentityWcdma *out) {
199 out->mcc = in->mcc;
200 out->mnc = in->mnc;
201 out->lac = in->lac;
202 out->cid = in->cid;
203 out->psc = in->psc;
204 out->uarfcn = in->uarfcn;
205 }
206
chppWwanConvertSignalStrengthWcdmaFromChre(const struct chreWwanSignalStrengthWcdma * in,struct ChppWwanSignalStrengthWcdma * out)207 static void chppWwanConvertSignalStrengthWcdmaFromChre(
208 const struct chreWwanSignalStrengthWcdma *in,
209 struct ChppWwanSignalStrengthWcdma *out) {
210 out->signalStrength = in->signalStrength;
211 out->bitErrorRate = in->bitErrorRate;
212 }
213
chppWwanConvertCellInfoWcdmaFromChre(const struct chreWwanCellInfoWcdma * in,struct ChppWwanCellInfoWcdma * out)214 static void chppWwanConvertCellInfoWcdmaFromChre(
215 const struct chreWwanCellInfoWcdma *in, struct ChppWwanCellInfoWcdma *out) {
216 chppWwanConvertCellIdentityWcdmaFromChre(&in->cellIdentityWcdma,
217 &out->cellIdentityWcdma);
218 chppWwanConvertSignalStrengthWcdmaFromChre(&in->signalStrengthWcdma,
219 &out->signalStrengthWcdma);
220 }
221
chppWwanConvertCellInfoFromChre(const struct chreWwanCellInfo * in,struct ChppWwanCellInfo * out)222 static void chppWwanConvertCellInfoFromChre(const struct chreWwanCellInfo *in,
223 struct ChppWwanCellInfo *out) {
224 out->timeStamp = in->timeStamp;
225 out->cellInfoType = in->cellInfoType;
226 out->timeStampType = in->timeStampType;
227 out->registered = in->registered;
228 out->reserved = 0;
229 memset(&out->CellInfo, 0, sizeof(out->CellInfo));
230 switch (in->cellInfoType) {
231 case CHRE_WWAN_CELL_INFO_TYPE_GSM:
232 chppWwanConvertCellInfoGsmFromChre(&in->CellInfo.gsm, &out->CellInfo.gsm);
233 break;
234 case CHRE_WWAN_CELL_INFO_TYPE_CDMA:
235 chppWwanConvertCellInfoCdmaFromChre(&in->CellInfo.cdma,
236 &out->CellInfo.cdma);
237 break;
238 case CHRE_WWAN_CELL_INFO_TYPE_LTE:
239 chppWwanConvertCellInfoLteFromChre(&in->CellInfo.lte, &out->CellInfo.lte);
240 break;
241 case CHRE_WWAN_CELL_INFO_TYPE_WCDMA:
242 chppWwanConvertCellInfoWcdmaFromChre(&in->CellInfo.wcdma,
243 &out->CellInfo.wcdma);
244 break;
245 case CHRE_WWAN_CELL_INFO_TYPE_TD_SCDMA:
246 chppWwanConvertCellInfoTdscdmaFromChre(&in->CellInfo.tdscdma,
247 &out->CellInfo.tdscdma);
248 break;
249 case CHRE_WWAN_CELL_INFO_TYPE_NR:
250 chppWwanConvertCellInfoNrFromChre(&in->CellInfo.nr, &out->CellInfo.nr);
251 break;
252 default:
253 CHPP_ASSERT(false);
254 }
255 }
256
chppWwanConvertCellInfoResultFromChre(const struct chreWwanCellInfoResult * in,struct ChppWwanCellInfoResult * out,uint8_t * payload,size_t payloadSize,uint16_t * vlaOffset)257 static void chppWwanConvertCellInfoResultFromChre(
258 const struct chreWwanCellInfoResult *in, struct ChppWwanCellInfoResult *out,
259 uint8_t *payload, size_t payloadSize, uint16_t *vlaOffset) {
260 out->version = CHRE_WWAN_CELL_INFO_RESULT_VERSION;
261 out->errorCode = in->errorCode;
262 out->cellInfoCount = in->cellInfoCount;
263 out->reserved = 0;
264 out->cookie = 0;
265
266 struct ChppWwanCellInfo *cells =
267 (struct ChppWwanCellInfo *)&payload[*vlaOffset];
268 out->cells.length =
269 (uint16_t)(in->cellInfoCount * sizeof(struct ChppWwanCellInfo));
270 CHPP_ASSERT((size_t)(*vlaOffset + out->cells.length) <= payloadSize);
271 if (out->cells.length > 0 && *vlaOffset + out->cells.length <= payloadSize) {
272 for (size_t i = 0; i < in->cellInfoCount; i++) {
273 chppWwanConvertCellInfoFromChre(&in->cells[i], &cells[i]);
274 }
275 out->cells.offset = *vlaOffset;
276 *vlaOffset += out->cells.length;
277 } else {
278 out->cells.offset = 0;
279 }
280 }
281
282 // Encoding (CHRE --> CHPP) top-level functions
283
chppWwanCellInfoResultFromChre(const struct chreWwanCellInfoResult * in,struct ChppWwanCellInfoResultWithHeader ** out,size_t * outSize)284 bool chppWwanCellInfoResultFromChre(
285 const struct chreWwanCellInfoResult *in,
286 struct ChppWwanCellInfoResultWithHeader **out, size_t *outSize) {
287 CHPP_NOT_NULL(out);
288 CHPP_NOT_NULL(outSize);
289
290 size_t payloadSize = chppWwanSizeOfCellInfoResultFromChre(in);
291 *out = chppMalloc(payloadSize);
292 if (*out != NULL) {
293 uint8_t *payload = (uint8_t *)&(*out)->payload;
294 uint16_t vlaOffset = sizeof(struct ChppWwanCellInfoResult);
295 chppWwanConvertCellInfoResultFromChre(in, &(*out)->payload, payload,
296 payloadSize, &vlaOffset);
297 *outSize = payloadSize;
298 return true;
299 }
300 return false;
301 }
302
303 // Decoding (CHPP --> CHRE) conversion functions
304
chppWwanConvertCellIdentityCdmaToChre(const struct ChppWwanCellIdentityCdma * in,struct chreWwanCellIdentityCdma * out)305 static bool chppWwanConvertCellIdentityCdmaToChre(
306 const struct ChppWwanCellIdentityCdma *in,
307 struct chreWwanCellIdentityCdma *out) {
308 out->networkId = in->networkId;
309 out->systemId = in->systemId;
310 out->basestationId = in->basestationId;
311 out->longitude = in->longitude;
312 out->latitude = in->latitude;
313
314 return true;
315 }
316
chppWwanConvertSignalStrengthCdmaToChre(const struct ChppWwanSignalStrengthCdma * in,struct chreWwanSignalStrengthCdma * out)317 static bool chppWwanConvertSignalStrengthCdmaToChre(
318 const struct ChppWwanSignalStrengthCdma *in,
319 struct chreWwanSignalStrengthCdma *out) {
320 out->dbm = in->dbm;
321 out->ecio = in->ecio;
322
323 return true;
324 }
325
chppWwanConvertSignalStrengthEvdoToChre(const struct ChppWwanSignalStrengthEvdo * in,struct chreWwanSignalStrengthEvdo * out)326 static bool chppWwanConvertSignalStrengthEvdoToChre(
327 const struct ChppWwanSignalStrengthEvdo *in,
328 struct chreWwanSignalStrengthEvdo *out) {
329 out->dbm = in->dbm;
330 out->ecio = in->ecio;
331 out->signalNoiseRatio = in->signalNoiseRatio;
332
333 return true;
334 }
335
chppWwanConvertCellInfoCdmaToChre(const struct ChppWwanCellInfoCdma * in,struct chreWwanCellInfoCdma * out)336 static bool chppWwanConvertCellInfoCdmaToChre(
337 const struct ChppWwanCellInfoCdma *in, struct chreWwanCellInfoCdma *out) {
338 if (!chppWwanConvertCellIdentityCdmaToChre(&in->cellIdentityCdma,
339 &out->cellIdentityCdma)) {
340 return false;
341 }
342 if (!chppWwanConvertSignalStrengthCdmaToChre(&in->signalStrengthCdma,
343 &out->signalStrengthCdma)) {
344 return false;
345 }
346 if (!chppWwanConvertSignalStrengthEvdoToChre(&in->signalStrengthEvdo,
347 &out->signalStrengthEvdo)) {
348 return false;
349 }
350
351 return true;
352 }
353
chppWwanConvertCellIdentityGsmToChre(const struct ChppWwanCellIdentityGsm * in,struct chreWwanCellIdentityGsm * out)354 static bool chppWwanConvertCellIdentityGsmToChre(
355 const struct ChppWwanCellIdentityGsm *in,
356 struct chreWwanCellIdentityGsm *out) {
357 out->mcc = in->mcc;
358 out->mnc = in->mnc;
359 out->lac = in->lac;
360 out->cid = in->cid;
361 out->arfcn = in->arfcn;
362 out->bsic = in->bsic;
363 memset(&out->reserved, 0, sizeof(out->reserved));
364
365 return true;
366 }
367
chppWwanConvertSignalStrengthGsmToChre(const struct ChppWwanSignalStrengthGsm * in,struct chreWwanSignalStrengthGsm * out)368 static bool chppWwanConvertSignalStrengthGsmToChre(
369 const struct ChppWwanSignalStrengthGsm *in,
370 struct chreWwanSignalStrengthGsm *out) {
371 out->signalStrength = in->signalStrength;
372 out->bitErrorRate = in->bitErrorRate;
373 out->timingAdvance = in->timingAdvance;
374
375 return true;
376 }
377
chppWwanConvertCellInfoGsmToChre(const struct ChppWwanCellInfoGsm * in,struct chreWwanCellInfoGsm * out)378 static bool chppWwanConvertCellInfoGsmToChre(
379 const struct ChppWwanCellInfoGsm *in, struct chreWwanCellInfoGsm *out) {
380 if (!chppWwanConvertCellIdentityGsmToChre(&in->cellIdentityGsm,
381 &out->cellIdentityGsm)) {
382 return false;
383 }
384 if (!chppWwanConvertSignalStrengthGsmToChre(&in->signalStrengthGsm,
385 &out->signalStrengthGsm)) {
386 return false;
387 }
388
389 return true;
390 }
391
chppWwanConvertCellIdentityLteToChre(const struct ChppWwanCellIdentityLte * in,struct chreWwanCellIdentityLte * out)392 static bool chppWwanConvertCellIdentityLteToChre(
393 const struct ChppWwanCellIdentityLte *in,
394 struct chreWwanCellIdentityLte *out) {
395 out->mcc = in->mcc;
396 out->mnc = in->mnc;
397 out->ci = in->ci;
398 out->pci = in->pci;
399 out->tac = in->tac;
400 out->earfcn = in->earfcn;
401
402 return true;
403 }
404
chppWwanConvertSignalStrengthLteToChre(const struct ChppWwanSignalStrengthLte * in,struct chreWwanSignalStrengthLte * out)405 static bool chppWwanConvertSignalStrengthLteToChre(
406 const struct ChppWwanSignalStrengthLte *in,
407 struct chreWwanSignalStrengthLte *out) {
408 out->signalStrength = in->signalStrength;
409 out->rsrp = in->rsrp;
410 out->rsrq = in->rsrq;
411 out->rssnr = in->rssnr;
412 out->cqi = in->cqi;
413 out->timingAdvance = in->timingAdvance;
414
415 return true;
416 }
417
chppWwanConvertCellInfoLteToChre(const struct ChppWwanCellInfoLte * in,struct chreWwanCellInfoLte * out)418 static bool chppWwanConvertCellInfoLteToChre(
419 const struct ChppWwanCellInfoLte *in, struct chreWwanCellInfoLte *out) {
420 if (!chppWwanConvertCellIdentityLteToChre(&in->cellIdentityLte,
421 &out->cellIdentityLte)) {
422 return false;
423 }
424 if (!chppWwanConvertSignalStrengthLteToChre(&in->signalStrengthLte,
425 &out->signalStrengthLte)) {
426 return false;
427 }
428
429 return true;
430 }
431
chppWwanConvertCellIdentityNrToChre(const struct ChppWwanCellIdentityNr * in,struct chreWwanCellIdentityNr * out)432 static bool chppWwanConvertCellIdentityNrToChre(
433 const struct ChppWwanCellIdentityNr *in,
434 struct chreWwanCellIdentityNr *out) {
435 out->mcc = in->mcc;
436 out->mnc = in->mnc;
437 out->nci0 = in->nci0;
438 out->nci1 = in->nci1;
439 out->pci = in->pci;
440 out->tac = in->tac;
441 out->nrarfcn = in->nrarfcn;
442
443 return true;
444 }
445
chppWwanConvertSignalStrengthNrToChre(const struct ChppWwanSignalStrengthNr * in,struct chreWwanSignalStrengthNr * out)446 static bool chppWwanConvertSignalStrengthNrToChre(
447 const struct ChppWwanSignalStrengthNr *in,
448 struct chreWwanSignalStrengthNr *out) {
449 out->ssRsrp = in->ssRsrp;
450 out->ssRsrq = in->ssRsrq;
451 out->ssSinr = in->ssSinr;
452 out->csiRsrp = in->csiRsrp;
453 out->csiRsrq = in->csiRsrq;
454 out->csiSinr = in->csiSinr;
455
456 return true;
457 }
458
chppWwanConvertCellInfoNrToChre(const struct ChppWwanCellInfoNr * in,struct chreWwanCellInfoNr * out)459 static bool chppWwanConvertCellInfoNrToChre(const struct ChppWwanCellInfoNr *in,
460 struct chreWwanCellInfoNr *out) {
461 if (!chppWwanConvertCellIdentityNrToChre(&in->cellIdentityNr,
462 &out->cellIdentityNr)) {
463 return false;
464 }
465 if (!chppWwanConvertSignalStrengthNrToChre(&in->signalStrengthNr,
466 &out->signalStrengthNr)) {
467 return false;
468 }
469
470 return true;
471 }
472
chppWwanConvertCellIdentityTdscdmaToChre(const struct ChppWwanCellIdentityTdscdma * in,struct chreWwanCellIdentityTdscdma * out)473 static bool chppWwanConvertCellIdentityTdscdmaToChre(
474 const struct ChppWwanCellIdentityTdscdma *in,
475 struct chreWwanCellIdentityTdscdma *out) {
476 out->mcc = in->mcc;
477 out->mnc = in->mnc;
478 out->lac = in->lac;
479 out->cid = in->cid;
480 out->cpid = in->cpid;
481
482 return true;
483 }
484
chppWwanConvertSignalStrengthTdscdmaToChre(const struct ChppWwanSignalStrengthTdscdma * in,struct chreWwanSignalStrengthTdscdma * out)485 static bool chppWwanConvertSignalStrengthTdscdmaToChre(
486 const struct ChppWwanSignalStrengthTdscdma *in,
487 struct chreWwanSignalStrengthTdscdma *out) {
488 out->rscp = in->rscp;
489
490 return true;
491 }
492
chppWwanConvertCellInfoTdscdmaToChre(const struct ChppWwanCellInfoTdscdma * in,struct chreWwanCellInfoTdscdma * out)493 static bool chppWwanConvertCellInfoTdscdmaToChre(
494 const struct ChppWwanCellInfoTdscdma *in,
495 struct chreWwanCellInfoTdscdma *out) {
496 if (!chppWwanConvertCellIdentityTdscdmaToChre(&in->cellIdentityTdscdma,
497 &out->cellIdentityTdscdma)) {
498 return false;
499 }
500 if (!chppWwanConvertSignalStrengthTdscdmaToChre(
501 &in->signalStrengthTdscdma, &out->signalStrengthTdscdma)) {
502 return false;
503 }
504
505 return true;
506 }
507
chppWwanConvertCellIdentityWcdmaToChre(const struct ChppWwanCellIdentityWcdma * in,struct chreWwanCellIdentityWcdma * out)508 static bool chppWwanConvertCellIdentityWcdmaToChre(
509 const struct ChppWwanCellIdentityWcdma *in,
510 struct chreWwanCellIdentityWcdma *out) {
511 out->mcc = in->mcc;
512 out->mnc = in->mnc;
513 out->lac = in->lac;
514 out->cid = in->cid;
515 out->psc = in->psc;
516 out->uarfcn = in->uarfcn;
517
518 return true;
519 }
520
chppWwanConvertSignalStrengthWcdmaToChre(const struct ChppWwanSignalStrengthWcdma * in,struct chreWwanSignalStrengthWcdma * out)521 static bool chppWwanConvertSignalStrengthWcdmaToChre(
522 const struct ChppWwanSignalStrengthWcdma *in,
523 struct chreWwanSignalStrengthWcdma *out) {
524 out->signalStrength = in->signalStrength;
525 out->bitErrorRate = in->bitErrorRate;
526
527 return true;
528 }
529
chppWwanConvertCellInfoWcdmaToChre(const struct ChppWwanCellInfoWcdma * in,struct chreWwanCellInfoWcdma * out)530 static bool chppWwanConvertCellInfoWcdmaToChre(
531 const struct ChppWwanCellInfoWcdma *in, struct chreWwanCellInfoWcdma *out) {
532 if (!chppWwanConvertCellIdentityWcdmaToChre(&in->cellIdentityWcdma,
533 &out->cellIdentityWcdma)) {
534 return false;
535 }
536 if (!chppWwanConvertSignalStrengthWcdmaToChre(&in->signalStrengthWcdma,
537 &out->signalStrengthWcdma)) {
538 return false;
539 }
540
541 return true;
542 }
543
chppWwanConvertCellInfoToChre(const struct ChppWwanCellInfo * in,struct chreWwanCellInfo * out)544 static bool chppWwanConvertCellInfoToChre(const struct ChppWwanCellInfo *in,
545 struct chreWwanCellInfo *out) {
546 out->timeStamp = in->timeStamp;
547 out->cellInfoType = in->cellInfoType;
548 out->timeStampType = in->timeStampType;
549 out->registered = in->registered;
550 out->reserved = 0;
551 memset(&out->CellInfo, 0, sizeof(out->CellInfo));
552 switch (in->cellInfoType) {
553 case CHRE_WWAN_CELL_INFO_TYPE_GSM:
554 if (!chppWwanConvertCellInfoGsmToChre(&in->CellInfo.gsm,
555 &out->CellInfo.gsm)) {
556 return false;
557 }
558 break;
559 case CHRE_WWAN_CELL_INFO_TYPE_CDMA:
560 if (!chppWwanConvertCellInfoCdmaToChre(&in->CellInfo.cdma,
561 &out->CellInfo.cdma)) {
562 return false;
563 }
564 break;
565 case CHRE_WWAN_CELL_INFO_TYPE_LTE:
566 if (!chppWwanConvertCellInfoLteToChre(&in->CellInfo.lte,
567 &out->CellInfo.lte)) {
568 return false;
569 }
570 break;
571 case CHRE_WWAN_CELL_INFO_TYPE_WCDMA:
572 if (!chppWwanConvertCellInfoWcdmaToChre(&in->CellInfo.wcdma,
573 &out->CellInfo.wcdma)) {
574 return false;
575 }
576 break;
577 case CHRE_WWAN_CELL_INFO_TYPE_TD_SCDMA:
578 if (!chppWwanConvertCellInfoTdscdmaToChre(&in->CellInfo.tdscdma,
579 &out->CellInfo.tdscdma)) {
580 return false;
581 }
582 break;
583 case CHRE_WWAN_CELL_INFO_TYPE_NR:
584 if (!chppWwanConvertCellInfoNrToChre(&in->CellInfo.nr,
585 &out->CellInfo.nr)) {
586 return false;
587 }
588 break;
589 default:
590 CHPP_ASSERT(false);
591 }
592
593 return true;
594 }
595
chppWwanConvertCellInfoResultToChre(const struct ChppWwanCellInfoResult * in,struct chreWwanCellInfoResult * out,size_t inSize)596 static bool chppWwanConvertCellInfoResultToChre(
597 const struct ChppWwanCellInfoResult *in, struct chreWwanCellInfoResult *out,
598 size_t inSize) {
599 out->version = CHRE_WWAN_CELL_INFO_RESULT_VERSION;
600 out->errorCode = in->errorCode;
601 out->cellInfoCount = in->cellInfoCount;
602 out->reserved = 0;
603 out->cookie = 0;
604
605 if (in->cells.length == 0) {
606 out->cells = NULL;
607 } else {
608 if (in->cells.offset + in->cells.length > inSize ||
609 in->cells.length !=
610 in->cellInfoCount * sizeof(struct ChppWwanCellInfo)) {
611 return false;
612 }
613
614 const struct ChppWwanCellInfo *cellsIn = (const struct ChppWwanCellInfo *)&(
615 (const uint8_t *)in)[in->cells.offset];
616
617 struct chreWwanCellInfo *cellsOut =
618 chppMalloc(in->cellInfoCount * sizeof(struct chreWwanCellInfo));
619 if (cellsOut == NULL) {
620 return false;
621 }
622
623 for (size_t i = 0; i < in->cellInfoCount; i++) {
624 if (!chppWwanConvertCellInfoToChre(&cellsIn[i], &cellsOut[i])) {
625 return false;
626 }
627 }
628 out->cells = cellsOut;
629 }
630
631 return true;
632 }
633
634 // Decoding (CHPP --> CHRE) top-level functions
635
chppWwanCellInfoResultToChre(const struct ChppWwanCellInfoResult * in,size_t inSize)636 struct chreWwanCellInfoResult *chppWwanCellInfoResultToChre(
637 const struct ChppWwanCellInfoResult *in, size_t inSize) {
638 struct chreWwanCellInfoResult *out = NULL;
639
640 if (inSize >= sizeof(struct ChppWwanCellInfoResult)) {
641 out = chppMalloc(sizeof(struct chreWwanCellInfoResult));
642 if (out != NULL) {
643 if (!chppWwanConvertCellInfoResultToChre(in, out, inSize)) {
644 CHPP_FREE_AND_NULLIFY(out);
645 }
646 }
647 }
648
649 return out;
650 }
651