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