1 /*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "at_network.h"
17
18 #include <signal.h>
19
20 #include "hril_notification.h"
21 #include "vendor_report.h"
22 #include "vendor_util.h"
23
24 #define NUM_COUNT 3
25 #define TIME_VALUE_LEN 30
26
27 static struct ReportInfo g_reportInfoForOperListToUse;
28 static pthread_mutex_t g_networkSearchInformationMutex = PTHREAD_MUTEX_INITIALIZER;
29
30 struct ResponseAck {
31 ResponseInfo *responseInfo;
32 uint8_t *respDataPointer;
33 int32_t respDataLen;
34 };
35
36 // RadioAccessFamily defines
37 const int32_t RAF_UNKNOWN = 1 << RADIO_TECHNOLOGY_UNKNOWN;
38 const int32_t RAF_GSM = 1 << RADIO_TECHNOLOGY_GSM;
39 const int32_t RAF_1XRTT = 1 << RADIO_TECHNOLOGY_1XRTT;
40 const int32_t RAF_WCDMA = 1 << RADIO_TECHNOLOGY_WCDMA;
41 const int32_t RAF_HSPA = 1 << RADIO_TECHNOLOGY_HSPA;
42 const int32_t RAF_HSPAP = 1 << RADIO_TECHNOLOGY_HSPAP;
43 const int32_t RAF_TD_SCDMA = 1 << RADIO_TECHNOLOGY_TD_SCDMA;
44 const int32_t RAF_EVDO = 1 << RADIO_TECHNOLOGY_EVDO;
45 const int32_t RAF_EHRPD = 1 << RADIO_TECHNOLOGY_EHRPD;
46 const int32_t RAF_LTE = 1 << RADIO_TECHNOLOGY_LTE;
47 const int32_t RAF_LTE_CA = 1 << RADIO_TECHNOLOGY_LTE_CA;
48 const int32_t RAF_NR = 1 << RADIO_TECHNOLOGY_NR;
49
50 // Group
51 const int32_t GSM = RAF_GSM;
52 const int32_t CDMA = RAF_1XRTT;
53 const int32_t EVDO = RAF_EVDO | RAF_EHRPD;
54 const int32_t HS = RAF_WCDMA | RAF_HSPA | RAF_HSPAP;
55 const int32_t WCDMA = HS;
56 const int32_t LTE = RAF_LTE | RAF_LTE_CA;
57 const int32_t NR = RAF_NR;
58
59 // NG
60 const int32_t RAF_2G = GSM | CDMA;
61 const int32_t RAF_3G = WCDMA | EVDO | RAF_TD_SCDMA;
62 const int32_t RAF_4G = LTE;
63 const int32_t RAF_5G = NR;
64 const int32_t RAF_AUTO = RAF_2G | RAF_3G | RAF_4G | RAF_5G;
65 const size_t TIME_VALUE_OFFSET = 2;
66 const int32_t ADD_LENGTH = 3;
67
GetResponseErrorCode(ResponseInfo * pResponseInfo)68 static int32_t GetResponseErrorCode(ResponseInfo *pResponseInfo)
69 {
70 char *pLine = NULL;
71 int32_t ret = HRIL_ERR_GENERIC_FAILURE;
72 if (pResponseInfo && pResponseInfo->result) {
73 pLine = pResponseInfo->result;
74 SkipATPrefix(&pLine);
75 NextInt(&pLine, &ret);
76 }
77
78 if (ret == -1) {
79 ret = HRIL_ERR_INVALID_RESPONSE;
80 }
81 TELEPHONY_LOGD("networks response error code: %{public}d", ret);
82 return ret;
83 }
84
ResponseNetworkReport(int32_t slotId,const ReqDataInfo * requestInfo,int32_t err,struct ResponseAck * respDataAck)85 static int32_t ResponseNetworkReport(
86 int32_t slotId, const ReqDataInfo *requestInfo, int32_t err, struct ResponseAck *respDataAck)
87 {
88 if (requestInfo == NULL) {
89 TELEPHONY_LOGE("requestInfo is nullptr!");
90 return HRIL_ERR_GENERIC_FAILURE;
91 }
92 if (respDataAck == NULL) {
93 TELEPHONY_LOGE("respDataAck is nullptr!");
94 return HRIL_ERR_GENERIC_FAILURE;
95 }
96 if (err < HRIL_ERR_SUCCESS) {
97 err = HRIL_ERR_GENERIC_FAILURE;
98 }
99 struct ReportInfo reportInfo;
100 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
101 OnNetworkReport(slotId, reportInfo, (const uint8_t *)(respDataAck->respDataPointer), respDataAck->respDataLen);
102 if (respDataAck->responseInfo != NULL) {
103 FreeResponseInfo(respDataAck->responseInfo);
104 }
105 return err;
106 }
107
ConvertActToRadioTech(HRilActTech actType)108 static HRilRadioTech ConvertActToRadioTech(HRilActTech actType)
109 {
110 switch (actType) {
111 case HRIL_RADIO_GSM:
112 case HRIL_RADIO_GSM_COMPACT:
113 case HRIL_RADIO_EGPRS:
114 return RADIO_TECHNOLOGY_GSM;
115 case HRIL_RADIO_HSDPA_HSUPA:
116 case HRIL_RADIO_HSDPA:
117 case HRIL_RADIO_HSUPA:
118 return RADIO_TECHNOLOGY_HSPA;
119 case HRIL_RADIO_HSPAP:
120 return RADIO_TECHNOLOGY_HSPAP;
121 case HRIL_RADIO_UTRAN:
122 return RADIO_TECHNOLOGY_WCDMA;
123 case HRIL_RADIO_EUTRAN:
124 return RADIO_TECHNOLOGY_LTE;
125 case HRIL_RADIO_CDMA:
126 case HRIL_RADIO_CDMA_IS95A:
127 case HRIL_RADIO_CDMA_IS95B:
128 return RADIO_TECHNOLOGY_1XRTT;
129 case HRIL_RADIO_CDMA_EVDO_0:
130 case HRIL_RADIO_CDMA_EVDO_A:
131 case HRIL_RADIO_CDMA_EVDO_B:
132 return RADIO_TECHNOLOGY_EVDO;
133 case HRIL_RADIO_CDMA_EHRPD:
134 return RADIO_TECHNOLOGY_EHRPD;
135 case HRIL_RADIO_TDSCDMA:
136 return RADIO_TECHNOLOGY_TD_SCDMA;
137 case HRIL_RADIO_LTE_CA:
138 return RADIO_TECHNOLOGY_LTE_CA;
139 case HRIL_RADIO_NR:
140 return RADIO_TECHNOLOGY_NR;
141 default:
142 return RADIO_TECHNOLOGY_UNKNOWN;
143 }
144 }
145
FindSemicolonCharNum(const char * srcStr)146 static int32_t FindSemicolonCharNum(const char *srcStr)
147 {
148 char *str = (char *)srcStr;
149 if (str == NULL) {
150 TELEPHONY_LOGE("Semicolon srcStr parameter is null.");
151 return -1;
152 }
153 if (*str == '\0') {
154 return -1;
155 }
156 int32_t charNum = 0;
157 while (*str != '\0') {
158 if (*str == ';') {
159 charNum++;
160 }
161 str++;
162 }
163 return charNum;
164 }
165
ConvertIntToHRilRegStatus(int32_t reg)166 static HRilRegStatus ConvertIntToHRilRegStatus(int32_t reg)
167 {
168 if ((reg >= NO_REG_MT_NO_SEARCH) && (reg <= REG_MT_EMERGENCY)) {
169 return (HRilRegStatus)reg;
170 } else {
171 return REG_MT_UNKNOWN;
172 }
173 }
174
ExtractRegStatus(const char * s,const HRilRegStatusInfo * hrilRegInfo)175 static int32_t ExtractRegStatus(const char *s, const HRilRegStatusInfo *hrilRegInfo)
176 {
177 char *str = (char *)s;
178 HRilRegStatusInfo *regStateInfo = (HRilRegStatusInfo *)hrilRegInfo;
179 int32_t info[MAX_5GREG_INFO_ITEM] = {0, 0, 0, RADIO_TECHNOLOGY_INVALID, 0, 0, 0};
180 const int32_t FORMAT_ONE_COMMA_NUM = 0;
181 const int32_t FORMAT_TWO_COMMA_NUM = 3;
182 const int32_t FORMAT_TWO_5G_COMMA_NUM = 6;
183 int32_t commaNum = FindCommaCharNum(str);
184 if (NextInt(&str, &(info[REG_STAT_POS])) != 0) {
185 return HRIL_ERR_INVALID_RESPONSE;
186 }
187 if (commaNum == FORMAT_ONE_COMMA_NUM) {
188 } else if ((commaNum == FORMAT_TWO_COMMA_NUM) || (commaNum == FORMAT_TWO_5G_COMMA_NUM)) {
189 if (NextIntFromHex(&str, &(info[REG_LAC_POS])) != 0) {
190 return HRIL_ERR_INVALID_RESPONSE;
191 }
192 if (NextIntFromHex(&str, &(info[REG_CELL_ID_POS])) != 0) {
193 return HRIL_ERR_INVALID_RESPONSE;
194 }
195 if (NextInt(&str, &(info[REG_ACT_POS])) != 0) {
196 return HRIL_ERR_INVALID_RESPONSE;
197 }
198 if (commaNum == FORMAT_TWO_5G_COMMA_NUM) {
199 if (NextInt(&str, &(info[REG_NR_AVAILABLE_POS])) != 0) {
200 return HRIL_ERR_INVALID_RESPONSE;
201 }
202 if (NextInt(&str, &(info[REG_EN_DC_AVAILABLE_POS])) != 0) {
203 return HRIL_ERR_INVALID_RESPONSE;
204 }
205 if (NextInt(&str, &(info[REG_DC_NR_RESTRICTED_POS])) != 0) {
206 return HRIL_ERR_INVALID_RESPONSE;
207 }
208 }
209 } else {
210 return HRIL_ERR_INVALID_RESPONSE;
211 }
212 regStateInfo->regStatus = ConvertIntToHRilRegStatus(info[REG_STAT_POS]);
213 regStateInfo->lacCode = info[REG_LAC_POS];
214 regStateInfo->cellId = info[REG_CELL_ID_POS];
215 regStateInfo->actType = ConvertActToRadioTech((HRilActTech)info[REG_ACT_POS]);
216 regStateInfo->isNrAvailable = ((info[REG_NR_AVAILABLE_POS] == 0) ? 0 : 1);
217 regStateInfo->isEnDcAvailable = ((info[REG_EN_DC_AVAILABLE_POS] == 0) ? 0 : 1);
218 regStateInfo->isDcNrRestricted = ((info[REG_DC_NR_RESTRICTED_POS] == 0) ? 0 : 1);
219 return HRIL_ERR_SUCCESS;
220 }
221
ParseRegStatusStr(const char * srcStr,HRilRegStatusInfo * hrilRegInfo)222 static int32_t ParseRegStatusStr(const char *srcStr, HRilRegStatusInfo *hrilRegInfo)
223 {
224 if (srcStr == NULL || hrilRegInfo == NULL) {
225 return HRIL_ERR_INVALID_PARAMETER;
226 }
227 if (ReportStrWith(srcStr, "+CREG:")) {
228 hrilRegInfo->regType = CS_REG_TYPE;
229 } else if (ReportStrWith(srcStr, "+CGREG:")) {
230 hrilRegInfo->regType = PS_REG_TYPE;
231 } else {
232 return HRIL_ERR_INVALID_RESPONSE;
233 }
234 char *str = (char *)srcStr;
235 if (SkipATPrefix(&str) < 0) {
236 TELEPHONY_LOGE("skip failed: [%{public}s]", str);
237 return HRIL_ERR_INVALID_RESPONSE;
238 }
239 const int32_t NUM_ONE = 1;
240 const int32_t NUM_THREE = 3;
241 const int32_t NUM_FOUR = 4;
242 const int32_t NUM_SIX = 6;
243 const int32_t NUM_SEVEN = 7;
244 hrilRegInfo->notifyMode = REG_NOTIFY_STAT_LAC_CELLID;
245 hrilRegInfo->regMsgType = REG_RESPONSE_TYPE;
246 int32_t commaNum = FindCommaCharNum(str);
247 if (commaNum == 0) {
248 hrilRegInfo->regMsgType = REG_NOTIFY_TYPE;
249 hrilRegInfo->notifyMode = REG_NOTIFY_STAT_ONLY;
250 } else if (commaNum == NUM_ONE) {
251 hrilRegInfo->notifyMode = REG_NOTIFY_STAT_ONLY;
252 } else if (commaNum == NUM_FOUR || commaNum == NUM_SEVEN) {
253 } else if (commaNum == NUM_THREE || commaNum == NUM_SIX) {
254 hrilRegInfo->regMsgType = REG_NOTIFY_TYPE;
255 } else {
256 hrilRegInfo->regMsgType = REG_NOTIFY_TYPE;
257 return HRIL_ERR_INVALID_RESPONSE;
258 }
259 int32_t skip = 0;
260 if (hrilRegInfo->regMsgType == REG_RESPONSE_TYPE) {
261 if ((NextInt(&str, &skip)) != 0) {
262 TELEPHONY_LOGE("skip failed: [%{public}s]", str);
263 return HRIL_ERR_INVALID_RESPONSE;
264 }
265 if ((skip != (int32_t)REG_NOTIFY_STAT_LAC_CELLID) && (skip != (int32_t)REG_NOTIFY_STAT_ONLY)) {
266 TELEPHONY_LOGE("notifyType check failed: [%{public}d]", skip);
267 return HRIL_ERR_INVALID_RESPONSE;
268 }
269 }
270 return ExtractRegStatus(str, hrilRegInfo);
271 }
272
ProcessRegStatus(const char * s,const HRilRegStatusInfo * hrilRegStateInfo)273 int32_t ProcessRegStatus(const char *s, const HRilRegStatusInfo *hrilRegStateInfo)
274 {
275 char *str = (char *)s;
276 HRilRegStatusInfo *regStateInfo = (HRilRegStatusInfo *)hrilRegStateInfo;
277 if ((str == NULL) || (regStateInfo == NULL)) {
278 TELEPHONY_LOGE("ProcessRegStatus s or regStateInfo param is null");
279 return HRIL_ERR_NULL_POINT;
280 } else {
281 (void)memset_s(regStateInfo, sizeof(HRilRegStatusInfo), 0, sizeof(HRilRegStatusInfo));
282 return ParseRegStatusStr(str, regStateInfo);
283 }
284 }
285
ParseGetGsmSignalStrength(const char * line,HRilRssi * hrilRssi)286 static void ParseGetGsmSignalStrength(const char *line, HRilRssi *hrilRssi)
287 {
288 char *lineStr = (char *)line;
289 if (lineStr == NULL || hrilRssi == NULL) {
290 TELEPHONY_LOGE("line or hrilRssi is null!!!");
291 return;
292 }
293 NextInt(&lineStr, &hrilRssi->gsmRssi.rxlev);
294 NextInt(&lineStr, &hrilRssi->gsmRssi.ber);
295 hrilRssi->gsmRssi.rxlev = -hrilRssi->gsmRssi.rxlev;
296 }
297
ParseGetLteSignalStrength(const char * line,HRilRssi * hrilRssi)298 static void ParseGetLteSignalStrength(const char *line, HRilRssi *hrilRssi)
299 {
300 char *lineStr = (char *)line;
301 if (lineStr == NULL || hrilRssi == NULL) {
302 TELEPHONY_LOGE("line or hrilRssi is null!!!");
303 return;
304 }
305 NextInt(&lineStr, &hrilRssi->lteRssi.rxlev);
306 NextInt(&lineStr, &hrilRssi->lteRssi.rsrq);
307 NextInt(&lineStr, &hrilRssi->lteRssi.rsrp);
308 NextInt(&lineStr, &hrilRssi->lteRssi.snr);
309 hrilRssi->lteRssi.rxlev = -hrilRssi->lteRssi.rxlev;
310 hrilRssi->lteRssi.rsrq = -hrilRssi->lteRssi.rsrq;
311 hrilRssi->lteRssi.rsrp = -hrilRssi->lteRssi.rsrp;
312 }
313
ParseGetWcdmaSignalStrength(const char * line,HRilRssi * hrilRssi)314 static void ParseGetWcdmaSignalStrength(const char *line, HRilRssi *hrilRssi)
315 {
316 char *lineStr = (char *)line;
317 if (lineStr == NULL || hrilRssi == NULL) {
318 TELEPHONY_LOGE("line or hrilRssi is null!!!");
319 return;
320 }
321 NextInt(&lineStr, &hrilRssi->wcdmaRssi.rxlev);
322 NextInt(&lineStr, &hrilRssi->wcdmaRssi.ecio);
323 NextInt(&lineStr, &hrilRssi->wcdmaRssi.rscp);
324 NextInt(&lineStr, &hrilRssi->wcdmaRssi.ber);
325 hrilRssi->wcdmaRssi.rxlev = -hrilRssi->wcdmaRssi.rxlev;
326 hrilRssi->wcdmaRssi.ecio = -hrilRssi->wcdmaRssi.ecio;
327 hrilRssi->wcdmaRssi.rscp = -hrilRssi->wcdmaRssi.rscp;
328 }
329
ParseGetTdScdmaSignalStrength(const char * line,HRilRssi * hrilRssi)330 static void ParseGetTdScdmaSignalStrength(const char *line, HRilRssi *hrilRssi)
331 {
332 char *lineStr = (char *)line;
333 if (lineStr == NULL || hrilRssi == NULL) {
334 TELEPHONY_LOGE("line or hrilRssi is null!!!");
335 return;
336 }
337 NextInt(&lineStr, &hrilRssi->tdScdmaRssi.rscp);
338 hrilRssi->tdScdmaRssi.rscp = -hrilRssi->tdScdmaRssi.rscp;
339 }
340
ParseGetCdmaSignalStrength(const char * line,HRilRssi * hrilRssi)341 static void ParseGetCdmaSignalStrength(const char *line, HRilRssi *hrilRssi)
342 {
343 char *lineStr = (char *)line;
344 if (lineStr == NULL || hrilRssi == NULL) {
345 TELEPHONY_LOGE("line or hrilRssi is null!!!");
346 return;
347 }
348 NextInt(&lineStr, &hrilRssi->cdmaRssi.absoluteRssi);
349 NextInt(&lineStr, &hrilRssi->cdmaRssi.ecno);
350 hrilRssi->cdmaRssi.absoluteRssi = -hrilRssi->cdmaRssi.absoluteRssi;
351 hrilRssi->cdmaRssi.ecno = -hrilRssi->cdmaRssi.ecno;
352 }
353
ParseGetNrSignalStrength(const char * line,HRilRssi * hrilRssi)354 static void ParseGetNrSignalStrength(const char *line, HRilRssi *hrilRssi)
355 {
356 char *lineStr = (char *)line;
357 if (lineStr == NULL || hrilRssi == NULL) {
358 TELEPHONY_LOGE("line or hrilRssi is null!!!");
359 return;
360 }
361 NextInt(&lineStr, &hrilRssi->nrRssi.rsrp);
362 NextInt(&lineStr, &hrilRssi->nrRssi.rsrq);
363 NextInt(&lineStr, &hrilRssi->nrRssi.sinr);
364 hrilRssi->nrRssi.rsrp = -hrilRssi->nrRssi.rsrp;
365 hrilRssi->nrRssi.rsrq = -hrilRssi->nrRssi.rsrq;
366 }
367
ProcessParamSignalStrength(const char * result,HRilRssi * hrilRssi)368 int32_t ProcessParamSignalStrength(const char *result, HRilRssi *hrilRssi)
369 {
370 char *resultStr = (char *)result;
371 char *c = NULL;
372 int32_t tmp = 0;
373 int32_t err = SkipATPrefix(&resultStr);
374 if (err < 0) {
375 TELEPHONY_LOGE("skip failed: [%{public}s]", resultStr);
376 return err;
377 }
378 err = NextInt(&resultStr, &tmp);
379 TELEPHONY_LOGD("ProcessParamSignalStrength enter -->, result %{public}s", resultStr);
380 if (err < 0) {
381 TELEPHONY_LOGE("read failed: %{public}d", err);
382 return err;
383 }
384 err = NextInt(&resultStr, &tmp);
385 TELEPHONY_LOGD("ProcessParamSignalStrength enter -->, result %{public}s", resultStr);
386 if (err < 0) {
387 TELEPHONY_LOGE("read failed: %{public}d", err);
388 return err;
389 }
390 err = NextStr(&resultStr, &c);
391 TELEPHONY_LOGD("ProcessParamSignalStrength enter -->, result %{public}s", resultStr);
392 if (err < 0) {
393 TELEPHONY_LOGE("read failed: %{public}d", err);
394 return err;
395 }
396 if (!strcmp(c, "GSM")) {
397 TELEPHONY_LOGD("ProcessParamSignalStrength enter GSM-->, result %{public}s", resultStr);
398 ParseGetGsmSignalStrength(resultStr, hrilRssi);
399 } else if (!strcmp(c, "LTE")) {
400 TELEPHONY_LOGD("ProcessParamSignalStrength enter LTE-->, result %{public}s", resultStr);
401 ParseGetLteSignalStrength(resultStr, hrilRssi);
402 } else if (!strcmp(c, "WCDMA")) {
403 TELEPHONY_LOGD("ProcessParamSignalStrength enter WCDMA-->, result %{public}s", resultStr);
404 ParseGetWcdmaSignalStrength(resultStr, hrilRssi);
405 } else if (!strcmp(c, "TDSCDMA")) {
406 TELEPHONY_LOGD("ProcessParamSignalStrength enter TDSCDMA-->, result %{public}s", resultStr);
407 ParseGetTdScdmaSignalStrength(resultStr, hrilRssi);
408 } else if (!strcmp(c, "CDMA")) {
409 TELEPHONY_LOGD("ProcessParamSignalStrength enter CDMA-->, result %{public}s", resultStr);
410 ParseGetCdmaSignalStrength(resultStr, hrilRssi);
411 } else if (!strcmp(c, "NR")) {
412 TELEPHONY_LOGD("ProcessParamSignalStrength enter NR-->, result %{public}s", resultStr);
413 ParseGetNrSignalStrength(resultStr, hrilRssi);
414 }
415 return HRIL_ERR_SUCCESS;
416 }
417
ProcessParamSignalStrengthNotify(const char * result,HRilRssi * hrilRssi)418 int32_t ProcessParamSignalStrengthNotify(const char *result, HRilRssi *hrilRssi)
419 {
420 char *resultStr = (char *)result;
421 char *c = NULL;
422 int32_t err = SkipATPrefix(&resultStr);
423 TELEPHONY_LOGD("ProcessParamSignalStrengthNotify enter -->, resultStr %{public}s", resultStr);
424 if (err < 0) {
425 TELEPHONY_LOGE("skip failed: %{public}s", resultStr);
426 return err;
427 }
428
429 err = NextStr(&resultStr, &c);
430 if (err < 0) {
431 TELEPHONY_LOGE("read failed: %{public}d", err);
432 return err;
433 }
434
435 if (!strcmp(c, "GSM")) {
436 ParseGetGsmSignalStrength(resultStr, hrilRssi);
437 } else if (!strcmp(c, "LTE")) {
438 ParseGetLteSignalStrength(resultStr, hrilRssi);
439 } else if (!strcmp(c, "WCDMA")) {
440 ParseGetWcdmaSignalStrength(resultStr, hrilRssi);
441 } else if (!strcmp(c, "TDSCDMA")) {
442 ParseGetTdScdmaSignalStrength(resultStr, hrilRssi);
443 } else if (!strcmp(c, "CDMA")) {
444 ParseGetCdmaSignalStrength(resultStr, hrilRssi);
445 } else if (!strcmp(c, "NR")) {
446 ParseGetNrSignalStrength(resultStr, hrilRssi);
447 }
448 return HRIL_ERR_SUCCESS;
449 }
450
ReqGetSignalStrength(const ReqDataInfo * requestInfo)451 void ReqGetSignalStrength(const ReqDataInfo *requestInfo)
452 {
453 if (requestInfo == NULL) {
454 return;
455 }
456 int32_t err = HRIL_ERR_SUCCESS;
457 struct ReportInfo reportInfo;
458 const int32_t REPORT_SIZE = 20;
459 ResponseInfo *responseInfo = NULL;
460 char *result = NULL;
461 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
462 int32_t ret = SendCommandLock("AT^HCSQ?", "^HCSQ:", DEFAULT_TIMEOUT, &responseInfo);
463 if (responseInfo == NULL) {
464 TELEPHONY_LOGE("responseInfo is nullptr!");
465 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
466 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
467 return;
468 }
469
470 if (ret != 0 || !responseInfo->success) {
471 err = GetResponseErrorCode(responseInfo);
472 TELEPHONY_LOGE("AT^HCSQ send failed");
473 }
474 if (responseInfo->head != NULL) {
475 result = responseInfo->head->data;
476 }
477 if (result == NULL) {
478 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
479 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
480 FreeResponseInfo(responseInfo);
481 return;
482 }
483 HRilRssi hrilRssi = {0};
484 if (strlen(result) > REPORT_SIZE) {
485 ret = ProcessParamSignalStrength(result, &hrilRssi);
486 } else {
487 ret = ProcessParamSignalStrengthNotify(result, &hrilRssi);
488 }
489 if (ret != 0) {
490 err = HRIL_ERR_GENERIC_FAILURE;
491 TELEPHONY_LOGE("SignalStrength is null!");
492 }
493
494 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
495 OnNetworkReport(requestInfo->slotId, reportInfo, (const uint8_t *)&hrilRssi, sizeof(HRilRssi));
496 FreeResponseInfo(responseInfo);
497 }
498
ReqGetCsRegStatus(const ReqDataInfo * requestInfo)499 void ReqGetCsRegStatus(const ReqDataInfo *requestInfo)
500 {
501 if (requestInfo == NULL) {
502 return;
503 }
504 int32_t err = HRIL_ERR_SUCCESS;
505 struct ReportInfo reportInfo;
506 ResponseInfo *responseInfo = NULL;
507 char *result = NULL;
508
509 int32_t ret = SendCommandLock("AT+CREG?", "+CREG:", DEFAULT_TIMEOUT, &responseInfo);
510 if (responseInfo == NULL) {
511 TELEPHONY_LOGE("responseInfo is nullptr!");
512 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
513 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
514 return;
515 }
516 if (ret != 0 || !responseInfo->success) {
517 err = GetResponseErrorCode(responseInfo);
518 TELEPHONY_LOGE("send AT CMD failed!");
519 }
520 if (responseInfo->head != NULL) {
521 result = responseInfo->head->data;
522 }
523 HRilRegStatusInfo regStatusInfo = {0};
524 ret = ProcessRegStatus(result, ®StatusInfo);
525 if (ret != 0) {
526 TELEPHONY_LOGE("ReqGetCsRegStatus CREG format unexpected: %{public}s", result);
527 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
528 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
529 FreeResponseInfo(responseInfo);
530 return;
531 }
532 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
533 OnNetworkReport(requestInfo->slotId, reportInfo, (const uint8_t *)®StatusInfo, sizeof(HRilRegStatusInfo));
534 FreeResponseInfo(responseInfo);
535 }
536
ReqGetPsRegStatus(const ReqDataInfo * requestInfo)537 void ReqGetPsRegStatus(const ReqDataInfo *requestInfo)
538 {
539 if (requestInfo == NULL) {
540 return;
541 }
542 int32_t err = HRIL_ERR_SUCCESS;
543 struct ReportInfo reportInfo;
544 ResponseInfo *responseInfo = NULL;
545 char *result = NULL;
546
547 int32_t ret = SendCommandLock("AT+CGREG?", "+CGREG:", DEFAULT_TIMEOUT, &responseInfo);
548 if (responseInfo == NULL) {
549 TELEPHONY_LOGE("responseInfo is nullptr!");
550 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
551 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
552 return;
553 }
554 if (ret != 0 || responseInfo->success == 0) {
555 err = GetResponseErrorCode(responseInfo);
556 TELEPHONY_LOGE("send AT CMD failed!");
557 }
558 if (responseInfo->head != NULL) {
559 result = responseInfo->head->data;
560 }
561 HRilRegStatusInfo regStatusInfo = {0};
562 ret = ProcessRegStatus(result, ®StatusInfo);
563 if (ret != 0) {
564 TELEPHONY_LOGE("ReqGetPsRegStatus CGREG format unexpected: %{public}s", result);
565 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
566 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
567 FreeResponseInfo(responseInfo);
568 return;
569 }
570 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
571 OnNetworkReport(requestInfo->slotId, reportInfo, (const uint8_t *)®StatusInfo, sizeof(HRilRegStatusInfo));
572 FreeResponseInfo(responseInfo);
573 }
574
ReqGetOperatorInfo(const ReqDataInfo * requestInfo)575 void ReqGetOperatorInfo(const ReqDataInfo *requestInfo)
576 {
577 if (requestInfo == NULL) {
578 return;
579 }
580 int32_t err = HRIL_ERR_SUCCESS;
581 struct ReportInfo reportInfo;
582 ResponseInfo *responseInfo = NULL;
583 char *result = NULL;
584 char *response[NUM_COUNT] = { "", "", "" };
585
586 int32_t ret = SendCommandLock(
587 "AT+COPS=3,0;+COPS?;+COPS=3,1;+COPS?;+COPS=3,2;+COPS?", "+COPS:", DEFAULT_TIMEOUT, &responseInfo);
588 if (responseInfo == NULL) {
589 TELEPHONY_LOGE("responseInfo is nullptr!");
590 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
591 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
592 return;
593 }
594 if (ret != 0 || !responseInfo->success) {
595 err = GetResponseErrorCode(responseInfo);
596 TELEPHONY_LOGE("send AT CMD failed!");
597 }
598 Line *pLine = responseInfo->head;
599 for (int32_t i = 0; pLine != NULL; i++, pLine = pLine->next) {
600 int32_t skip = 0;
601 result = pLine->data;
602 SkipATPrefix(&result);
603 ret = NextInt(&result, &skip);
604 if (ret == -1) {
605 TELEPHONY_LOGE("read failed");
606 break;
607 }
608 ret = NextInt(&result, &skip);
609 if (ret == -1) {
610 TELEPHONY_LOGE("read failed");
611 break;
612 }
613 ret = NextStr(&result, &response[i]);
614 TELEPHONY_LOGD("result[%{public}d]: %{public}s", i, response[i]);
615 if (ret == -1) {
616 response[i] = "";
617 TELEPHONY_LOGE("read failed");
618 break;
619 }
620 }
621 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
622 OnNetworkReport(requestInfo->slotId, reportInfo, (const uint8_t *)response, NUM_COUNT);
623 FreeResponseInfo(responseInfo);
624 }
625
MoveLeftBracket(char ** pStr)626 static int32_t MoveLeftBracket(char **pStr)
627 {
628 if (*pStr == NULL) {
629 TELEPHONY_LOGE("pStr is nullptr");
630 return -1;
631 }
632 *pStr = strchr(*pStr, '(');
633 if (*pStr == NULL) {
634 TELEPHONY_LOGE("pStr is nullptr");
635 return -1;
636 }
637 (*pStr)++;
638 return 0;
639 }
640
GetNetworkSearchInformationPause(void)641 void GetNetworkSearchInformationPause(void)
642 {
643 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
644 pthread_mutex_lock(&g_networkSearchInformationMutex);
645 g_reportInfoForOperListToUse.error = HRIL_ERR_NETWORK_SEARCHING_INTERRUPTED;
646 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
647 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId, g_reportInfoForOperListToUse, NULL, 0);
648 }
649 SetAtPauseFlag(false);
650 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
651 g_reportInfoForOperListToUse.requestInfo = NULL;
652 }
653 pthread_mutex_unlock(&g_networkSearchInformationMutex);
654 }
655
PerformTimeOut(int32_t sigFlag)656 void PerformTimeOut(int32_t sigFlag)
657 {
658 if (SIGALRM == sigFlag) {
659 pthread_mutex_lock(&g_networkSearchInformationMutex);
660 bool sendFlag = GetAtPauseFlag();
661 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
662 if (sendFlag) {
663 g_reportInfoForOperListToUse.error = HRIL_ERR_NETWORK_SEARCH_TIMEOUT;
664 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
665 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId,
666 g_reportInfoForOperListToUse, NULL, 0);
667 }
668 SetAtPauseFlag(false);
669 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
670 g_reportInfoForOperListToUse.requestInfo = NULL;
671 }
672 TELEPHONY_LOGI("ReqGetNetworkSearchInformation response timeout!");
673 }
674 pthread_mutex_unlock(&g_networkSearchInformationMutex);
675 }
676 return;
677 }
678
ReqGetNetworkSearchInformation(const ReqDataInfo * requestInfo)679 void ReqGetNetworkSearchInformation(const ReqDataInfo *requestInfo)
680 {
681 if (requestInfo == NULL) {
682 return;
683 }
684 ResponseInfo *responseInfo = NULL;
685 const int32_t SECOND = 120;
686 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
687 pthread_mutex_lock(&g_networkSearchInformationMutex);
688 alarm(0);
689 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
690 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NETWORK_SEARCHING, HRIL_RESPONSE, 0);
691 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
692 pthread_mutex_unlock(&g_networkSearchInformationMutex);
693 TELEPHONY_LOGE("ReqGetNetworkSearchInformation repeat Send!");
694 return;
695 }
696 if (signal(SIGALRM, PerformTimeOut) == SIG_ERR) {
697 TELEPHONY_LOGE("ReqGetNetworkSearchInformation signal PerformTimeOut is SIG_ERR!");
698 pthread_mutex_unlock(&g_networkSearchInformationMutex);
699 return;
700 }
701 int32_t ret = SendCommandNetWorksLock("AT+COPS=?", "+COPS:", DEFAULT_TIMEOUT, &responseInfo);
702
703 g_reportInfoForOperListToUse = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
704 if ((ret != 0 && ret != AT_ERR_WAITING) || (responseInfo != NULL && !responseInfo->success)) {
705 TELEPHONY_LOGE("send AT CMD failed!");
706 SetAtPauseFlag(false);
707 g_reportInfoForOperListToUse.error = GetResponseErrorCode(responseInfo);
708 OnNetworkReport(requestInfo->slotId, g_reportInfoForOperListToUse, NULL, 1);
709 if (responseInfo != NULL) {
710 FreeResponseInfo(responseInfo);
711 }
712 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
713 g_reportInfoForOperListToUse.requestInfo = NULL;
714 }
715 pthread_mutex_unlock(&g_networkSearchInformationMutex);
716 return;
717 }
718 alarm(SECOND);
719 if (responseInfo != NULL) {
720 FreeResponseInfo(responseInfo);
721 }
722 pthread_mutex_unlock(&g_networkSearchInformationMutex);
723 SetWatchFunction(GetNetworkSearchInformationPause);
724 }
725
ParseOperInfoItem(char ** lineInfo,char ** const longNameInfo,char ** const shortNameInfo,char ** const numericInfo)726 static int32_t ParseOperInfoItem(
727 char **lineInfo, char **const longNameInfo, char **const shortNameInfo, char **const numericInfo)
728 {
729 if (lineInfo == NULL || longNameInfo == NULL || shortNameInfo == NULL || numericInfo == NULL) {
730 return -1;
731 }
732 char *data = *lineInfo;
733 char **longNameInfoStr = (char **)longNameInfo;
734 char **shortNameInfoStr = (char **)shortNameInfo;
735 char **numericInfoStr = (char **)numericInfo;
736 int32_t ret = NextStr(&data, longNameInfoStr);
737 if (ret < 0) {
738 return -1;
739 }
740 TELEPHONY_LOGD("ok , longName:%{public}s", *longNameInfoStr);
741
742 ret = NextStr(&data, shortNameInfoStr);
743 if (ret < 0) {
744 return -1;
745 }
746 TELEPHONY_LOGD("ok , shortName:%{public}s", *shortNameInfoStr);
747
748 ret = NextStr(&data, numericInfoStr);
749 if (ret < 0) {
750 return -1;
751 }
752 TELEPHONY_LOGD("ok , numeric:%{public}s", *numericInfoStr);
753 *lineInfo = data;
754 return 0;
755 }
756
ParseOperListInfo(const char * lineInfo,int32_t count,AvailableOperInfo * pOperInfo,AvailableOperInfo ** ppOperInfo)757 int32_t ParseOperListInfo(
758 const char *lineInfo, int32_t count, AvailableOperInfo *pOperInfo, AvailableOperInfo **ppOperInfo)
759 {
760 if (lineInfo == NULL || pOperInfo == NULL) {
761 return 0;
762 }
763 int32_t state = 0;
764 int32_t rat = 0;
765 int32_t operCount = 0;
766 char *line = (char *)lineInfo;
767 int32_t item = count;
768 for (int32_t i = 0; i < item && operCount < item; i++) {
769 int32_t ret = MoveLeftBracket(&line);
770 if (ret < 0) {
771 break;
772 }
773 ret = NextInt(&line, &state);
774 if (ret < 0) {
775 break;
776 }
777 char *longName = NULL;
778 char *shortName = NULL;
779 char *numeric = NULL;
780 ret = ParseOperInfoItem(&line, &longName, &shortName, &numeric);
781 if (ret < 0) {
782 break;
783 }
784 ret = NextIntByRightBracket(&line, &rat);
785 if (ret < 0) {
786 break;
787 }
788 if (state > 0) {
789 pOperInfo[operCount].status = state;
790 TELEPHONY_LOGD("pOperInfo , status:%{public}d", pOperInfo[i].status);
791 pOperInfo[operCount].longName = longName;
792 TELEPHONY_LOGD("pOperInfo , longName:%{public}s", longName);
793 pOperInfo[operCount].numeric = numeric;
794 TELEPHONY_LOGD("pOperInfo , numeric:%{public}s", numeric);
795 pOperInfo[operCount].shortName = shortName;
796 TELEPHONY_LOGD("pOperInfo , shortName:%{public}s", shortName);
797 pOperInfo[operCount].rat = rat;
798 TELEPHONY_LOGD("pOperInfo , rat:%{public}d", rat);
799 operCount++;
800 }
801 }
802 return operCount;
803 }
804
ParseListItemNum(const char * list)805 int32_t ParseListItemNum(const char *list)
806 {
807 int32_t item = 0;
808 if (list == NULL) {
809 TELEPHONY_LOGI("ProcessOperListToUse result is null");
810 } else {
811 char *line = (char *)list;
812 while (*line != '\0') {
813 if (*line == ')') {
814 item++;
815 }
816 line++;
817 }
818 }
819 return item;
820 }
821
DealNetworkSearchInformation(int32_t operCount,AvailableOperInfo ** ppOperInfo,AvailableOperInfo * pOperInfo)822 static void DealNetworkSearchInformation(
823 int32_t operCount, AvailableOperInfo **ppOperInfo, AvailableOperInfo *pOperInfo)
824 {
825 if (operCount == 0) {
826 pthread_mutex_lock(&g_networkSearchInformationMutex);
827 SetAtPauseFlag(false);
828 alarm(0);
829 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
830 g_reportInfoForOperListToUse.error = HRIL_ERR_INVALID_RESPONSE;
831 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId, g_reportInfoForOperListToUse, NULL, 0);
832 g_reportInfoForOperListToUse.requestInfo = NULL;
833 }
834 pthread_mutex_unlock(&g_networkSearchInformationMutex);
835 } else {
836 pthread_mutex_lock(&g_networkSearchInformationMutex);
837 SetAtPauseFlag(false);
838 alarm(0);
839 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
840 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId, g_reportInfoForOperListToUse,
841 (const uint8_t *)ppOperInfo, operCount);
842 g_reportInfoForOperListToUse.requestInfo = NULL;
843 }
844 pthread_mutex_unlock(&g_networkSearchInformationMutex);
845 }
846 if (ppOperInfo != NULL) {
847 free(ppOperInfo);
848 }
849 if (pOperInfo != NULL) {
850 free(pOperInfo);
851 }
852 }
853
ErrorHandling(void)854 static int32_t ErrorHandling(void)
855 {
856 TELEPHONY_LOGE("This command resolution is not supported.");
857 return HRIL_ERR_GENERIC_FAILURE;
858 }
859
ParseCellInfoGsm(const char * str,CellInfo * ci)860 static int32_t ParseCellInfoGsm(const char *str, CellInfo *ci)
861 {
862 if (str == NULL || ci == NULL) {
863 return -1;
864 }
865 char *pStr = (char *)str;
866 char *pat = NULL;
867 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
868 TELEPHONY_LOGD("ParseCellInfoGsm %{public}s", pStr);
869 if (SkipATPrefix(&pStr) < 0) {
870 return ErrorHandling();
871 }
872 if (NextStr(&pStr, &pat) < 0) {
873 return ErrorHandling();
874 }
875 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.band) < 0) {
876 return ErrorHandling();
877 }
878 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.arfcn) < 0) {
879 return ErrorHandling();
880 }
881 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.bsic) < 0) {
882 return ErrorHandling();
883 }
884 if (NextIntFromHex(&pStr, &ci->ServiceCellParas.gsm.cellId) < 0) {
885 return ErrorHandling();
886 }
887 if (NextIntFromHex(&pStr, &ci->ServiceCellParas.gsm.lac) < 0) {
888 return ErrorHandling();
889 }
890 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.rxlev) < 0) {
891 return ErrorHandling();
892 }
893 ci->ratType = NETWORK_TYPE_GSM;
894 return HRIL_ERR_SUCCESS;
895 }
896
ParseCellInfoLte(const char * str,CellInfo * ci)897 static int32_t ParseCellInfoLte(const char *str, CellInfo *ci)
898 {
899 if (str == NULL || ci == NULL) {
900 return -1;
901 }
902 char *pStr = (char *)str;
903 char *pat = NULL;
904 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
905 TELEPHONY_LOGD("ParseCellInfoLte %{public}s", pStr);
906 if (SkipATPrefix(&pStr) < 0) {
907 return ErrorHandling();
908 }
909 if (NextStr(&pStr, &pat) < 0) {
910 return ErrorHandling();
911 }
912 if (NextInt(&pStr, &ci->ServiceCellParas.lte.arfcn) < 0) {
913 return ErrorHandling();
914 }
915 if (NextIntFromHex(&pStr, &ci->ServiceCellParas.lte.pci) < 0) {
916 return ErrorHandling();
917 }
918 if (NextInt(&pStr, &ci->ServiceCellParas.lte.rsrp) < 0) {
919 return ErrorHandling();
920 }
921 if (NextInt(&pStr, &ci->ServiceCellParas.lte.rsrq) < 0) {
922 return ErrorHandling();
923 }
924 if (NextInt(&pStr, &ci->ServiceCellParas.lte.rxlev) < 0) {
925 return ErrorHandling();
926 }
927 ci->ratType = NETWORK_TYPE_LTE;
928 return HRIL_ERR_SUCCESS;
929 }
930
ParseCellInfoWcdma(const char * str,CellInfo * ci)931 static int32_t ParseCellInfoWcdma(const char *str, CellInfo *ci)
932 {
933 if (str == NULL || ci == NULL) {
934 return -1;
935 }
936 char *pStr = (char *)str;
937 char *pat = NULL;
938 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
939 TELEPHONY_LOGD("ParseCellInfoWcdma %{public}s", pStr);
940 if (SkipATPrefix(&pStr) < 0) {
941 return ErrorHandling();
942 }
943 if (NextStr(&pStr, &pat) < 0) {
944 return ErrorHandling();
945 }
946 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.arfcn) < 0) {
947 return ErrorHandling();
948 }
949 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.psc) < 0) {
950 return ErrorHandling();
951 }
952 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.rscp) < 0) {
953 return ErrorHandling();
954 }
955 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.ecno) < 0) {
956 return ErrorHandling();
957 }
958 ci->ratType = NETWORK_TYPE_WCDMA;
959 return HRIL_ERR_SUCCESS;
960 }
961
ParseCellInfoCdma(const char * str,CellInfo * ci)962 static int32_t ParseCellInfoCdma(const char *str, CellInfo *ci)
963 {
964 if (str == NULL || ci == NULL) {
965 return -1;
966 }
967 char *pStr = (char *)str;
968 char *pat = NULL;
969 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
970 TELEPHONY_LOGD("ParseCellInfoCdma %{public}s", pStr);
971 if (SkipATPrefix(&pStr) < 0) {
972 return ErrorHandling();
973 }
974 if (NextStr(&pStr, &pat) < 0) {
975 return ErrorHandling();
976 }
977 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.systemId) < 0) {
978 return ErrorHandling();
979 }
980 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.networkId) < 0) {
981 return ErrorHandling();
982 }
983 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.baseId) < 0) {
984 return ErrorHandling();
985 }
986 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.zoneId) < 0) {
987 return ErrorHandling();
988 }
989 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.pilotPn) < 0) {
990 return ErrorHandling();
991 }
992 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.pilotStrength) < 0) {
993 return ErrorHandling();
994 }
995 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.channel) < 0) {
996 return ErrorHandling();
997 }
998 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.longitude) < 0) {
999 return ErrorHandling();
1000 }
1001 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.latitude) < 0) {
1002 return ErrorHandling();
1003 }
1004 ci->ratType = NETWORK_TYPE_CDMA;
1005 return HRIL_ERR_SUCCESS;
1006 }
1007
ParseCellInfoTdscdma(const char * str,CellInfo * ci)1008 static int32_t ParseCellInfoTdscdma(const char *str, CellInfo *ci)
1009 {
1010 if (str == NULL || ci == NULL) {
1011 return -1;
1012 }
1013 char *pStr = (char *)str;
1014 char *pat = NULL;
1015 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
1016 TELEPHONY_LOGD("ParseCellInfoTdscdma %{public}s", pStr);
1017 if (SkipATPrefix(&pStr) < 0) {
1018 return ErrorHandling();
1019 }
1020 if (NextStr(&pStr, &pat) < 0) {
1021 return ErrorHandling();
1022 }
1023 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.arfcn) < 0) {
1024 return ErrorHandling();
1025 }
1026 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.syncId) < 0) {
1027 return ErrorHandling();
1028 }
1029 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.sc) < 0) {
1030 return ErrorHandling();
1031 }
1032 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.cellId) < 0) {
1033 return ErrorHandling();
1034 }
1035 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.lac) < 0) {
1036 return ErrorHandling();
1037 }
1038 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.rscp) < 0) {
1039 return ErrorHandling();
1040 }
1041 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.drx) < 0) {
1042 return ErrorHandling();
1043 }
1044 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.rac) < 0) {
1045 return ErrorHandling();
1046 }
1047 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.cpid) < 0) {
1048 return ErrorHandling();
1049 }
1050 ci->ratType = NETWORK_TYPE_TDSCDMA;
1051 return HRIL_ERR_SUCCESS;
1052 }
1053
ParseCellInfoNr(const char * str,CellInfo * ci)1054 static int32_t ParseCellInfoNr(const char *str, CellInfo *ci)
1055 {
1056 if (str == NULL || ci == NULL) {
1057 return -1;
1058 }
1059 char *pStr = (char *)str;
1060 char *pat = NULL;
1061 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
1062 TELEPHONY_LOGD("ParseCellInfoNr %{public}s", pStr);
1063 if (SkipATPrefix(&pStr) < 0) {
1064 return ErrorHandling();
1065 }
1066 if (NextStr(&pStr, &pat) < 0) {
1067 return ErrorHandling();
1068 }
1069 if (NextInt(&pStr, &ci->ServiceCellParas.nr.nrArfcn) < 0) {
1070 return ErrorHandling();
1071 }
1072 if (NextInt(&pStr, &ci->ServiceCellParas.nr.pci) < 0) {
1073 return ErrorHandling();
1074 }
1075 if (NextInt(&pStr, &ci->ServiceCellParas.nr.tac) < 0) {
1076 return ErrorHandling();
1077 }
1078 if (NextInt64(&pStr, &ci->ServiceCellParas.nr.nci) < 0) {
1079 return ErrorHandling();
1080 }
1081 ci->ratType = NETWORK_TYPE_NR;
1082 return HRIL_ERR_SUCCESS;
1083 }
1084
ParseCellInfos(const char * str,const CellInfo * cellInfo)1085 static int32_t ParseCellInfos(const char *str, const CellInfo *cellInfo)
1086 {
1087 CellInfo *ci = (CellInfo *)cellInfo;
1088 char *pStr = (char *)str;
1089 if (pStr == NULL) {
1090 TELEPHONY_LOGE("pStr is null.");
1091 return HRIL_ERR_GENERIC_FAILURE;
1092 }
1093 TELEPHONY_LOGD("ParseCellInfos %{public}s", pStr);
1094 if (ReportStrWith(pStr, "^MONNC: GSM")) {
1095 if (ParseCellInfoGsm(pStr, ci) != 0) {
1096 TELEPHONY_LOGE("parse gsm command failed!");
1097 return HRIL_ERR_GENERIC_FAILURE;
1098 }
1099 } else if (ReportStrWith(pStr, "^MONNC: WCDMA")) {
1100 if (ParseCellInfoWcdma(pStr, ci) != 0) {
1101 TELEPHONY_LOGE("parse wcdma command failed!");
1102 return HRIL_ERR_GENERIC_FAILURE;
1103 }
1104 } else if (ReportStrWith(pStr, "^MONNC: CDMA")) {
1105 if (ParseCellInfoCdma(pStr, ci) != 0) {
1106 TELEPHONY_LOGE("parse cdma command failed!");
1107 return HRIL_ERR_GENERIC_FAILURE;
1108 }
1109 } else if (ReportStrWith(pStr, "^MONNC: TDSCDMA")) {
1110 if (ParseCellInfoTdscdma(pStr, ci) != 0) {
1111 TELEPHONY_LOGE("parse tdscdma command failed!");
1112 return HRIL_ERR_GENERIC_FAILURE;
1113 }
1114 } else if (ReportStrWith(pStr, "^MONNC: LTE")) {
1115 if (ParseCellInfoLte(pStr, ci) != 0) {
1116 TELEPHONY_LOGE("parse lte command failed!");
1117 return HRIL_ERR_GENERIC_FAILURE;
1118 }
1119 } else if (ReportStrWith(pStr, "^MONNC: NR")) {
1120 if (ParseCellInfoNr(pStr, ci) != 0) {
1121 TELEPHONY_LOGE("parse nr command failed!");
1122 return HRIL_ERR_GENERIC_FAILURE;
1123 }
1124 } else if (ReportStrWith(pStr, "^MONNC: NONE")) {
1125 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
1126 TELEPHONY_LOGD("ParseCellInfos ^MONNC: NONE branch");
1127 } else {
1128 TELEPHONY_LOGE("%{public}s This command resolution not supported.", pStr);
1129 return HRIL_ERR_GENERIC_FAILURE;
1130 }
1131 return HRIL_ERR_SUCCESS;
1132 }
1133
ReqGetNeighboringCellInfoList(const ReqDataInfo * requestInfo)1134 void ReqGetNeighboringCellInfoList(const ReqDataInfo *requestInfo)
1135 {
1136 if (requestInfo == NULL) {
1137 return;
1138 }
1139 int32_t err = HRIL_ERR_SUCCESS;
1140 int32_t countCellInfo = 0;
1141 int32_t index = 0;
1142 ResponseInfo *responseInfo = NULL;
1143 Line *pLine = NULL;
1144 CellInfo *cellInfo = NULL;
1145 CellInfoList cellInfoList = { 0, NULL };
1146 int32_t ret = SendCommandLock("AT^MONNC", "^MONNC:", DEFAULT_TIMEOUT, &responseInfo);
1147 struct ResponseAck respDataAck = { responseInfo, NULL, 0 };
1148 respDataAck.respDataPointer = (uint8_t *)&cellInfoList;
1149 respDataAck.respDataLen = sizeof(CellInfoList);
1150 if (responseInfo == NULL) {
1151 TELEPHONY_LOGE("responseInfo is nullptr");
1152 err = HRIL_ERR_INVALID_RESPONSE;
1153 ResponseNetworkReport(HRIL_SIM_SLOT_0, requestInfo, err, &respDataAck);
1154 return;
1155 }
1156 if (ret != 0 || responseInfo->success == 0) {
1157 TELEPHONY_LOGE("send AT CMD failed!");
1158 err = (ret != 0) ? HRIL_ERR_GENERIC_FAILURE : HRIL_ERR_CMD_SEND_FAILURE;
1159 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1160 return;
1161 }
1162 for (countCellInfo = 0, pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1163 countCellInfo++;
1164 }
1165 if (countCellInfo == 0) {
1166 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1167 return;
1168 }
1169 TELEPHONY_LOGD("countCellInfo:%{public}d", countCellInfo);
1170 cellInfo = (CellInfo *)calloc(countCellInfo, sizeof(CellInfo));
1171 if (cellInfo == NULL) {
1172 TELEPHONY_LOGE("cellInfoList alloc failed!");
1173 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_MEMORY_FULL, &respDataAck);
1174 return;
1175 }
1176 for (pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1177 if (ParseCellInfos(pLine->data, &cellInfo[index]) != 0) {
1178 continue;
1179 }
1180 index++;
1181 }
1182 cellInfoList.itemNum = index;
1183 cellInfoList.cellNearbyInfo = cellInfo;
1184 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1185 free(cellInfo);
1186 return;
1187 }
1188
ParseGetGsmCellInfoLine(char * line,CurrentCellInfoVendor * response)1189 static void ParseGetGsmCellInfoLine(char *line, CurrentCellInfoVendor *response)
1190 {
1191 if (line == NULL || response == NULL) {
1192 return;
1193 }
1194 NextInt(&line, &response->ServiceCellParas.gsm.band);
1195 NextInt(&line, &response->ServiceCellParas.gsm.arfcn);
1196 NextInt(&line, &response->ServiceCellParas.gsm.bsic);
1197 NextIntFromHex(&line, &response->ServiceCellParas.gsm.cellId);
1198 NextIntFromHex(&line, &response->ServiceCellParas.gsm.lac);
1199 NextInt(&line, &response->ServiceCellParas.gsm.rxlev);
1200 NextInt(&line, &response->ServiceCellParas.gsm.rxQuality);
1201 NextInt(&line, &response->ServiceCellParas.gsm.ta);
1202 response->ServiceCellParas.gsm.rxlev = -response->ServiceCellParas.gsm.rxlev;
1203 TELEPHONY_LOGD("ParseGetGsmCellInfoLine band:%{private}d,arfcn:%{private}d,bsic:%{private}d,cellId:%{private}d"
1204 "lac:%{private}d,rxlev:%{private}d,rxQuality:%{private}d,ta:%{private}d",
1205 response->ServiceCellParas.gsm.band, response->ServiceCellParas.gsm.arfcn, response->ServiceCellParas.gsm.bsic,
1206 response->ServiceCellParas.gsm.cellId, response->ServiceCellParas.gsm.lac, response->ServiceCellParas.gsm.rxlev,
1207 response->ServiceCellParas.gsm.rxQuality, response->ServiceCellParas.gsm.ta);
1208 }
1209
ParseGetLteCellInfoLine(char * line,CurrentCellInfoVendor * response)1210 static void ParseGetLteCellInfoLine(char *line, CurrentCellInfoVendor *response)
1211 {
1212 if (line == NULL || response == NULL) {
1213 return;
1214 }
1215 NextInt(&line, &response->ServiceCellParas.lte.arfcn);
1216 NextIntFromHex(&line, &response->ServiceCellParas.lte.cellId);
1217 NextIntFromHex(&line, &response->ServiceCellParas.lte.pci);
1218 NextIntFromHex(&line, &response->ServiceCellParas.lte.tac);
1219 NextInt(&line, &response->ServiceCellParas.lte.rsrp);
1220 NextInt(&line, &response->ServiceCellParas.lte.rsrq);
1221 NextInt(&line, &response->ServiceCellParas.lte.rssi);
1222 response->ServiceCellParas.lte.rsrp = -response->ServiceCellParas.lte.rsrp;
1223 TELEPHONY_LOGD("ParseGetLteCellInfoLine arfcn:%{private}d,cellId:%{private}d,pci:%{private}d"
1224 "tac:%{private}d,rsrp:%{private}d,rsrq:%{private}d,rssi:%{private}d",
1225 response->ServiceCellParas.lte.arfcn, response->ServiceCellParas.lte.cellId, response->ServiceCellParas.lte.pci,
1226 response->ServiceCellParas.lte.tac, response->ServiceCellParas.lte.rsrp, response->ServiceCellParas.lte.rsrq,
1227 response->ServiceCellParas.lte.rssi);
1228 }
1229
ParseGetWcdmaCellInfoLine(char * line,CurrentCellInfoVendor * response)1230 static void ParseGetWcdmaCellInfoLine(char *line, CurrentCellInfoVendor *response)
1231 {
1232 if (line == NULL || response == NULL) {
1233 return;
1234 }
1235 NextInt(&line, &response->ServiceCellParas.wcdma.arfcn);
1236 NextInt(&line, &response->ServiceCellParas.wcdma.psc);
1237 NextIntFromHex(&line, &response->ServiceCellParas.wcdma.cellId);
1238 NextIntFromHex(&line, &response->ServiceCellParas.wcdma.lac);
1239 NextInt(&line, &response->ServiceCellParas.wcdma.rscp);
1240 NextInt(&line, &response->ServiceCellParas.wcdma.rxlev);
1241 NextInt(&line, &response->ServiceCellParas.wcdma.ecno);
1242 NextInt(&line, &response->ServiceCellParas.wcdma.drx);
1243 NextInt(&line, &response->ServiceCellParas.wcdma.ura);
1244 response->ServiceCellParas.wcdma.rscp = -response->ServiceCellParas.wcdma.rscp;
1245 TELEPHONY_LOGD("ParseGetWcdmaCellInfoLine arfcn:%{private}d,psc:%{private}d,cellId:%{private}d,lac:%{private}d"
1246 "rscp:%{private}d,rxlev:%{private}d,ecno:%{private}d,drx:%{private}d,ura:%{private}d",
1247 response->ServiceCellParas.wcdma.arfcn, response->ServiceCellParas.wcdma.psc,
1248 response->ServiceCellParas.wcdma.cellId, response->ServiceCellParas.wcdma.lac,
1249 response->ServiceCellParas.wcdma.rscp, response->ServiceCellParas.wcdma.rxlev,
1250 response->ServiceCellParas.wcdma.ecno, response->ServiceCellParas.wcdma.drx,
1251 response->ServiceCellParas.wcdma.ura);
1252 }
1253
ParseGetCdmaCellInfoLine(char * line,CurrentCellInfoVendor * response)1254 static void ParseGetCdmaCellInfoLine(char *line, CurrentCellInfoVendor *response)
1255 {
1256 if (line == NULL || response == NULL) {
1257 return;
1258 }
1259 NextInt(&line, &response->ServiceCellParas.cdma.systemId);
1260 NextInt(&line, &response->ServiceCellParas.cdma.networkId);
1261 NextIntFromHex(&line, &response->ServiceCellParas.cdma.baseId);
1262 NextIntFromHex(&line, &response->ServiceCellParas.cdma.zoneId);
1263 NextInt(&line, &response->ServiceCellParas.cdma.pilotPn);
1264 NextInt(&line, &response->ServiceCellParas.cdma.pilotStrength);
1265 NextInt(&line, &response->ServiceCellParas.cdma.channel);
1266 NextInt(&line, &response->ServiceCellParas.cdma.longitude);
1267 NextInt(&line, &response->ServiceCellParas.cdma.latitude);
1268 response->ServiceCellParas.cdma.pilotStrength = -response->ServiceCellParas.cdma.pilotStrength;
1269 TELEPHONY_LOGD(
1270 "ParseGetCdmaCellInfoLine systemId:%{private}d,networkId:%{private}d,baseId:%{private}d,zoneId:%{private}d"
1271 "pilotPn:%{private}d,pilotStrength:%{private}d,channel:%{private}d,longitude:%{private}d,latitude:%{private}d",
1272 response->ServiceCellParas.cdma.systemId, response->ServiceCellParas.cdma.networkId,
1273 response->ServiceCellParas.cdma.baseId, response->ServiceCellParas.cdma.zoneId,
1274 response->ServiceCellParas.cdma.pilotPn, response->ServiceCellParas.cdma.pilotStrength,
1275 response->ServiceCellParas.cdma.channel, response->ServiceCellParas.cdma.longitude,
1276 response->ServiceCellParas.cdma.latitude);
1277 }
1278
ParseGetTdscdmaCellInfoLine(char * line,CurrentCellInfoVendor * response)1279 static void ParseGetTdscdmaCellInfoLine(char *line, CurrentCellInfoVendor *response)
1280 {
1281 if (line == NULL || response == NULL) {
1282 return;
1283 }
1284 NextInt(&line, &response->ServiceCellParas.tdscdma.arfcn);
1285 NextInt(&line, &response->ServiceCellParas.tdscdma.syncId);
1286 NextInt(&line, &response->ServiceCellParas.tdscdma.sc);
1287 NextIntFromHex(&line, &response->ServiceCellParas.tdscdma.cellId);
1288 NextIntFromHex(&line, &response->ServiceCellParas.tdscdma.lac);
1289 NextInt(&line, &response->ServiceCellParas.tdscdma.rscp);
1290 NextInt(&line, &response->ServiceCellParas.tdscdma.drx);
1291 NextIntFromHex(&line, &response->ServiceCellParas.tdscdma.rac);
1292 NextInt(&line, &response->ServiceCellParas.tdscdma.cpid);
1293 response->ServiceCellParas.tdscdma.rscp = -response->ServiceCellParas.tdscdma.rscp;
1294 TELEPHONY_LOGD("ParseGetTdscdmaCellInfoLine arfcn:%{private}d,syncId:%{private}d,sc:%{private}d,cellId:%{private}d,"
1295 "lac:%{private}d,rscp:%{private}d,drx:%{private}d,rac:%{private}d,cpid:%{private}d,",
1296 response->ServiceCellParas.tdscdma.arfcn, response->ServiceCellParas.tdscdma.syncId,
1297 response->ServiceCellParas.tdscdma.sc, response->ServiceCellParas.tdscdma.cellId,
1298 response->ServiceCellParas.tdscdma.lac, response->ServiceCellParas.tdscdma.rscp,
1299 response->ServiceCellParas.tdscdma.drx, response->ServiceCellParas.tdscdma.rac,
1300 response->ServiceCellParas.tdscdma.cpid);
1301 }
1302
ParseGetNrCellInfoLine(char * line,CurrentCellInfoVendor * response)1303 static void ParseGetNrCellInfoLine(char *line, CurrentCellInfoVendor *response)
1304 {
1305 if (line == NULL || response == NULL) {
1306 return;
1307 }
1308 NextInt(&line, &response->ServiceCellParas.nr.nrArfcn);
1309 NextInt(&line, &response->ServiceCellParas.nr.pci);
1310 NextInt(&line, &response->ServiceCellParas.nr.tac);
1311 NextInt64(&line, &response->ServiceCellParas.nr.nci);
1312 }
1313
ParseGetCurrentCellInfoResponseLineSwitch(const char * str,const CurrentCellInfoVendor * hrilResponse)1314 static int32_t ParseGetCurrentCellInfoResponseLineSwitch(const char *str, const CurrentCellInfoVendor *hrilResponse)
1315 {
1316 char *line = (char *)str;
1317 CurrentCellInfoVendor *response = (CurrentCellInfoVendor *)hrilResponse;
1318 if ((line == NULL) || (response == NULL)) {
1319 TELEPHONY_LOGE("ParseGetCurrentCellInfoResponseLineSwitch line or response param is null");
1320 return HRIL_ERR_NULL_POINT;
1321 }
1322 switch (response->ratType) {
1323 case NETWORK_TYPE_GSM:
1324 ParseGetGsmCellInfoLine(line, response);
1325 break;
1326 case NETWORK_TYPE_LTE:
1327 ParseGetLteCellInfoLine(line, response);
1328 break;
1329 case NETWORK_TYPE_WCDMA:
1330 ParseGetWcdmaCellInfoLine(line, response);
1331 break;
1332 case NETWORK_TYPE_CDMA:
1333 ParseGetCdmaCellInfoLine(line, response);
1334 break;
1335 case NETWORK_TYPE_TDSCDMA:
1336 ParseGetTdscdmaCellInfoLine(line, response);
1337 break;
1338 case NETWORK_TYPE_NR:
1339 ParseGetNrCellInfoLine(line, response);
1340 break;
1341 default:
1342 TELEPHONY_LOGE("ParseGetCellInfoResponseLineSwitch is not support cell, line = %{public}s", line);
1343 break;
1344 }
1345 return HRIL_ERR_SUCCESS;
1346 }
1347
ParseGetCurrentCellInfoResponseLine(char * line,CurrentCellInfoVendor * response)1348 static int32_t ParseGetCurrentCellInfoResponseLine(char *line, CurrentCellInfoVendor *response)
1349 {
1350 if (line == NULL || response == NULL) {
1351 return -1;
1352 }
1353 char *c = NULL;
1354 TELEPHONY_LOGD("ParseGetCurrentCellInfoResponseLine line %{public}s", line);
1355 int32_t err = SkipATPrefix(&line);
1356 if (err < 0) {
1357 return err;
1358 }
1359 err = NextStr(&line, &c);
1360 if (err < 0) {
1361 return err;
1362 }
1363 if (!strcmp(c, "GSM")) {
1364 response->ratType = NETWORK_TYPE_GSM;
1365 } else if (!strcmp(c, "LTE")) {
1366 response->ratType = NETWORK_TYPE_LTE;
1367 } else if (!strcmp(c, "WCDMA")) {
1368 response->ratType = NETWORK_TYPE_WCDMA;
1369 } else if (!strcmp(c, "CDMA")) {
1370 response->ratType = NETWORK_TYPE_CDMA;
1371 } else if (!strcmp(c, "TDSCDMA")) {
1372 response->ratType = NETWORK_TYPE_TDSCDMA;
1373 } else if (!strcmp(c, "NR")) {
1374 response->ratType = NETWORK_TYPE_NR;
1375 } else if (!strcmp(c, "NONE")) {
1376 (void)memset_s(response, sizeof(CurrentCellInfoVendor), 0, sizeof(CurrentCellInfoVendor));
1377 response->ratType = NETWORK_TYPE_UNKNOWN;
1378 return HRIL_ERR_SUCCESS;
1379 } else {
1380 TELEPHONY_LOGI("ParseCurrentCellInfo unSupport ratType line %{public}s", line);
1381 return -1;
1382 }
1383 err = NextInt(&line, &response->mcc);
1384 if (err < 0) {
1385 return err;
1386 }
1387 err = NextInt(&line, &response->mnc);
1388 if (err < 0) {
1389 return err;
1390 }
1391 ParseGetCurrentCellInfoResponseLineSwitch(line, response);
1392 return HRIL_ERR_SUCCESS;
1393 }
1394
ProcessCurrentCellList(struct ReportInfo reportInfo,const char * s)1395 int32_t ProcessCurrentCellList(struct ReportInfo reportInfo, const char *s)
1396 {
1397 char *str = (char *)s;
1398 if (str == NULL) {
1399 TELEPHONY_LOGE("ProcessCurrentCellList Str is null.");
1400 return HRIL_ERR_GENERIC_FAILURE;
1401 }
1402 int32_t err = SkipATPrefix(&str);
1403 if (err < 0) {
1404 TELEPHONY_LOGE("ProcessCurrentCellList skip failed: [%{public}s]", str);
1405 return HRIL_ERR_GENERIC_FAILURE;
1406 }
1407 int32_t semicolonNum = FindSemicolonCharNum(str);
1408 if (semicolonNum > 0) {
1409 CurrentCellInfoVendor *cciv = NULL;
1410 CurrentCellInfoList cellList = {0, NULL};
1411 cciv = (CurrentCellInfoVendor *)calloc(semicolonNum, sizeof(CurrentCellInfoVendor));
1412 if (cciv == NULL) {
1413 TELEPHONY_LOGE("^MONSC: notify CurrentCellInfoVendor alloc failed!");
1414 return HRIL_ERR_MEMORY_FULL;
1415 }
1416 for (int32_t i = 0; i < semicolonNum; i++) {
1417 char *pStr = strsep(&str, ";");
1418 if (ParseGetCurrentCellInfoResponseLine(pStr, &cciv[cellList.itemNum]) != 0) {
1419 continue;
1420 }
1421 cellList.itemNum++;
1422 }
1423 cellList.currentCellInfo = cciv;
1424 reportInfo.error = HRIL_ERR_SUCCESS;
1425 reportInfo.type = HRIL_NOTIFICATION;
1426 reportInfo.notifyId = HNOTI_NETWORK_CURRENT_CELL_UPDATED;
1427 OnNetworkReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&cellList, sizeof(CurrentCellInfoList));
1428 if (cellList.currentCellInfo != NULL) {
1429 free(cellList.currentCellInfo);
1430 }
1431 return HRIL_ERR_SUCCESS;
1432 } else {
1433 TELEPHONY_LOGW("^MONSC: notify str format unexpected: %{public}s", str);
1434 return HRIL_ERR_GENERIC_FAILURE;
1435 }
1436 }
1437
ReqGetCurrentCellInfo(const ReqDataInfo * requestInfo)1438 void ReqGetCurrentCellInfo(const ReqDataInfo *requestInfo)
1439 {
1440 if (requestInfo == NULL) {
1441 return;
1442 }
1443 int32_t err = HRIL_ERR_SUCCESS;
1444 int32_t countCellInfo = 0;
1445 int32_t index = 0;
1446 ResponseInfo *responseInfo = NULL;
1447 Line *pLine = NULL;
1448 CurrentCellInfoVendor *currCellInfo = NULL;
1449 CurrentCellInfoList currCellInfoList = { 0, NULL };
1450 int32_t ret = SendCommandLock("AT^MONSC", "^MONSC:", DEFAULT_TIMEOUT, &responseInfo);
1451 struct ResponseAck respDataAck = { responseInfo, NULL, 0 };
1452 respDataAck.respDataPointer = (uint8_t *)&currCellInfoList;
1453 respDataAck.respDataLen = sizeof(CurrentCellInfoList);
1454 if (responseInfo == NULL) {
1455 TELEPHONY_LOGE("AT^MONSC responseInfo is nullptr");
1456 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1457 return;
1458 }
1459 if (ret != 0 || responseInfo->success == 0) {
1460 TELEPHONY_LOGE("AT^MONSC send AT CMD failed!");
1461 err = (ret != 0) ? HRIL_ERR_GENERIC_FAILURE : HRIL_ERR_CMD_SEND_FAILURE;
1462 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1463 return;
1464 }
1465 for (countCellInfo = 0, pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1466 countCellInfo++;
1467 }
1468 if (countCellInfo == 0) {
1469 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1470 return;
1471 }
1472 currCellInfo = (CurrentCellInfoVendor *)calloc(countCellInfo, sizeof(CurrentCellInfoVendor));
1473 if (currCellInfo == NULL) {
1474 TELEPHONY_LOGE("currentCellList countCellInfo:%{public}d,currCellInfo alloc failed!", countCellInfo);
1475 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_MEMORY_FULL, &respDataAck);
1476 return;
1477 }
1478 for (pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1479 if (ParseGetCurrentCellInfoResponseLine(pLine->data, &currCellInfo[index]) != 0) {
1480 continue;
1481 }
1482 index++;
1483 }
1484 currCellInfoList.itemNum = index;
1485 currCellInfoList.currentCellInfo = currCellInfo;
1486 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1487 free(currCellInfo);
1488 return;
1489 }
1490
OperListErrorHandler(AvailableOperInfo ** ppOperInfo,AvailableOperInfo * pOperInfo)1491 static int32_t OperListErrorHandler(AvailableOperInfo **ppOperInfo, AvailableOperInfo *pOperInfo)
1492 {
1493 TELEPHONY_LOGE("ReqGetNetworkSearchInformation Failed");
1494 DealNetworkSearchInformation(0, ppOperInfo, pOperInfo);
1495 return HRIL_ERR_GENERIC_FAILURE;
1496 }
1497
ProcessOperListToUse(const char * list)1498 int32_t ProcessOperListToUse(const char *list)
1499 {
1500 const int32_t UNUSED_ITEM_COUNT = 2;
1501 AvailableOperInfo **ppOperInfo = NULL;
1502 AvailableOperInfo *pOperInfo = NULL;
1503 SetAtPauseFlag(false);
1504 alarm(0);
1505 int32_t item = ParseListItemNum(list);
1506 if (item <= UNUSED_ITEM_COUNT) {
1507 return OperListErrorHandler(ppOperInfo, pOperInfo);
1508 }
1509 char *line = (char *)list;
1510 int32_t ret = SkipATPrefix(&line);
1511 if (ret < 0) {
1512 return OperListErrorHandler(ppOperInfo, pOperInfo);
1513 }
1514
1515 item = item - UNUSED_ITEM_COUNT;
1516 ppOperInfo = (AvailableOperInfo **)malloc(item * sizeof(AvailableOperInfo *));
1517 if (!ppOperInfo) {
1518 TELEPHONY_LOGE("ppOperInfo malloc fail");
1519 return OperListErrorHandler(ppOperInfo, pOperInfo);
1520 }
1521
1522 pOperInfo = (AvailableOperInfo *)malloc(item * sizeof(AvailableOperInfo));
1523 if (!pOperInfo) {
1524 TELEPHONY_LOGE("pOperInfo malloc fail");
1525 return OperListErrorHandler(ppOperInfo, pOperInfo);
1526 }
1527 (void)memset_s(pOperInfo, item * sizeof(AvailableOperInfo), 0, item * sizeof(AvailableOperInfo));
1528 for (int32_t j = 0; j < item; j++) {
1529 ppOperInfo[j] = &(pOperInfo[j]);
1530 }
1531
1532 int32_t operCount = ParseOperListInfo(line, item, pOperInfo, ppOperInfo);
1533 if (operCount != 0) {
1534 DealNetworkSearchInformation(operCount, ppOperInfo, pOperInfo);
1535 } else {
1536 return OperListErrorHandler(ppOperInfo, pOperInfo);
1537 }
1538 return HRIL_ERR_SUCCESS;
1539 }
1540
PrepareSetNetworkSelectionMode(char * cmd,const HRilSetNetworkModeInfo * setModeInfo)1541 static bool PrepareSetNetworkSelectionMode(char *cmd, const HRilSetNetworkModeInfo *setModeInfo)
1542 {
1543 if (cmd == NULL || setModeInfo == NULL) {
1544 return false;
1545 }
1546 bool ret = true;
1547 TELEPHONY_LOGD("setModeInfo, serial123 = %{public}d", setModeInfo->selectMode);
1548 if (setModeInfo->selectMode == 0) {
1549 (void)sprintf_s(cmd, MAX_CMD_LENGTH, "%s", "AT+COPS=0");
1550 } else if (setModeInfo->selectMode == 1) {
1551 if (setModeInfo->oper == NULL) {
1552 ret = false;
1553 } else {
1554 (void)sprintf_s(cmd, MAX_CMD_LENGTH, "AT+COPS=1,2,%s", setModeInfo->oper);
1555 }
1556 } else {
1557 ret = false;
1558 }
1559 return ret;
1560 }
1561
ReqSetNetworkSelectionMode(const ReqDataInfo * requestInfo,const HRilSetNetworkModeInfo * data)1562 void ReqSetNetworkSelectionMode(const ReqDataInfo *requestInfo, const HRilSetNetworkModeInfo *data)
1563 {
1564 if (requestInfo == NULL) {
1565 return;
1566 }
1567
1568 ResponseInfo *responseInfo = NULL;
1569 char cmd[MAX_CMD_LENGTH] = {0};
1570 char *cmdBuff = cmd;
1571 struct ReportInfo reportInfo;
1572 HRilSetNetworkModeInfo *setModeInfo = (HRilSetNetworkModeInfo *)data;
1573 if (setModeInfo == NULL) {
1574 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
1575 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 1);
1576 TELEPHONY_LOGE("SetAutomaticMode HRIL_ERR_NULL_POINT");
1577 return;
1578 }
1579 if (!PrepareSetNetworkSelectionMode(cmdBuff, setModeInfo)) {
1580 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1581 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 1);
1582 TELEPHONY_LOGE("SetAutomaticMode HRIL_ERR_INVALID_PARAMETER");
1583 return;
1584 }
1585 TELEPHONY_LOGD("requestSetAutomaticModeForNetworks, cmd = %{public}s", cmd);
1586 int32_t err = SendCommandLock(cmd, NULL, 0, &responseInfo);
1587
1588 if (responseInfo == NULL) {
1589 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
1590 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 1);
1591 TELEPHONY_LOGE("SetAutomaticMode responseInfo == NULL");
1592 return;
1593 }
1594 TELEPHONY_LOGD("SetAutomaticModeForNetworks, responseInfo->success = %{public}d", responseInfo->success);
1595 if (err != 0 || responseInfo->success == 0) {
1596 TELEPHONY_LOGE("ret is not equal to HDF_SUCCESS!");
1597 err = GetResponseErrorCode(responseInfo);
1598 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1599 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1600 TELEPHONY_LOGE("SetAutomaticMode HRIL_ERR_GENERIC_FAILURE");
1601 FreeResponseInfo(responseInfo);
1602 return;
1603 }
1604 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1605 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1606 FreeResponseInfo(responseInfo);
1607 }
1608
ReqGetNetworkSelectionMode(const ReqDataInfo * requestInfo)1609 void ReqGetNetworkSelectionMode(const ReqDataInfo *requestInfo)
1610 {
1611 if (requestInfo == NULL) {
1612 return;
1613 }
1614 int32_t err = HRIL_ERR_SUCCESS;
1615 ResponseInfo *responseInfo = NULL;
1616 int32_t state = 0;
1617 struct ReportInfo reportInfo;
1618 int32_t ret = SendCommandLock("AT+COPS?", "+COPS:", DEFAULT_TIMEOUT, &responseInfo);
1619 struct ResponseAck respDataAck = { responseInfo, NULL, 0 };
1620 if (responseInfo == NULL) {
1621 TELEPHONY_LOGE("responseInfo is nullptr");
1622 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
1623 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1624 return;
1625 }
1626 if (ret != 0 || responseInfo->success == 0) {
1627 err = GetResponseErrorCode(responseInfo);
1628 TELEPHONY_LOGE("send AT CMD failed!");
1629 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1630 return;
1631 }
1632 if (responseInfo->head == NULL) {
1633 TELEPHONY_LOGE("no data!");
1634 err = HRIL_ERR_NULL_POINT;
1635 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1636 return;
1637 }
1638 char *line = responseInfo->head->data;
1639 ret = SkipATPrefix(&line);
1640 if (ret < 0) {
1641 err = HRIL_ERR_INVALID_RESPONSE;
1642 TELEPHONY_LOGE("Response is Invalid!");
1643 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1644 return;
1645 }
1646 ret = NextInt(&line, &state);
1647 if (ret < 0) {
1648 err = HRIL_ERR_INVALID_RESPONSE;
1649 TELEPHONY_LOGE("Response is Invalid!");
1650 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1651 return;
1652 }
1653 int32_t mode = (int32_t)state;
1654 respDataAck.respDataPointer = (uint8_t *)&mode;
1655 respDataAck.respDataLen = sizeof(int32_t);
1656 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_SUCCESS, &respDataAck);
1657 NotifyNetWorkTime(requestInfo->slotId);
1658 return;
1659 }
1660
IntToNetTypeCmd(int32_t value,char * dst,int32_t dstMaxSize)1661 static int32_t IntToNetTypeCmd(int32_t value, char *dst, int32_t dstMaxSize)
1662 {
1663 int32_t len = MAX_CMD_LENGTH - 1;
1664 (void)strcat_s(dst, len, "AT^SYSCFGEX=\"");
1665 const int32_t MAX_PREFERRED_NET_ENUM = 99;
1666 const int32_t MIN_CHAR_ARRAY_SIZE = 50;
1667 const int32_t CONVERT_FAIL = -1;
1668 const int32_t DECIMAL = 10;
1669 if ((value > MAX_PREFERRED_NET_ENUM) || (value < 0) || (dstMaxSize < MIN_CHAR_ARRAY_SIZE)) {
1670 return CONVERT_FAIL;
1671 }
1672 int32_t pos = strlen(dst);
1673 if (pos > len - ADD_LENGTH) {
1674 return CONVERT_FAIL;
1675 }
1676 if (value < DECIMAL) {
1677 dst[pos++] = '0';
1678 dst[pos++] = (value % DECIMAL) + '0';
1679 } else {
1680 dst[pos++] = (value / DECIMAL) + '0';
1681 dst[pos++] = (value % DECIMAL) + '0';
1682 }
1683 dst[pos++] = '\"';
1684 dst[pos] = '\0';
1685 return 0;
1686 }
1687
PrepareCommandByNetworkType(HRilPreferredNetworkType net)1688 static char *PrepareCommandByNetworkType(HRilPreferredNetworkType net)
1689 {
1690 char *cmd = (char *)calloc(1, MAX_CMD_LENGTH);
1691 if (cmd != NULL) {
1692 TELEPHONY_LOGD("SetPreferredNetwork, net = %{public}d", net);
1693 if (net == HRIL_NETWORK_AUTO) {
1694 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"00\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1695 } else if (net == HRIL_NETWORK_GSM) {
1696 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"01\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1697 } else if (net == HRIL_NETWORK_WCDMA) {
1698 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"02\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1699 } else if (net == HRIL_NETWORK_LTE) {
1700 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"03\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1701 } else if (net == HRIL_NETWORK_LTE_WCDMA_GSM) {
1702 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"030201\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1703 } else if (net == HRIL_NETWORK_WCDMA_GSM) {
1704 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"0201\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1705 } else if (net == HRIL_NETWORK_LTE_WCDMA) {
1706 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"0302\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1707 } else {
1708 if (((net > HRIL_NETWORK_WCDMA_GSM) && (net <= HRIL_NETWORK_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA)) ||
1709 ((net >= HRIL_NETWORK_NR) && (net <= HRIL_NETWORK_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA))) {
1710 char dst[MAX_CMD_LENGTH] = {0};
1711 IntToNetTypeCmd(net, dst, MAX_CMD_LENGTH);
1712 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", dst);
1713 } else {
1714 free(cmd);
1715 cmd = NULL;
1716 }
1717 }
1718 }
1719 return cmd;
1720 }
1721
ReqSetPreferredNetwork(const ReqDataInfo * requestInfo,const int32_t * data)1722 void ReqSetPreferredNetwork(const ReqDataInfo *requestInfo, const int32_t *data)
1723 {
1724 if (requestInfo == NULL) {
1725 return;
1726 }
1727 ResponseInfo *responseInfo = NULL;
1728 struct ReportInfo reportInfo;
1729 if (data == NULL) {
1730 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1731 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1732 return;
1733 }
1734 int32_t net = *(int32_t *)data;
1735 int32_t err = HRIL_ERR_INVALID_PARAMETER;
1736 char *cmd = PrepareCommandByNetworkType(net);
1737 if (cmd == NULL) {
1738 TELEPHONY_LOGE("RequestReqSetPreferredNetwork HRIL_ERR_INVALID_PARAMETER cmd NULL");
1739 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1740 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1741 return;
1742 }
1743 err = SendCommandLock(cmd, NULL, 0, &responseInfo);
1744 if (cmd != NULL) {
1745 free(cmd);
1746 cmd = NULL;
1747 }
1748 if (responseInfo == NULL) {
1749 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
1750 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1751 return;
1752 }
1753 if (err != 0 || responseInfo->success == 0) {
1754 err = GetResponseErrorCode(responseInfo);
1755 }
1756 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1757 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1758 FreeResponseInfo(responseInfo);
1759 }
1760
ParseNetTypeStr(const char * netType)1761 static int32_t ParseNetTypeStr(const char *netType)
1762 {
1763 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
1764 if (netType == NULL) {
1765 TELEPHONY_LOGE("ParseNetTypeStr netType is null");
1766 return -1;
1767 }
1768 TELEPHONY_LOGD("netType: [%{public}s]", netType);
1769 if (strcmp(netType, AUTO_TYPE) == 0) {
1770 return HRIL_NETWORK_AUTO;
1771 } else if (strcmp(netType, GSM_TYPE) == 0) {
1772 return HRIL_NETWORK_GSM;
1773 } else if (strcmp(netType, WCDMA_TYPE) == 0) {
1774 return HRIL_NETWORK_WCDMA;
1775 } else if (strcmp(netType, LTE_TYPE) == 0) {
1776 return HRIL_NETWORK_LTE;
1777 } else if (strcmp(netType, LTE_WCDMA_TYPE) == 0) {
1778 return HRIL_NETWORK_LTE_WCDMA;
1779 } else if (strcmp(netType, LTE_WCDMA_GSM_TYPE) == 0) {
1780 return HRIL_NETWORK_LTE_WCDMA_GSM;
1781 } else if (strcmp(netType, WCDMA_GSM_TYPE) == 0) {
1782 return HRIL_NETWORK_WCDMA_GSM;
1783 } else {
1784 int32_t net = ConvertCharToInt32(netType);
1785 if (((net > HRIL_NETWORK_WCDMA_GSM) && (net <= HRIL_NETWORK_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA)) ||
1786 ((net >= HRIL_NETWORK_NR) && (net <= HRIL_NETWORK_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA))) {
1787 return net;
1788 } else {
1789 return -1;
1790 }
1791 }
1792 }
1793
ReqGetPreferredNetwork(const ReqDataInfo * requestInfo)1794 void ReqGetPreferredNetwork(const ReqDataInfo *requestInfo)
1795 {
1796 if (requestInfo == NULL) {
1797 return;
1798 }
1799 int32_t err = HRIL_ERR_SUCCESS;
1800 ResponseInfo *responseInfo = NULL;
1801 char *netTypeStr = "";
1802 int32_t ret = SendCommandLock("AT^SYSCFGEX?", "^SYSCFGEX:", DEFAULT_TIMEOUT, &responseInfo);
1803 struct ResponseAck respDataAck = { responseInfo, NULL, 0 };
1804 if (responseInfo == NULL) {
1805 TELEPHONY_LOGE("responseInfo is null");
1806 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_NULL_POINT, &respDataAck);
1807 return;
1808 }
1809 respDataAck.responseInfo = responseInfo;
1810 if (ret != 0 || !responseInfo->success) {
1811 err = GetResponseErrorCode(responseInfo);
1812 TELEPHONY_LOGE("send AT CMD failed!");
1813 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1814 return;
1815 }
1816 if (responseInfo->head == NULL) {
1817 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1818 return;
1819 }
1820 Line *pLine = responseInfo->head;
1821 char *line = pLine->data;
1822 if (SkipATPrefix(&line) < 0) {
1823 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1824 return;
1825 }
1826 if (NextStr(&line, &netTypeStr) < 0) {
1827 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1828 return;
1829 }
1830 int32_t netType = ParseNetTypeStr(netTypeStr);
1831 respDataAck.respDataPointer = (uint8_t *)&netType;
1832 respDataAck.respDataLen = sizeof(int32_t);
1833 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_SUCCESS, &respDataAck);
1834 }
1835
ProcessPhyChnlCfgNotify(struct ReportInfo reportInfo,char * srcStr)1836 void ProcessPhyChnlCfgNotify(struct ReportInfo reportInfo, char *srcStr)
1837 {
1838 int32_t contextIds[] = { 7, 8, 9 };
1839 HRilPhyChannelConfig configInfo = { 1, 2, 3, 4, 5, 6, 3 };
1840 configInfo.contextIds = contextIds;
1841 HRilChannelConfigList configInfoList = { 1, &configInfo };
1842 reportInfo.error = HRIL_ERR_SUCCESS;
1843 reportInfo.type = HRIL_NOTIFICATION;
1844 reportInfo.notifyId = HNOTI_NETWORK_PHY_CHNL_CFG_UPDATED;
1845 OnNetworkReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&configInfoList, sizeof(HRilChannelConfigList));
1846 }
1847
ReqGetPhysicalChannelConfig(const ReqDataInfo * requestInfo)1848 void ReqGetPhysicalChannelConfig(const ReqDataInfo *requestInfo)
1849 {
1850 if (requestInfo == NULL) {
1851 TELEPHONY_LOGE("ReqGetPhysicalChannelConfig requestInfo is NULL");
1852 return;
1853 }
1854 int32_t contextIds[] = { 7, 8, 9 };
1855 HRilPhyChannelConfig configInfo = { HRIL_SERVING_CELL_PRIMARY, RADIO_TECHNOLOGY_GSM, 1, 2, 3, 4, 5, 6, 1 };
1856 configInfo.contextIds = contextIds;
1857 HRilChannelConfigList configInfoList = { 1, &configInfo };
1858 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
1859 OnNetworkReport(requestInfo->slotId, reportInfo, (const uint8_t *)&configInfoList, sizeof(HRilChannelConfigList));
1860 }
1861
ReqSetLocateUpdates(const ReqDataInfo * requestInfo,HRilRegNotifyMode mode)1862 void ReqSetLocateUpdates(const ReqDataInfo *requestInfo, HRilRegNotifyMode mode)
1863 {
1864 if (requestInfo == NULL) {
1865 return;
1866 }
1867 ResponseInfo *responseInfo = NULL;
1868 char *cmd = NULL;
1869 if (mode == REG_NOTIFY_STAT_LAC_CELLID) {
1870 cmd = "AT+CREG=2";
1871 } else if (mode == REG_NOTIFY_STAT_ONLY) {
1872 cmd = "AT+CREG=1";
1873 } else {
1874 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1875 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1876 TELEPHONY_LOGE("ReqSetLocateUpdates: locateUpdateMode > 1");
1877 return;
1878 }
1879 int32_t err = SendCommandLock(cmd, NULL, DEFAULT_TIMEOUT, &responseInfo);
1880 if (responseInfo == NULL) {
1881 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
1882 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1883 TELEPHONY_LOGE("ReqSetLocateUpdates responseInfo == NULL");
1884 return;
1885 }
1886 TELEPHONY_LOGD("ReqSetLocateUpdates, responseInfo->success = %{public}d", responseInfo->success);
1887 if (err != 0 || responseInfo->success == 0) {
1888 err = GetResponseErrorCode(responseInfo);
1889 TELEPHONY_LOGE("ReqSetLocateUpdates errcode = %{public}d", err);
1890 }
1891 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1892 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1893 FreeResponseInfo(responseInfo);
1894 }
1895
ReqSetNotificationFilter(const ReqDataInfo * requestInfo,const int32_t * newFilter)1896 void ReqSetNotificationFilter(const ReqDataInfo *requestInfo, const int32_t *newFilter)
1897 {
1898 if (requestInfo == NULL) {
1899 TELEPHONY_LOGE("ReqSetNotificationFilter requestInfo is NULL");
1900 return;
1901 }
1902 if (newFilter == NULL) {
1903 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1904 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1905 return;
1906 }
1907 TELEPHONY_LOGD("ReqSetNotificationFilter success");
1908 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
1909 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1910 }
1911
ReqSetDeviceState(const ReqDataInfo * requestInfo,const int32_t * deviceStateType,const int32_t * deviceStateOn)1912 void ReqSetDeviceState(const ReqDataInfo *requestInfo, const int32_t *deviceStateType, const int32_t *deviceStateOn)
1913 {
1914 if (requestInfo == NULL) {
1915 TELEPHONY_LOGE("ReqSetDeviceState requestInfo is NULL");
1916 return;
1917 }
1918
1919 if (deviceStateType == NULL || deviceStateOn == NULL) {
1920 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1921 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1922 return;
1923 }
1924 TELEPHONY_LOGD("ReqSetDeviceState success");
1925 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
1926 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1927 }
1928
NotifyNetWorkTime(int32_t slotId)1929 void NotifyNetWorkTime(int32_t slotId)
1930 {
1931 ResponseInfo *responseInfo = NULL;
1932 char timeStr[TIME_VALUE_LEN] = { 0 };
1933 struct ReportInfo reportInfo = { 0 };
1934
1935 int32_t ret = SendCommandLock("AT+CCLK?", "+CCLK:", DEFAULT_TIMEOUT, &responseInfo);
1936 if (ret != 0 || responseInfo->success == 0) {
1937 TELEPHONY_LOGE("send AT CMD failed!");
1938 return;
1939 }
1940 if (responseInfo->head == NULL) {
1941 TELEPHONY_LOGE("no data!");
1942 return;
1943 }
1944 Line *pLine = responseInfo->head;
1945 if (pLine->data == NULL) {
1946 TELEPHONY_LOGE("no data!");
1947 return;
1948 }
1949 char *line = pLine->data;
1950 ret = SkipATPrefix(&line);
1951 if (ret < 0) {
1952 TELEPHONY_LOGE("format error!");
1953 return;
1954 }
1955 size_t len = strlen(line) - 1;
1956 if (len <= TIME_VALUE_OFFSET) {
1957 TELEPHONY_LOGE("invalid len!");
1958 return;
1959 }
1960 for (size_t i = TIME_VALUE_OFFSET; i < len; i++) {
1961 timeStr[i - TIME_VALUE_OFFSET] = *(line + i);
1962 }
1963 TELEPHONY_LOGI("netTime:%{public}s", timeStr);
1964 reportInfo.notifyId = HNOTI_NETWORK_TIME_UPDATED;
1965 reportInfo.type = HRIL_NOTIFICATION;
1966 reportInfo.error = HRIL_ERR_SUCCESS;
1967 OnNetworkReport(GetSlotId(NULL), reportInfo, (const uint8_t *)timeStr, TIME_VALUE_LEN);
1968 FreeResponseInfo(responseInfo);
1969 }
1970