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_call.h"
17
18 #include "hril_notification.h"
19 #include "securec.h"
20 #include "vendor_report.h"
21 #include "vendor_util.h"
22
23 #undef DEFAULT_TIMEOUT
24 #define DEFAULT_TIMEOUT 5000
25 #define DEFAULT_TIMEOUT_CLCK 50000
26
27 CallNotify g_callNotifyTab[] = {
28 {"^CCALLSTATE:", ReportCallStateUpdated},
29 {"+CUSD:", ReportCallUssdNotice},
30 {"+CIREPH:", ReportSrvccStatusUpdate},
31 {"^CSCHANNELINFO:", ReportCsChannelInfo},
32 {"^XLEMA:", ReportEmergencyNumberList},
33 };
34
35 static int32_t lastCcCause = HRIL_ERR_CALL_CAUSE;
36 static const int32_t MAX_CALL_NUM = 100;
37
OnCallReportErrorMessages(const ReqDataInfo * requestInfo,int32_t err,ResponseInfo * pResponse)38 static void OnCallReportErrorMessages(const ReqDataInfo *requestInfo, int32_t err, ResponseInfo *pResponse)
39 {
40 int32_t errorNo = HRIL_ERR_SUCCESS;
41 ModemReportErrorInfo errInfo = GetReportErrorInfo(pResponse);
42 errorNo = (err != HRIL_ERR_SUCCESS) ? err : errInfo.errorNo;
43 TELEPHONY_LOGW("Report error! ret:%{public}d", errorNo);
44 FreeResponseInfo(pResponse);
45 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, errorNo, HRIL_RESPONSE, 0);
46 reportInfo.modemErrInfo = errInfo;
47 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
48 }
49
ParseDiffPart(int32_t isAllInfo,char ** pLine,HRilCallInfo * outCall)50 static int32_t ParseDiffPart(int32_t isAllInfo, char **pLine, HRilCallInfo *outCall)
51 {
52 if (outCall == NULL) {
53 return HRIL_ERR_NULL_POINT;
54 }
55 int32_t tmp = 0;
56 if (isAllInfo) {
57 if (NextInt(pLine, &outCall->voiceDomain) < 0) {
58 return HRIL_ERR_NULL_POINT;
59 }
60 if (NextInt(pLine, &outCall->callType) < 0) {
61 return HRIL_ERR_NULL_POINT;
62 }
63 NextInt(pLine, &tmp); // ignore
64 } else {
65 outCall->voiceDomain = INT_DEFAULT_VALUE;
66 outCall->callType = INT_DEFAULT_VALUE;
67 }
68 return 0;
69 }
70
CallCmdCLCC(const char * lineCmd,HRilCallInfo * outCall)71 static int32_t CallCmdCLCC(const char *lineCmd, HRilCallInfo *outCall)
72 {
73 char *pLine = (char *)lineCmd;
74 int32_t state;
75 int32_t mode;
76
77 if (pLine == NULL || outCall == NULL) {
78 TELEPHONY_LOGE("src or desc pointer is null.");
79 return HRIL_ERR_NULL_POINT;
80 }
81 int32_t isAllInfo = ReportStrWith(pLine, "^CLCC:");
82 if (SkipATPrefix(&pLine) < 0) {
83 return HRIL_ERR_NULL_POINT;
84 }
85 if (NextInt(&pLine, &outCall->index) < 0) {
86 return HRIL_ERR_NULL_POINT;
87 }
88 if (NextInt(&pLine, &outCall->dir) < 0) {
89 return HRIL_ERR_NULL_POINT;
90 }
91 if (NextInt(&pLine, &state) < 0) {
92 return HRIL_ERR_NULL_POINT;
93 }
94 outCall->state = (HRilCallState)state;
95 if (NextInt(&pLine, &mode) < 0) {
96 return HRIL_ERR_NULL_POINT;
97 }
98 outCall->mode = (HRilCallMode)mode;
99 if (NextInt(&pLine, &outCall->mpty) < 0) {
100 return HRIL_ERR_NULL_POINT;
101 }
102 if (ParseDiffPart(isAllInfo, &pLine, outCall)) {
103 return HRIL_ERR_NULL_POINT;
104 }
105 if (NextStr(&pLine, &outCall->number) < 0) {
106 return HRIL_ERR_NULL_POINT;
107 }
108 if (NextInt(&pLine, &outCall->type) < 0) {
109 return HRIL_ERR_NULL_POINT;
110 }
111
112 if (pLine != NULL) { // The data returned by some modules does not have this alpha data.
113 if (NextStr(&pLine, &outCall->alpha) < 0) {
114 return HRIL_ERR_NULL_POINT;
115 }
116 }
117 return HRIL_ERR_SUCCESS;
118 }
119
ReportCallStateUpdated(const char * str)120 void ReportCallStateUpdated(const char *str)
121 {
122 int32_t err = HRIL_ERR_SUCCESS;
123 char *pStr = (char *)str;
124 int callId = 0;
125 int voiceDomain = 0;
126 int state = 0;
127 ReqDataInfo requestInfo = {0};
128 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
129
130 if (SkipATPrefix(&pStr) < 0) {
131 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
132 }
133 if (NextInt(&pStr, &callId) < 0) {
134 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
135 }
136 if (NextInt(&pStr, &state) < 0) {
137 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
138 }
139 if (NextInt(&pStr, &voiceDomain) < 0) {
140 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
141 }
142
143 struct ReportInfo reportInfo = CreateReportInfo(&requestInfo, err, HRIL_NOTIFICATION, HNOTI_CALL_STATE_UPDATED);
144 reportInfo.modemErrInfo = errInfo;
145 OnCallReport(GetSlotId(NULL), reportInfo, NULL, 0);
146 }
147
ReportSrvccStatusUpdate(const char * str)148 void ReportSrvccStatusUpdate(const char *str)
149 {
150 int32_t err = HRIL_ERR_SUCCESS;
151 char *pStr = (char *)str;
152 HRilCallSrvccStatus srvccStatus = {0};
153 ReqDataInfo requestInfo = {0};
154 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
155
156 if (SkipATPrefix(&pStr) < 0) {
157 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
158 }
159 if (err == HRIL_ERR_SUCCESS && NextInt(&pStr, &srvccStatus.status) < 0) {
160 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
161 }
162
163 struct ReportInfo reportInfo =
164 CreateReportInfo(&requestInfo, err, HRIL_NOTIFICATION, HNOTI_CALL_SRVCC_STATUS_REPORT);
165 reportInfo.modemErrInfo = errInfo;
166 OnCallReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&srvccStatus, sizeof(HRilCallSrvccStatus));
167 }
168
ReportCsChannelInfo(const char * str)169 void ReportCsChannelInfo(const char *str)
170 {
171 int32_t err = HRIL_ERR_SUCCESS;
172 char *pStr = (char *)str;
173 HRilCallCsChannelInfo csChannelInfo = {0};
174 ReqDataInfo requestInfo = {0};
175 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
176 /* 0 network alerting; 1 local alerting */
177 int32_t ringbackVoiceFlag = 0;
178
179 if (SkipATPrefix(&pStr) < 0) {
180 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
181 }
182 if (err == HRIL_ERR_SUCCESS && NextInt(&pStr, &csChannelInfo.status) < 0) {
183 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
184 }
185 if (err == HRIL_ERR_SUCCESS && NextInt(&pStr, &csChannelInfo.voiceDomain) < 0) {
186 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
187 }
188
189 ringbackVoiceFlag = !csChannelInfo.status;
190 struct ReportInfo reportInfo =
191 CreateReportInfo(&requestInfo, err, HRIL_NOTIFICATION, HNOTI_CALL_RINGBACK_VOICE_REPORT);
192 reportInfo.modemErrInfo = errInfo;
193 OnCallReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&ringbackVoiceFlag, sizeof(int32_t));
194 }
195
IsCallNoticeCmd(const char * str)196 int32_t IsCallNoticeCmd(const char *str)
197 {
198 int32_t tabSize = sizeof(g_callNotifyTab) / sizeof(CallNotify);
199 for (int32_t i = 0; i < tabSize; i++) {
200 if (ReportStrWith(str, g_callNotifyTab[i].cmd)) {
201 return 1;
202 }
203 }
204 return 0;
205 }
206
CallReportInfoProcess(const char * str)207 void CallReportInfoProcess(const char *str)
208 {
209 int32_t tabSize = sizeof(g_callNotifyTab) / sizeof(CallNotify);
210 for (int32_t i = 0; i < tabSize; i++) {
211 if (ReportStrWith(str, g_callNotifyTab[i].cmd)) {
212 g_callNotifyTab[i].function(str);
213 break;
214 }
215 }
216 }
217
ReportEmergencyNumberList(const char * str)218 void ReportEmergencyNumberList(const char *str)
219 {
220 int32_t err = HRIL_ERR_SUCCESS;
221 char *pStr = (char *)str;
222 HRilEmergencyInfo pEmergencyInfo = {0};
223 ReqDataInfo requestInfo = {0};
224 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
225
226 if (SkipATPrefix(&pStr) < 0) {
227 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
228 }
229 if (NextInt(&pStr, &pEmergencyInfo.index) < 0) {
230 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
231 }
232 if (NextInt(&pStr, &pEmergencyInfo.total) < 0) {
233 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
234 }
235 if (NextStr(&pStr, &pEmergencyInfo.eccNum) < 0) {
236 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
237 }
238 if (NextInt(&pStr, &pEmergencyInfo.category) < 0) {
239 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
240 }
241 if (NextInt(&pStr, &pEmergencyInfo.simpresent) < 0) {
242 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
243 }
244 if (NextStr(&pStr, &pEmergencyInfo.mcc) < 0) {
245 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
246 }
247 if (NextInt(&pStr, &pEmergencyInfo.abnormalService) < 0) {
248 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
249 }
250
251 struct ReportInfo reportInfo =
252 CreateReportInfo(&requestInfo, err, HRIL_NOTIFICATION, HNOTI_CALL_EMERGENCY_NUMBER_REPORT);
253 reportInfo.modemErrInfo = errInfo;
254 OnCallReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&pEmergencyInfo, sizeof(pEmergencyInfo));
255 }
256
ReportCallUssdNotice(const char * str)257 void ReportCallUssdNotice(const char *str)
258 {
259 int32_t err = HRIL_ERR_SUCCESS;
260 char *pStr = (char *)str;
261 HRilUssdNoticeInfo ussdNoticeInfo = {0};
262 ReqDataInfo requestInfo = {0};
263 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
264
265 if (SkipATPrefix(&pStr) < 0) {
266 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
267 }
268 if (NextInt(&pStr, &ussdNoticeInfo.m) < 0) {
269 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
270 }
271 if (NextStr(&pStr, &ussdNoticeInfo.str) < 0) {
272 err = HRIL_ERR_INVALID_MODEM_PARAMETER;
273 }
274 struct ReportInfo reportInfo = CreateReportInfo(&requestInfo, err, HRIL_NOTIFICATION, HNOTI_CALL_USSD_REPORT);
275 reportInfo.modemErrInfo = errInfo;
276 OnCallReport(GetSlotId(NULL), reportInfo, (const uint8_t *)&ussdNoticeInfo, sizeof(HRilUssdNoticeInfo));
277 }
278
InitCallListCmdBuffer(const ResponseInfo * pResponse,int32_t * callNum,HRilCallInfo ** pCalls)279 static int32_t InitCallListCmdBuffer(const ResponseInfo *pResponse, int32_t *callNum, HRilCallInfo **pCalls)
280 {
281 int32_t ret;
282 int32_t callNumTmp = 0;
283 Line *pLine = NULL;
284 HRilCallInfo *pCallsTmp = NULL;
285
286 if (pResponse == NULL || pCalls == NULL || callNum == NULL) {
287 TELEPHONY_LOGE("params: %{public}p,%{public}p,%{public}p", pResponse, callNum, pCalls);
288 return HRIL_ERR_NULL_POINT;
289 }
290
291 *callNum = 0;
292 *pCalls = NULL;
293
294 for (pLine = pResponse->head; pLine != NULL; pLine = pLine->next) {
295 callNumTmp++;
296 }
297 if (!callNumTmp) {
298 callNumTmp++; // Malloc size cannot be 0.
299 }
300 if (callNumTmp > MAX_CALL_NUM) {
301 TELEPHONY_LOGE("callNumTmp is invalid");
302 return HRIL_ERR_INVALID_PARAMETER;
303 }
304 pCallsTmp = (HRilCallInfo *)malloc(callNumTmp * sizeof(HRilCallInfo));
305 if (pCallsTmp == NULL) {
306 TELEPHONY_LOGE("ReqGetCallList malloc pCalls failure");
307 return HRIL_ERR_MEMORY_FULL;
308 }
309 ret = memset_s(pCallsTmp, callNumTmp * sizeof(HRilCallInfo), 0, callNumTmp * sizeof(HRilCallInfo));
310 if (ret != EOK) {
311 TELEPHONY_LOGE("memset_s is failed!");
312 free(pCallsTmp);
313 pCallsTmp = NULL;
314 return ret;
315 }
316
317 *pCalls = pCallsTmp;
318 *callNum = callNumTmp;
319
320 return HRIL_ERR_SUCCESS;
321 }
322
BuildCallInfoList(const ReqDataInfo * requestInfo,ResponseInfo * response)323 int32_t BuildCallInfoList(const ReqDataInfo *requestInfo, ResponseInfo *response)
324 {
325 int32_t ret = 0;
326 int32_t callNum = 0;
327 int32_t validCallNum = 0;
328 int32_t err = HRIL_ERR_SUCCESS;
329 Line *pLine = NULL;
330 ResponseInfo *pResponse = response;
331 HRilCallInfo *pCalls = NULL;
332
333 if (pResponse == NULL || requestInfo == NULL) {
334 TELEPHONY_LOGE("response or requestInfo is null.");
335 return HRIL_ERR_NULL_POINT;
336 }
337 if (pResponse->success == 0) {
338 TELEPHONY_LOGE("send cmd return ERROR");
339 err = HRIL_ERR_GENERIC_FAILURE;
340 }
341
342 ret = InitCallListCmdBuffer(pResponse, &callNum, &pCalls);
343 if (ret != HRIL_ERR_SUCCESS) {
344 TELEPHONY_LOGE("init command failed: %{public}d", ret);
345 return ret;
346 }
347
348 for (pLine = pResponse->head; pLine != NULL && validCallNum < callNum; pLine = pLine->next) {
349 ret = CallCmdCLCC(pLine->data, pCalls + validCallNum);
350 if (ret != 0) {
351 TELEPHONY_LOGE("Parse CLCC data is fail. ret:%{public}d", ret);
352 continue;
353 }
354 validCallNum++;
355 }
356
357 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
358 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)pCalls, sizeof(HRilCallInfo) * validCallNum);
359 FreeResponseInfo(pResponse);
360 free(pCalls);
361 return HRIL_ERR_SUCCESS;
362 }
363
ReqGetCallList(const ReqDataInfo * requestInfo)364 void ReqGetCallList(const ReqDataInfo *requestInfo)
365 {
366 int32_t ret;
367 ResponseInfo *pResponse = NULL;
368 int32_t err = HRIL_ERR_SUCCESS;
369 long timeOut = DEFAULT_TIMEOUT;
370
371 ret = SendCommandLock("AT+CLCC", "+CLCC:", timeOut, &pResponse);
372 if (ret || (pResponse != NULL && !pResponse->success)) {
373 err = ret ? ret : err;
374 TELEPHONY_LOGE("cmd send failed, err:%{public}d", err);
375 if (err < HRIL_ERR_SUCCESS) {
376 err = HRIL_ERR_GENERIC_FAILURE;
377 }
378 OnCallReportErrorMessages(requestInfo, err, pResponse);
379 return;
380 }
381 err = BuildCallInfoList(requestInfo, pResponse);
382 if (err != HRIL_ERR_SUCCESS) {
383 if (err < HRIL_ERR_SUCCESS) {
384 err = HRIL_ERR_GENERIC_FAILURE;
385 }
386 TELEPHONY_LOGE("Build Call Info List is failed.");
387 OnCallReportErrorMessages(requestInfo, err, pResponse);
388 }
389 }
390
ReqDial(const ReqDataInfo * requestInfo,const HRilDial * data,size_t dataLen)391 void ReqDial(const ReqDataInfo *requestInfo, const HRilDial *data, size_t dataLen)
392 {
393 HRilDial *pDial = NULL;
394 char cmd[MAX_CMD_LENGTH] = {0};
395 const char *clir = NULL;
396 int32_t ret;
397 int32_t err = HRIL_ERR_SUCCESS;
398 ResponseInfo *pResponse = NULL;
399
400 if (data == NULL) {
401 TELEPHONY_LOGE("data is null!!!");
402 return;
403 }
404
405 pDial = (HRilDial *)data;
406 switch (pDial->clir) {
407 case CALL_CLIR_INVOCATION:
408 clir = "I";
409 break; /* invocation */
410 case CALL_CLIR_SUPPRESSION:
411 clir = "i";
412 break; /* suppression */
413 case CALL_CLIR_SUBSCRIPTION_DEFAULT:
414 default:
415 clir = "";
416 break; /* subscription default */
417 }
418
419 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "ATD%s%s;", pDial->address, clir);
420 if (ret < 0) {
421 TELEPHONY_LOGE("GenerateCommand is failed!");
422 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
423 return;
424 }
425 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
426 if (ret != 0) {
427 err = HRIL_ERR_CMD_SEND_FAILURE;
428 TELEPHONY_LOGE("ATD send failed");
429 } else {
430 if (pResponse == NULL || !pResponse->success) {
431 TELEPHONY_LOGE("ReqDial return ERROR");
432 err = HRIL_ERR_CMD_NO_CARRIER;
433 }
434 }
435
436 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
437 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
438 FreeResponseInfo(pResponse);
439 }
440
ReqHangup(const ReqDataInfo * requestInfo,const uint32_t * data,size_t dataLen)441 void ReqHangup(const ReqDataInfo *requestInfo, const uint32_t *data, size_t dataLen)
442 {
443 const int32_t *pLine = NULL;
444 int32_t ret;
445 int32_t err = HRIL_ERR_SUCCESS;
446 char cmd[MAX_CMD_LENGTH] = {0};
447 ResponseInfo *pResponse = NULL;
448
449 if (data == NULL) {
450 TELEPHONY_LOGE("data is null!!!");
451 return;
452 }
453 pLine = (const int32_t *)data;
454 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CHLD=1%d", pLine[0]);
455 if (ret < 0) {
456 TELEPHONY_LOGE("GenerateCommand is failed!");
457 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
458 return;
459 }
460 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
461 if (ret != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
462 TELEPHONY_LOGE("AT+CHLD send failed");
463 err = HRIL_ERR_GENERIC_FAILURE;
464 }
465
466 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
467 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
468 FreeResponseInfo(pResponse);
469 }
470
ReqReject(const ReqDataInfo * requestInfo)471 void ReqReject(const ReqDataInfo *requestInfo)
472 {
473 ResponseInfo *pResponse = NULL;
474 int32_t ret;
475 int32_t err = HRIL_ERR_SUCCESS;
476
477 ret = SendCommandLock("ATH", NULL, 0, &pResponse);
478 if (ret != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
479 TELEPHONY_LOGE("ATH send failed");
480 err = HRIL_ERR_GENERIC_FAILURE;
481 }
482
483 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
484 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
485 FreeResponseInfo(pResponse);
486 }
487
ReqAnswer(const ReqDataInfo * requestInfo)488 void ReqAnswer(const ReqDataInfo *requestInfo)
489 {
490 int32_t ret;
491 int32_t err = HRIL_ERR_SUCCESS;
492 ResponseInfo *pResponse = NULL;
493
494 ret = SendCommandLock("ATA", NULL, 0, &pResponse);
495 if (ret != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
496 err = HRIL_ERR_GENERIC_FAILURE;
497 }
498
499 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
500 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
501 FreeResponseInfo(pResponse);
502 }
503
504 // Calling line identification presentation
ReqGetClip(const ReqDataInfo * requestInfo)505 void ReqGetClip(const ReqDataInfo *requestInfo)
506 {
507 HRilGetClipResult result = {0};
508 int32_t err = HRIL_ERR_SUCCESS;
509 ResponseInfo *pResponse = NULL;
510
511 err = SendCommandLock("AT+CLIP?", "+CLIP", 0, &pResponse);
512 if (err == HRIL_ERR_SUCCESS) {
513 if (pResponse == NULL || !pResponse->success) {
514 TELEPHONY_LOGE("CLIP return ERROR");
515 err = HRIL_ERR_GENERIC_FAILURE;
516 } else {
517 if (pResponse->head != NULL) {
518 char *line = pResponse->head->data;
519 SkipATPrefix(&line);
520 NextInt(&line, &result.action);
521 NextInt(&line, &result.clipStat);
522 } else {
523 TELEPHONY_LOGE("ERROR: ReqGetClip pResponse->head is null");
524 err = HRIL_ERR_GENERIC_FAILURE;
525 }
526 }
527 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
528 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&result, sizeof(result));
529 FreeResponseInfo(pResponse);
530 } else {
531 TELEPHONY_LOGE("ReqGetClip send failed");
532 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_CMD_SEND_FAILURE, HRIL_RESPONSE, 0);
533 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&result, 0);
534 }
535 }
536
ReqSetClip(const ReqDataInfo * requestInfo,int32_t action)537 void ReqSetClip(const ReqDataInfo *requestInfo, int32_t action)
538 {
539 char cmd[MAX_CMD_LENGTH] = {0};
540 int32_t err = HRIL_ERR_SUCCESS;
541 ResponseInfo *pResponse = NULL;
542
543 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLIP=%d", action);
544 if (ret < 0) {
545 TELEPHONY_LOGE("GenerateCommand is failed!");
546 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
547 return;
548 }
549 err = SendCommandLock(cmd, NULL, 0, &pResponse);
550 if (err == HRIL_ERR_SUCCESS) {
551 if (pResponse == NULL || !pResponse->success) {
552 TELEPHONY_LOGE("ReqSetClip return ERROR");
553 err = HRIL_ERR_GENERIC_FAILURE;
554 }
555
556 FreeResponseInfo(pResponse);
557 } else {
558 TELEPHONY_LOGE("ReqSetClip send failed");
559 err = HRIL_ERR_GENERIC_FAILURE;
560 }
561 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
562 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
563 }
564
ReqGetClir(const ReqDataInfo * requestInfo)565 void ReqGetClir(const ReqDataInfo *requestInfo)
566 {
567 HRilGetCallClirResult result = {0};
568 int32_t err = HRIL_ERR_SUCCESS;
569 ResponseInfo *pResponse = NULL;
570
571 err = SendCommandLock("AT+CLIR?", "+CLIR", 0, &pResponse);
572 if (err == HRIL_ERR_SUCCESS) {
573 if (pResponse == NULL || !pResponse->success) {
574 TELEPHONY_LOGE("CLIR return ERROR");
575 err = HRIL_ERR_GENERIC_FAILURE;
576 } else {
577 if (pResponse->head != NULL) {
578 char *line = pResponse->head->data;
579 SkipATPrefix(&line);
580 NextInt(&line, &result.action);
581 NextInt(&line, &result.clirStat);
582 } else {
583 TELEPHONY_LOGE("ERROR: ReqGetClir pResponse->head is null");
584 err = HRIL_ERR_GENERIC_FAILURE;
585 }
586 }
587 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
588 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&result, sizeof(result));
589 FreeResponseInfo(pResponse);
590 } else {
591 TELEPHONY_LOGE("ReqGetClir send failed");
592 err = HRIL_ERR_CMD_SEND_FAILURE;
593 OnCallReportErrorMessages(requestInfo, err, pResponse);
594 }
595 }
596
ReqSetClir(const ReqDataInfo * requestInfo,int32_t action)597 void ReqSetClir(const ReqDataInfo *requestInfo, int32_t action)
598 {
599 char cmd[MAX_CMD_LENGTH] = {0};
600 int32_t err = HRIL_ERR_SUCCESS;
601 ResponseInfo *pResponse = NULL;
602
603 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLIR=%d", action);
604 if (ret < 0) {
605 TELEPHONY_LOGE("GenerateCommand is failed!");
606 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
607 return;
608 }
609 err = SendCommandLock(cmd, NULL, 0, &pResponse);
610 if (err != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
611 TELEPHONY_LOGE("ReqSetClir send failed");
612 err = HRIL_ERR_GENERIC_FAILURE;
613 }
614 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
615 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
616 FreeResponseInfo(pResponse);
617 }
618
ReqStartDtmf(const ReqDataInfo * requestInfo,CallDtmfInfo info)619 void ReqStartDtmf(const ReqDataInfo *requestInfo, CallDtmfInfo info)
620 {
621 char cmd[MAX_CMD_LENGTH] = {0};
622 int32_t err = HRIL_ERR_SUCCESS;
623 ResponseInfo *pResponse = NULL;
624
625 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^DTMF=%d,%c,1,0", info.callId, info.dtmfKey[0]);
626 if (ret < 0) {
627 TELEPHONY_LOGE("GenerateCommand is failed!");
628 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
629 return;
630 }
631 err = SendCommandLock(cmd, NULL, 0, &pResponse);
632 if (err != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
633 TELEPHONY_LOGE("ReqStartDtmf send failed");
634 err = HRIL_ERR_GENERIC_FAILURE;
635 }
636 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
637 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
638 FreeResponseInfo(pResponse);
639 }
640
ReqSendDtmf(const ReqDataInfo * requestInfo,CallDtmfInfo info)641 void ReqSendDtmf(const ReqDataInfo *requestInfo, CallDtmfInfo info)
642 {
643 char cmd[MAX_CMD_LENGTH] = {0};
644 int32_t err = HRIL_ERR_SUCCESS;
645 ResponseInfo *pResponse = NULL;
646 int32_t stringLength = 0;
647 int32_t ret;
648
649 if (info.dtmfKey == NULL) {
650 err = HRIL_ERR_NULL_POINT;
651 OnCallReportErrorMessages(requestInfo, err, NULL);
652 return;
653 }
654
655 for (stringLength = 0; stringLength < info.stringLength; stringLength++) {
656 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^DTMF=%d,%c,%d,%d", info.callId, info.dtmfKey[stringLength],
657 info.onLength, info.offLength);
658 if (ret < 0) {
659 TELEPHONY_LOGE("GenerateCommand is failed!");
660 continue;
661 }
662 err = SendCommandLock(cmd, NULL, 0, &pResponse);
663 if (err != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
664 TELEPHONY_LOGE("ReqSendDtmf send failed");
665 err = HRIL_ERR_GENERIC_FAILURE;
666 break;
667 }
668 }
669 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
670 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
671 FreeResponseInfo(pResponse);
672 }
673
ReqStopDtmf(const ReqDataInfo * requestInfo,CallDtmfInfo info)674 void ReqStopDtmf(const ReqDataInfo *requestInfo, CallDtmfInfo info)
675 {
676 char cmd[MAX_CMD_LENGTH] = {0};
677 int32_t err = HRIL_ERR_SUCCESS;
678 ResponseInfo *pResponse = NULL;
679
680 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^DTMF=%d,%c,0,0", info.callId, info.dtmfKey[0]);
681 if (ret < 0) {
682 TELEPHONY_LOGE("GenerateCommand is failed!");
683 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
684 return;
685 }
686 err = SendCommandLock(cmd, NULL, 0, &pResponse);
687 if (err != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
688 TELEPHONY_LOGE("ReqStopDtmf send failed");
689 err = HRIL_ERR_GENERIC_FAILURE;
690 }
691 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
692 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
693 FreeResponseInfo(pResponse);
694 }
695
HoldCallAndUnHoldCallAtSend(const ReqDataInfo * requestInfo)696 static void HoldCallAndUnHoldCallAtSend(const ReqDataInfo *requestInfo)
697 {
698 int32_t ret;
699 int32_t err = HRIL_ERR_SUCCESS;
700 ResponseInfo *pResponse = NULL;
701
702 ret = SendCommandLock("AT+CHLD=2", NULL, 0, &pResponse);
703 if (ret != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
704 TELEPHONY_LOGE("ATA send failed");
705 err = HRIL_ERR_GENERIC_FAILURE;
706 }
707
708 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
709 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
710 FreeResponseInfo(pResponse);
711 }
712
ReqHoldCall(const ReqDataInfo * requestInfo)713 void ReqHoldCall(const ReqDataInfo *requestInfo)
714 {
715 HoldCallAndUnHoldCallAtSend(requestInfo);
716 }
717
ReqUnHoldCall(const ReqDataInfo * requestInfo)718 void ReqUnHoldCall(const ReqDataInfo *requestInfo)
719 {
720 HoldCallAndUnHoldCallAtSend(requestInfo);
721 }
722
ReqSwitchCall(const ReqDataInfo * requestInfo)723 void ReqSwitchCall(const ReqDataInfo *requestInfo)
724 {
725 HoldCallAndUnHoldCallAtSend(requestInfo);
726 }
727
ReqCombineConference(const ReqDataInfo * requestInfo,int32_t callType)728 void ReqCombineConference(const ReqDataInfo *requestInfo, int32_t callType)
729 {
730 char cmd[MAX_CMD_LENGTH] = {0};
731 int32_t ret = 0;
732 int32_t count = 3;
733 int32_t err = HRIL_ERR_SUCCESS;
734
735 /* call type
736 * 0: Voice call
737 * 1: Video call: send one-way video, two-way voice
738 * 2: Video call: one-way receiving video, two-way voice
739 * 3: Video call: two-way video, two-way voice
740 */
741 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CHLD=3");
742 if (ret < 0) {
743 TELEPHONY_LOGE("GenerateCommand is failed!");
744 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
745 return;
746 }
747 // "Adds a held call to the conversation"
748 if (callType >= 0 && callType <= count) {
749 long timeout = DEFAULT_TIMEOUT;
750 ret = SendCommandLock(cmd, NULL, timeout, NULL);
751 if (ret != HRIL_ERR_SUCCESS) {
752 TELEPHONY_LOGE("ATA send failed");
753 err = HRIL_ERR_CMD_SEND_FAILURE;
754 }
755 } else {
756 TELEPHONY_LOGE("onRequest HREQ_CALL_COMBINE_CONFERENCE args error!!! \n");
757 err = HRIL_ERR_INVALID_PARAMETER;
758 }
759 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
760 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
761 }
762
ReqSeparateConference(const ReqDataInfo * requestInfo,int32_t callIndex,int32_t callType)763 void ReqSeparateConference(const ReqDataInfo *requestInfo, int32_t callIndex, int32_t callType)
764 {
765 char cmd[MAX_CMD_LENGTH] = {0};
766 int32_t ret = 0;
767 int32_t count = 3;
768 int32_t err = HRIL_ERR_SUCCESS;
769 ResponseInfo *pResponse = NULL;
770
771 // Make sure that party is in a valid range.
772 // (Note: The Telephony middle layer imposes a range of 1 to 7.
773 // It's sufficient for us to just make sure it's single digit.)
774 if ((callIndex > 0) && (callType >= 0 && callType <= count)) {
775 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CHLD=2%d", callIndex);
776 if (ret < 0) {
777 TELEPHONY_LOGE("GenerateCommand is failed!");
778 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
779 return;
780 }
781 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
782 if (ret != HRIL_ERR_SUCCESS) {
783 TELEPHONY_LOGE("ATA send failed");
784 err = HRIL_ERR_CMD_SEND_FAILURE;
785 } else {
786 if (pResponse == NULL || !pResponse->success) {
787 TELEPHONY_LOGE("ATA send failed");
788 err = HRIL_ERR_GENERIC_FAILURE;
789 }
790 }
791 } else {
792 TELEPHONY_LOGE("onRequest req split args error!!!");
793 err = HRIL_ERR_INVALID_PARAMETER;
794 }
795 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
796 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
797 FreeResponseInfo(pResponse);
798 }
799
ReqCallSupplement(const ReqDataInfo * requestInfo,int32_t type)800 void ReqCallSupplement(const ReqDataInfo *requestInfo, int32_t type)
801 {
802 char cmd[MAX_CMD_LENGTH] = {0};
803 int32_t ret = 0;
804 int32_t err = HRIL_ERR_SUCCESS;
805 ResponseInfo *pResponse = NULL;
806
807 switch (type) {
808 case TYPE_HANG_UP_HOLD_WAIT: {
809 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CHLD=0");
810 if (ret < 0) {
811 TELEPHONY_LOGE("GenerateCommand is failed!");
812 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
813 return;
814 }
815 break;
816 }
817 case TYPE_HANG_UP_ACTIVE: {
818 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CHLD=1");
819 if (ret < 0) {
820 TELEPHONY_LOGE("GenerateCommand is failed!");
821 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
822 return;
823 }
824 break;
825 }
826 default: {
827 TELEPHONY_LOGW("ReqCallSupplement warring, type is invalid");
828 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
829 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
830 FreeResponseInfo(pResponse);
831 return;
832 }
833 }
834
835 const long timeout = 3000;
836 ret = SendCommandLock(cmd, NULL, timeout, &pResponse);
837 if (ret != HRIL_ERR_SUCCESS) {
838 TELEPHONY_LOGE("ReqCallSupplement cmd send failed");
839 err = HRIL_ERR_CMD_SEND_FAILURE;
840 } else {
841 if (pResponse == NULL || !pResponse->success) {
842 TELEPHONY_LOGE("cmd send return error");
843 err = HRIL_ERR_GENERIC_FAILURE;
844 }
845 }
846
847 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
848 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
849 FreeResponseInfo(pResponse);
850 }
851
ReqGetCallWaiting(const ReqDataInfo * requestInfo)852 void ReqGetCallWaiting(const ReqDataInfo *requestInfo)
853 {
854 int32_t err = HRIL_ERR_SUCCESS;
855 ResponseInfo *pResponse = NULL;
856 HRilCallWaitResult hrilCallWaitResult = {0};
857 char *line = NULL;
858 const long timeout = 80000;
859 err = SendCommandLock("AT+CCWA=1,2,1", "+CCWA:", timeout, &pResponse);
860 if (err != HRIL_ERR_SUCCESS) {
861 TELEPHONY_LOGE("ReqGetCallWaiting return, CCWA send failed");
862 err = HRIL_ERR_CMD_SEND_FAILURE;
863 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
864 OnCallReport(
865 GetSlotId(requestInfo), reportInfo, (const uint8_t *)&hrilCallWaitResult, sizeof(HRilCallWaitResult));
866 return;
867 }
868 if (pResponse == NULL || !pResponse->success) {
869 TELEPHONY_LOGE("Get CCWA return ERROR");
870 err = HRIL_ERR_GENERIC_FAILURE;
871 } else {
872 if (pResponse->head != NULL) {
873 line = pResponse->head->data;
874 SkipATPrefix(&line);
875 NextInt(&line, &hrilCallWaitResult.status);
876 NextInt(&line, &hrilCallWaitResult.classCw);
877 } else {
878 TELEPHONY_LOGE("ERROR: ReqGetCallWaiting pResponse->head is null");
879 err = HRIL_ERR_GENERIC_FAILURE;
880 }
881 }
882 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
883 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&hrilCallWaitResult, sizeof(HRilCallWaitResult));
884 FreeResponseInfo(pResponse);
885 }
886
ReqSetCallWaiting(const ReqDataInfo * requestInfo,int32_t active)887 void ReqSetCallWaiting(const ReqDataInfo *requestInfo, int32_t active)
888 {
889 char cmd[MAX_CMD_LENGTH] = {0};
890 int32_t err = HRIL_ERR_SUCCESS;
891 ResponseInfo *pResponse = NULL;
892 const long timeout = 500;
893
894 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CCWA=1,%d,1", active);
895 if (ret < 0) {
896 TELEPHONY_LOGE("GenerateCommand is failed!");
897 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
898 return;
899 }
900 err = SendCommandLock(cmd, NULL, timeout, &pResponse);
901 if (err != HRIL_ERR_SUCCESS) {
902 TELEPHONY_LOGE("ReqSetCallWaiting return, CCWA send failed");
903 err = HRIL_ERR_CMD_SEND_FAILURE;
904 } else {
905 if (pResponse == NULL || !pResponse->success) {
906 err = HRIL_ERR_GENERIC_FAILURE;
907 }
908 }
909 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
910 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
911 FreeResponseInfo(pResponse);
912 }
913
ReqSetCallTransferInfo(const ReqDataInfo * requestInfo,HRilCFInfo info)914 void ReqSetCallTransferInfo(const ReqDataInfo *requestInfo, HRilCFInfo info)
915 {
916 int32_t numType;
917 const int32_t NUM_F = 145;
918 const int32_t NUM_S = 129;
919 int32_t err = HRIL_ERR_SUCCESS;
920 ResponseInfo *pResponse = NULL;
921 char cmd[MAX_CMD_LENGTH] = {0};
922
923 if (info.reason > CALL_FORWARD_REASON_ALL_CCF || info.mode > CALL_FORWARD_MODE_ERASURE) {
924 TELEPHONY_LOGE("ReqSetCallTransferInfo call forwarding parameter err!!");
925 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
926 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
927 return;
928 }
929
930 if (info.number != NULL && info.number[0] == '+') {
931 numType = NUM_F;
932 } else {
933 numType = NUM_S;
934 }
935
936 int32_t ret = GenerateCommand(
937 cmd, MAX_CMD_LENGTH, "AT+CCFC=%d,%d,\"%s\",%d,%d", info.reason, info.mode, info.number, numType, info.classx);
938 if (ret < 0) {
939 TELEPHONY_LOGE("GenerateCommand is failed!");
940 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
941 return;
942 }
943 err = SendCommandLock(cmd, NULL, 0, &pResponse);
944 if (err != HRIL_ERR_SUCCESS) {
945 TELEPHONY_LOGE("CCFC send failed");
946 err = HRIL_ERR_CMD_SEND_FAILURE;
947 } else {
948 if (pResponse == NULL || !pResponse->success) {
949 err = HRIL_ERR_GENERIC_FAILURE;
950 }
951 }
952 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
953 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
954 FreeResponseInfo(pResponse);
955 }
956
ReqGetCallTransferInfo(const ReqDataInfo * requestInfo,int32_t reason)957 void ReqGetCallTransferInfo(const ReqDataInfo *requestInfo, int32_t reason)
958 {
959 char cmd[MAX_CMD_LENGTH] = {0};
960 int32_t err = HRIL_ERR_SUCCESS;
961 ResponseInfo *pResponse = NULL;
962 HRilCFQueryInfo queryInfo = {0};
963 char *line = NULL;
964
965 if (reason > CALL_FORWARD_REASON_ALL_CCF) {
966 TELEPHONY_LOGE("ReqGetCallTransferInfo call forwarding parameter err!!");
967 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_PARAMETER, HRIL_RESPONSE, 0);
968 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
969 return;
970 }
971 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CCFC=%d,2", reason);
972 if (ret < 0) {
973 TELEPHONY_LOGE("GenerateCommand is failed!");
974 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
975 return;
976 }
977 err = SendCommandLock(cmd, "+CCFC", 0, &pResponse);
978 if (err != HRIL_ERR_SUCCESS) {
979 TELEPHONY_LOGE("CCFC send failed");
980 err = HRIL_ERR_CMD_SEND_FAILURE;
981 } else if (pResponse != NULL) {
982 if (!pResponse->success) {
983 TELEPHONY_LOGE("CCFC send and return ERROR");
984 err = HRIL_ERR_GENERIC_FAILURE;
985 } else {
986 if (pResponse->head) {
987 line = pResponse->head->data;
988 SkipATPrefix(&line);
989 NextInt(&line, &queryInfo.status);
990 NextInt(&line, &queryInfo.classx);
991 NextStr(&line, &queryInfo.number);
992 NextInt(&line, &queryInfo.type);
993 } else {
994 TELEPHONY_LOGE("ERROR: ReqGetCallTransferInfo pResponse->head is null");
995 err = HRIL_ERR_GENERIC_FAILURE;
996 }
997 }
998 } else {
999 TELEPHONY_LOGE("ERROR: ReqGetCallTransferInfo pResponse is null");
1000 err = HRIL_ERR_GENERIC_FAILURE;
1001 }
1002 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1003 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&queryInfo, sizeof(queryInfo));
1004 FreeResponseInfo(pResponse);
1005 }
1006
ReqGetCallRestriction(const ReqDataInfo * requestInfo,const char * fac)1007 void ReqGetCallRestriction(const ReqDataInfo *requestInfo, const char *fac)
1008 {
1009 long long timeOut = DEFAULT_TIMEOUT_CLCK;
1010 int32_t err = HRIL_ERR_SUCCESS;
1011 ResponseInfo *pResponse = NULL;
1012 HRilCallRestrictionResult result = {0};
1013 char *line = NULL;
1014 char cmd[MAX_CMD_LENGTH] = {0};
1015
1016 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",2", fac);
1017 if (ret < 0) {
1018 TELEPHONY_LOGE("GenerateCommand is failed!");
1019 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1020 return;
1021 }
1022 err = SendCommandLock(cmd, "+CLCK:", timeOut, &pResponse);
1023 if (err != HRIL_ERR_SUCCESS) {
1024 TELEPHONY_LOGE("CLCK send failed err = %{public}d", err);
1025 err = HRIL_ERR_CMD_SEND_FAILURE;
1026 } else if (pResponse != NULL) {
1027 if (!pResponse->success) {
1028 TELEPHONY_LOGE("ERROR: ReqGetCallRestriction return ERROR");
1029 err = HRIL_ERR_GENERIC_FAILURE;
1030 } else {
1031 if (pResponse->head) {
1032 line = pResponse->head->data;
1033 SkipATPrefix(&line);
1034 NextInt(&line, &result.status);
1035 NextInt(&line, &result.classCw);
1036 } else {
1037 TELEPHONY_LOGE("ERROR: ReqGetCallRestriction pResponse->head is null");
1038 err = HRIL_ERR_GENERIC_FAILURE;
1039 }
1040 }
1041 } else {
1042 TELEPHONY_LOGE("ERROR: ReqGetCallRestriction pResponse is null");
1043 err = HRIL_ERR_GENERIC_FAILURE;
1044 }
1045 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1046 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&result, sizeof(HRilCallRestrictionResult));
1047 FreeResponseInfo(pResponse);
1048 }
1049
ReqSetCallRestriction(const ReqDataInfo * requestInfo,CallRestrictionInfo info)1050 void ReqSetCallRestriction(const ReqDataInfo *requestInfo, CallRestrictionInfo info)
1051 {
1052 long long timeOut = DEFAULT_TIMEOUT;
1053 char cmd[MAX_CMD_LENGTH] = {0};
1054 int32_t err = HRIL_ERR_SUCCESS;
1055 ResponseInfo *pResponse = NULL;
1056
1057 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",%d,\"%s\"", info.fac, info.mode, info.password);
1058 if (ret < 0) {
1059 TELEPHONY_LOGE("GenerateCommand is failed!");
1060 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1061 return;
1062 }
1063 err = SendCommandLock(cmd, NULL, timeOut, &pResponse);
1064 if (err != HRIL_ERR_SUCCESS) {
1065 TELEPHONY_LOGE("CLCK send failed");
1066 err = HRIL_ERR_CMD_SEND_FAILURE;
1067 } else {
1068 if (pResponse == NULL || !pResponse->success) {
1069 err = HRIL_ERR_GENERIC_FAILURE;
1070 }
1071 }
1072 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1073 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1074 FreeResponseInfo(pResponse);
1075 }
1076
ReqSetBarringPassword(const ReqDataInfo * requestInfo,HRilSetBarringInfo info)1077 void ReqSetBarringPassword(const ReqDataInfo *requestInfo, HRilSetBarringInfo info)
1078 {
1079 long long timeOut = DEFAULT_TIMEOUT;
1080 char cmd[MAX_CMD_LENGTH] = { 0 };
1081 ResponseInfo *pResponse = NULL;
1082
1083 int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPWD=\"%s\",\"%s\",\"%s\"", info.fac,
1084 info.oldPassword, info.newPassword);
1085 if (ret < 0) {
1086 TELEPHONY_LOGE("GenerateCommand is failed!");
1087 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1088 return;
1089 }
1090 int32_t err = SendCommandLock(cmd, NULL, timeOut, &pResponse);
1091 if (err != HRIL_ERR_SUCCESS) {
1092 TELEPHONY_LOGE("CPWD send failed");
1093 err = HRIL_ERR_CMD_SEND_FAILURE;
1094 } else if (pResponse != NULL) {
1095 if (!pResponse->success) {
1096 TELEPHONY_LOGE("ERROR: ReqSetBarringPassword return ERROR");
1097 err = HRIL_ERR_GENERIC_FAILURE;
1098 }
1099 } else {
1100 TELEPHONY_LOGE("ERROR: ReqSetBarringPassword pResponse is null");
1101 err = HRIL_ERR_GENERIC_FAILURE;
1102 }
1103 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1104 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1105 FreeResponseInfo(pResponse);
1106 }
1107
ReqGetCallPreferenceMode(const ReqDataInfo * requestInfo)1108 void ReqGetCallPreferenceMode(const ReqDataInfo *requestInfo)
1109 {
1110 char *line = NULL;
1111 int32_t mode = VENDOR_FAIL;
1112 int32_t ret = VENDOR_FAIL;
1113 int32_t err = HRIL_ERR_SUCCESS;
1114 ResponseInfo *pResponse = NULL;
1115
1116 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
1117 ret = SendCommandLock("AT+CEVDP?", "+CEVDP:", 0, &pResponse);
1118 if (ret || pResponse == NULL || !pResponse->success) {
1119 err = (ret != HRIL_ERR_SUCCESS) ? HRIL_ERR_CMD_SEND_FAILURE : err;
1120 TELEPHONY_LOGE("cmd send failed, err:%{public}d", err);
1121 OnCallReportErrorMessages(requestInfo, err, pResponse);
1122 return;
1123 }
1124 if (pResponse->head) {
1125 line = pResponse->head->data;
1126 err = SkipATPrefix(&line);
1127 if (err == 0) {
1128 err = NextInt(&line, &mode);
1129 TELEPHONY_LOGI("mode:%{public}d", mode);
1130 } else {
1131 TELEPHONY_LOGE("response error");
1132 }
1133 } else {
1134 TELEPHONY_LOGE("ERROR: pResponse->head is null");
1135 err = HRIL_ERR_GENERIC_FAILURE;
1136 }
1137 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1138 reportInfo.modemErrInfo = errInfo;
1139 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&mode, sizeof(mode));
1140 FreeResponseInfo(pResponse);
1141 }
1142
ReqSetCallPreferenceMode(const ReqDataInfo * requestInfo,int32_t mode)1143 void ReqSetCallPreferenceMode(const ReqDataInfo *requestInfo, int32_t mode)
1144 {
1145 int32_t ret = VENDOR_FAIL;
1146 int32_t err = HRIL_ERR_SUCCESS;
1147 int32_t value = HRIL_CALL_MODE_CS_1ST_PS_2ND;
1148 char cmd[MAX_CMD_LENGTH] = {0};
1149 ResponseInfo *pResponse = NULL;
1150
1151 ModemReportErrorInfo errInfo = InitModemReportErrorInfo();
1152 value = mode;
1153 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CEVDP=%d", value);
1154 if (ret < 0) {
1155 TELEPHONY_LOGE("GenerateCommand is failed!");
1156 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1157 return;
1158 }
1159 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
1160 if (ret || (pResponse != NULL && !pResponse->success)) {
1161 errInfo = GetReportErrorInfo(pResponse);
1162 err = errInfo.errorNo;
1163 TELEPHONY_LOGE("cmd send failed, err:%{public}d", ret ? ret : err);
1164 }
1165 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1166 reportInfo.modemErrInfo = errInfo;
1167 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1168 FreeResponseInfo(pResponse);
1169 }
1170
ReqSetUssd(const ReqDataInfo * requestInfo,const char * str)1171 void ReqSetUssd(const ReqDataInfo *requestInfo, const char *str)
1172 {
1173 int32_t ret;
1174 int32_t err = HRIL_ERR_SUCCESS;
1175 char cmd[MAX_CMD_LENGTH] = {0};
1176 ResponseInfo *pResponse = NULL;
1177 ModemReportErrorInfo errInfo = {};
1178
1179 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CUSD=1, \"% s\" , 15", str);
1180 if (ret < 0) {
1181 TELEPHONY_LOGE("GenerateCommand is failed!");
1182 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1183 return;
1184 }
1185 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
1186 if (ret || (pResponse != NULL && !pResponse->success)) {
1187 errInfo = GetReportErrorInfo(pResponse);
1188 err = errInfo.errorNo;
1189 TELEPHONY_LOGE("cmd send failed, err:%{public}d", ret ? ret : err);
1190 }
1191 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1192 reportInfo.modemErrInfo = errInfo;
1193 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1194 FreeResponseInfo(pResponse);
1195 }
1196
ReqCloseUnFinishedUssd(const ReqDataInfo * requestInfo)1197 void ReqCloseUnFinishedUssd(const ReqDataInfo *requestInfo)
1198 {
1199 int32_t ret;
1200 int32_t err = HRIL_ERR_SUCCESS;
1201 ResponseInfo *pResponse = NULL;
1202 ModemReportErrorInfo errInfo = {};
1203
1204 ret = SendCommandLock("AT+CUSD=2", NULL, 0, &pResponse);
1205 if (ret || (pResponse != NULL && !pResponse->success)) {
1206 errInfo = GetReportErrorInfo(pResponse);
1207 err = errInfo.errorNo;
1208 TELEPHONY_LOGE("cmd send failed, err:%{public}d", ret ? ret : err);
1209 }
1210 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1211 reportInfo.modemErrInfo = errInfo;
1212 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1213 FreeResponseInfo(pResponse);
1214 }
1215
ReqGetUssd(const ReqDataInfo * requestInfo)1216 void ReqGetUssd(const ReqDataInfo *requestInfo)
1217 {
1218 int32_t ret;
1219 char *line = NULL;
1220 int32_t cusd = 0;
1221 int32_t err = HRIL_ERR_SUCCESS;
1222 ResponseInfo *pResponse = NULL;
1223 ModemReportErrorInfo errInfo = {};
1224
1225 ret = SendCommandLock("AT+CUSD?", "+CUSD:", 0, &pResponse);
1226 if (ret || pResponse == NULL || !pResponse->success) {
1227 err = ret ? ret : err;
1228 TELEPHONY_LOGE("cmd send failed, err:%{public}d", err);
1229 OnCallReportErrorMessages(requestInfo, err, pResponse);
1230 return;
1231 }
1232 if (pResponse->head) {
1233 line = pResponse->head->data;
1234 err = SkipATPrefix(&line);
1235 if (err == 0) {
1236 err = NextInt(&line, &cusd);
1237 TELEPHONY_LOGI("+CUSD:%{public}d", cusd);
1238 } else {
1239 TELEPHONY_LOGE("response error");
1240 }
1241 } else {
1242 TELEPHONY_LOGE("ERROR: pResponse->head is null");
1243 err = HRIL_ERR_GENERIC_FAILURE;
1244 }
1245 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1246 reportInfo.modemErrInfo = errInfo;
1247 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cusd, sizeof(cusd));
1248 FreeResponseInfo(pResponse);
1249 }
1250
ReqSetMute(const ReqDataInfo * requestInfo,int32_t mute)1251 void ReqSetMute(const ReqDataInfo *requestInfo, int32_t mute)
1252 {
1253 int32_t ret;
1254 int32_t err = HRIL_ERR_SUCCESS;
1255 char cmd[MAX_CMD_LENGTH] = {0};
1256 ResponseInfo *pResponse = NULL;
1257 ModemReportErrorInfo errInfo = {};
1258
1259 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMUT=%d ", mute);
1260 if (ret < 0) {
1261 TELEPHONY_LOGE("GenerateCommand is failed!");
1262 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1263 return;
1264 }
1265 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
1266 if (ret || (pResponse != NULL && !pResponse->success)) {
1267 errInfo = GetReportErrorInfo(pResponse);
1268 err = errInfo.errorNo;
1269 TELEPHONY_LOGE("cmd send failed, err:%{public}d", ret ? ret : err);
1270 }
1271 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1272 reportInfo.modemErrInfo = errInfo;
1273 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1274 FreeResponseInfo(pResponse);
1275 }
1276
ReqGetMute(const ReqDataInfo * requestInfo)1277 void ReqGetMute(const ReqDataInfo *requestInfo)
1278 {
1279 int32_t ret;
1280 char *line = NULL;
1281 int32_t mute = 0;
1282 int32_t err = HRIL_ERR_SUCCESS;
1283 ResponseInfo *pResponse = NULL;
1284 ModemReportErrorInfo errInfo = {};
1285
1286 ret = SendCommandLock("AT+CMUT?", "+CMUT:", 0, &pResponse);
1287 if (ret || pResponse == NULL || !pResponse->success) {
1288 err = ret ? ret : err;
1289 TELEPHONY_LOGE("cmd send failed, err:%{public}d", err);
1290 OnCallReportErrorMessages(requestInfo, err, pResponse);
1291 return;
1292 }
1293 if (pResponse->head) {
1294 line = pResponse->head->data;
1295 err = SkipATPrefix(&line);
1296 if (err == 0) {
1297 err = NextInt(&line, &mute);
1298 TELEPHONY_LOGI("+CMUT:%{public}d", mute);
1299 } else {
1300 TELEPHONY_LOGE("response error");
1301 }
1302 } else {
1303 TELEPHONY_LOGE("ERROR: pResponse->head is null");
1304 err = HRIL_ERR_GENERIC_FAILURE;
1305 }
1306 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1307 reportInfo.modemErrInfo = errInfo;
1308 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&mute, sizeof(mute));
1309 FreeResponseInfo(pResponse);
1310 }
1311
CallCmdXLEMA(const char * lineCmd,HRilEmergencyInfo * outCall)1312 static int32_t CallCmdXLEMA(const char *lineCmd, HRilEmergencyInfo *outCall)
1313 {
1314 char *pLine = (char *)lineCmd;
1315
1316 if (pLine == NULL || outCall == NULL) {
1317 TELEPHONY_LOGE("src or desc pointer is null.");
1318 return HRIL_ERR_NULL_POINT;
1319 }
1320
1321 if (SkipATPrefix(&pLine) < 0) {
1322 return HRIL_ERR_NULL_POINT;
1323 }
1324 if (NextInt(&pLine, &outCall->index) < 0) {
1325 return HRIL_ERR_NULL_POINT;
1326 }
1327 if (NextInt(&pLine, &outCall->total) < 0) {
1328 return HRIL_ERR_NULL_POINT;
1329 }
1330 if (NextStr(&pLine, &outCall->eccNum) < 0) {
1331 return HRIL_ERR_NULL_POINT;
1332 }
1333 if (NextInt(&pLine, &outCall->category) < 0) {
1334 return HRIL_ERR_NULL_POINT;
1335 }
1336 if (NextInt(&pLine, &outCall->simpresent) < 0) {
1337 return HRIL_ERR_NULL_POINT;
1338 }
1339 if (NextStr(&pLine, &outCall->mcc) < 0) {
1340 return HRIL_ERR_NULL_POINT;
1341 }
1342 if (NextInt(&pLine, &outCall->abnormalService) < 0) {
1343 return HRIL_ERR_NULL_POINT;
1344 }
1345 return HRIL_ERR_SUCCESS;
1346 }
1347
InitGetEmergencyCallList(const ResponseInfo * pResponse,int32_t * callNum,HRilEmergencyInfo ** pEmergencyCalls)1348 static int32_t InitGetEmergencyCallList(const ResponseInfo *pResponse, int32_t *callNum,
1349 HRilEmergencyInfo **pEmergencyCalls)
1350 {
1351 int32_t ret;
1352 int32_t callNumTmp = 0;
1353 Line *pLine = NULL;
1354 HRilEmergencyInfo *pEmergencyCallsTmp = NULL;
1355
1356 if (pResponse == NULL || pEmergencyCalls == NULL || callNum == NULL) {
1357 TELEPHONY_LOGE("params: %{public}p,%{public}p,%{public}p", pResponse, callNum, pEmergencyCalls);
1358 return HRIL_ERR_NULL_POINT;
1359 }
1360
1361 *callNum = 0;
1362 *pEmergencyCalls = NULL;
1363
1364 for (pLine = pResponse->head; pLine != NULL; pLine = pLine->next) {
1365 callNumTmp++;
1366 }
1367 if (!callNumTmp) {
1368 callNumTmp++; // Malloc size cannot be 0.
1369 }
1370 pEmergencyCallsTmp = (HRilEmergencyInfo *)malloc(callNumTmp * sizeof(HRilEmergencyInfo));
1371 if (pEmergencyCallsTmp == NULL) {
1372 TELEPHONY_LOGE("ReqGetCallList malloc pCalls failure");
1373 return HRIL_ERR_MEMORY_FULL;
1374 }
1375 ret = memset_s(
1376 pEmergencyCallsTmp, callNumTmp * sizeof(HRilEmergencyInfo), 0, callNumTmp * sizeof(HRilEmergencyInfo));
1377 if (ret != EOK) {
1378 TELEPHONY_LOGE("memset_s is failed!");
1379 free(pEmergencyCallsTmp);
1380 pEmergencyCallsTmp = NULL;
1381 return ret;
1382 }
1383
1384 *pEmergencyCalls = pEmergencyCallsTmp;
1385 *callNum = callNumTmp;
1386
1387 return HRIL_ERR_SUCCESS;
1388 }
1389
BuildGetEmergencyCallList(const ReqDataInfo * requestInfo,ResponseInfo * response)1390 int32_t BuildGetEmergencyCallList(const ReqDataInfo *requestInfo, ResponseInfo *response)
1391 {
1392 int32_t ret = 0;
1393 int32_t callNum = 0;
1394 int32_t validCallNum = 0;
1395 int32_t err = HRIL_ERR_SUCCESS;
1396 Line *pLine = NULL;
1397 ResponseInfo *pResponse = response;
1398 HRilEmergencyInfo *pEmergencyCalls = NULL;
1399
1400 if (pResponse == NULL || requestInfo == NULL) {
1401 TELEPHONY_LOGE("response or requestInfo is null.");
1402 return HRIL_ERR_NULL_POINT;
1403 }
1404 if (pResponse->success == 0) {
1405 TELEPHONY_LOGE("send cmd return ERROR");
1406 err = HRIL_ERR_GENERIC_FAILURE;
1407 }
1408
1409 ret = InitGetEmergencyCallList(pResponse, &callNum, &pEmergencyCalls);
1410 if (ret != HRIL_ERR_SUCCESS) {
1411 TELEPHONY_LOGE("init command failed: %{public}d", ret);
1412 return ret;
1413 }
1414
1415 for (pLine = pResponse->head; pLine != NULL && validCallNum < callNum; pLine = pLine->next) {
1416 ret = CallCmdXLEMA(pLine->data, pEmergencyCalls + validCallNum);
1417 if (ret != 0) {
1418 TELEPHONY_LOGE("Parse CLCC data is fail. ret:%{public}d", ret);
1419 continue;
1420 }
1421 validCallNum++;
1422 }
1423
1424 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1425 OnCallReport(
1426 GetSlotId(requestInfo), reportInfo, (const uint8_t *)pEmergencyCalls, sizeof(HRilEmergencyInfo) * validCallNum);
1427 FreeResponseInfo(pResponse);
1428 free(pEmergencyCalls);
1429 return HRIL_ERR_SUCCESS;
1430 }
1431
ReqGetEmergencyCallList(const ReqDataInfo * requestInfo)1432 void ReqGetEmergencyCallList(const ReqDataInfo *requestInfo)
1433 {
1434 int32_t ret;
1435 ResponseInfo *pResponse = NULL;
1436 int32_t err = HRIL_ERR_SUCCESS;
1437 long timeOut = DEFAULT_TIMEOUT;
1438
1439 ret = SendCommandLock("AT^XLEMA?", "^XLEMA:", timeOut, &pResponse);
1440 if (ret || (pResponse != NULL && !pResponse->success)) {
1441 err = (ret != HRIL_ERR_SUCCESS) ? HRIL_ERR_CMD_SEND_FAILURE : err;
1442 TELEPHONY_LOGE("cmd send failed, err:%{public}d", err);
1443 OnCallReportErrorMessages(requestInfo, err, pResponse);
1444 return;
1445 }
1446 err = BuildGetEmergencyCallList(requestInfo, pResponse);
1447 if (err != HRIL_ERR_SUCCESS) {
1448 TELEPHONY_LOGE("Build Call Info List is failed.");
1449 OnCallReportErrorMessages(requestInfo, err, pResponse);
1450 }
1451 }
1452
ReqSetEmergencyCallList(const ReqDataInfo * requestInfo,HRilEmergencyInfo * emergencyInfo,const int len)1453 void ReqSetEmergencyCallList(const ReqDataInfo *requestInfo, HRilEmergencyInfo *emergencyInfo, const int len)
1454 {
1455 TELEPHONY_LOGI("ReqSetEmergencyCallList start");
1456 int32_t ret = 0;
1457 int32_t err = HRIL_ERR_SUCCESS;
1458 char cmd[MAX_CMD_LENGTH] = {0};
1459 ResponseInfo *pResponse = NULL;
1460 ModemReportErrorInfo errInfo = {};
1461 for (int i = 0; i < len; i++) {
1462 ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^NVM=%d,%d,\"%s\",%d,%d,%s,%d", emergencyInfo[i].index,
1463 emergencyInfo[i].total, emergencyInfo[i].eccNum, emergencyInfo[i].category, emergencyInfo[i].simpresent,
1464 emergencyInfo[i].mcc, emergencyInfo[i].abnormalService);
1465 if (ret < 0) {
1466 TELEPHONY_LOGE("GenerateCommand is failed!");
1467 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1468 return;
1469 }
1470 ret = SendCommandLock(cmd, NULL, 0, &pResponse);
1471 if (ret || (pResponse != NULL && !pResponse->success)) {
1472 errInfo = GetReportErrorInfo(pResponse);
1473 err = errInfo.errorNo;
1474 TELEPHONY_LOGE("cmd send failed, err:%{public}d", ret ? ret : err);
1475 }
1476 }
1477 TELEPHONY_LOGI("ReqSetEmergencyCallList end");
1478 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1479 reportInfo.modemErrInfo = errInfo;
1480 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1481 FreeResponseInfo(pResponse);
1482 }
1483
ReqGetCallFailReason(const ReqDataInfo * requestInfo)1484 void ReqGetCallFailReason(const ReqDataInfo *requestInfo)
1485 {
1486 int32_t err = HRIL_ERR_SUCCESS;
1487 ResponseInfo *pResponse = NULL;
1488 ModemReportErrorInfo errInfo = {};
1489
1490 if (lastCcCause == HRIL_ERR_CALL_CAUSE) {
1491 TELEPHONY_LOGE("lastCcCause is none!");
1492 OnCallReportErrorMessages(requestInfo, HRIL_ERR_GENERIC_FAILURE, NULL);
1493 return;
1494 }
1495
1496 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1497 reportInfo.modemErrInfo = errInfo;
1498 OnCallReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lastCcCause, sizeof(lastCcCause));
1499 FreeResponseInfo(pResponse);
1500 }
1501
ReqSetVonrSwitch(const ReqDataInfo * requestInfo,int32_t status)1502 void ReqSetVonrSwitch(const ReqDataInfo *requestInfo, int32_t status)
1503 {
1504 int32_t err = HRIL_ERR_SUCCESS;
1505 ResponseInfo *pResponse = NULL;
1506
1507 struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
1508 OnCallReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
1509 FreeResponseInfo(pResponse);
1510 }
1511