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 bool sendFlag = GetAtPauseFlag();
660 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
661 if (sendFlag) {
662 g_reportInfoForOperListToUse.error = HRIL_ERR_NETWORK_SEARCH_TIMEOUT;
663 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
664 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId,
665 g_reportInfoForOperListToUse, NULL, 0);
666 }
667 SetAtPauseFlag(false);
668 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
669 g_reportInfoForOperListToUse.requestInfo = NULL;
670 }
671 TELEPHONY_LOGI("ReqGetNetworkSearchInformation response timeout!");
672 }
673 }
674 return;
675 }
676
ReqGetNetworkSearchInformation(const ReqDataInfo * requestInfo)677 void ReqGetNetworkSearchInformation(const ReqDataInfo *requestInfo)
678 {
679 if (requestInfo == NULL) {
680 return;
681 }
682 ResponseInfo *responseInfo = NULL;
683 const int32_t SECOND = 120;
684 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
685 pthread_mutex_lock(&g_networkSearchInformationMutex);
686 alarm(0);
687 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
688 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NETWORK_SEARCHING, HRIL_RESPONSE, 0);
689 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
690 pthread_mutex_unlock(&g_networkSearchInformationMutex);
691 TELEPHONY_LOGE("ReqGetNetworkSearchInformation repeat Send!");
692 return;
693 }
694 if (signal(SIGALRM, PerformTimeOut) == SIG_ERR) {
695 TELEPHONY_LOGE("ReqGetNetworkSearchInformation signal PerformTimeOut is SIG_ERR!");
696 pthread_mutex_unlock(&g_networkSearchInformationMutex);
697 return;
698 }
699 int32_t ret = SendCommandNetWorksLock("AT+COPS=?", "+COPS:", DEFAULT_TIMEOUT, &responseInfo);
700
701 g_reportInfoForOperListToUse = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
702 if ((ret != 0 && ret != AT_ERR_WAITING) || (responseInfo != NULL && !responseInfo->success)) {
703 TELEPHONY_LOGE("send AT CMD failed!");
704 SetAtPauseFlag(false);
705 g_reportInfoForOperListToUse.error = GetResponseErrorCode(responseInfo);
706 OnNetworkReport(requestInfo->slotId, g_reportInfoForOperListToUse, NULL, 1);
707 if (responseInfo != NULL) {
708 FreeResponseInfo(responseInfo);
709 }
710 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
711 g_reportInfoForOperListToUse.requestInfo = NULL;
712 }
713 pthread_mutex_unlock(&g_networkSearchInformationMutex);
714 return;
715 }
716 alarm(SECOND);
717 if (responseInfo != NULL) {
718 FreeResponseInfo(responseInfo);
719 }
720 pthread_mutex_unlock(&g_networkSearchInformationMutex);
721 SetWatchFunction(GetNetworkSearchInformationPause);
722 }
723
ParseOperInfoItem(char ** lineInfo,char ** const longNameInfo,char ** const shortNameInfo,char ** const numericInfo)724 static int32_t ParseOperInfoItem(
725 char **lineInfo, char **const longNameInfo, char **const shortNameInfo, char **const numericInfo)
726 {
727 if (lineInfo == NULL || longNameInfo == NULL || shortNameInfo == NULL || numericInfo == NULL) {
728 return -1;
729 }
730 char *data = *lineInfo;
731 char **longNameInfoStr = (char **)longNameInfo;
732 char **shortNameInfoStr = (char **)shortNameInfo;
733 char **numericInfoStr = (char **)numericInfo;
734 int32_t ret = NextStr(&data, longNameInfoStr);
735 if (ret < 0) {
736 return -1;
737 }
738 TELEPHONY_LOGD("ok , longName:%{public}s", *longNameInfoStr);
739
740 ret = NextStr(&data, shortNameInfoStr);
741 if (ret < 0) {
742 return -1;
743 }
744 TELEPHONY_LOGD("ok , shortName:%{public}s", *shortNameInfoStr);
745
746 ret = NextStr(&data, numericInfoStr);
747 if (ret < 0) {
748 return -1;
749 }
750 TELEPHONY_LOGD("ok , numeric:%{public}s", *numericInfoStr);
751 *lineInfo = data;
752 return 0;
753 }
754
ParseOperListInfo(const char * lineInfo,int32_t count,AvailableOperInfo * pOperInfo,AvailableOperInfo ** ppOperInfo)755 int32_t ParseOperListInfo(
756 const char *lineInfo, int32_t count, AvailableOperInfo *pOperInfo, AvailableOperInfo **ppOperInfo)
757 {
758 if (lineInfo == NULL || pOperInfo == NULL) {
759 return 0;
760 }
761 int32_t state = 0;
762 int32_t rat = 0;
763 int32_t operCount = 0;
764 char *line = (char *)lineInfo;
765 int32_t item = count;
766 for (int32_t i = 0; i < item && operCount < item; i++) {
767 int32_t ret = MoveLeftBracket(&line);
768 if (ret < 0) {
769 break;
770 }
771 ret = NextInt(&line, &state);
772 if (ret < 0) {
773 break;
774 }
775 char *longName = NULL;
776 char *shortName = NULL;
777 char *numeric = NULL;
778 ret = ParseOperInfoItem(&line, &longName, &shortName, &numeric);
779 if (ret < 0) {
780 break;
781 }
782 ret = NextIntByRightBracket(&line, &rat);
783 if (ret < 0) {
784 break;
785 }
786 if (state > 0) {
787 pOperInfo[operCount].status = state;
788 TELEPHONY_LOGD("pOperInfo , status:%{public}d", pOperInfo[i].status);
789 pOperInfo[operCount].longName = longName;
790 TELEPHONY_LOGD("pOperInfo , longName:%{public}s", longName);
791 pOperInfo[operCount].numeric = numeric;
792 TELEPHONY_LOGD("pOperInfo , numeric:%{public}s", numeric);
793 pOperInfo[operCount].shortName = shortName;
794 TELEPHONY_LOGD("pOperInfo , shortName:%{public}s", shortName);
795 pOperInfo[operCount].rat = rat;
796 TELEPHONY_LOGD("pOperInfo , rat:%{public}d", rat);
797 operCount++;
798 }
799 }
800 return operCount;
801 }
802
ParseListItemNum(const char * list)803 int32_t ParseListItemNum(const char *list)
804 {
805 int32_t item = 0;
806 if (list == NULL) {
807 TELEPHONY_LOGI("ProcessOperListToUse result is null");
808 } else {
809 char *line = (char *)list;
810 while (*line != '\0') {
811 if (*line == ')') {
812 item++;
813 }
814 line++;
815 }
816 }
817 return item;
818 }
819
DealNetworkSearchInformation(int32_t operCount,AvailableOperInfo ** ppOperInfo,AvailableOperInfo * pOperInfo)820 static void DealNetworkSearchInformation(
821 int32_t operCount, AvailableOperInfo **ppOperInfo, AvailableOperInfo *pOperInfo)
822 {
823 if (operCount == 0) {
824 pthread_mutex_lock(&g_networkSearchInformationMutex);
825 SetAtPauseFlag(false);
826 alarm(0);
827 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
828 g_reportInfoForOperListToUse.error = HRIL_ERR_INVALID_RESPONSE;
829 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId, g_reportInfoForOperListToUse, NULL, 0);
830 g_reportInfoForOperListToUse.requestInfo = NULL;
831 }
832 pthread_mutex_unlock(&g_networkSearchInformationMutex);
833 } else {
834 pthread_mutex_lock(&g_networkSearchInformationMutex);
835 SetAtPauseFlag(false);
836 alarm(0);
837 if (g_reportInfoForOperListToUse.requestInfo != NULL) {
838 OnNetworkReport(g_reportInfoForOperListToUse.requestInfo->slotId, g_reportInfoForOperListToUse,
839 (const uint8_t *)ppOperInfo, operCount);
840 g_reportInfoForOperListToUse.requestInfo = NULL;
841 }
842 pthread_mutex_unlock(&g_networkSearchInformationMutex);
843 }
844 if (ppOperInfo != NULL) {
845 free(ppOperInfo);
846 }
847 if (pOperInfo != NULL) {
848 free(pOperInfo);
849 }
850 }
851
ErrorHandling(void)852 static int32_t ErrorHandling(void)
853 {
854 TELEPHONY_LOGE("This command resolution is not supported.");
855 return HRIL_ERR_GENERIC_FAILURE;
856 }
857
ParseCellInfoGsm(const char * str,CellInfo * ci)858 static int32_t ParseCellInfoGsm(const char *str, CellInfo *ci)
859 {
860 if (str == NULL || ci == NULL) {
861 return -1;
862 }
863 char *pStr = (char *)str;
864 char *pat = NULL;
865 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
866 TELEPHONY_LOGD("ParseCellInfoGsm %{public}s", pStr);
867 if (SkipATPrefix(&pStr) < 0) {
868 return ErrorHandling();
869 }
870 if (NextStr(&pStr, &pat) < 0) {
871 return ErrorHandling();
872 }
873 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.band) < 0) {
874 return ErrorHandling();
875 }
876 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.arfcn) < 0) {
877 return ErrorHandling();
878 }
879 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.bsic) < 0) {
880 return ErrorHandling();
881 }
882 if (NextIntFromHex(&pStr, &ci->ServiceCellParas.gsm.cellId) < 0) {
883 return ErrorHandling();
884 }
885 if (NextIntFromHex(&pStr, &ci->ServiceCellParas.gsm.lac) < 0) {
886 return ErrorHandling();
887 }
888 if (NextInt(&pStr, &ci->ServiceCellParas.gsm.rxlev) < 0) {
889 return ErrorHandling();
890 }
891 ci->ratType = NETWORK_TYPE_GSM;
892 return HRIL_ERR_SUCCESS;
893 }
894
ParseCellInfoLte(const char * str,CellInfo * ci)895 static int32_t ParseCellInfoLte(const char *str, CellInfo *ci)
896 {
897 if (str == NULL || ci == NULL) {
898 return -1;
899 }
900 char *pStr = (char *)str;
901 char *pat = NULL;
902 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
903 TELEPHONY_LOGD("ParseCellInfoLte %{public}s", pStr);
904 if (SkipATPrefix(&pStr) < 0) {
905 return ErrorHandling();
906 }
907 if (NextStr(&pStr, &pat) < 0) {
908 return ErrorHandling();
909 }
910 if (NextInt(&pStr, &ci->ServiceCellParas.lte.arfcn) < 0) {
911 return ErrorHandling();
912 }
913 if (NextIntFromHex(&pStr, &ci->ServiceCellParas.lte.pci) < 0) {
914 return ErrorHandling();
915 }
916 if (NextInt(&pStr, &ci->ServiceCellParas.lte.rsrp) < 0) {
917 return ErrorHandling();
918 }
919 if (NextInt(&pStr, &ci->ServiceCellParas.lte.rsrq) < 0) {
920 return ErrorHandling();
921 }
922 if (NextInt(&pStr, &ci->ServiceCellParas.lte.rxlev) < 0) {
923 return ErrorHandling();
924 }
925 ci->ratType = NETWORK_TYPE_LTE;
926 return HRIL_ERR_SUCCESS;
927 }
928
ParseCellInfoWcdma(const char * str,CellInfo * ci)929 static int32_t ParseCellInfoWcdma(const char *str, CellInfo *ci)
930 {
931 if (str == NULL || ci == NULL) {
932 return -1;
933 }
934 char *pStr = (char *)str;
935 char *pat = NULL;
936 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
937 TELEPHONY_LOGD("ParseCellInfoWcdma %{public}s", pStr);
938 if (SkipATPrefix(&pStr) < 0) {
939 return ErrorHandling();
940 }
941 if (NextStr(&pStr, &pat) < 0) {
942 return ErrorHandling();
943 }
944 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.arfcn) < 0) {
945 return ErrorHandling();
946 }
947 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.psc) < 0) {
948 return ErrorHandling();
949 }
950 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.rscp) < 0) {
951 return ErrorHandling();
952 }
953 if (NextInt(&pStr, &ci->ServiceCellParas.wcdma.ecno) < 0) {
954 return ErrorHandling();
955 }
956 ci->ratType = NETWORK_TYPE_WCDMA;
957 return HRIL_ERR_SUCCESS;
958 }
959
ParseCellInfoCdma(const char * str,CellInfo * ci)960 static int32_t ParseCellInfoCdma(const char *str, CellInfo *ci)
961 {
962 if (str == NULL || ci == NULL) {
963 return -1;
964 }
965 char *pStr = (char *)str;
966 char *pat = NULL;
967 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
968 TELEPHONY_LOGD("ParseCellInfoCdma %{public}s", pStr);
969 if (SkipATPrefix(&pStr) < 0) {
970 return ErrorHandling();
971 }
972 if (NextStr(&pStr, &pat) < 0) {
973 return ErrorHandling();
974 }
975 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.systemId) < 0) {
976 return ErrorHandling();
977 }
978 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.networkId) < 0) {
979 return ErrorHandling();
980 }
981 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.baseId) < 0) {
982 return ErrorHandling();
983 }
984 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.zoneId) < 0) {
985 return ErrorHandling();
986 }
987 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.pilotPn) < 0) {
988 return ErrorHandling();
989 }
990 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.pilotStrength) < 0) {
991 return ErrorHandling();
992 }
993 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.channel) < 0) {
994 return ErrorHandling();
995 }
996 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.longitude) < 0) {
997 return ErrorHandling();
998 }
999 if (NextInt(&pStr, &ci->ServiceCellParas.cdma.latitude) < 0) {
1000 return ErrorHandling();
1001 }
1002 ci->ratType = NETWORK_TYPE_CDMA;
1003 return HRIL_ERR_SUCCESS;
1004 }
1005
ParseCellInfoTdscdma(const char * str,CellInfo * ci)1006 static int32_t ParseCellInfoTdscdma(const char *str, CellInfo *ci)
1007 {
1008 if (str == NULL || ci == NULL) {
1009 return -1;
1010 }
1011 char *pStr = (char *)str;
1012 char *pat = NULL;
1013 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
1014 TELEPHONY_LOGD("ParseCellInfoTdscdma %{public}s", pStr);
1015 if (SkipATPrefix(&pStr) < 0) {
1016 return ErrorHandling();
1017 }
1018 if (NextStr(&pStr, &pat) < 0) {
1019 return ErrorHandling();
1020 }
1021 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.arfcn) < 0) {
1022 return ErrorHandling();
1023 }
1024 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.syncId) < 0) {
1025 return ErrorHandling();
1026 }
1027 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.sc) < 0) {
1028 return ErrorHandling();
1029 }
1030 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.cellId) < 0) {
1031 return ErrorHandling();
1032 }
1033 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.lac) < 0) {
1034 return ErrorHandling();
1035 }
1036 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.rscp) < 0) {
1037 return ErrorHandling();
1038 }
1039 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.drx) < 0) {
1040 return ErrorHandling();
1041 }
1042 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.rac) < 0) {
1043 return ErrorHandling();
1044 }
1045 if (NextInt(&pStr, &ci->ServiceCellParas.tdscdma.cpid) < 0) {
1046 return ErrorHandling();
1047 }
1048 ci->ratType = NETWORK_TYPE_TDSCDMA;
1049 return HRIL_ERR_SUCCESS;
1050 }
1051
ParseCellInfoNr(const char * str,CellInfo * ci)1052 static int32_t ParseCellInfoNr(const char *str, CellInfo *ci)
1053 {
1054 if (str == NULL || ci == NULL) {
1055 return -1;
1056 }
1057 char *pStr = (char *)str;
1058 char *pat = NULL;
1059 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
1060 TELEPHONY_LOGD("ParseCellInfoNr %{public}s", pStr);
1061 if (SkipATPrefix(&pStr) < 0) {
1062 return ErrorHandling();
1063 }
1064 if (NextStr(&pStr, &pat) < 0) {
1065 return ErrorHandling();
1066 }
1067 if (NextInt(&pStr, &ci->ServiceCellParas.nr.nrArfcn) < 0) {
1068 return ErrorHandling();
1069 }
1070 if (NextInt(&pStr, &ci->ServiceCellParas.nr.pci) < 0) {
1071 return ErrorHandling();
1072 }
1073 if (NextInt(&pStr, &ci->ServiceCellParas.nr.tac) < 0) {
1074 return ErrorHandling();
1075 }
1076 if (NextInt64(&pStr, &ci->ServiceCellParas.nr.nci) < 0) {
1077 return ErrorHandling();
1078 }
1079 ci->ratType = NETWORK_TYPE_NR;
1080 return HRIL_ERR_SUCCESS;
1081 }
1082
ParseCellInfos(const char * str,const CellInfo * cellInfo)1083 static int32_t ParseCellInfos(const char *str, const CellInfo *cellInfo)
1084 {
1085 CellInfo *ci = (CellInfo *)cellInfo;
1086 char *pStr = (char *)str;
1087 if (pStr == NULL) {
1088 TELEPHONY_LOGE("pStr is null.");
1089 return HRIL_ERR_GENERIC_FAILURE;
1090 }
1091 TELEPHONY_LOGD("ParseCellInfos %{public}s", pStr);
1092 if (ReportStrWith(pStr, "^MONNC: GSM")) {
1093 if (ParseCellInfoGsm(pStr, ci) != 0) {
1094 TELEPHONY_LOGE("parse gsm command failed!");
1095 return HRIL_ERR_GENERIC_FAILURE;
1096 }
1097 } else if (ReportStrWith(pStr, "^MONNC: WCDMA")) {
1098 if (ParseCellInfoWcdma(pStr, ci) != 0) {
1099 TELEPHONY_LOGE("parse wcdma command failed!");
1100 return HRIL_ERR_GENERIC_FAILURE;
1101 }
1102 } else if (ReportStrWith(pStr, "^MONNC: CDMA")) {
1103 if (ParseCellInfoCdma(pStr, ci) != 0) {
1104 TELEPHONY_LOGE("parse cdma command failed!");
1105 return HRIL_ERR_GENERIC_FAILURE;
1106 }
1107 } else if (ReportStrWith(pStr, "^MONNC: TDSCDMA")) {
1108 if (ParseCellInfoTdscdma(pStr, ci) != 0) {
1109 TELEPHONY_LOGE("parse tdscdma command failed!");
1110 return HRIL_ERR_GENERIC_FAILURE;
1111 }
1112 } else if (ReportStrWith(pStr, "^MONNC: LTE")) {
1113 if (ParseCellInfoLte(pStr, ci) != 0) {
1114 TELEPHONY_LOGE("parse lte command failed!");
1115 return HRIL_ERR_GENERIC_FAILURE;
1116 }
1117 } else if (ReportStrWith(pStr, "^MONNC: NR")) {
1118 if (ParseCellInfoNr(pStr, ci) != 0) {
1119 TELEPHONY_LOGE("parse nr command failed!");
1120 return HRIL_ERR_GENERIC_FAILURE;
1121 }
1122 } else if (ReportStrWith(pStr, "^MONNC: NONE")) {
1123 (void)memset_s(ci, sizeof(CellInfo), 0, sizeof(CellInfo));
1124 TELEPHONY_LOGD("ParseCellInfos ^MONNC: NONE branch");
1125 } else {
1126 TELEPHONY_LOGE("%{public}s This command resolution not supported.", pStr);
1127 return HRIL_ERR_GENERIC_FAILURE;
1128 }
1129 return HRIL_ERR_SUCCESS;
1130 }
1131
ReqGetNeighboringCellInfoList(const ReqDataInfo * requestInfo)1132 void ReqGetNeighboringCellInfoList(const ReqDataInfo *requestInfo)
1133 {
1134 if (requestInfo == NULL) {
1135 return;
1136 }
1137 int32_t err = HRIL_ERR_SUCCESS;
1138 int32_t countCellInfo = 0;
1139 int32_t index = 0;
1140 ResponseInfo *responseInfo = NULL;
1141 Line *pLine = NULL;
1142 CellInfo *cellInfo = NULL;
1143 CellInfoList cellInfoList = { 0, NULL };
1144 int32_t ret = SendCommandLock("AT^MONNC", "^MONNC:", DEFAULT_TIMEOUT, &responseInfo);
1145 struct ResponseAck respDataAck = { responseInfo, (uint8_t *)&cellInfoList, sizeof(CellInfoList) };
1146 if (responseInfo == NULL) {
1147 TELEPHONY_LOGE("responseInfo is nullptr");
1148 ResponseNetworkReport(HRIL_SIM_SLOT_0, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1149 return;
1150 }
1151 if (ret != 0 || responseInfo->success == 0) {
1152 TELEPHONY_LOGE("send AT CMD failed!");
1153 err = (ret != 0) ? HRIL_ERR_GENERIC_FAILURE : HRIL_ERR_CMD_SEND_FAILURE;
1154 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1155 return;
1156 }
1157 for (countCellInfo = 0, pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1158 countCellInfo++;
1159 }
1160 if (countCellInfo == 0) {
1161 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1162 return;
1163 }
1164 TELEPHONY_LOGD("countCellInfo:%{public}d", countCellInfo);
1165 cellInfo = (CellInfo *)calloc(countCellInfo, sizeof(CellInfo));
1166 if (cellInfo == NULL) {
1167 TELEPHONY_LOGE("cellInfoList alloc failed!");
1168 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_MEMORY_FULL, &respDataAck);
1169 return;
1170 }
1171 for (pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1172 if (ParseCellInfos(pLine->data, &cellInfo[index]) != 0) {
1173 continue;
1174 }
1175 index++;
1176 }
1177 cellInfoList.itemNum = index;
1178 cellInfoList.cellNearbyInfo = cellInfo;
1179 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1180 free(cellInfo);
1181 return;
1182 }
1183
ParseGetGsmCellInfoLine(char * line,CurrentCellInfoVendor * response)1184 static void ParseGetGsmCellInfoLine(char *line, CurrentCellInfoVendor *response)
1185 {
1186 if (line == NULL || response == NULL) {
1187 return;
1188 }
1189 NextInt(&line, &response->ServiceCellParas.gsm.band);
1190 NextInt(&line, &response->ServiceCellParas.gsm.arfcn);
1191 NextInt(&line, &response->ServiceCellParas.gsm.bsic);
1192 NextIntFromHex(&line, &response->ServiceCellParas.gsm.cellId);
1193 NextIntFromHex(&line, &response->ServiceCellParas.gsm.lac);
1194 NextInt(&line, &response->ServiceCellParas.gsm.rxlev);
1195 NextInt(&line, &response->ServiceCellParas.gsm.rxQuality);
1196 NextInt(&line, &response->ServiceCellParas.gsm.ta);
1197 response->ServiceCellParas.gsm.rxlev = -response->ServiceCellParas.gsm.rxlev;
1198 TELEPHONY_LOGD("ParseGetGsmCellInfoLine band:%{private}d,arfcn:%{private}d,bsic:%{private}d,cellId:%{private}d"
1199 "lac:%{private}d,rxlev:%{private}d,rxQuality:%{private}d,ta:%{private}d",
1200 response->ServiceCellParas.gsm.band, response->ServiceCellParas.gsm.arfcn, response->ServiceCellParas.gsm.bsic,
1201 response->ServiceCellParas.gsm.cellId, response->ServiceCellParas.gsm.lac, response->ServiceCellParas.gsm.rxlev,
1202 response->ServiceCellParas.gsm.rxQuality, response->ServiceCellParas.gsm.ta);
1203 }
1204
ParseGetLteCellInfoLine(char * line,CurrentCellInfoVendor * response)1205 static void ParseGetLteCellInfoLine(char *line, CurrentCellInfoVendor *response)
1206 {
1207 if (line == NULL || response == NULL) {
1208 return;
1209 }
1210 NextInt(&line, &response->ServiceCellParas.lte.arfcn);
1211 NextIntFromHex(&line, &response->ServiceCellParas.lte.cellId);
1212 NextIntFromHex(&line, &response->ServiceCellParas.lte.pci);
1213 NextIntFromHex(&line, &response->ServiceCellParas.lte.tac);
1214 NextInt(&line, &response->ServiceCellParas.lte.rsrp);
1215 NextInt(&line, &response->ServiceCellParas.lte.rsrq);
1216 NextInt(&line, &response->ServiceCellParas.lte.rssi);
1217 response->ServiceCellParas.lte.rsrp = -response->ServiceCellParas.lte.rsrp;
1218 TELEPHONY_LOGD("ParseGetLteCellInfoLine arfcn:%{private}d,cellId:%{private}d,pci:%{private}d"
1219 "tac:%{private}d,rsrp:%{private}d,rsrq:%{private}d,rssi:%{private}d",
1220 response->ServiceCellParas.lte.arfcn, response->ServiceCellParas.lte.cellId, response->ServiceCellParas.lte.pci,
1221 response->ServiceCellParas.lte.tac, response->ServiceCellParas.lte.rsrp, response->ServiceCellParas.lte.rsrq,
1222 response->ServiceCellParas.lte.rssi);
1223 }
1224
ParseGetWcdmaCellInfoLine(char * line,CurrentCellInfoVendor * response)1225 static void ParseGetWcdmaCellInfoLine(char *line, CurrentCellInfoVendor *response)
1226 {
1227 if (line == NULL || response == NULL) {
1228 return;
1229 }
1230 NextInt(&line, &response->ServiceCellParas.wcdma.arfcn);
1231 NextInt(&line, &response->ServiceCellParas.wcdma.psc);
1232 NextIntFromHex(&line, &response->ServiceCellParas.wcdma.cellId);
1233 NextIntFromHex(&line, &response->ServiceCellParas.wcdma.lac);
1234 NextInt(&line, &response->ServiceCellParas.wcdma.rscp);
1235 NextInt(&line, &response->ServiceCellParas.wcdma.rxlev);
1236 NextInt(&line, &response->ServiceCellParas.wcdma.ecno);
1237 NextInt(&line, &response->ServiceCellParas.wcdma.drx);
1238 NextInt(&line, &response->ServiceCellParas.wcdma.ura);
1239 response->ServiceCellParas.wcdma.rscp = -response->ServiceCellParas.wcdma.rscp;
1240 TELEPHONY_LOGD("ParseGetWcdmaCellInfoLine arfcn:%{private}d,psc:%{private}d,cellId:%{private}d,lac:%{private}d"
1241 "rscp:%{private}d,rxlev:%{private}d,ecno:%{private}d,drx:%{private}d,ura:%{private}d",
1242 response->ServiceCellParas.wcdma.arfcn, response->ServiceCellParas.wcdma.psc,
1243 response->ServiceCellParas.wcdma.cellId, response->ServiceCellParas.wcdma.lac,
1244 response->ServiceCellParas.wcdma.rscp, response->ServiceCellParas.wcdma.rxlev,
1245 response->ServiceCellParas.wcdma.ecno, response->ServiceCellParas.wcdma.drx,
1246 response->ServiceCellParas.wcdma.ura);
1247 }
1248
ParseGetCdmaCellInfoLine(char * line,CurrentCellInfoVendor * response)1249 static void ParseGetCdmaCellInfoLine(char *line, CurrentCellInfoVendor *response)
1250 {
1251 if (line == NULL || response == NULL) {
1252 return;
1253 }
1254 NextInt(&line, &response->ServiceCellParas.cdma.systemId);
1255 NextInt(&line, &response->ServiceCellParas.cdma.networkId);
1256 NextIntFromHex(&line, &response->ServiceCellParas.cdma.baseId);
1257 NextIntFromHex(&line, &response->ServiceCellParas.cdma.zoneId);
1258 NextInt(&line, &response->ServiceCellParas.cdma.pilotPn);
1259 NextInt(&line, &response->ServiceCellParas.cdma.pilotStrength);
1260 NextInt(&line, &response->ServiceCellParas.cdma.channel);
1261 NextInt(&line, &response->ServiceCellParas.cdma.longitude);
1262 NextInt(&line, &response->ServiceCellParas.cdma.latitude);
1263 response->ServiceCellParas.cdma.pilotStrength = -response->ServiceCellParas.cdma.pilotStrength;
1264 TELEPHONY_LOGD(
1265 "ParseGetCdmaCellInfoLine systemId:%{private}d,networkId:%{private}d,baseId:%{private}d,zoneId:%{private}d"
1266 "pilotPn:%{private}d,pilotStrength:%{private}d,channel:%{private}d,longitude:%{private}d,latitude:%{private}d",
1267 response->ServiceCellParas.cdma.systemId, response->ServiceCellParas.cdma.networkId,
1268 response->ServiceCellParas.cdma.baseId, response->ServiceCellParas.cdma.zoneId,
1269 response->ServiceCellParas.cdma.pilotPn, response->ServiceCellParas.cdma.pilotStrength,
1270 response->ServiceCellParas.cdma.channel, response->ServiceCellParas.cdma.longitude,
1271 response->ServiceCellParas.cdma.latitude);
1272 }
1273
ParseGetTdscdmaCellInfoLine(char * line,CurrentCellInfoVendor * response)1274 static void ParseGetTdscdmaCellInfoLine(char *line, CurrentCellInfoVendor *response)
1275 {
1276 if (line == NULL || response == NULL) {
1277 return;
1278 }
1279 NextInt(&line, &response->ServiceCellParas.tdscdma.arfcn);
1280 NextInt(&line, &response->ServiceCellParas.tdscdma.syncId);
1281 NextInt(&line, &response->ServiceCellParas.tdscdma.sc);
1282 NextIntFromHex(&line, &response->ServiceCellParas.tdscdma.cellId);
1283 NextIntFromHex(&line, &response->ServiceCellParas.tdscdma.lac);
1284 NextInt(&line, &response->ServiceCellParas.tdscdma.rscp);
1285 NextInt(&line, &response->ServiceCellParas.tdscdma.drx);
1286 NextIntFromHex(&line, &response->ServiceCellParas.tdscdma.rac);
1287 NextInt(&line, &response->ServiceCellParas.tdscdma.cpid);
1288 response->ServiceCellParas.tdscdma.rscp = -response->ServiceCellParas.tdscdma.rscp;
1289 TELEPHONY_LOGD("ParseGetTdscdmaCellInfoLine arfcn:%{private}d,syncId:%{private}d,sc:%{private}d,cellId:%{private}d,"
1290 "lac:%{private}d,rscp:%{private}d,drx:%{private}d,rac:%{private}d,cpid:%{private}d,",
1291 response->ServiceCellParas.tdscdma.arfcn, response->ServiceCellParas.tdscdma.syncId,
1292 response->ServiceCellParas.tdscdma.sc, response->ServiceCellParas.tdscdma.cellId,
1293 response->ServiceCellParas.tdscdma.lac, response->ServiceCellParas.tdscdma.rscp,
1294 response->ServiceCellParas.tdscdma.drx, response->ServiceCellParas.tdscdma.rac,
1295 response->ServiceCellParas.tdscdma.cpid);
1296 }
1297
ParseGetNrCellInfoLine(char * line,CurrentCellInfoVendor * response)1298 static void ParseGetNrCellInfoLine(char *line, CurrentCellInfoVendor *response)
1299 {
1300 if (line == NULL || response == NULL) {
1301 return;
1302 }
1303 NextInt(&line, &response->ServiceCellParas.nr.nrArfcn);
1304 NextInt(&line, &response->ServiceCellParas.nr.pci);
1305 NextInt(&line, &response->ServiceCellParas.nr.tac);
1306 NextInt64(&line, &response->ServiceCellParas.nr.nci);
1307 }
1308
ParseGetCurrentCellInfoResponseLineSwitch(const char * str,const CurrentCellInfoVendor * hrilResponse)1309 static int32_t ParseGetCurrentCellInfoResponseLineSwitch(const char *str, const CurrentCellInfoVendor *hrilResponse)
1310 {
1311 char *line = (char *)str;
1312 CurrentCellInfoVendor *response = (CurrentCellInfoVendor *)hrilResponse;
1313 if ((line == NULL) || (response == NULL)) {
1314 TELEPHONY_LOGE("ParseGetCurrentCellInfoResponseLineSwitch line or response param is null");
1315 return HRIL_ERR_NULL_POINT;
1316 }
1317 switch (response->ratType) {
1318 case NETWORK_TYPE_GSM:
1319 ParseGetGsmCellInfoLine(line, response);
1320 break;
1321 case NETWORK_TYPE_LTE:
1322 ParseGetLteCellInfoLine(line, response);
1323 break;
1324 case NETWORK_TYPE_WCDMA:
1325 ParseGetWcdmaCellInfoLine(line, response);
1326 break;
1327 case NETWORK_TYPE_CDMA:
1328 ParseGetCdmaCellInfoLine(line, response);
1329 break;
1330 case NETWORK_TYPE_TDSCDMA:
1331 ParseGetTdscdmaCellInfoLine(line, response);
1332 break;
1333 case NETWORK_TYPE_NR:
1334 ParseGetNrCellInfoLine(line, response);
1335 break;
1336 default:
1337 TELEPHONY_LOGE("ParseGetCellInfoResponseLineSwitch is not support cell, line = %{public}s", line);
1338 break;
1339 }
1340 return HRIL_ERR_SUCCESS;
1341 }
1342
ParseGetCurrentCellInfoResponseLine(char * line,CurrentCellInfoVendor * response)1343 static int32_t ParseGetCurrentCellInfoResponseLine(char *line, CurrentCellInfoVendor *response)
1344 {
1345 if (line == NULL || response == NULL) {
1346 return -1;
1347 }
1348 char *c = NULL;
1349 TELEPHONY_LOGD("ParseGetCurrentCellInfoResponseLine line %{public}s", line);
1350 int32_t err = SkipATPrefix(&line);
1351 if (err < 0) {
1352 return err;
1353 }
1354 err = NextStr(&line, &c);
1355 if (err < 0) {
1356 return err;
1357 }
1358 if (!strcmp(c, "GSM")) {
1359 response->ratType = NETWORK_TYPE_GSM;
1360 } else if (!strcmp(c, "LTE")) {
1361 response->ratType = NETWORK_TYPE_LTE;
1362 } else if (!strcmp(c, "WCDMA")) {
1363 response->ratType = NETWORK_TYPE_WCDMA;
1364 } else if (!strcmp(c, "CDMA")) {
1365 response->ratType = NETWORK_TYPE_CDMA;
1366 } else if (!strcmp(c, "TDSCDMA")) {
1367 response->ratType = NETWORK_TYPE_TDSCDMA;
1368 } else if (!strcmp(c, "NR")) {
1369 response->ratType = NETWORK_TYPE_NR;
1370 } else if (!strcmp(c, "NONE")) {
1371 (void)memset_s(response, sizeof(CurrentCellInfoVendor), 0, sizeof(CurrentCellInfoVendor));
1372 response->ratType = NETWORK_TYPE_UNKNOWN;
1373 return HRIL_ERR_SUCCESS;
1374 } else {
1375 TELEPHONY_LOGI("ParseCurrentCellInfo unSupport ratType line %{public}s", line);
1376 return -1;
1377 }
1378 err = NextInt(&line, &response->mcc);
1379 if (err < 0) {
1380 return err;
1381 }
1382 err = NextInt(&line, &response->mnc);
1383 if (err < 0) {
1384 return err;
1385 }
1386 ParseGetCurrentCellInfoResponseLineSwitch(line, response);
1387 return HRIL_ERR_SUCCESS;
1388 }
1389
ProcessCurrentCellList(struct ReportInfo reportInfo,const char * s)1390 int32_t ProcessCurrentCellList(struct ReportInfo reportInfo, const char *s)
1391 {
1392 char *str = (char *)s;
1393 if (str == NULL) {
1394 TELEPHONY_LOGE("ProcessCurrentCellList Str is null.");
1395 return HRIL_ERR_GENERIC_FAILURE;
1396 }
1397 int32_t err = SkipATPrefix(&str);
1398 if (err < 0) {
1399 TELEPHONY_LOGE("ProcessCurrentCellList skip failed: [%{public}s]", str);
1400 return HRIL_ERR_GENERIC_FAILURE;
1401 }
1402 int32_t semicolonNum = FindSemicolonCharNum(str);
1403 if (semicolonNum > 0) {
1404 CurrentCellInfoVendor *cciv = NULL;
1405 CurrentCellInfoList cellList = {0, NULL};
1406 cciv = (CurrentCellInfoVendor *)calloc(semicolonNum, sizeof(CurrentCellInfoVendor));
1407 if (cciv == NULL) {
1408 TELEPHONY_LOGE("^MONSC: notify CurrentCellInfoVendor alloc failed!");
1409 return HRIL_ERR_MEMORY_FULL;
1410 }
1411 for (int32_t i = 0; i < semicolonNum; i++) {
1412 char *pStr = strsep(&str, ";");
1413 if (ParseGetCurrentCellInfoResponseLine(pStr, &cciv[cellList.itemNum]) != 0) {
1414 continue;
1415 }
1416 cellList.itemNum++;
1417 }
1418 cellList.currentCellInfo = cciv;
1419 reportInfo.error = HRIL_ERR_SUCCESS;
1420 reportInfo.type = HRIL_NOTIFICATION;
1421 reportInfo.notifyId = HNOTI_NETWORK_CURRENT_CELL_UPDATED;
1422 OnNetworkReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&cellList, sizeof(CurrentCellInfoList));
1423 if (cellList.currentCellInfo != NULL) {
1424 free(cellList.currentCellInfo);
1425 }
1426 return HRIL_ERR_SUCCESS;
1427 } else {
1428 TELEPHONY_LOGW("^MONSC: notify str format unexpected: %{public}s", str);
1429 return HRIL_ERR_GENERIC_FAILURE;
1430 }
1431 }
1432
ReqGetCurrentCellInfo(const ReqDataInfo * requestInfo)1433 void ReqGetCurrentCellInfo(const ReqDataInfo *requestInfo)
1434 {
1435 if (requestInfo == NULL) {
1436 return;
1437 }
1438 int32_t err = HRIL_ERR_SUCCESS;
1439 int32_t countCellInfo = 0;
1440 int32_t index = 0;
1441 ResponseInfo *responseInfo = NULL;
1442 Line *pLine = NULL;
1443 CurrentCellInfoVendor *currCellInfo = NULL;
1444 CurrentCellInfoList currCellInfoList = { 0, NULL };
1445 int32_t ret = SendCommandLock("AT^MONSC", "^MONSC:", DEFAULT_TIMEOUT, &responseInfo);
1446 struct ResponseAck respDataAck = { responseInfo, (uint8_t *)&currCellInfoList, sizeof(CurrentCellInfoList) };
1447 if (responseInfo == NULL) {
1448 TELEPHONY_LOGE("AT^MONSC responseInfo is nullptr");
1449 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1450 return;
1451 }
1452 if (ret != 0 || responseInfo->success == 0) {
1453 TELEPHONY_LOGE("AT^MONSC send AT CMD failed!");
1454 err = (ret != 0) ? HRIL_ERR_GENERIC_FAILURE : HRIL_ERR_CMD_SEND_FAILURE;
1455 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1456 return;
1457 }
1458 for (countCellInfo = 0, pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1459 countCellInfo++;
1460 }
1461 if (countCellInfo == 0) {
1462 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1463 return;
1464 }
1465 currCellInfo = (CurrentCellInfoVendor *)calloc(countCellInfo, sizeof(CurrentCellInfoVendor));
1466 if (currCellInfo == NULL) {
1467 TELEPHONY_LOGE("currentCellList countCellInfo:%{public}d,currCellInfo alloc failed!", countCellInfo);
1468 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_MEMORY_FULL, &respDataAck);
1469 return;
1470 }
1471 for (pLine = responseInfo->head; pLine != NULL; pLine = pLine->next) {
1472 if (ParseGetCurrentCellInfoResponseLine(pLine->data, &currCellInfo[index]) != 0) {
1473 continue;
1474 }
1475 index++;
1476 }
1477 currCellInfoList.itemNum = index;
1478 currCellInfoList.currentCellInfo = currCellInfo;
1479 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1480 free(currCellInfo);
1481 return;
1482 }
1483
OperListErrorHandler(AvailableOperInfo ** ppOperInfo,AvailableOperInfo * pOperInfo)1484 static int32_t OperListErrorHandler(AvailableOperInfo **ppOperInfo, AvailableOperInfo *pOperInfo)
1485 {
1486 TELEPHONY_LOGE("ReqGetNetworkSearchInformation Failed");
1487 DealNetworkSearchInformation(0, ppOperInfo, pOperInfo);
1488 return HRIL_ERR_GENERIC_FAILURE;
1489 }
1490
ProcessOperListToUse(const char * list)1491 int32_t ProcessOperListToUse(const char *list)
1492 {
1493 const int32_t UNUSED_ITEM_COUNT = 2;
1494 AvailableOperInfo **ppOperInfo = NULL;
1495 AvailableOperInfo *pOperInfo = NULL;
1496 SetAtPauseFlag(false);
1497 alarm(0);
1498 int32_t item = ParseListItemNum(list);
1499 if (item <= UNUSED_ITEM_COUNT) {
1500 return OperListErrorHandler(ppOperInfo, pOperInfo);
1501 }
1502 char *line = (char *)list;
1503 int32_t ret = SkipATPrefix(&line);
1504 if (ret < 0) {
1505 return OperListErrorHandler(ppOperInfo, pOperInfo);
1506 }
1507
1508 item = item - UNUSED_ITEM_COUNT;
1509 ppOperInfo = (AvailableOperInfo **)malloc(item * sizeof(AvailableOperInfo *));
1510 if (!ppOperInfo) {
1511 TELEPHONY_LOGE("ppOperInfo malloc fail");
1512 return OperListErrorHandler(ppOperInfo, pOperInfo);
1513 }
1514
1515 pOperInfo = (AvailableOperInfo *)malloc(item * sizeof(AvailableOperInfo));
1516 if (!pOperInfo) {
1517 TELEPHONY_LOGE("pOperInfo malloc fail");
1518 return OperListErrorHandler(ppOperInfo, pOperInfo);
1519 }
1520 (void)memset_s(pOperInfo, item * sizeof(AvailableOperInfo), 0, item * sizeof(AvailableOperInfo));
1521 for (int32_t j = 0; j < item; j++) {
1522 ppOperInfo[j] = &(pOperInfo[j]);
1523 }
1524
1525 int32_t operCount = ParseOperListInfo(line, item, pOperInfo, ppOperInfo);
1526 if (operCount != 0) {
1527 DealNetworkSearchInformation(operCount, ppOperInfo, pOperInfo);
1528 } else {
1529 return OperListErrorHandler(ppOperInfo, pOperInfo);
1530 }
1531 return HRIL_ERR_SUCCESS;
1532 }
1533
PrepareSetNetworkSelectionMode(char * cmd,const HRilSetNetworkModeInfo * setModeInfo)1534 static bool PrepareSetNetworkSelectionMode(char *cmd, const HRilSetNetworkModeInfo *setModeInfo)
1535 {
1536 if (cmd == NULL || setModeInfo == NULL) {
1537 return false;
1538 }
1539 bool ret = true;
1540 TELEPHONY_LOGD("setModeInfo, serial123 = %{public}d", setModeInfo->selectMode);
1541 if (setModeInfo->selectMode == 0) {
1542 (void)sprintf_s(cmd, MAX_CMD_LENGTH, "%s", "AT+COPS=0");
1543 } else if (setModeInfo->selectMode == 1) {
1544 if (setModeInfo->oper == NULL) {
1545 ret = false;
1546 } else {
1547 (void)sprintf_s(cmd, MAX_CMD_LENGTH, "AT+COPS=1,2,%s", setModeInfo->oper);
1548 }
1549 } else {
1550 ret = false;
1551 }
1552 return ret;
1553 }
1554
ReqSetNetworkSelectionMode(const ReqDataInfo * requestInfo,const HRilSetNetworkModeInfo * data)1555 void ReqSetNetworkSelectionMode(const ReqDataInfo *requestInfo, const HRilSetNetworkModeInfo *data)
1556 {
1557 if (requestInfo == NULL) {
1558 return;
1559 }
1560
1561 ResponseInfo *responseInfo = NULL;
1562 char cmd[MAX_CMD_LENGTH] = {0};
1563 char *cmdBuff = cmd;
1564 struct ReportInfo reportInfo;
1565 HRilSetNetworkModeInfo *setModeInfo = (HRilSetNetworkModeInfo *)data;
1566 if (setModeInfo == NULL) {
1567 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
1568 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 1);
1569 TELEPHONY_LOGE("SetAutomaticMode HRIL_ERR_NULL_POINT");
1570 return;
1571 }
1572 if (!PrepareSetNetworkSelectionMode(cmdBuff, setModeInfo)) {
1573 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1574 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 1);
1575 TELEPHONY_LOGE("SetAutomaticMode HRIL_ERR_INVALID_PARAMETER");
1576 return;
1577 }
1578 TELEPHONY_LOGD("requestSetAutomaticModeForNetworks, cmd = %{public}s", cmd);
1579 int32_t err = SendCommandLock(cmd, NULL, 0, &responseInfo);
1580
1581 if (responseInfo == NULL) {
1582 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
1583 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 1);
1584 TELEPHONY_LOGE("SetAutomaticMode responseInfo == NULL");
1585 return;
1586 }
1587 TELEPHONY_LOGD("SetAutomaticModeForNetworks, responseInfo->success = %{public}d", responseInfo->success);
1588 if (err != 0 || responseInfo->success == 0) {
1589 TELEPHONY_LOGE("ret is not equal to HDF_SUCCESS!");
1590 err = GetResponseErrorCode(responseInfo);
1591 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1592 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1593 TELEPHONY_LOGE("SetAutomaticMode HRIL_ERR_GENERIC_FAILURE");
1594 FreeResponseInfo(responseInfo);
1595 return;
1596 }
1597 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1598 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1599 FreeResponseInfo(responseInfo);
1600 }
1601
ReqGetNetworkSelectionMode(const ReqDataInfo * requestInfo)1602 void ReqGetNetworkSelectionMode(const ReqDataInfo *requestInfo)
1603 {
1604 if (requestInfo == NULL) {
1605 return;
1606 }
1607 int32_t err = HRIL_ERR_SUCCESS;
1608 ResponseInfo *responseInfo = NULL;
1609 int32_t state = 0;
1610 struct ReportInfo reportInfo;
1611 int32_t ret = SendCommandLock("AT+COPS?", "+COPS:", DEFAULT_TIMEOUT, &responseInfo);
1612 struct ResponseAck respDataAck = { responseInfo, NULL, 0 };
1613 if (responseInfo == NULL) {
1614 TELEPHONY_LOGE("responseInfo is nullptr");
1615 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_NULL_POINT, HRIL_RESPONSE, 0);
1616 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1617 return;
1618 }
1619 if (ret != 0 || responseInfo->success == 0) {
1620 err = GetResponseErrorCode(responseInfo);
1621 TELEPHONY_LOGE("send AT CMD failed!");
1622 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1623 return;
1624 }
1625 if (responseInfo->head == NULL) {
1626 TELEPHONY_LOGE("no data!");
1627 err = HRIL_ERR_NULL_POINT;
1628 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1629 return;
1630 }
1631 char *line = responseInfo->head->data;
1632 ret = SkipATPrefix(&line);
1633 if (ret < 0) {
1634 err = HRIL_ERR_INVALID_RESPONSE;
1635 TELEPHONY_LOGE("Response is Invalid!");
1636 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1637 return;
1638 }
1639 ret = NextInt(&line, &state);
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 int32_t mode = (int32_t)state;
1647 respDataAck.respDataPointer = (uint8_t *)&mode;
1648 respDataAck.respDataLen = sizeof(int32_t);
1649 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_SUCCESS, &respDataAck);
1650 NotifyNetWorkTime(requestInfo->slotId);
1651 return;
1652 }
1653
IntToNetTypeCmd(int32_t value,char * dst,int32_t dstMaxSize)1654 static int32_t IntToNetTypeCmd(int32_t value, char *dst, int32_t dstMaxSize)
1655 {
1656 int32_t len = MAX_CMD_LENGTH - 1;
1657 (void)strcat_s(dst, len, "AT^SYSCFGEX=\"");
1658 const int32_t MAX_PREFERRED_NET_ENUM = 99;
1659 const int32_t MIN_CHAR_ARRAY_SIZE = 50;
1660 const int32_t CONVERT_FAIL = -1;
1661 const int32_t DECIMAL = 10;
1662 if ((value > MAX_PREFERRED_NET_ENUM) || (value < 0) || (dstMaxSize < MIN_CHAR_ARRAY_SIZE)) {
1663 return CONVERT_FAIL;
1664 }
1665 int32_t pos = strlen(dst);
1666 if (pos > len - ADD_LENGTH) {
1667 return CONVERT_FAIL;
1668 }
1669 if (value < DECIMAL) {
1670 dst[pos++] = '0';
1671 dst[pos++] = (value % DECIMAL) + '0';
1672 } else {
1673 dst[pos++] = (value / DECIMAL) + '0';
1674 dst[pos++] = (value % DECIMAL) + '0';
1675 }
1676 dst[pos++] = '\"';
1677 dst[pos] = '\0';
1678 return 0;
1679 }
1680
PrepareCommandByNetworkType(HRilPreferredNetworkType net)1681 static char *PrepareCommandByNetworkType(HRilPreferredNetworkType net)
1682 {
1683 char *cmd = (char *)calloc(1, MAX_CMD_LENGTH);
1684 if (cmd != NULL) {
1685 TELEPHONY_LOGD("SetPreferredNetwork, net = %{public}d", net);
1686 if (net == HRIL_NETWORK_AUTO) {
1687 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"00\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1688 } else if (net == HRIL_NETWORK_GSM) {
1689 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"01\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1690 } else if (net == HRIL_NETWORK_WCDMA) {
1691 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"02\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1692 } else if (net == HRIL_NETWORK_LTE) {
1693 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"03\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1694 } else if (net == HRIL_NETWORK_LTE_WCDMA_GSM) {
1695 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"030201\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1696 } else if (net == HRIL_NETWORK_WCDMA_GSM) {
1697 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"0201\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1698 } else if (net == HRIL_NETWORK_LTE_WCDMA) {
1699 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", "AT^SYSCFGEX=\"0302\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,0,0");
1700 } else {
1701 if (((net > HRIL_NETWORK_WCDMA_GSM) && (net <= HRIL_NETWORK_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA)) ||
1702 ((net >= HRIL_NETWORK_NR) && (net <= HRIL_NETWORK_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA))) {
1703 char dst[MAX_CMD_LENGTH] = {0};
1704 IntToNetTypeCmd(net, dst, MAX_CMD_LENGTH);
1705 GenerateCommand(cmd, MAX_CMD_LENGTH, "%s", dst);
1706 } else {
1707 free(cmd);
1708 cmd = NULL;
1709 }
1710 }
1711 }
1712 return cmd;
1713 }
1714
ReqSetPreferredNetwork(const ReqDataInfo * requestInfo,const int32_t * data)1715 void ReqSetPreferredNetwork(const ReqDataInfo *requestInfo, const int32_t *data)
1716 {
1717 if (requestInfo == NULL) {
1718 return;
1719 }
1720 ResponseInfo *responseInfo = NULL;
1721 struct ReportInfo reportInfo;
1722 if (data == NULL) {
1723 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1724 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1725 return;
1726 }
1727 int32_t net = *(int32_t *)data;
1728 int32_t err = HRIL_ERR_INVALID_PARAMETER;
1729 char *cmd = PrepareCommandByNetworkType(net);
1730 if (cmd == NULL) {
1731 TELEPHONY_LOGE("RequestReqSetPreferredNetwork HRIL_ERR_INVALID_PARAMETER cmd NULL");
1732 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1733 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1734 return;
1735 }
1736 err = SendCommandLock(cmd, NULL, 0, &responseInfo);
1737 if (cmd != NULL) {
1738 free(cmd);
1739 cmd = NULL;
1740 }
1741 if (responseInfo == NULL) {
1742 reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
1743 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1744 return;
1745 }
1746 if (err != 0 || responseInfo->success == 0) {
1747 err = GetResponseErrorCode(responseInfo);
1748 }
1749 reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1750 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1751 FreeResponseInfo(responseInfo);
1752 }
1753
ParseNetTypeStr(const char * netType)1754 static int32_t ParseNetTypeStr(const char *netType)
1755 {
1756 TELEPHONY_LOGD("enter to [%{public}s]:%{public}d", __func__, __LINE__);
1757 if (netType == NULL) {
1758 TELEPHONY_LOGE("ParseNetTypeStr netType is null");
1759 return -1;
1760 }
1761 TELEPHONY_LOGD("netType: [%{public}s]", netType);
1762 if (strcmp(netType, AUTO_TYPE) == 0) {
1763 return HRIL_NETWORK_AUTO;
1764 } else if (strcmp(netType, GSM_TYPE) == 0) {
1765 return HRIL_NETWORK_GSM;
1766 } else if (strcmp(netType, WCDMA_TYPE) == 0) {
1767 return HRIL_NETWORK_WCDMA;
1768 } else if (strcmp(netType, LTE_TYPE) == 0) {
1769 return HRIL_NETWORK_LTE;
1770 } else if (strcmp(netType, LTE_WCDMA_TYPE) == 0) {
1771 return HRIL_NETWORK_LTE_WCDMA;
1772 } else if (strcmp(netType, LTE_WCDMA_GSM_TYPE) == 0) {
1773 return HRIL_NETWORK_LTE_WCDMA_GSM;
1774 } else if (strcmp(netType, WCDMA_GSM_TYPE) == 0) {
1775 return HRIL_NETWORK_WCDMA_GSM;
1776 } else {
1777 int32_t net = ConvertCharToInt32(netType);
1778 if (((net > HRIL_NETWORK_WCDMA_GSM) && (net <= HRIL_NETWORK_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA)) ||
1779 ((net >= HRIL_NETWORK_NR) && (net <= HRIL_NETWORK_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA))) {
1780 return net;
1781 } else {
1782 return -1;
1783 }
1784 }
1785 }
1786
ReqGetPreferredNetwork(const ReqDataInfo * requestInfo)1787 void ReqGetPreferredNetwork(const ReqDataInfo *requestInfo)
1788 {
1789 if (requestInfo == NULL) {
1790 return;
1791 }
1792 int32_t err = HRIL_ERR_SUCCESS;
1793 ResponseInfo *responseInfo = NULL;
1794 char *netTypeStr = "";
1795 int32_t ret = SendCommandLock("AT^SYSCFGEX?", "^SYSCFGEX:", DEFAULT_TIMEOUT, &responseInfo);
1796 struct ResponseAck respDataAck = { responseInfo, NULL, 0 };
1797 if (responseInfo == NULL) {
1798 TELEPHONY_LOGE("responseInfo is null");
1799 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_NULL_POINT, &respDataAck);
1800 return;
1801 }
1802 respDataAck.responseInfo = responseInfo;
1803 if (ret != 0 || !responseInfo->success) {
1804 err = GetResponseErrorCode(responseInfo);
1805 TELEPHONY_LOGE("send AT CMD failed!");
1806 ResponseNetworkReport(requestInfo->slotId, requestInfo, err, &respDataAck);
1807 return;
1808 }
1809 if (responseInfo->head == NULL) {
1810 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1811 return;
1812 }
1813 Line *pLine = responseInfo->head;
1814 char *line = pLine->data;
1815 if (SkipATPrefix(&line) < 0) {
1816 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1817 return;
1818 }
1819 if (NextStr(&line, &netTypeStr) < 0) {
1820 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_INVALID_RESPONSE, &respDataAck);
1821 return;
1822 }
1823 int32_t netType = ParseNetTypeStr(netTypeStr);
1824 respDataAck.respDataPointer = (uint8_t *)&netType;
1825 respDataAck.respDataLen = sizeof(int32_t);
1826 ResponseNetworkReport(requestInfo->slotId, requestInfo, HRIL_ERR_SUCCESS, &respDataAck);
1827 }
1828
ProcessPhyChnlCfgNotify(struct ReportInfo reportInfo,char * srcStr)1829 void ProcessPhyChnlCfgNotify(struct ReportInfo reportInfo, char *srcStr)
1830 {
1831 int32_t contextIds[] = { 7, 8, 9 };
1832 HRilPhyChannelConfig configInfo = { 1, 2, 3, 4, 5, 6, 3 };
1833 configInfo.contextIds = contextIds;
1834 HRilChannelConfigList configInfoList = { 1, &configInfo };
1835 reportInfo.error = HRIL_ERR_SUCCESS;
1836 reportInfo.type = HRIL_NOTIFICATION;
1837 reportInfo.notifyId = HNOTI_NETWORK_PHY_CHNL_CFG_UPDATED;
1838 OnNetworkReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&configInfoList, sizeof(HRilChannelConfigList));
1839 }
1840
ReqGetPhysicalChannelConfig(const ReqDataInfo * requestInfo)1841 void ReqGetPhysicalChannelConfig(const ReqDataInfo *requestInfo)
1842 {
1843 if (requestInfo == NULL) {
1844 TELEPHONY_LOGE("ReqGetPhysicalChannelConfig requestInfo is NULL");
1845 return;
1846 }
1847 int32_t contextIds[] = { 7, 8, 9 };
1848 HRilPhyChannelConfig configInfo = { HRIL_SERVING_CELL_PRIMARY, RADIO_TECHNOLOGY_GSM, 1, 2, 3, 4, 5, 6, 1 };
1849 configInfo.contextIds = contextIds;
1850 HRilChannelConfigList configInfoList = { 1, &configInfo };
1851 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
1852 OnNetworkReport(requestInfo->slotId, reportInfo, (const uint8_t *)&configInfoList, sizeof(HRilChannelConfigList));
1853 }
1854
ReqSetLocateUpdates(const ReqDataInfo * requestInfo,HRilRegNotifyMode mode)1855 void ReqSetLocateUpdates(const ReqDataInfo *requestInfo, HRilRegNotifyMode mode)
1856 {
1857 if (requestInfo == NULL) {
1858 return;
1859 }
1860 ResponseInfo *responseInfo = NULL;
1861 char *cmd = NULL;
1862 if (mode == REG_NOTIFY_STAT_LAC_CELLID) {
1863 cmd = "AT+CREG=2";
1864 } else if (mode == REG_NOTIFY_STAT_ONLY) {
1865 cmd = "AT+CREG=1";
1866 } else {
1867 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1868 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1869 TELEPHONY_LOGE("ReqSetLocateUpdates: locateUpdateMode > 1");
1870 return;
1871 }
1872 int32_t err = SendCommandLock(cmd, NULL, DEFAULT_TIMEOUT, &responseInfo);
1873 if (responseInfo == NULL) {
1874 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
1875 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1876 TELEPHONY_LOGE("ReqSetLocateUpdates responseInfo == NULL");
1877 return;
1878 }
1879 TELEPHONY_LOGD("ReqSetLocateUpdates, responseInfo->success = %{public}d", responseInfo->success);
1880 if (err != 0 || responseInfo->success == 0) {
1881 err = GetResponseErrorCode(responseInfo);
1882 TELEPHONY_LOGE("ReqSetLocateUpdates errcode = %{public}d", err);
1883 }
1884 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1885 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1886 FreeResponseInfo(responseInfo);
1887 }
1888
ReqSetNotificationFilter(const ReqDataInfo * requestInfo,const int32_t * newFilter)1889 void ReqSetNotificationFilter(const ReqDataInfo *requestInfo, const int32_t *newFilter)
1890 {
1891 if (requestInfo == NULL) {
1892 TELEPHONY_LOGE("ReqSetNotificationFilter requestInfo is NULL");
1893 return;
1894 }
1895 if (newFilter == NULL) {
1896 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1897 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1898 return;
1899 }
1900 TELEPHONY_LOGD("ReqSetNotificationFilter success");
1901 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
1902 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1903 }
1904
ReqSetDeviceState(const ReqDataInfo * requestInfo,const int32_t * deviceStateType,const int32_t * deviceStateOn)1905 void ReqSetDeviceState(const ReqDataInfo *requestInfo, const int32_t *deviceStateType, const int32_t *deviceStateOn)
1906 {
1907 if (requestInfo == NULL) {
1908 TELEPHONY_LOGE("ReqSetDeviceState requestInfo is NULL");
1909 return;
1910 }
1911
1912 if (deviceStateType == NULL || deviceStateOn == NULL) {
1913 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
1914 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1915 return;
1916 }
1917 TELEPHONY_LOGD("ReqSetDeviceState success");
1918 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
1919 OnNetworkReport(requestInfo->slotId, reportInfo, NULL, 0);
1920 }
1921
NotifyNetWorkTime(int32_t slotId)1922 void NotifyNetWorkTime(int32_t slotId)
1923 {
1924 ResponseInfo *responseInfo = NULL;
1925 char timeStr[TIME_VALUE_LEN] = { 0 };
1926 struct ReportInfo reportInfo = { 0 };
1927
1928 int32_t ret = SendCommandLock("AT+CCLK?", "+CCLK:", DEFAULT_TIMEOUT, &responseInfo);
1929 if (ret != 0 || responseInfo->success == 0) {
1930 TELEPHONY_LOGE("send AT CMD failed!");
1931 return;
1932 }
1933 if (responseInfo->head == NULL) {
1934 TELEPHONY_LOGE("no data!");
1935 return;
1936 }
1937 Line *pLine = responseInfo->head;
1938 if (pLine->data == NULL) {
1939 TELEPHONY_LOGE("no data!");
1940 return;
1941 }
1942 char *line = pLine->data;
1943 ret = SkipATPrefix(&line);
1944 if (ret < 0) {
1945 TELEPHONY_LOGE("format error!");
1946 return;
1947 }
1948 size_t len = strlen(line) - 1;
1949 if (len <= TIME_VALUE_OFFSET) {
1950 TELEPHONY_LOGE("invalid len!");
1951 return;
1952 }
1953 for (size_t i = TIME_VALUE_OFFSET; i < len; i++) {
1954 timeStr[i - TIME_VALUE_OFFSET] = *(line + i);
1955 }
1956 TELEPHONY_LOGI("netTime:%{public}s", timeStr);
1957 reportInfo.notifyId = HNOTI_NETWORK_TIME_UPDATED;
1958 reportInfo.type = HRIL_NOTIFICATION;
1959 reportInfo.error = HRIL_ERR_SUCCESS;
1960 OnNetworkReport(GetSlotId(NULL), reportInfo, (const uint8_t *)timeStr, TIME_VALUE_LEN);
1961 FreeResponseInfo(responseInfo);
1962 }
1963