• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_sms.h"
17 
18 #include "vendor_report.h"
19 
20 static int32_t g_cmdLength = 2;
21 
ProcessCellBroadcast(char * pBuff,HRilCBConfigReportInfo * response)22 int32_t ProcessCellBroadcast(char *pBuff, HRilCBConfigReportInfo *response)
23 {
24     char *tmp = NULL;
25     int32_t ret;
26     int32_t count = 0;
27 
28     if (pBuff == NULL || response == NULL) {
29         return -1;
30     }
31     tmp = pBuff;
32     while (*tmp != '\0' && tmp != NULL) {
33         if (*tmp == ',') {
34             count++;
35         }
36         tmp++;
37     }
38     SkipATPrefix(&pBuff);
39     if (count > 1) {
40         ret = NextInt(&pBuff, &response->sn);
41         if (ret == -1) {
42             TELEPHONY_LOGE("sn is null");
43         }
44         ret = NextInt(&pBuff, &response->mid);
45         if (ret == -1) {
46             TELEPHONY_LOGE("mid is null");
47         }
48         ret = NextInt(&pBuff, &response->page);
49         if (ret == -1) {
50             TELEPHONY_LOGE("page is null");
51         }
52         ret = NextInt(&pBuff, &response->pages);
53         if (ret == -1) {
54             TELEPHONY_LOGE("pages is null");
55         }
56         ret = NextStr(&pBuff, &response->dcs);
57         if (ret == -1) {
58             TELEPHONY_LOGE("dcs is null");
59         }
60     } else {
61         ret = NextInt(&pBuff, &response->length);
62         if (ret == -1) {
63             TELEPHONY_LOGE("mode is null");
64         }
65     }
66     return count;
67 }
68 
HandlerSmsResult(HRilSmsResponse * response,struct ReportInfo * reportInfo,const ReqDataInfo * requestInfo,int32_t * err,ResponseInfo * responseInfo)69 static void HandlerSmsResult(HRilSmsResponse *response, struct ReportInfo *reportInfo, const ReqDataInfo *requestInfo,
70     int32_t *err, ResponseInfo *responseInfo)
71 {
72     if (reportInfo == NULL || err == NULL) {
73         return;
74     }
75     char *pLine = NULL;
76     *err = HRIL_ERR_GENERIC_FAILURE;
77     if (responseInfo && responseInfo->result) {
78         pLine = responseInfo->result;
79         SkipATPrefix(&pLine);
80         NextInt(&pLine, err);
81     }
82     if (*err == -1) {
83         *err = HRIL_ERR_INVALID_RESPONSE;
84     }
85     *reportInfo = CreateReportInfo(requestInfo, *err, HRIL_RESPONSE, 0);
86     OnSmsReport(GetSlotId(requestInfo), *reportInfo, NULL, 0);
87     FreeResponseInfo(responseInfo);
88 }
89 
HandleResult(int32_t * err,char * result,const ResponseInfo * responseInfo,HRilSmsResponse * response)90 static void HandleResult(int32_t *err, char *result, const ResponseInfo *responseInfo, HRilSmsResponse *response)
91 {
92     if (response == NULL || err == NULL || responseInfo == NULL) {
93         TELEPHONY_LOGE("response is NULL");
94         return;
95     }
96     if (responseInfo->head != NULL) {
97         result = responseInfo->head->data;
98         SkipATPrefix(&result);
99         *err = NextInt(&result, &response->msgRef);
100         if (*err != 0) {
101             TELEPHONY_LOGE("NextInt in ReqSendGsmSms is failed!");
102         }
103     } else {
104         response->msgRef = 1;
105     }
106 }
107 
ReqSendGsmSms(const ReqDataInfo * requestInfo,const char * const * data,size_t dataLen)108 void ReqSendGsmSms(const ReqDataInfo *requestInfo, const char *const *data, size_t dataLen)
109 {
110     if (data == NULL) {
111         return;
112     }
113     char *smsc = NULL;
114     char smscTemp[MAX_CMD_LENGTH] = {0};
115     const char *pdu = NULL;
116     char cmd[MAX_CMD_LENGTH] = {0};
117     char smsPdu[MAX_CMD_LENGTH] = {0};
118     char *result = NULL;
119     int32_t err;
120     struct ReportInfo reportInfo = {0};
121     ResponseInfo *responseInfo = NULL;
122     HRilSmsResponse response = {0};
123     smsc = ((char **)data)[0];
124 
125     if (smsc == NULL) {
126         err = GenerateCommand(smscTemp, MAX_CMD_LENGTH, "%s", "00");
127         if (err < 0) {
128             TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
129             HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
130         }
131         smsc = smscTemp;
132     }
133     pdu = ((const char **)data)[1];
134     err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGS=%d", strlen(pdu) / g_cmdLength);
135     if (err < 0) {
136         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
137         HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
138         return;
139     }
140     err = GenerateCommand(smsPdu, MAX_CMD_LENGTH, "%s%s", smsc, pdu);
141     if (err < 0) {
142         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
143         HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
144         return;
145     }
146     err = SendCommandSmsLock(cmd, smsPdu, "+CMGS:", 0, &responseInfo);
147     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
148         HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
149         return;
150     }
151     HandleResult(&err, result, responseInfo, &response);
152     reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
153     OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&response, sizeof(HRilSmsResponse));
154     FreeResponseInfo(responseInfo);
155 }
156 
ReqSendSmsAck(const ReqDataInfo * requestInfo,const int32_t * data,size_t dataLen)157 void ReqSendSmsAck(const ReqDataInfo *requestInfo, const int32_t *data, size_t dataLen)
158 {
159     int32_t ackFlag;
160     int32_t err;
161     if (data == NULL) {
162         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
163         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
164         return;
165     }
166     ackFlag = ((int32_t *)data)[0];
167     if (ackFlag == 1) {
168         err = SendCommandLock("AT+CNMA=1", NULL, 0, NULL);
169     } else if (ackFlag == 0) {
170         err = SendCommandLock("AT+CNMA=2", NULL, 0, NULL);
171     } else {
172         TELEPHONY_LOGE("unsupported arg to HREQ_SMS_SEND_SMS_ACKNOWLEDGE\n");
173         err = HRIL_ERR_GENERIC_FAILURE;
174     }
175     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
176     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
177 }
178 
ReqSendCdmaSms(const ReqDataInfo * requestInfo,const char * data,size_t dataLen)179 void ReqSendCdmaSms(const ReqDataInfo *requestInfo, const char *data, size_t dataLen)
180 {
181     char *result = NULL;
182     int32_t err;
183     ResponseInfo *responseInfo = NULL;
184     struct ReportInfo reportInfo = {0};
185     HRilSmsResponse response = {0};
186 
187     if (data == NULL) {
188         reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
189         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
190         FreeResponseInfo(responseInfo);
191         return;
192     }
193     responseInfo = (ResponseInfo *)malloc(sizeof(ResponseInfo));
194     if (responseInfo == NULL) {
195         err = HRIL_ERR_GENERIC_FAILURE;
196     }
197     err = SendCommandLock("AT+COPS?", "COPS?", 0, &responseInfo);
198     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
199         TELEPHONY_LOGE("AT+COPS? send failed");
200         HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
201         FreeResponseInfo(responseInfo);
202         return;
203     }
204     err = SendCommandLock("AT$QCMGF=0", "$QCMGF=0", 0, &responseInfo);
205     if (err != 0 || responseInfo == NULL || !responseInfo->success) {
206         response.msgRef = HRIL_ERR_GENERIC_FAILURE;
207         reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
208         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
209         FreeResponseInfo(responseInfo);
210         return;
211     }
212     if (responseInfo->head != NULL) {
213         result = responseInfo->head->data;
214         SkipATPrefix(&result);
215         NextInt(&result, &response.msgRef);
216     } else {
217         response.msgRef = 1;
218     }
219     reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
220     OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&response, sizeof(HRilSmsResponse));
221     FreeResponseInfo(responseInfo);
222 }
223 
ReqSendCdmaSmsAck(const ReqDataInfo * requestInfo,const char * data,size_t dataLen)224 void ReqSendCdmaSmsAck(const ReqDataInfo *requestInfo, const char *data, size_t dataLen)
225 {
226     int32_t err = HRIL_ERR_SUCCESS;
227     TELEPHONY_LOGE("data=%{public}p dataLen=%{public}zu", data, dataLen);
228     if (err > 0) {
229         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
230         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
231         return;
232     }
233     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
234     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
235 }
236 
SimMessageError(struct ReportInfo * reportInfo,const ReqDataInfo * requestInfo,int32_t * err,ResponseInfo * responseInfo)237 static void SimMessageError(
238     struct ReportInfo *reportInfo, const ReqDataInfo *requestInfo, int32_t *err, ResponseInfo *responseInfo)
239 {
240     if (reportInfo == NULL || err == NULL) {
241         return;
242     }
243     *reportInfo = CreateReportInfo(requestInfo, *err, HRIL_RESPONSE, 0);
244     OnSmsReport(GetSlotId(requestInfo), *reportInfo, NULL, 0);
245     FreeResponseInfo(responseInfo);
246 }
247 
WriteSimMessage(const ReqDataInfo * requestInfo,const HRilSmsWriteSms * data,size_t dataLen)248 static void WriteSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
249 {
250     char cmd[MAX_CMD_LENGTH] = {0};
251     char smsPdu[MAX_CMD_LENGTH] = {0};
252     int32_t err;
253     HRilSmsWriteSms *msg = NULL;
254     ResponseInfo *responseInfo = NULL;
255     struct ReportInfo reportInfo = {0};
256     if (data == NULL) {
257         reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
258         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
259         FreeResponseInfo(responseInfo);
260         return;
261     }
262     msg = ((HRilSmsWriteSms *)data);
263     if (msg->smsc == NULL || (strcmp(msg->smsc, "") == 0)) {
264         if (strcpy_s(msg->smsc, strlen("00") + 1, "00") != EOK) {
265             TELEPHONY_LOGE("Set smsc failed");
266             return;
267         }
268     }
269     int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGW=%d,%d", strlen(msg->pdu) / g_cmdLength, msg->state);
270     if (ret < 0) {
271         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", ret);
272         SimMessageError(&reportInfo, requestInfo, &ret, responseInfo);
273         return;
274     }
275     int32_t tmp = GenerateCommand(smsPdu, MAX_CMD_LENGTH, "%s%s", msg->smsc, msg->pdu);
276     if (tmp < 0) {
277         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", tmp);
278         SimMessageError(&reportInfo, requestInfo, &tmp, responseInfo);
279         return;
280     }
281     err = SendCommandSmsLock(cmd, smsPdu, "+CMGW:", 0, &responseInfo);
282     (void)memset_s(cmd, MAX_CMD_LENGTH, 0, MAX_CMD_LENGTH);
283     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
284         err = HRIL_ERR_GENERIC_FAILURE;
285         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
286         return;
287     }
288     reportInfo = CreateReportInfo(requestInfo, VENDOR_SUCCESS, HRIL_RESPONSE, 0);
289     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
290     FreeResponseInfo(responseInfo);
291 }
292 
UpdateSimMessage(const ReqDataInfo * requestInfo,const HRilSmsWriteSms * data,size_t dataLen)293 static void UpdateSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
294 {
295     char cmd[MAX_CMD_LENGTH] = {0};
296     char smsPdu[MAX_CMD_LENGTH] = {0};
297     int32_t err;
298     HRilSmsWriteSms *msg = NULL;
299     ResponseInfo *responseInfo = NULL;
300     struct ReportInfo reportInfo = {0};
301     if (data == NULL) {
302         reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
303         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
304         FreeResponseInfo(responseInfo);
305         return;
306     }
307     msg = ((HRilSmsWriteSms *)data);
308     err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGW=%zu,%d", strlen(msg->pdu) / g_cmdLength, msg->state);
309     if (err < 0) {
310         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
311         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
312         return;
313     }
314     err = GenerateCommand(smsPdu, MAX_CMD_LENGTH, "%s", msg->pdu);
315     if (err < 0) {
316         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
317         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
318         return;
319     }
320     err = SendCommandSmsLock(cmd, smsPdu, "+CMGW:", 0, &responseInfo);
321     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
322         err = HRIL_ERR_GENERIC_FAILURE;
323         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
324         return;
325     }
326     int32_t res = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGD=%d", msg->index);
327     if (res < 0) {
328         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", res);
329         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
330         return;
331     }
332     err = SendCommandLock(cmd, "+CMGD:", 0, &responseInfo);
333     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
334         err = HRIL_ERR_GENERIC_FAILURE;
335         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
336         return;
337     }
338     reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
339     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
340     FreeResponseInfo(responseInfo);
341 }
342 
ReqWriteSimMessage(const ReqDataInfo * requestInfo,const HRilSmsWriteSms * data,size_t dataLen)343 void ReqWriteSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
344 {
345     HRilSmsWriteSms *msg = NULL;
346     ResponseInfo *responseInfo = NULL;
347 
348     if (data == NULL) {
349         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
350         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
351         FreeResponseInfo(responseInfo);
352         return;
353     }
354     msg = ((HRilSmsWriteSms *)data);
355     if (msg->index < 0) {
356         WriteSimMessage(requestInfo, data, dataLen);
357     } else {
358         UpdateSimMessage(requestInfo, data, dataLen);
359     }
360 }
361 
ReqDelSimMessage(const ReqDataInfo * requestInfo,const int32_t * data,size_t dataLen)362 void ReqDelSimMessage(const ReqDataInfo *requestInfo, const int32_t *data, size_t dataLen)
363 {
364     char cmd[MAX_CMD_LENGTH] = {0};
365     int32_t err;
366     int32_t index;
367     ResponseInfo *responseInfo = NULL;
368 
369     if (data == NULL) {
370         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
371         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
372         FreeResponseInfo(responseInfo);
373         return;
374     }
375     index = ((int32_t *)data)[0];
376     err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGD=%d", index);
377     if (err < 0) {
378         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
379         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
380         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
381         FreeResponseInfo(responseInfo);
382         return;
383     }
384 
385     err = SendCommandLock(cmd, "+CMGD:", 0, &responseInfo);
386     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
387         err = HRIL_ERR_GENERIC_FAILURE;
388         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
389         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
390         FreeResponseInfo(responseInfo);
391         return;
392     }
393     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
394     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
395     FreeResponseInfo(responseInfo);
396 }
397 
ReqSetSmscAddr(const ReqDataInfo * requestInfo,const HRilServiceCenterAddress * data,size_t dataLen)398 void ReqSetSmscAddr(const ReqDataInfo *requestInfo, const HRilServiceCenterAddress *data, size_t dataLen)
399 {
400     char cmd[MAX_CMD_LENGTH] = {0};
401     int32_t err;
402     HRilServiceCenterAddress *address = NULL;
403     ResponseInfo *responseInfo = NULL;
404 
405     if (data == NULL) {
406         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
407         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
408         FreeResponseInfo(responseInfo);
409         return;
410     }
411     address = ((HRilServiceCenterAddress *)data);
412 
413     if (address->tosca == 0) {
414         err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCA=\"%s\"", address->address);
415     } else {
416         err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCA=\"%s\",%d", address->address, address->tosca);
417     }
418     if (err < 0) {
419         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
420         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
421         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
422         FreeResponseInfo(responseInfo);
423         return;
424     }
425     err = SendCommandLock(cmd, "+CSCA:", 0, &responseInfo);
426     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
427         err = HRIL_ERR_GENERIC_FAILURE;
428         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
429         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
430         FreeResponseInfo(responseInfo);
431         return;
432     }
433     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
434     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
435     FreeResponseInfo(responseInfo);
436 }
437 
ReqGetSmscAddr(const ReqDataInfo * requestInfo)438 void ReqGetSmscAddr(const ReqDataInfo *requestInfo)
439 {
440     char *result = NULL;
441     int32_t err;
442     ResponseInfo *responseInfo = NULL;
443     HRilServiceCenterAddress response;
444 
445     err = SendCommandLock("AT+CSCA?", "+CSCA:", 0, &responseInfo);
446     if (err != 0 || responseInfo == NULL || !responseInfo->success) {
447         err = HRIL_ERR_GENERIC_FAILURE;
448         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
449         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
450         FreeResponseInfo(responseInfo);
451         return;
452     }
453     if (responseInfo->head != NULL) {
454         result = responseInfo->head->data;
455     }
456     if (result == NULL) {
457         TELEPHONY_LOGE("ReqGetSmscAddr result is null");
458     } else {
459         SkipATPrefix(&result);
460         err = NextStr(&result, &response.address);
461         if (err == -1) {
462             TELEPHONY_LOGE("NextStr in ReqGetSmscAddr is failed!");
463             if (strcpy_s(response.address, strlen("") + 1, "") != EOK) {
464                 return;
465             }
466         }
467         err = NextInt(&result, &response.tosca);
468         if (err == -1) {
469             TELEPHONY_LOGE("NextInt in ReqGetSmscAddr is failed!");
470             response.tosca = 0;
471         }
472     }
473     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
474     OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&response, sizeof(HRilServiceCenterAddress));
475     FreeResponseInfo(responseInfo);
476 }
477 
ReqGetCBConfig(const ReqDataInfo * requestInfo)478 void ReqGetCBConfig(const ReqDataInfo *requestInfo)
479 {
480     char *line = NULL;
481     int32_t err;
482     ResponseInfo *responseInfo = NULL;
483     HRilCBConfigInfo cellBroadcast = {0};
484 
485     err = SendCommandLock("AT+CSCB?", "+CSCB:", 0, &responseInfo);
486     if (err != 0 || responseInfo == NULL || !responseInfo->success) {
487         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
488         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
489         FreeResponseInfo(responseInfo);
490         return;
491     }
492     if (responseInfo->head == NULL) {
493         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
494         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
495         FreeResponseInfo(responseInfo);
496         return;
497     }
498     line = responseInfo->head->data;
499     SkipATPrefix(&line);
500     err = NextInt(&line, &cellBroadcast.mode);
501     if (err > 0) {
502         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
503         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
504         FreeResponseInfo(responseInfo);
505         return;
506     }
507     err = NextStr(&line, &cellBroadcast.mids);
508     if (err > 0) {
509         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
510         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
511         FreeResponseInfo(responseInfo);
512         return;
513     }
514     err = NextStr(&line, &cellBroadcast.dcss);
515     if (err > 0) {
516         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
517         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
518         FreeResponseInfo(responseInfo);
519         return;
520     }
521     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, VENDOR_SUCCESS, HRIL_RESPONSE, 0);
522     OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cellBroadcast, sizeof(HRilCBConfigInfo));
523     FreeResponseInfo(responseInfo);
524 }
525 
ReqSetCBConfig(const ReqDataInfo * requestInfo,const HRilCBConfigInfo * data,size_t dataLen)526 void ReqSetCBConfig(const ReqDataInfo *requestInfo, const HRilCBConfigInfo *data, size_t dataLen)
527 {
528     char cmd[MAX_CMD_LENGTH] = {0};
529     int32_t err;
530     int32_t ret;
531     HRilCBConfigInfo *cellBroadcast = NULL;
532     ResponseInfo *responseInfo = NULL;
533 
534     if (data == NULL) {
535         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
536         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
537         FreeResponseInfo(responseInfo);
538         return;
539     }
540     cellBroadcast = ((HRilCBConfigInfo *)data);
541     if (strcmp(cellBroadcast->mids, "") && !strcmp(cellBroadcast->dcss, "")) {
542         ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d,\"%s\"", cellBroadcast->mode, cellBroadcast->mids);
543     } else if (strcmp(cellBroadcast->mids, "") && strcmp(cellBroadcast->dcss, "")) {
544         ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d,\"%s\",\"%s\"", cellBroadcast->mode, cellBroadcast->mids,
545             cellBroadcast->dcss);
546     } else if (strcmp(cellBroadcast->dcss, "") && !strcmp(cellBroadcast->mids, "")) {
547         ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d,,\"%s\"", cellBroadcast->mode, cellBroadcast->dcss);
548     } else {
549         ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d", cellBroadcast->mode);
550     }
551     if (ret < 0) {
552         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", ret);
553         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
554         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
555         FreeResponseInfo(responseInfo);
556         return;
557     }
558     err = SendCommandLock(cmd, "+CSCB:", 0, &responseInfo);
559     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
560         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
561         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
562         FreeResponseInfo(responseInfo);
563         return;
564     }
565     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, VENDOR_SUCCESS, HRIL_RESPONSE, 0);
566     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
567     FreeResponseInfo(responseInfo);
568 }
569 
ReqGetCdmaCBConfig(const ReqDataInfo * requestInfo)570 void ReqGetCdmaCBConfig(const ReqDataInfo *requestInfo)
571 {
572     char checked = '0';
573     char lineBuff[MAX_CMD_LENGTH] = {0};
574     char *line = lineBuff;
575     int32_t err = HRIL_ERR_SUCCESS;
576     int32_t service = 1;
577     int32_t language = 1;
578     ResponseInfo *responseInfo = NULL;
579     HRilCdmaCBConfigInfo cdmaCBConfig = {0};
580 
581     int32_t ret = GenerateCommand(lineBuff, MAX_CMD_LENGTH, "AT:%d,%d,%c", service, language, checked);
582     if (ret < 0) {
583         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", ret);
584         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
585         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
586         FreeResponseInfo(responseInfo);
587         return;
588     }
589     SkipATPrefix(&line);
590     err = NextInt(&line, &cdmaCBConfig.service);
591     if (err > 0) {
592         err = HRIL_ERR_GENERIC_FAILURE;
593         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
594         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
595         FreeResponseInfo(responseInfo);
596         return;
597     }
598     err = NextInt(&line, &cdmaCBConfig.language);
599     if (err > 0) {
600         err = HRIL_ERR_GENERIC_FAILURE;
601         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
602         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
603         FreeResponseInfo(responseInfo);
604         return;
605     }
606     char *tmp = NULL;
607     err = NextStr(&line, &tmp);
608     if (err > 0 || tmp == NULL || tmp[0] == '\0') {
609         err = HRIL_ERR_GENERIC_FAILURE;
610         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
611         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
612         FreeResponseInfo(responseInfo);
613         return;
614     }
615     cdmaCBConfig.checked = tmp[0];
616     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
617     OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cdmaCBConfig, sizeof(HRilCdmaCBConfigInfo));
618     FreeResponseInfo(responseInfo);
619 }
620 
ReqSetCdmaCBConfig(const ReqDataInfo * requestInfo,const HRilCdmaCBConfigInfo * data,size_t dataLen)621 void ReqSetCdmaCBConfig(const ReqDataInfo *requestInfo, const HRilCdmaCBConfigInfo *data, size_t dataLen)
622 {
623     int32_t err;
624     ResponseInfo *responseInfo = NULL;
625 
626     if (data == NULL) {
627         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
628         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
629         FreeResponseInfo(responseInfo);
630         return;
631     }
632     int32_t size = dataLen / sizeof(HRilCdmaCBConfigInfo);
633     if (size <= 0) {
634         err = HRIL_ERR_GENERIC_FAILURE;
635         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
636         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
637         FreeResponseInfo(responseInfo);
638         return;
639     }
640     err = HRIL_ERR_SUCCESS;
641     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
642     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
643     FreeResponseInfo(responseInfo);
644 }
645 
ReqAddCdmaSimMessage(const ReqDataInfo * requestInfo,const HRilSmsWriteSms * data,size_t dataLen)646 void ReqAddCdmaSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
647 {
648     char cmd[MAX_CMD_LENGTH] = {0};
649     int32_t err;
650     HRilSmsWriteSms *cdmaMsg = NULL;
651     ResponseInfo *responseInfo = NULL;
652     struct ReportInfo reportInfo = {0};
653     if (data == NULL) {
654         reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
655         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
656         FreeResponseInfo(responseInfo);
657         return;
658     }
659     cdmaMsg = ((HRilSmsWriteSms *)data);
660     err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPMS=%d,%d%s", cdmaMsg->index, cdmaMsg->state, cdmaMsg->pdu);
661     if (err < 0) {
662         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
663         reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
664         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
665         FreeResponseInfo(responseInfo);
666         return;
667     }
668     err = SendCommandLock(cmd, "+CPMS:", 0, &responseInfo);
669     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
670         err = HRIL_ERR_GENERIC_FAILURE;
671         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
672         return;
673     }
674     reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
675     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
676     FreeResponseInfo(responseInfo);
677 }
678 
ReqDelCdmaSimMessage(const ReqDataInfo * requestInfo,const int32_t * data,size_t dataLen)679 void ReqDelCdmaSimMessage(const ReqDataInfo *requestInfo, const int32_t *data, size_t dataLen)
680 {
681     char cmd[MAX_CMD_LENGTH] = {0};
682     int32_t err;
683     int32_t index;
684     ResponseInfo *responseInfo = NULL;
685     if (data == NULL) {
686         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
687         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
688         FreeResponseInfo(responseInfo);
689         return;
690     }
691     index = ((int32_t *)data)[0];
692     err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGD=%d", index);
693     if (err < 0) {
694         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
695         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
696         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
697         FreeResponseInfo(responseInfo);
698         return;
699     }
700     err = SendCommandLock(cmd, "+CMGD:", 0, &responseInfo);
701     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
702         err = HRIL_ERR_GENERIC_FAILURE;
703         struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
704         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
705         FreeResponseInfo(responseInfo);
706         return;
707     }
708     struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
709     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
710     FreeResponseInfo(responseInfo);
711 }
712 
ReqUpdateCdmaSimMessage(const ReqDataInfo * requestInfo,const HRilSmsWriteSms * data,size_t dataLen)713 void ReqUpdateCdmaSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
714 {
715     char cmd[MAX_CMD_LENGTH] = {0};
716     int32_t err;
717     HRilSmsWriteSms *cdmaMsg = NULL;
718     ResponseInfo *responseInfo = NULL;
719     struct ReportInfo reportInfo = {0};
720     if (data == NULL) {
721         reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
722         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
723         FreeResponseInfo(responseInfo);
724         return;
725     }
726     cdmaMsg = ((HRilSmsWriteSms *)data);
727     err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPMS=%d,%d%s", cdmaMsg->index, cdmaMsg->state, cdmaMsg->pdu);
728     if (err < 0) {
729         TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
730         reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
731         OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
732         FreeResponseInfo(responseInfo);
733         return;
734     }
735     err = SendCommandLock(cmd, "+CPMS:", 0, &responseInfo);
736     if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
737         err = HRIL_ERR_GENERIC_FAILURE;
738         SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
739         return;
740     }
741     reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
742     OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
743     FreeResponseInfo(responseInfo);
744 }
745