111fccf17Sopenharmony_ci/*
211fccf17Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
311fccf17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
411fccf17Sopenharmony_ci * you may not use this file except in compliance with the License.
511fccf17Sopenharmony_ci * You may obtain a copy of the License at
611fccf17Sopenharmony_ci *
711fccf17Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
811fccf17Sopenharmony_ci *
911fccf17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1011fccf17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1111fccf17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1211fccf17Sopenharmony_ci * See the License for the specific language governing permissions and
1311fccf17Sopenharmony_ci * limitations under the License.
1411fccf17Sopenharmony_ci */
1511fccf17Sopenharmony_ci
1611fccf17Sopenharmony_ci#include "at_sms.h"
1711fccf17Sopenharmony_ci
1811fccf17Sopenharmony_ci#include <string.h>
1911fccf17Sopenharmony_ci
2011fccf17Sopenharmony_ci#include "hril_notification.h"
2111fccf17Sopenharmony_ci#include "vendor_report.h"
2211fccf17Sopenharmony_ci
2311fccf17Sopenharmony_cistatic int32_t g_cmdLength = 2;
2411fccf17Sopenharmony_cichar *g_commaStr = ",";
2511fccf17Sopenharmony_cichar *g_hyphenStr = "-";
2611fccf17Sopenharmony_ci#define MAX_LENGTH 100
2711fccf17Sopenharmony_ci#define MAX_DIMEN_LENGTH 20
2811fccf17Sopenharmony_ci#define CHNL_LEN 6
2911fccf17Sopenharmony_ci
3011fccf17Sopenharmony_ciint32_t ProcessCellBroadcast(char *pBuff, HRilCBConfigReportInfo *response)
3111fccf17Sopenharmony_ci{
3211fccf17Sopenharmony_ci    char *tmp = NULL;
3311fccf17Sopenharmony_ci    int32_t ret;
3411fccf17Sopenharmony_ci    int32_t count = 0;
3511fccf17Sopenharmony_ci
3611fccf17Sopenharmony_ci    if (pBuff == NULL || response == NULL) {
3711fccf17Sopenharmony_ci        return -1;
3811fccf17Sopenharmony_ci    }
3911fccf17Sopenharmony_ci    tmp = pBuff;
4011fccf17Sopenharmony_ci    while (*tmp != '\0' && tmp != NULL) {
4111fccf17Sopenharmony_ci        if (*tmp == ',') {
4211fccf17Sopenharmony_ci            count++;
4311fccf17Sopenharmony_ci        }
4411fccf17Sopenharmony_ci        tmp++;
4511fccf17Sopenharmony_ci    }
4611fccf17Sopenharmony_ci    SkipATPrefix(&pBuff);
4711fccf17Sopenharmony_ci    if (count > 1) {
4811fccf17Sopenharmony_ci        ret = NextInt(&pBuff, &response->sn);
4911fccf17Sopenharmony_ci        if (ret == -1) {
5011fccf17Sopenharmony_ci            TELEPHONY_LOGE("sn is null");
5111fccf17Sopenharmony_ci        }
5211fccf17Sopenharmony_ci        ret = NextInt(&pBuff, &response->mid);
5311fccf17Sopenharmony_ci        if (ret == -1) {
5411fccf17Sopenharmony_ci            TELEPHONY_LOGE("mid is null");
5511fccf17Sopenharmony_ci        }
5611fccf17Sopenharmony_ci        ret = NextInt(&pBuff, &response->page);
5711fccf17Sopenharmony_ci        if (ret == -1) {
5811fccf17Sopenharmony_ci            TELEPHONY_LOGE("page is null");
5911fccf17Sopenharmony_ci        }
6011fccf17Sopenharmony_ci        ret = NextInt(&pBuff, &response->pages);
6111fccf17Sopenharmony_ci        if (ret == -1) {
6211fccf17Sopenharmony_ci            TELEPHONY_LOGE("pages is null");
6311fccf17Sopenharmony_ci        }
6411fccf17Sopenharmony_ci        ret = NextStr(&pBuff, &response->dcs);
6511fccf17Sopenharmony_ci        if (ret == -1) {
6611fccf17Sopenharmony_ci            TELEPHONY_LOGE("dcs is null");
6711fccf17Sopenharmony_ci        }
6811fccf17Sopenharmony_ci    } else {
6911fccf17Sopenharmony_ci        ret = NextInt(&pBuff, &response->length);
7011fccf17Sopenharmony_ci        if (ret == -1) {
7111fccf17Sopenharmony_ci            TELEPHONY_LOGE("mode is null");
7211fccf17Sopenharmony_ci        }
7311fccf17Sopenharmony_ci    }
7411fccf17Sopenharmony_ci    return count;
7511fccf17Sopenharmony_ci}
7611fccf17Sopenharmony_ci
7711fccf17Sopenharmony_cistatic void HandlerSmsResult(HRilSmsResponse *response, struct ReportInfo *reportInfo, const ReqDataInfo *requestInfo,
7811fccf17Sopenharmony_ci    int32_t *err, ResponseInfo *responseInfo)
7911fccf17Sopenharmony_ci{
8011fccf17Sopenharmony_ci    if (reportInfo == NULL || err == NULL) {
8111fccf17Sopenharmony_ci        return;
8211fccf17Sopenharmony_ci    }
8311fccf17Sopenharmony_ci    char *pLine = NULL;
8411fccf17Sopenharmony_ci    *err = HRIL_ERR_GENERIC_FAILURE;
8511fccf17Sopenharmony_ci    if (responseInfo && responseInfo->result) {
8611fccf17Sopenharmony_ci        pLine = responseInfo->result;
8711fccf17Sopenharmony_ci        SkipATPrefix(&pLine);
8811fccf17Sopenharmony_ci        NextInt(&pLine, err);
8911fccf17Sopenharmony_ci    }
9011fccf17Sopenharmony_ci    if (*err == -1) {
9111fccf17Sopenharmony_ci        *err = HRIL_ERR_INVALID_RESPONSE;
9211fccf17Sopenharmony_ci    }
9311fccf17Sopenharmony_ci    *reportInfo = CreateReportInfo(requestInfo, *err, HRIL_RESPONSE, 0);
9411fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), *reportInfo, NULL, 0);
9511fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
9611fccf17Sopenharmony_ci}
9711fccf17Sopenharmony_ci
9811fccf17Sopenharmony_cistatic void HandleResult(int32_t *err, char *result, const ResponseInfo *responseInfo, HRilSmsResponse *response)
9911fccf17Sopenharmony_ci{
10011fccf17Sopenharmony_ci    if (response == NULL || err == NULL || responseInfo == NULL) {
10111fccf17Sopenharmony_ci        TELEPHONY_LOGE("response is NULL");
10211fccf17Sopenharmony_ci        return;
10311fccf17Sopenharmony_ci    }
10411fccf17Sopenharmony_ci    if (responseInfo->head != NULL) {
10511fccf17Sopenharmony_ci        result = responseInfo->head->data;
10611fccf17Sopenharmony_ci        SkipATPrefix(&result);
10711fccf17Sopenharmony_ci        *err = NextInt(&result, &response->msgRef);
10811fccf17Sopenharmony_ci        if (*err != 0) {
10911fccf17Sopenharmony_ci            TELEPHONY_LOGE("NextInt in ReqSendGsmSms is failed!");
11011fccf17Sopenharmony_ci        }
11111fccf17Sopenharmony_ci    } else {
11211fccf17Sopenharmony_ci        response->msgRef = 1;
11311fccf17Sopenharmony_ci    }
11411fccf17Sopenharmony_ci}
11511fccf17Sopenharmony_ci
11611fccf17Sopenharmony_civoid ReqSendGsmSms(const ReqDataInfo *requestInfo, const char *const *data, size_t dataLen)
11711fccf17Sopenharmony_ci{
11811fccf17Sopenharmony_ci    if (data == NULL || dataLen <= 1) {
11911fccf17Sopenharmony_ci        TELEPHONY_LOGE("data error");
12011fccf17Sopenharmony_ci        return;
12111fccf17Sopenharmony_ci    }
12211fccf17Sopenharmony_ci    char *smsc = NULL;
12311fccf17Sopenharmony_ci    char smscTemp[MAX_CMD_LENGTH] = {0};
12411fccf17Sopenharmony_ci    const char *pdu = NULL;
12511fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
12611fccf17Sopenharmony_ci    char smsPdu[MAX_CMD_LENGTH] = {0};
12711fccf17Sopenharmony_ci    char *result = NULL;
12811fccf17Sopenharmony_ci    int32_t err;
12911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
13011fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
13111fccf17Sopenharmony_ci    HRilSmsResponse response = {0};
13211fccf17Sopenharmony_ci    smsc = ((char **)data)[0];
13311fccf17Sopenharmony_ci
13411fccf17Sopenharmony_ci    if (smsc == NULL) {
13511fccf17Sopenharmony_ci        err = GenerateCommand(smscTemp, MAX_CMD_LENGTH, "%s", "00");
13611fccf17Sopenharmony_ci        if (err < 0) {
13711fccf17Sopenharmony_ci            TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
13811fccf17Sopenharmony_ci            HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
13911fccf17Sopenharmony_ci        }
14011fccf17Sopenharmony_ci        smsc = smscTemp;
14111fccf17Sopenharmony_ci    }
14211fccf17Sopenharmony_ci    pdu = ((const char **)data)[1];
14311fccf17Sopenharmony_ci    err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGS=%d", strlen(pdu) / g_cmdLength);
14411fccf17Sopenharmony_ci    if (err < 0) {
14511fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
14611fccf17Sopenharmony_ci        HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
14711fccf17Sopenharmony_ci        return;
14811fccf17Sopenharmony_ci    }
14911fccf17Sopenharmony_ci    err = GenerateCommand(smsPdu, MAX_CMD_LENGTH, "%s%s", smsc, pdu);
15011fccf17Sopenharmony_ci    if (err < 0) {
15111fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
15211fccf17Sopenharmony_ci        HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
15311fccf17Sopenharmony_ci        return;
15411fccf17Sopenharmony_ci    }
15511fccf17Sopenharmony_ci    err = SendCommandSmsLock(cmd, smsPdu, "+CMGS:", 0, &responseInfo);
15611fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
15711fccf17Sopenharmony_ci        HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
15811fccf17Sopenharmony_ci        return;
15911fccf17Sopenharmony_ci    }
16011fccf17Sopenharmony_ci    HandleResult(&err, result, responseInfo, &response);
16111fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
16211fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&response, sizeof(HRilSmsResponse));
16311fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
16411fccf17Sopenharmony_ci}
16511fccf17Sopenharmony_ci
16611fccf17Sopenharmony_civoid ReqSendSmsAck(const ReqDataInfo *requestInfo, const int32_t *data, size_t dataLen)
16711fccf17Sopenharmony_ci{
16811fccf17Sopenharmony_ci    int32_t ackFlag;
16911fccf17Sopenharmony_ci    int32_t err;
17011fccf17Sopenharmony_ci    if (data == NULL || dataLen == 0) {
17111fccf17Sopenharmony_ci        TELEPHONY_LOGE("data error");
17211fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
17311fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
17411fccf17Sopenharmony_ci        return;
17511fccf17Sopenharmony_ci    }
17611fccf17Sopenharmony_ci    ackFlag = ((int32_t *)data)[0];
17711fccf17Sopenharmony_ci    if (ackFlag == 1) {
17811fccf17Sopenharmony_ci        err = SendCommandLock("AT+CNMA=1", NULL, 0, NULL);
17911fccf17Sopenharmony_ci    } else if (ackFlag == 0) {
18011fccf17Sopenharmony_ci        err = SendCommandLock("AT+CNMA=2", NULL, 0, NULL);
18111fccf17Sopenharmony_ci    } else {
18211fccf17Sopenharmony_ci        TELEPHONY_LOGE("unsupported arg to HREQ_SMS_SEND_SMS_ACKNOWLEDGE\n");
18311fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
18411fccf17Sopenharmony_ci    }
18511fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
18611fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
18711fccf17Sopenharmony_ci}
18811fccf17Sopenharmony_ci
18911fccf17Sopenharmony_civoid ReqSendCdmaSms(const ReqDataInfo *requestInfo, const char *data, size_t dataLen)
19011fccf17Sopenharmony_ci{
19111fccf17Sopenharmony_ci    char *result = NULL;
19211fccf17Sopenharmony_ci    int32_t err;
19311fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
19411fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
19511fccf17Sopenharmony_ci    HRilSmsResponse response = {0};
19611fccf17Sopenharmony_ci
19711fccf17Sopenharmony_ci    if (data == NULL) {
19811fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
19911fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
20011fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
20111fccf17Sopenharmony_ci        return;
20211fccf17Sopenharmony_ci    }
20311fccf17Sopenharmony_ci    err = SendCommandLock("AT+COPS?", "COPS?", 0, &responseInfo);
20411fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
20511fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+COPS? send failed");
20611fccf17Sopenharmony_ci        HandlerSmsResult(&response, &reportInfo, requestInfo, &err, responseInfo);
20711fccf17Sopenharmony_ci        // responseInfo freed in HandlerSmsResult
20811fccf17Sopenharmony_ci        return;
20911fccf17Sopenharmony_ci    }
21011fccf17Sopenharmony_ci    err = SendCommandLock("AT$QCMGF=0", "$QCMGF=0", 0, &responseInfo);
21111fccf17Sopenharmony_ci    if (err != 0 || responseInfo == NULL || !responseInfo->success) {
21211fccf17Sopenharmony_ci        response.msgRef = HRIL_ERR_GENERIC_FAILURE;
21311fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
21411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
21511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
21611fccf17Sopenharmony_ci        return;
21711fccf17Sopenharmony_ci    }
21811fccf17Sopenharmony_ci    if (responseInfo->head != NULL) {
21911fccf17Sopenharmony_ci        result = responseInfo->head->data;
22011fccf17Sopenharmony_ci        SkipATPrefix(&result);
22111fccf17Sopenharmony_ci        NextInt(&result, &response.msgRef);
22211fccf17Sopenharmony_ci    } else {
22311fccf17Sopenharmony_ci        response.msgRef = 1;
22411fccf17Sopenharmony_ci    }
22511fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
22611fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&response, sizeof(HRilSmsResponse));
22711fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
22811fccf17Sopenharmony_ci}
22911fccf17Sopenharmony_ci
23011fccf17Sopenharmony_civoid ReqSendCdmaSmsAck(const ReqDataInfo *requestInfo, const char *data, size_t dataLen)
23111fccf17Sopenharmony_ci{
23211fccf17Sopenharmony_ci    int32_t err = HRIL_ERR_SUCCESS;
23311fccf17Sopenharmony_ci    if (err > 0) {
23411fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
23511fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
23611fccf17Sopenharmony_ci        return;
23711fccf17Sopenharmony_ci    }
23811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
23911fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
24011fccf17Sopenharmony_ci}
24111fccf17Sopenharmony_ci
24211fccf17Sopenharmony_cistatic void SimMessageError(
24311fccf17Sopenharmony_ci    struct ReportInfo *reportInfo, const ReqDataInfo *requestInfo, int32_t *err, ResponseInfo *responseInfo)
24411fccf17Sopenharmony_ci{
24511fccf17Sopenharmony_ci    if (reportInfo == NULL || err == NULL) {
24611fccf17Sopenharmony_ci        return;
24711fccf17Sopenharmony_ci    }
24811fccf17Sopenharmony_ci    *reportInfo = CreateReportInfo(requestInfo, *err, HRIL_RESPONSE, 0);
24911fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), *reportInfo, NULL, 0);
25011fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
25111fccf17Sopenharmony_ci}
25211fccf17Sopenharmony_ci
25311fccf17Sopenharmony_cistatic void WriteSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
25411fccf17Sopenharmony_ci{
25511fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = { 0 };
25611fccf17Sopenharmony_ci    char smsPdu[MAX_CMD_LENGTH] = { 0 };
25711fccf17Sopenharmony_ci    int32_t err;
25811fccf17Sopenharmony_ci    HRilSmsWriteSms *msg = NULL;
25911fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
26011fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
26111fccf17Sopenharmony_ci    if (data == NULL) {
26211fccf17Sopenharmony_ci        TELEPHONY_LOGE("data is nullptr");
26311fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
26411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
26511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
26611fccf17Sopenharmony_ci        return;
26711fccf17Sopenharmony_ci    }
26811fccf17Sopenharmony_ci    msg = ((HRilSmsWriteSms *)data);
26911fccf17Sopenharmony_ci    if (msg->smsc == NULL || (strcmp(msg->smsc, "") == 0)) {
27011fccf17Sopenharmony_ci        if (msg->smsc != NULL) {
27111fccf17Sopenharmony_ci            free(msg->smsc);
27211fccf17Sopenharmony_ci        }
27311fccf17Sopenharmony_ci        msg->smsc = (char *)malloc(strlen("00") + 1);
27411fccf17Sopenharmony_ci        if (strcpy_s(msg->smsc, strlen("00") + 1, "00") != EOK) {
27511fccf17Sopenharmony_ci            TELEPHONY_LOGE("Set smsc failed");
27611fccf17Sopenharmony_ci            reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
27711fccf17Sopenharmony_ci            OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
27811fccf17Sopenharmony_ci            FreeResponseInfo(responseInfo);
27911fccf17Sopenharmony_ci            return;
28011fccf17Sopenharmony_ci        }
28111fccf17Sopenharmony_ci    }
28211fccf17Sopenharmony_ci    int32_t ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGW=%d,%d", strlen(msg->pdu) / g_cmdLength, msg->state);
28311fccf17Sopenharmony_ci    if (ret < 0) {
28411fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", ret);
28511fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &ret, responseInfo);
28611fccf17Sopenharmony_ci        return;
28711fccf17Sopenharmony_ci    }
28811fccf17Sopenharmony_ci    int32_t tmp = GenerateCommand(smsPdu, MAX_CMD_LENGTH, "%s%s", msg->smsc, msg->pdu);
28911fccf17Sopenharmony_ci    if (tmp < 0) {
29011fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &tmp, responseInfo);
29111fccf17Sopenharmony_ci        return;
29211fccf17Sopenharmony_ci    }
29311fccf17Sopenharmony_ci    err = SendCommandSmsLock(cmd, smsPdu, "+CMGW:", 0, &responseInfo);
29411fccf17Sopenharmony_ci    ret = memset_s(cmd, MAX_CMD_LENGTH, 0, MAX_CMD_LENGTH);
29511fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success) || ret != EOK) {
29611fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
29711fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
29811fccf17Sopenharmony_ci        return;
29911fccf17Sopenharmony_ci    }
30011fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, VENDOR_SUCCESS, HRIL_RESPONSE, 0);
30111fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
30211fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
30311fccf17Sopenharmony_ci}
30411fccf17Sopenharmony_ci
30511fccf17Sopenharmony_cistatic void UpdateSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
30611fccf17Sopenharmony_ci{
30711fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
30811fccf17Sopenharmony_ci    char smsPdu[MAX_CMD_LENGTH] = { 0 };
30911fccf17Sopenharmony_ci    HRilSmsWriteSms *msg = NULL;
31011fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
31111fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
31211fccf17Sopenharmony_ci    if (!CheckSimMessageValid(requestInfo, data, dataLen, msg)) {
31311fccf17Sopenharmony_ci        TELEPHONY_LOGE("sim message data error");
31411fccf17Sopenharmony_ci        return;
31511fccf17Sopenharmony_ci    }
31611fccf17Sopenharmony_ci    msg = ((HRilSmsWriteSms *)data);
31711fccf17Sopenharmony_ci    int32_t err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGW=%zu,%d", strlen(msg->pdu) / g_cmdLength, msg->state);
31811fccf17Sopenharmony_ci    if (err < 0) {
31911fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
32011fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
32111fccf17Sopenharmony_ci        return;
32211fccf17Sopenharmony_ci    }
32311fccf17Sopenharmony_ci    err = GenerateCommand(smsPdu, MAX_CMD_LENGTH, "%s%s", msg->smsc, msg->pdu);
32411fccf17Sopenharmony_ci    if (err < 0) {
32511fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
32611fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
32711fccf17Sopenharmony_ci        return;
32811fccf17Sopenharmony_ci    }
32911fccf17Sopenharmony_ci    err = SendCommandSmsLock(cmd, smsPdu, "+CMGW:", 0, &responseInfo);
33011fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
33111fccf17Sopenharmony_ci        TELEPHONY_LOGE("ExecuteCommand failed");
33211fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
33311fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
33411fccf17Sopenharmony_ci        return;
33511fccf17Sopenharmony_ci    }
33611fccf17Sopenharmony_ci    int32_t res = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGD=%d", msg->index);
33711fccf17Sopenharmony_ci    if (res < 0) {
33811fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", res);
33911fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
34011fccf17Sopenharmony_ci        return;
34111fccf17Sopenharmony_ci    }
34211fccf17Sopenharmony_ci    err = SendCommandLock(cmd, "+CMGD:", 0, &responseInfo);
34311fccf17Sopenharmony_ci    int32_t ret = memset_s(cmd, MAX_CMD_LENGTH, 0, MAX_CMD_LENGTH);
34411fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success) || ret != EOK) {
34511fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
34611fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
34711fccf17Sopenharmony_ci        return;
34811fccf17Sopenharmony_ci    }
34911fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
35011fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
35111fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
35211fccf17Sopenharmony_ci}
35311fccf17Sopenharmony_ci
35411fccf17Sopenharmony_cibool CheckSimMessageValid(
35511fccf17Sopenharmony_ci    const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen, HRilSmsWriteSms *msg)
35611fccf17Sopenharmony_ci{
35711fccf17Sopenharmony_ci    if (data == NULL) {
35811fccf17Sopenharmony_ci        TELEPHONY_LOGE("data is nullptr");
35911fccf17Sopenharmony_ci        ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
36011fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
36111fccf17Sopenharmony_ci        return false;
36211fccf17Sopenharmony_ci    }
36311fccf17Sopenharmony_ci    msg = ((HRilSmsWriteSms *)data);
36411fccf17Sopenharmony_ci    if (msg == NULL) {
36511fccf17Sopenharmony_ci        TELEPHONY_LOGE("msg is nullptr");
36611fccf17Sopenharmony_ci        return false;
36711fccf17Sopenharmony_ci    }
36811fccf17Sopenharmony_ci    if (msg->smsc == NULL || (strcmp(msg->smsc, "") == 0)) {
36911fccf17Sopenharmony_ci        if (msg->smsc != NULL) {
37011fccf17Sopenharmony_ci            free(msg->smsc);
37111fccf17Sopenharmony_ci        }
37211fccf17Sopenharmony_ci        msg->smsc = (char *)malloc(strlen("00") + 1);
37311fccf17Sopenharmony_ci        if (strcpy_s(msg->smsc, strlen("00") + 1, "00") != EOK) {
37411fccf17Sopenharmony_ci            TELEPHONY_LOGE("Set smsc failed");
37511fccf17Sopenharmony_ci            ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
37611fccf17Sopenharmony_ci            OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
37711fccf17Sopenharmony_ci            return false;
37811fccf17Sopenharmony_ci        }
37911fccf17Sopenharmony_ci    }
38011fccf17Sopenharmony_ci    return true;
38111fccf17Sopenharmony_ci}
38211fccf17Sopenharmony_ci
38311fccf17Sopenharmony_civoid ReqWriteSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
38411fccf17Sopenharmony_ci{
38511fccf17Sopenharmony_ci    HRilSmsWriteSms *msg = NULL;
38611fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
38711fccf17Sopenharmony_ci
38811fccf17Sopenharmony_ci    if (data == NULL) {
38911fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
39011fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
39111fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
39211fccf17Sopenharmony_ci        return;
39311fccf17Sopenharmony_ci    }
39411fccf17Sopenharmony_ci    msg = ((HRilSmsWriteSms *)data);
39511fccf17Sopenharmony_ci    if (msg->index < 0) {
39611fccf17Sopenharmony_ci        WriteSimMessage(requestInfo, data, dataLen);
39711fccf17Sopenharmony_ci    } else {
39811fccf17Sopenharmony_ci        UpdateSimMessage(requestInfo, data, dataLen);
39911fccf17Sopenharmony_ci    }
40011fccf17Sopenharmony_ci}
40111fccf17Sopenharmony_ci
40211fccf17Sopenharmony_civoid ReqDelSimMessage(const ReqDataInfo *requestInfo, const int32_t *data, size_t dataLen)
40311fccf17Sopenharmony_ci{
40411fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
40511fccf17Sopenharmony_ci    if (data == NULL || dataLen == 0) {
40611fccf17Sopenharmony_ci        TELEPHONY_LOGE("data error");
40711fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
40811fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
40911fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
41011fccf17Sopenharmony_ci        return;
41111fccf17Sopenharmony_ci    }
41211fccf17Sopenharmony_ci    int32_t index = ((int32_t *)data)[0] - 1;
41311fccf17Sopenharmony_ci    if (index < 0) {
41411fccf17Sopenharmony_ci        TELEPHONY_LOGE("invalid index:%d", index);
41511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
41611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
41711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
41811fccf17Sopenharmony_ci        return;
41911fccf17Sopenharmony_ci    }
42011fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = { 0 };
42111fccf17Sopenharmony_ci    int32_t err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGD=%d", index);
42211fccf17Sopenharmony_ci    if (err < 0) {
42311fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
42411fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
42511fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
42611fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
42711fccf17Sopenharmony_ci        return;
42811fccf17Sopenharmony_ci    }
42911fccf17Sopenharmony_ci
43011fccf17Sopenharmony_ci    err = SendCommandLock(cmd, "+CMGD:", 0, &responseInfo);
43111fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
43211fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
43311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
43411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
43511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
43611fccf17Sopenharmony_ci        return;
43711fccf17Sopenharmony_ci    }
43811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
43911fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
44011fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
44111fccf17Sopenharmony_ci}
44211fccf17Sopenharmony_ci
44311fccf17Sopenharmony_civoid ReqSetSmscAddr(const ReqDataInfo *requestInfo, const HRilServiceCenterAddress *data, size_t dataLen)
44411fccf17Sopenharmony_ci{
44511fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
44611fccf17Sopenharmony_ci    int32_t err;
44711fccf17Sopenharmony_ci    HRilServiceCenterAddress *address = NULL;
44811fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
44911fccf17Sopenharmony_ci
45011fccf17Sopenharmony_ci    if (data == NULL) {
45111fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
45211fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
45311fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
45411fccf17Sopenharmony_ci        return;
45511fccf17Sopenharmony_ci    }
45611fccf17Sopenharmony_ci    address = ((HRilServiceCenterAddress *)data);
45711fccf17Sopenharmony_ci
45811fccf17Sopenharmony_ci    if (address->tosca == 0) {
45911fccf17Sopenharmony_ci        err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCA=\"%s\"", address->address);
46011fccf17Sopenharmony_ci    } else {
46111fccf17Sopenharmony_ci        err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCA=\"%s\",%d", address->address, address->tosca);
46211fccf17Sopenharmony_ci    }
46311fccf17Sopenharmony_ci    if (err < 0) {
46411fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
46511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
46611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
46711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
46811fccf17Sopenharmony_ci        return;
46911fccf17Sopenharmony_ci    }
47011fccf17Sopenharmony_ci    err = SendCommandLock(cmd, "+CSCA:", 0, &responseInfo);
47111fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
47211fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
47311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
47411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
47511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
47611fccf17Sopenharmony_ci        return;
47711fccf17Sopenharmony_ci    }
47811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
47911fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
48011fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
48111fccf17Sopenharmony_ci}
48211fccf17Sopenharmony_ci
48311fccf17Sopenharmony_civoid ReqGetSmscAddr(const ReqDataInfo *requestInfo)
48411fccf17Sopenharmony_ci{
48511fccf17Sopenharmony_ci    char *result = NULL;
48611fccf17Sopenharmony_ci    int32_t err;
48711fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
48811fccf17Sopenharmony_ci    HRilServiceCenterAddress response;
48911fccf17Sopenharmony_ci
49011fccf17Sopenharmony_ci    err = SendCommandLock("AT+CSCA?", "+CSCA:", 0, &responseInfo);
49111fccf17Sopenharmony_ci    if (err != 0 || responseInfo == NULL || !responseInfo->success) {
49211fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
49311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
49411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
49511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
49611fccf17Sopenharmony_ci        return;
49711fccf17Sopenharmony_ci    }
49811fccf17Sopenharmony_ci    if (responseInfo->head != NULL) {
49911fccf17Sopenharmony_ci        result = responseInfo->head->data;
50011fccf17Sopenharmony_ci    }
50111fccf17Sopenharmony_ci    if (result == NULL) {
50211fccf17Sopenharmony_ci        TELEPHONY_LOGE("ReqGetSmscAddr result is null");
50311fccf17Sopenharmony_ci    } else {
50411fccf17Sopenharmony_ci        SkipATPrefix(&result);
50511fccf17Sopenharmony_ci        err = NextStr(&result, &response.address);
50611fccf17Sopenharmony_ci        if (err == -1) {
50711fccf17Sopenharmony_ci            TELEPHONY_LOGE("NextStr in ReqGetSmscAddr is failed!");
50811fccf17Sopenharmony_ci            if (strcpy_s(response.address, strlen("") + 1, "") != EOK) {
50911fccf17Sopenharmony_ci                return;
51011fccf17Sopenharmony_ci            }
51111fccf17Sopenharmony_ci        }
51211fccf17Sopenharmony_ci        err = NextInt(&result, &response.tosca);
51311fccf17Sopenharmony_ci        if (err == -1) {
51411fccf17Sopenharmony_ci            TELEPHONY_LOGE("NextInt in ReqGetSmscAddr is failed!");
51511fccf17Sopenharmony_ci            response.tosca = 0;
51611fccf17Sopenharmony_ci        }
51711fccf17Sopenharmony_ci    }
51811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
51911fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&response, sizeof(HRilServiceCenterAddress));
52011fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
52111fccf17Sopenharmony_ci}
52211fccf17Sopenharmony_ci
52311fccf17Sopenharmony_civoid ReqGetCBConfigInfo(const ReqDataInfo *requestInfo, ResponseInfo *responseInfo, HRilCBConfigInfo *cellBroadcast,
52411fccf17Sopenharmony_ci    char *mids, char *dcss, int32_t mode)
52511fccf17Sopenharmony_ci{
52611fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, VENDOR_SUCCESS, HRIL_RESPONSE, 0);
52711fccf17Sopenharmony_ci    bool midsEmpty = (mids == NULL || mids[0] == '\0');
52811fccf17Sopenharmony_ci    char *token;
52911fccf17Sopenharmony_ci    char copy[MAX_LENGTH] = { 0 };
53011fccf17Sopenharmony_ci    if (strcpy_s(copy, MAX_LENGTH, mids) != EOK) {
53111fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
53211fccf17Sopenharmony_ci        return;
53311fccf17Sopenharmony_ci    }
53411fccf17Sopenharmony_ci    char delimiter[] = ",";
53511fccf17Sopenharmony_ci    char *p = NULL;
53611fccf17Sopenharmony_ci    token = strtok_r(copy, delimiter, &p);
53711fccf17Sopenharmony_ci    int32_t position = 0;
53811fccf17Sopenharmony_ci    char midsTotal[MAX_LENGTH][MAX_DIMEN_LENGTH] = { 0 };
53911fccf17Sopenharmony_ci    while (!midsEmpty && token != NULL && position < MAX_LENGTH) {
54011fccf17Sopenharmony_ci        size_t length = strlen(token);
54111fccf17Sopenharmony_ci        size_t place = 0;
54211fccf17Sopenharmony_ci        while (place < length && place < MAX_DIMEN_LENGTH && token[place] != '\0') {
54311fccf17Sopenharmony_ci            midsTotal[position][place] = token[place];
54411fccf17Sopenharmony_ci            place++;
54511fccf17Sopenharmony_ci        }
54611fccf17Sopenharmony_ci        position++;
54711fccf17Sopenharmony_ci        token = strtok_r(NULL, delimiter, &p);
54811fccf17Sopenharmony_ci    }
54911fccf17Sopenharmony_ci    int32_t index = 0;
55011fccf17Sopenharmony_ci    int32_t locate = 0;
55111fccf17Sopenharmony_ci    while (index < position) {
55211fccf17Sopenharmony_ci        locate = GetCBConfigData(midsTotal[index], dcss, mode, cellBroadcast, locate);
55311fccf17Sopenharmony_ci        index++;
55411fccf17Sopenharmony_ci    }
55511fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cellBroadcast, sizeof(HRilCBConfigInfo) * locate);
55611fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
55711fccf17Sopenharmony_ci}
55811fccf17Sopenharmony_ci
55911fccf17Sopenharmony_civoid ReqGetCBConfig(const ReqDataInfo *requestInfo)
56011fccf17Sopenharmony_ci{
56111fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
56211fccf17Sopenharmony_ci    HRilCBConfigInfo cellBroadcast[MAX_LENGTH] = { 0 };
56311fccf17Sopenharmony_ci    int32_t err = SendCommandLock("AT+CSCB?", "+CSCB:", 0, &responseInfo);
56411fccf17Sopenharmony_ci    if (err != 0 || responseInfo == NULL || !responseInfo->success || responseInfo->head == NULL) {
56511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
56611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
56711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
56811fccf17Sopenharmony_ci        return;
56911fccf17Sopenharmony_ci    }
57011fccf17Sopenharmony_ci    char *line = responseInfo->head->data;
57111fccf17Sopenharmony_ci    SkipATPrefix(&line);
57211fccf17Sopenharmony_ci    int32_t mode;
57311fccf17Sopenharmony_ci    err = NextInt(&line, &mode);
57411fccf17Sopenharmony_ci    if (err > 0) {
57511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
57611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
57711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
57811fccf17Sopenharmony_ci        return;
57911fccf17Sopenharmony_ci    }
58011fccf17Sopenharmony_ci    char *mids;
58111fccf17Sopenharmony_ci    err = NextStr(&line, &mids);
58211fccf17Sopenharmony_ci    if (err > 0) {
58311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
58411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
58511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
58611fccf17Sopenharmony_ci        return;
58711fccf17Sopenharmony_ci    }
58811fccf17Sopenharmony_ci    char *dcss;
58911fccf17Sopenharmony_ci    err = NextStr(&line, &dcss);
59011fccf17Sopenharmony_ci    if (err > 0) {
59111fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
59211fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
59311fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
59411fccf17Sopenharmony_ci        return;
59511fccf17Sopenharmony_ci    }
59611fccf17Sopenharmony_ci    ReqGetCBConfigInfo(requestInfo, responseInfo, cellBroadcast, mids, dcss, mode);
59711fccf17Sopenharmony_ci}
59811fccf17Sopenharmony_ci
59911fccf17Sopenharmony_civoid SetCellBroadcastInfo(HRilCBConfigInfo *cellBroadcast, int32_t locate, char *startMid, char *endMid, char *startDcs,
60011fccf17Sopenharmony_ci    char *endDcs, bool dcssEmpty, int32_t mode)
60111fccf17Sopenharmony_ci{
60211fccf17Sopenharmony_ci    if (cellBroadcast == NULL || locate < 0) {
60311fccf17Sopenharmony_ci        TELEPHONY_LOGE("cellBroadcast is null");
60411fccf17Sopenharmony_ci        return;
60511fccf17Sopenharmony_ci    }
60611fccf17Sopenharmony_ci    if (startMid == NULL || endMid == NULL) {
60711fccf17Sopenharmony_ci        TELEPHONY_LOGE("startMid or endMid is null");
60811fccf17Sopenharmony_ci        return;
60911fccf17Sopenharmony_ci    }
61011fccf17Sopenharmony_ci    cellBroadcast[locate].startOfServiceId = atoi(startMid);
61111fccf17Sopenharmony_ci    cellBroadcast[locate].endOfServiceId = atoi(endMid);
61211fccf17Sopenharmony_ci    if (!dcssEmpty) {
61311fccf17Sopenharmony_ci        if (startDcs == NULL || endDcs == NULL) {
61411fccf17Sopenharmony_ci            TELEPHONY_LOGE("startDcs or endDcs is null");
61511fccf17Sopenharmony_ci            return;
61611fccf17Sopenharmony_ci        }
61711fccf17Sopenharmony_ci        cellBroadcast[locate].startOfCodeScheme = atoi(startDcs);
61811fccf17Sopenharmony_ci        cellBroadcast[locate].endOfCodeScheme = atoi(endDcs);
61911fccf17Sopenharmony_ci    }
62011fccf17Sopenharmony_ci    cellBroadcast[locate].selected = mode;
62111fccf17Sopenharmony_ci}
62211fccf17Sopenharmony_ci
62311fccf17Sopenharmony_ciint32_t GetCBConfigData(char *token, char *dcss, int32_t mode, HRilCBConfigInfo *cellBroadcast, int32_t locate)
62411fccf17Sopenharmony_ci{
62511fccf17Sopenharmony_ci    char *ttoken;
62611fccf17Sopenharmony_ci    char ddelimiter[] = "-";
62711fccf17Sopenharmony_ci    char ccopy[MAX_LENGTH] = { 0 };
62811fccf17Sopenharmony_ci    if (strcpy_s(ccopy, MAX_LENGTH, token) != EOK) {
62911fccf17Sopenharmony_ci        return MAX_LENGTH;
63011fccf17Sopenharmony_ci    }
63111fccf17Sopenharmony_ci    char *startMid = NULL;
63211fccf17Sopenharmony_ci    char *endMid = NULL;
63311fccf17Sopenharmony_ci    char *p = NULL;
63411fccf17Sopenharmony_ci    ttoken = strtok_r(ccopy, ddelimiter, &p);
63511fccf17Sopenharmony_ci    for (int32_t index = 0; ttoken != NULL; index++) {
63611fccf17Sopenharmony_ci        if (index == 0) {
63711fccf17Sopenharmony_ci            startMid = ttoken;
63811fccf17Sopenharmony_ci            endMid = ttoken;
63911fccf17Sopenharmony_ci        } else {
64011fccf17Sopenharmony_ci            endMid = ttoken;
64111fccf17Sopenharmony_ci            break;
64211fccf17Sopenharmony_ci        }
64311fccf17Sopenharmony_ci        ttoken = strtok_r(NULL, ddelimiter, &p);
64411fccf17Sopenharmony_ci    }
64511fccf17Sopenharmony_ci    char copyDcs[MAX_LENGTH] = { 0 };
64611fccf17Sopenharmony_ci    bool dcssEmpty = (dcss == NULL || dcss[0] == '\0');
64711fccf17Sopenharmony_ci    if (strcpy_s(copyDcs, MAX_LENGTH, dcss) != EOK) {
64811fccf17Sopenharmony_ci        return MAX_LENGTH;
64911fccf17Sopenharmony_ci    }
65011fccf17Sopenharmony_ci    char *startDcs = NULL;
65111fccf17Sopenharmony_ci    char *endDcs = NULL;
65211fccf17Sopenharmony_ci    char delimiterDcs[] = "-";
65311fccf17Sopenharmony_ci    char *tokenDcs;
65411fccf17Sopenharmony_ci    char *q = NULL;
65511fccf17Sopenharmony_ci    tokenDcs = strtok_r(copyDcs, delimiterDcs, &q);
65611fccf17Sopenharmony_ci    for (int32_t index = 0; !dcssEmpty && tokenDcs != NULL; index++) {
65711fccf17Sopenharmony_ci        if (index == 0) {
65811fccf17Sopenharmony_ci            startDcs = tokenDcs;
65911fccf17Sopenharmony_ci            endDcs = tokenDcs;
66011fccf17Sopenharmony_ci        } else {
66111fccf17Sopenharmony_ci            endDcs = tokenDcs;
66211fccf17Sopenharmony_ci            break;
66311fccf17Sopenharmony_ci        }
66411fccf17Sopenharmony_ci        tokenDcs = strtok_r(NULL, delimiterDcs, &q);
66511fccf17Sopenharmony_ci    }
66611fccf17Sopenharmony_ci    if (locate < MAX_LENGTH) {
66711fccf17Sopenharmony_ci        SetCellBroadcastInfo(cellBroadcast, locate, startMid, endMid, startDcs, endDcs, dcssEmpty, mode);
66811fccf17Sopenharmony_ci    }
66911fccf17Sopenharmony_ci    locate++;
67011fccf17Sopenharmony_ci    return locate;
67111fccf17Sopenharmony_ci}
67211fccf17Sopenharmony_ci
67311fccf17Sopenharmony_cibool UpdataMids(int32_t locate, char *mids, char *start, char *end)
67411fccf17Sopenharmony_ci{
67511fccf17Sopenharmony_ci    if (locate == 0) {
67611fccf17Sopenharmony_ci        if (strcpy_s(mids, MAX_LENGTH, start) != EOK) {
67711fccf17Sopenharmony_ci            return false;
67811fccf17Sopenharmony_ci        }
67911fccf17Sopenharmony_ci    } else {
68011fccf17Sopenharmony_ci        if (strcat_s(mids, MAX_LENGTH, g_commaStr) != EOK) {
68111fccf17Sopenharmony_ci            return false;
68211fccf17Sopenharmony_ci        }
68311fccf17Sopenharmony_ci        if (strcat_s(mids, MAX_LENGTH, start) != EOK) {
68411fccf17Sopenharmony_ci            return false;
68511fccf17Sopenharmony_ci        }
68611fccf17Sopenharmony_ci    }
68711fccf17Sopenharmony_ci    if (strcat_s(mids, MAX_LENGTH, g_hyphenStr) != EOK) {
68811fccf17Sopenharmony_ci        return false;
68911fccf17Sopenharmony_ci    }
69011fccf17Sopenharmony_ci    if (strcat_s(mids, MAX_LENGTH, end) != EOK) {
69111fccf17Sopenharmony_ci        return false;
69211fccf17Sopenharmony_ci    }
69311fccf17Sopenharmony_ci    return true;
69411fccf17Sopenharmony_ci}
69511fccf17Sopenharmony_ci
69611fccf17Sopenharmony_cibool UpdataMidValues(int32_t locate, char *mids, char *start)
69711fccf17Sopenharmony_ci{
69811fccf17Sopenharmony_ci    if (locate == 0) {
69911fccf17Sopenharmony_ci        if (strcpy_s(mids, MAX_LENGTH, start) != EOK) {
70011fccf17Sopenharmony_ci            return false;
70111fccf17Sopenharmony_ci        }
70211fccf17Sopenharmony_ci    } else {
70311fccf17Sopenharmony_ci        if (strcat_s(mids, MAX_LENGTH, g_commaStr) != EOK) {
70411fccf17Sopenharmony_ci            return false;
70511fccf17Sopenharmony_ci        }
70611fccf17Sopenharmony_ci        if (strcat_s(mids, MAX_LENGTH, start) != EOK) {
70711fccf17Sopenharmony_ci            return false;
70811fccf17Sopenharmony_ci        }
70911fccf17Sopenharmony_ci    }
71011fccf17Sopenharmony_ci    return true;
71111fccf17Sopenharmony_ci}
71211fccf17Sopenharmony_ci
71311fccf17Sopenharmony_cibool GetDcss(const HRilCBConfigInfo *data, int32_t len, char *dcss)
71411fccf17Sopenharmony_ci{
71511fccf17Sopenharmony_ci    for (int32_t locate = 0; locate < len && (locate + 1) * (CHNL_LEN + CHNL_LEN + 1) < MAX_LENGTH; locate++) {
71611fccf17Sopenharmony_ci        if (data[locate].startOfCodeScheme > data[locate].endOfCodeScheme) {
71711fccf17Sopenharmony_ci            TELEPHONY_LOGE("result.dcss is invalid");
71811fccf17Sopenharmony_ci            return false;
71911fccf17Sopenharmony_ci        } else if (data[locate].startOfCodeScheme < data[locate].endOfCodeScheme) {
72011fccf17Sopenharmony_ci            char start[CHNL_LEN] = { 0 };
72111fccf17Sopenharmony_ci            sprintf_s(start, CHNL_LEN, "%d", data[locate].startOfCodeScheme);
72211fccf17Sopenharmony_ci            char end[CHNL_LEN] = { 0 };
72311fccf17Sopenharmony_ci            sprintf_s(end, CHNL_LEN, "%d", data[locate].endOfCodeScheme);
72411fccf17Sopenharmony_ci            if (locate != 0) {
72511fccf17Sopenharmony_ci                break;
72611fccf17Sopenharmony_ci            }
72711fccf17Sopenharmony_ci            if (strcpy_s(dcss, MAX_LENGTH, start) != EOK) {
72811fccf17Sopenharmony_ci                return false;
72911fccf17Sopenharmony_ci            }
73011fccf17Sopenharmony_ci            if (strcat_s(dcss, MAX_LENGTH, g_hyphenStr) != EOK) {
73111fccf17Sopenharmony_ci                return false;
73211fccf17Sopenharmony_ci            }
73311fccf17Sopenharmony_ci            if (strcat_s(dcss, MAX_LENGTH, end) != EOK) {
73411fccf17Sopenharmony_ci                return false;
73511fccf17Sopenharmony_ci            }
73611fccf17Sopenharmony_ci        } else {
73711fccf17Sopenharmony_ci            char start[CHNL_LEN] = { 0 };
73811fccf17Sopenharmony_ci            sprintf_s(start, CHNL_LEN, "%d", data[locate].startOfCodeScheme);
73911fccf17Sopenharmony_ci            if (locate != 0) {
74011fccf17Sopenharmony_ci                break;
74111fccf17Sopenharmony_ci            }
74211fccf17Sopenharmony_ci            if (strcpy_s(dcss, MAX_LENGTH, start) != EOK) {
74311fccf17Sopenharmony_ci                return false;
74411fccf17Sopenharmony_ci            }
74511fccf17Sopenharmony_ci        }
74611fccf17Sopenharmony_ci    }
74711fccf17Sopenharmony_ci    return true;
74811fccf17Sopenharmony_ci}
74911fccf17Sopenharmony_ci
75011fccf17Sopenharmony_cibool GetMidsAndDcss(const HRilCBConfigInfo *data, int32_t len, char *mids, char *dcss)
75111fccf17Sopenharmony_ci{
75211fccf17Sopenharmony_ci    for (int32_t locate = 0; locate < len && (locate + 1) * (CHNL_LEN + CHNL_LEN + 1) < MAX_LENGTH; locate++) {
75311fccf17Sopenharmony_ci        if (data[locate].startOfServiceId < data[locate].endOfServiceId) {
75411fccf17Sopenharmony_ci            char start[CHNL_LEN] = { 0 };
75511fccf17Sopenharmony_ci            sprintf_s(start, CHNL_LEN, "%d", data[locate].startOfServiceId);
75611fccf17Sopenharmony_ci            char end[CHNL_LEN] = { 0 };
75711fccf17Sopenharmony_ci            sprintf_s(end, CHNL_LEN, "%d", data[locate].endOfServiceId);
75811fccf17Sopenharmony_ci            if (!UpdataMids(locate, mids, start, end)) {
75911fccf17Sopenharmony_ci                return false;
76011fccf17Sopenharmony_ci            }
76111fccf17Sopenharmony_ci        } else {
76211fccf17Sopenharmony_ci            char start[CHNL_LEN] = { 0 };
76311fccf17Sopenharmony_ci            sprintf_s(start, CHNL_LEN, "%d", data[locate].startOfServiceId);
76411fccf17Sopenharmony_ci            if (UpdataMidValues(locate, mids, start)) {
76511fccf17Sopenharmony_ci                return false;
76611fccf17Sopenharmony_ci            }
76711fccf17Sopenharmony_ci        }
76811fccf17Sopenharmony_ci        if (!GetDcss(data, len, dcss)) {
76911fccf17Sopenharmony_ci            return false;
77011fccf17Sopenharmony_ci        }
77111fccf17Sopenharmony_ci    }
77211fccf17Sopenharmony_ci    return true;
77311fccf17Sopenharmony_ci}
77411fccf17Sopenharmony_ci
77511fccf17Sopenharmony_civoid ReqSetCBConfig(const ReqDataInfo *requestInfo, const HRilCBConfigInfo *data, size_t dataLen)
77611fccf17Sopenharmony_ci{
77711fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = { 0 };
77811fccf17Sopenharmony_ci    int32_t err;
77911fccf17Sopenharmony_ci    int32_t ret;
78011fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
78111fccf17Sopenharmony_ci    int32_t len = (int32_t)(dataLen / sizeof(HRilCBConfigInfo));
78211fccf17Sopenharmony_ci    if (data == NULL || len == 0) {
78311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
78411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
78511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
78611fccf17Sopenharmony_ci        return;
78711fccf17Sopenharmony_ci    }
78811fccf17Sopenharmony_ci    int32_t mode = data[0].selected;
78911fccf17Sopenharmony_ci    char mids[MAX_LENGTH] = { 0 };
79011fccf17Sopenharmony_ci    char dcss[MAX_LENGTH] = { 0 };
79111fccf17Sopenharmony_ci    if (!GetMidsAndDcss(data, len, mids, dcss)) {
79211fccf17Sopenharmony_ci        return;
79311fccf17Sopenharmony_ci    }
79411fccf17Sopenharmony_ci    if (strcmp(mids, "") && !strcmp(dcss, "")) {
79511fccf17Sopenharmony_ci        ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d,\"%s\"", mode, mids);
79611fccf17Sopenharmony_ci    } else if (strcmp(mids, "") && strcmp(dcss, "")) {
79711fccf17Sopenharmony_ci        ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d,\"%s\",\"%s\"", mode, mids, dcss);
79811fccf17Sopenharmony_ci    } else if (strcmp(dcss, "") && !strcmp(mids, "")) {
79911fccf17Sopenharmony_ci        ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d,,\"%s\"", mode, dcss);
80011fccf17Sopenharmony_ci    } else {
80111fccf17Sopenharmony_ci        ret = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CSCB=%d", mode);
80211fccf17Sopenharmony_ci    }
80311fccf17Sopenharmony_ci    if (ret < 0) {
80411fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", ret);
80511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
80611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
80711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
80811fccf17Sopenharmony_ci        return;
80911fccf17Sopenharmony_ci    }
81011fccf17Sopenharmony_ci    err = SendCommandLock(cmd, "+CSCB:", 0, &responseInfo);
81111fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
81211fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, AT_ERR_GENERIC, HRIL_RESPONSE, 0);
81311fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
81411fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
81511fccf17Sopenharmony_ci        return;
81611fccf17Sopenharmony_ci    }
81711fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, VENDOR_SUCCESS, HRIL_RESPONSE, 0);
81811fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
81911fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
82011fccf17Sopenharmony_ci}
82111fccf17Sopenharmony_ci
82211fccf17Sopenharmony_civoid ReqGetCdmaCBConfig(const ReqDataInfo *requestInfo)
82311fccf17Sopenharmony_ci{
82411fccf17Sopenharmony_ci    char checked = '0';
82511fccf17Sopenharmony_ci    char lineBuff[MAX_CMD_LENGTH] = {0};
82611fccf17Sopenharmony_ci    char *line = lineBuff;
82711fccf17Sopenharmony_ci    int32_t err = HRIL_ERR_SUCCESS;
82811fccf17Sopenharmony_ci    int32_t service = 1;
82911fccf17Sopenharmony_ci    int32_t language = 1;
83011fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
83111fccf17Sopenharmony_ci    HRilCdmaCBConfigInfo cdmaCBConfig = {0};
83211fccf17Sopenharmony_ci
83311fccf17Sopenharmony_ci    int32_t ret = GenerateCommand(lineBuff, MAX_CMD_LENGTH, "AT:%d,%d,%c", service, language, checked);
83411fccf17Sopenharmony_ci    if (ret < 0) {
83511fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", ret);
83611fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
83711fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
83811fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
83911fccf17Sopenharmony_ci        return;
84011fccf17Sopenharmony_ci    }
84111fccf17Sopenharmony_ci    SkipATPrefix(&line);
84211fccf17Sopenharmony_ci    err = NextInt(&line, &cdmaCBConfig.service);
84311fccf17Sopenharmony_ci    if (err > 0) {
84411fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
84511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
84611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
84711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
84811fccf17Sopenharmony_ci        return;
84911fccf17Sopenharmony_ci    }
85011fccf17Sopenharmony_ci    err = NextInt(&line, &cdmaCBConfig.language);
85111fccf17Sopenharmony_ci    if (err > 0) {
85211fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
85311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
85411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
85511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
85611fccf17Sopenharmony_ci        return;
85711fccf17Sopenharmony_ci    }
85811fccf17Sopenharmony_ci    char *tmp = NULL;
85911fccf17Sopenharmony_ci    err = NextStr(&line, &tmp);
86011fccf17Sopenharmony_ci    if (err > 0 || tmp == NULL || tmp[0] == '\0') {
86111fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
86211fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
86311fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
86411fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
86511fccf17Sopenharmony_ci        return;
86611fccf17Sopenharmony_ci    }
86711fccf17Sopenharmony_ci    cdmaCBConfig.checked = tmp[0];
86811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
86911fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cdmaCBConfig, sizeof(HRilCdmaCBConfigInfo));
87011fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
87111fccf17Sopenharmony_ci}
87211fccf17Sopenharmony_ci
87311fccf17Sopenharmony_civoid ReqSetCdmaCBConfig(const ReqDataInfo *requestInfo, const HRilCdmaCBConfigInfo *data, size_t dataLen)
87411fccf17Sopenharmony_ci{
87511fccf17Sopenharmony_ci    int32_t err;
87611fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
87711fccf17Sopenharmony_ci
87811fccf17Sopenharmony_ci    if (data == NULL) {
87911fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
88011fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
88111fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
88211fccf17Sopenharmony_ci        return;
88311fccf17Sopenharmony_ci    }
88411fccf17Sopenharmony_ci    int32_t size = dataLen / sizeof(HRilCdmaCBConfigInfo);
88511fccf17Sopenharmony_ci    if (size <= 0) {
88611fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
88711fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
88811fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
88911fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
89011fccf17Sopenharmony_ci        return;
89111fccf17Sopenharmony_ci    }
89211fccf17Sopenharmony_ci    err = HRIL_ERR_SUCCESS;
89311fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
89411fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
89511fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
89611fccf17Sopenharmony_ci}
89711fccf17Sopenharmony_ci
89811fccf17Sopenharmony_civoid ReqAddCdmaSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteCdmaSms *data, size_t dataLen)
89911fccf17Sopenharmony_ci{
90011fccf17Sopenharmony_ci    if (data == NULL) {
90111fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
90211fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
90311fccf17Sopenharmony_ci        return;
90411fccf17Sopenharmony_ci    }
90511fccf17Sopenharmony_ci    HRilSmsWriteCdmaSms *cdmaSms = (HRilSmsWriteCdmaSms *)data;
90611fccf17Sopenharmony_ci    HRilCdmaSmsMessageInfo *cdmaMsg = &cdmaSms->cdmaMessageInfo;
90711fccf17Sopenharmony_ci    TELEPHONY_LOGD(
90811fccf17Sopenharmony_ci        "CreateCdmaPdu = %{public}x, %{public}x, %{public}x", cdmaMsg->serviceId, cdmaMsg->isExist, cdmaMsg->type);
90911fccf17Sopenharmony_ci    TELEPHONY_LOGD("CreateCdmaPdu2 = %{public}x, %{public}x, %{public}x", cdmaMsg->address.digitMode,
91011fccf17Sopenharmony_ci        cdmaMsg->address.mode, cdmaMsg->address.type);
91111fccf17Sopenharmony_ci    TELEPHONY_LOGD("CreateCdmaPdu3 = %{public}x, %{public}x, %{public}s", cdmaMsg->address.plan,
91211fccf17Sopenharmony_ci        cdmaMsg->address.number, cdmaMsg->address.bytes);
91311fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
91411fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
91511fccf17Sopenharmony_ci}
91611fccf17Sopenharmony_ci
91711fccf17Sopenharmony_civoid ReqDelCdmaSimMessage(const ReqDataInfo *requestInfo, const int32_t *data, size_t dataLen)
91811fccf17Sopenharmony_ci{
91911fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
92011fccf17Sopenharmony_ci    int32_t err;
92111fccf17Sopenharmony_ci    int32_t index;
92211fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
92311fccf17Sopenharmony_ci    if (data == NULL || dataLen == 0) {
92411fccf17Sopenharmony_ci        TELEPHONY_LOGE("data error");
92511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
92611fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
92711fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
92811fccf17Sopenharmony_ci        return;
92911fccf17Sopenharmony_ci    }
93011fccf17Sopenharmony_ci    index = ((int32_t *)data)[0] - 1;
93111fccf17Sopenharmony_ci    if (index < 0) {
93211fccf17Sopenharmony_ci        TELEPHONY_LOGE("invalid index:%d", index);
93311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
93411fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
93511fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
93611fccf17Sopenharmony_ci        return;
93711fccf17Sopenharmony_ci    }
93811fccf17Sopenharmony_ci    err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CMGD=%d", index);
93911fccf17Sopenharmony_ci    if (err < 0) {
94011fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
94111fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
94211fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
94311fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
94411fccf17Sopenharmony_ci        return;
94511fccf17Sopenharmony_ci    }
94611fccf17Sopenharmony_ci    err = SendCommandLock(cmd, "+CMGD:", 0, &responseInfo);
94711fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
94811fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
94911fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
95011fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
95111fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
95211fccf17Sopenharmony_ci        return;
95311fccf17Sopenharmony_ci    }
95411fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
95511fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
95611fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
95711fccf17Sopenharmony_ci}
95811fccf17Sopenharmony_ci
95911fccf17Sopenharmony_civoid ReqUpdateCdmaSimMessage(const ReqDataInfo *requestInfo, const HRilSmsWriteSms *data, size_t dataLen)
96011fccf17Sopenharmony_ci{
96111fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
96211fccf17Sopenharmony_ci    int32_t err;
96311fccf17Sopenharmony_ci    HRilSmsWriteSms *cdmaMsg = NULL;
96411fccf17Sopenharmony_ci    ResponseInfo *responseInfo = NULL;
96511fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
96611fccf17Sopenharmony_ci    if (data == NULL) {
96711fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_GENERIC_FAILURE, HRIL_RESPONSE, 0);
96811fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
96911fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
97011fccf17Sopenharmony_ci        return;
97111fccf17Sopenharmony_ci    }
97211fccf17Sopenharmony_ci    cdmaMsg = ((HRilSmsWriteSms *)data);
97311fccf17Sopenharmony_ci    err = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPMS=%d,%d%s", cdmaMsg->index, cdmaMsg->state, cdmaMsg->pdu);
97411fccf17Sopenharmony_ci    if (err < 0) {
97511fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", err);
97611fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
97711fccf17Sopenharmony_ci        OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
97811fccf17Sopenharmony_ci        FreeResponseInfo(responseInfo);
97911fccf17Sopenharmony_ci        return;
98011fccf17Sopenharmony_ci    }
98111fccf17Sopenharmony_ci    err = SendCommandLock(cmd, "+CPMS:", 0, &responseInfo);
98211fccf17Sopenharmony_ci    if (err != 0 || (responseInfo != NULL && !responseInfo->success)) {
98311fccf17Sopenharmony_ci        err = HRIL_ERR_GENERIC_FAILURE;
98411fccf17Sopenharmony_ci        SimMessageError(&reportInfo, requestInfo, &err, responseInfo);
98511fccf17Sopenharmony_ci        return;
98611fccf17Sopenharmony_ci    }
98711fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, err, HRIL_RESPONSE, 0);
98811fccf17Sopenharmony_ci    OnSmsReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
98911fccf17Sopenharmony_ci    FreeResponseInfo(responseInfo);
99011fccf17Sopenharmony_ci}
991