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