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