111fccf17Sopenharmony_ci/*
211fccf17Sopenharmony_ci * Copyright (C) 2021-2024 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_sim.h"
1711fccf17Sopenharmony_ci
1811fccf17Sopenharmony_ci#include "hril_notification.h"
1911fccf17Sopenharmony_ci#include "securec.h"
2011fccf17Sopenharmony_ci
2111fccf17Sopenharmony_ci#include "vendor_adapter.h"
2211fccf17Sopenharmony_ci#include "vendor_report.h"
2311fccf17Sopenharmony_ci
2411fccf17Sopenharmony_cistatic const int32_t ERR = -1;
2511fccf17Sopenharmony_ci
2611fccf17Sopenharmony_cistatic int32_t GetSimType(void)
2711fccf17Sopenharmony_ci{
2811fccf17Sopenharmony_ci    char *pLine = NULL;
2911fccf17Sopenharmony_ci    int32_t ret;
3011fccf17Sopenharmony_ci    int32_t simType = 0;
3111fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
3211fccf17Sopenharmony_ci
3311fccf17Sopenharmony_ci    ret = SendCommandLock("AT^CARDMODE", "^CARDMODE:", 0, &pResponse);
3411fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
3511fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^CARDMODE send failed");
3611fccf17Sopenharmony_ci        return HRIL_SIM_TYPE_UNKNOWN;
3711fccf17Sopenharmony_ci    }
3811fccf17Sopenharmony_ci    if (pResponse->head) {
3911fccf17Sopenharmony_ci        pLine = pResponse->head->data;
4011fccf17Sopenharmony_ci    }
4111fccf17Sopenharmony_ci    ret = SkipATPrefix(&pLine);
4211fccf17Sopenharmony_ci    if (ret < 0) {
4311fccf17Sopenharmony_ci        return HRIL_SIM_TYPE_UNKNOWN;
4411fccf17Sopenharmony_ci    }
4511fccf17Sopenharmony_ci    ret = NextInt(&pLine, &simType);
4611fccf17Sopenharmony_ci    if (ret < 0) {
4711fccf17Sopenharmony_ci        return HRIL_SIM_TYPE_UNKNOWN;
4811fccf17Sopenharmony_ci    }
4911fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
5011fccf17Sopenharmony_ci    return simType;
5111fccf17Sopenharmony_ci}
5211fccf17Sopenharmony_ci
5311fccf17Sopenharmony_cistatic int32_t GetSimState(char *pLine, char *pResult, ResponseInfo *pResponse)
5411fccf17Sopenharmony_ci{
5511fccf17Sopenharmony_ci    int32_t status = HRIL_SIM_NOT_INSERTED;
5611fccf17Sopenharmony_ci    int32_t ret;
5711fccf17Sopenharmony_ci    ret = SkipATPrefix(&pLine);
5811fccf17Sopenharmony_ci    if (ret != 0) {
5911fccf17Sopenharmony_ci        return HRIL_SIM_NOT_READY;
6011fccf17Sopenharmony_ci    }
6111fccf17Sopenharmony_ci    ret = NextStr(&pLine, &pResult);
6211fccf17Sopenharmony_ci    if (ret != 0) {
6311fccf17Sopenharmony_ci        return HRIL_SIM_NOT_READY;
6411fccf17Sopenharmony_ci    }
6511fccf17Sopenharmony_ci    if (strcmp(pResult, "READY") == 0) {
6611fccf17Sopenharmony_ci        status = HRIL_SIM_READY;
6711fccf17Sopenharmony_ci    } else if (strcmp(pResult, "SIM PIN") == 0) {
6811fccf17Sopenharmony_ci        status = HRIL_SIM_PIN;
6911fccf17Sopenharmony_ci    } else if (strcmp(pResult, "SIM PUK") == 0) {
7011fccf17Sopenharmony_ci        status = HRIL_SIM_PUK;
7111fccf17Sopenharmony_ci    } else if (strcmp(pResult, "PH-NET PIN") == 0) {
7211fccf17Sopenharmony_ci        status = HRIL_PH_NET_PIN;
7311fccf17Sopenharmony_ci    } else if (strcmp(pResult, "PH-NET PUK") == 0) {
7411fccf17Sopenharmony_ci        status = HRIL_PH_NET_PIN;
7511fccf17Sopenharmony_ci    } else if (!ReportStrWith(pResponse->result, "+CME ERROR:")) {
7611fccf17Sopenharmony_ci        status = HRIL_SIM_NOT_READY;
7711fccf17Sopenharmony_ci    }
7811fccf17Sopenharmony_ci    return status;
7911fccf17Sopenharmony_ci}
8011fccf17Sopenharmony_ci
8111fccf17Sopenharmony_cistatic int32_t ParseSimResponseResult(char *pLine, HRilSimIOResponse *pSimResponse)
8211fccf17Sopenharmony_ci{
8311fccf17Sopenharmony_ci    if (pSimResponse == NULL) {
8411fccf17Sopenharmony_ci        return ERR;
8511fccf17Sopenharmony_ci    }
8611fccf17Sopenharmony_ci    int32_t err = SkipATPrefix(&pLine);
8711fccf17Sopenharmony_ci    if (err != 0) {
8811fccf17Sopenharmony_ci        return err;
8911fccf17Sopenharmony_ci    }
9011fccf17Sopenharmony_ci    err = NextInt(&pLine, &pSimResponse->sw1);
9111fccf17Sopenharmony_ci    if (err != 0) {
9211fccf17Sopenharmony_ci        return err;
9311fccf17Sopenharmony_ci    }
9411fccf17Sopenharmony_ci    err = NextInt(&pLine, &pSimResponse->sw2);
9511fccf17Sopenharmony_ci    if (err != 0) {
9611fccf17Sopenharmony_ci        return err;
9711fccf17Sopenharmony_ci    }
9811fccf17Sopenharmony_ci
9911fccf17Sopenharmony_ci    if ((pLine != NULL && *pLine != '\0')) {
10011fccf17Sopenharmony_ci        err = NextStr(&pLine, &pSimResponse->response);
10111fccf17Sopenharmony_ci        if (err != 0) {
10211fccf17Sopenharmony_ci            return err;
10311fccf17Sopenharmony_ci        }
10411fccf17Sopenharmony_ci    }
10511fccf17Sopenharmony_ci    return 0;
10611fccf17Sopenharmony_ci}
10711fccf17Sopenharmony_ci
10811fccf17Sopenharmony_cistatic int32_t ParseSimPinInputTimesResult(char *pLine, HRilPinInputTimes *pinInputTimes)
10911fccf17Sopenharmony_ci{
11011fccf17Sopenharmony_ci    int32_t err = HRIL_ERR_GENERIC_FAILURE;
11111fccf17Sopenharmony_ci    if (pinInputTimes == NULL) {
11211fccf17Sopenharmony_ci        TELEPHONY_LOGE("pinInputTimes is null!!!");
11311fccf17Sopenharmony_ci        return err;
11411fccf17Sopenharmony_ci    }
11511fccf17Sopenharmony_ci    err = SkipATPrefix(&pLine);
11611fccf17Sopenharmony_ci    if (err != 0) {
11711fccf17Sopenharmony_ci        return err;
11811fccf17Sopenharmony_ci    }
11911fccf17Sopenharmony_ci    err = NextStr(&pLine, &pinInputTimes->code);
12011fccf17Sopenharmony_ci    if (err != 0) {
12111fccf17Sopenharmony_ci        return err;
12211fccf17Sopenharmony_ci    }
12311fccf17Sopenharmony_ci    err = NextInt(&pLine, &pinInputTimes->times);
12411fccf17Sopenharmony_ci    size_t atProlen = 0;
12511fccf17Sopenharmony_ci    if (err != 0 && strlen(pLine) == atProlen) {
12611fccf17Sopenharmony_ci        return err;
12711fccf17Sopenharmony_ci    }
12811fccf17Sopenharmony_ci    err = NextInt(&pLine, &pinInputTimes->pukTimes);
12911fccf17Sopenharmony_ci    if (err != 0) {
13011fccf17Sopenharmony_ci        return err;
13111fccf17Sopenharmony_ci    }
13211fccf17Sopenharmony_ci    err = NextInt(&pLine, &pinInputTimes->pinTimes);
13311fccf17Sopenharmony_ci    if (err != 0) {
13411fccf17Sopenharmony_ci        return err;
13511fccf17Sopenharmony_ci    }
13611fccf17Sopenharmony_ci    err = NextInt(&pLine, &pinInputTimes->puk2Times);
13711fccf17Sopenharmony_ci    if (err != 0) {
13811fccf17Sopenharmony_ci        return err;
13911fccf17Sopenharmony_ci    }
14011fccf17Sopenharmony_ci    err = NextInt(&pLine, &pinInputTimes->pin2Times);
14111fccf17Sopenharmony_ci    if (err != 0) {
14211fccf17Sopenharmony_ci        return err;
14311fccf17Sopenharmony_ci    }
14411fccf17Sopenharmony_ci    return 0;
14511fccf17Sopenharmony_ci}
14611fccf17Sopenharmony_ci
14711fccf17Sopenharmony_cistatic int32_t ParseUnlockSimLockResult(char *pLine, HRilLockStatus *lockStatus)
14811fccf17Sopenharmony_ci{
14911fccf17Sopenharmony_ci    int32_t err = HRIL_ERR_GENERIC_FAILURE;
15011fccf17Sopenharmony_ci    if (lockStatus == NULL) {
15111fccf17Sopenharmony_ci        TELEPHONY_LOGE("lockStatus is null!!!");
15211fccf17Sopenharmony_ci        return err;
15311fccf17Sopenharmony_ci    }
15411fccf17Sopenharmony_ci    err = SkipATPrefix(&pLine);
15511fccf17Sopenharmony_ci    if (err != 0) {
15611fccf17Sopenharmony_ci        return err;
15711fccf17Sopenharmony_ci    }
15811fccf17Sopenharmony_ci    err = NextInt(&pLine, &lockStatus->result);
15911fccf17Sopenharmony_ci    if (err != 0) {
16011fccf17Sopenharmony_ci        return err;
16111fccf17Sopenharmony_ci    }
16211fccf17Sopenharmony_ci    err = NextInt(&pLine, &lockStatus->remain);
16311fccf17Sopenharmony_ci    TELEPHONY_LOGD("ParseUnlockSimLockResult, lockStatus->result: %{public}d", lockStatus->result);
16411fccf17Sopenharmony_ci    TELEPHONY_LOGD("ParseUnlockSimLockResult, lockStatus->remain: %{public}d", lockStatus->remain);
16511fccf17Sopenharmony_ci    if (err != 0) {
16611fccf17Sopenharmony_ci        return err;
16711fccf17Sopenharmony_ci    }
16811fccf17Sopenharmony_ci    return 0;
16911fccf17Sopenharmony_ci}
17011fccf17Sopenharmony_ci
17111fccf17Sopenharmony_civoid ReqGetSimStatus(const ReqDataInfo *requestInfo)
17211fccf17Sopenharmony_ci{
17311fccf17Sopenharmony_ci    char *pLine = NULL;
17411fccf17Sopenharmony_ci    char *pResult = NULL;
17511fccf17Sopenharmony_ci    int32_t ret;
17611fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
17711fccf17Sopenharmony_ci    HRilCardState cardState = {0};
17811fccf17Sopenharmony_ci
17911fccf17Sopenharmony_ci    HRilRadioState radioState = GetRadioState();
18011fccf17Sopenharmony_ci    if (radioState == HRIL_RADIO_POWER_STATE_UNAVAILABLE || radioState == HRIL_RADIO_POWER_STATE_OFF) {
18111fccf17Sopenharmony_ci        cardState.simState = HRIL_SIM_NOT_READY;
18211fccf17Sopenharmony_ci    }
18311fccf17Sopenharmony_ci    cardState.simType = GetSimType();
18411fccf17Sopenharmony_ci    ret = SendCommandLock("AT+CPIN?", "+CPIN:", 0, &pResponse);
18511fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
18611fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CPIN? send failed");
18711fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
18811fccf17Sopenharmony_ci            pLine = pResponse->result;
18911fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
19011fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
19111fccf17Sopenharmony_ci        } else {
19211fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
19311fccf17Sopenharmony_ci        }
19411fccf17Sopenharmony_ci        if (ret == HRIL_ERR_NO_SIMCARD_INSERTED) {
19511fccf17Sopenharmony_ci            cardState.simState = HRIL_SIM_NOT_INSERTED;
19611fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
19711fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cardState, sizeof(HRilCardState));
19811fccf17Sopenharmony_ci        } else {
19911fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
20011fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
20111fccf17Sopenharmony_ci        }
20211fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
20311fccf17Sopenharmony_ci        return;
20411fccf17Sopenharmony_ci    }
20511fccf17Sopenharmony_ci    if (pResponse->head) {
20611fccf17Sopenharmony_ci        pLine = pResponse->head->data;
20711fccf17Sopenharmony_ci    }
20811fccf17Sopenharmony_ci    cardState.simState = GetSimState(pLine, pResult, pResponse);
20911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
21011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&cardState, sizeof(HRilCardState));
21111fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
21211fccf17Sopenharmony_ci}
21311fccf17Sopenharmony_ci
21411fccf17Sopenharmony_cistatic int32_t ReqGetSimIOFDNWrite(HRilSimIO *pSim, ResponseInfo **ppResponse, size_t dataLen)
21511fccf17Sopenharmony_ci{
21611fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
21711fccf17Sopenharmony_ci    int32_t tmp = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",%d,\"%s\"", "FD", 1, pSim->pin2);
21811fccf17Sopenharmony_ci    if (tmp < 0) {
21911fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed");
22011fccf17Sopenharmony_ci        return VENDOR_FAIL;
22111fccf17Sopenharmony_ci    }
22211fccf17Sopenharmony_ci    int32_t ret = SendCommandLock(cmd, "+CLCK", 0, ppResponse);
22311fccf17Sopenharmony_ci    if (ret != 0 || (ppResponse != NULL && (*ppResponse != NULL) && !(*ppResponse)->success)) {
22411fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CLCK failed");
22511fccf17Sopenharmony_ci        return HRIL_ERR_CMD_SEND_FAILURE;
22611fccf17Sopenharmony_ci    }
22711fccf17Sopenharmony_ci    tmp = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CRSM=%d,%d,%d,%d,%d,\"%s\",\"%s\"", pSim->command, pSim->fileid,
22811fccf17Sopenharmony_ci        pSim->p1, pSim->p2, pSim->p3, ((pSim->data == NULL) ? "" : (pSim->data)), pSim->pathid);
22911fccf17Sopenharmony_ci    if (tmp < 0) {
23011fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed");
23111fccf17Sopenharmony_ci        return VENDOR_FAIL;
23211fccf17Sopenharmony_ci    }
23311fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CRSM", 0, ppResponse);
23411fccf17Sopenharmony_ci    if (ret != 0 || (ppResponse != NULL && (*ppResponse != NULL) && !(*ppResponse)->success)) {
23511fccf17Sopenharmony_ci        return HRIL_ERR_CMD_SEND_FAILURE;
23611fccf17Sopenharmony_ci    }
23711fccf17Sopenharmony_ci    tmp = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",%d,\"%s\"", "FD", 0, pSim->pin2);
23811fccf17Sopenharmony_ci    if (tmp < 0) {
23911fccf17Sopenharmony_ci        return VENDOR_FAIL;
24011fccf17Sopenharmony_ci    }
24111fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CLCK", 0, ppResponse);
24211fccf17Sopenharmony_ci    if (ret != 0 || (ppResponse != NULL && (*ppResponse != NULL) && !(*ppResponse)->success)) {
24311fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CLCK failed");
24411fccf17Sopenharmony_ci        return HRIL_ERR_CMD_SEND_FAILURE;
24511fccf17Sopenharmony_ci    }
24611fccf17Sopenharmony_ci    return HRIL_ERR_SUCCESS;
24711fccf17Sopenharmony_ci}
24811fccf17Sopenharmony_ci
24911fccf17Sopenharmony_cistatic int32_t ReqGetSimIOFDN(HRilSimIO *pSim, ResponseInfo **ppResponse, size_t dataLen)
25011fccf17Sopenharmony_ci{
25111fccf17Sopenharmony_ci    const char *queryCmd = "AT+CLCK=\"FD\",2";
25211fccf17Sopenharmony_ci    int32_t ret = SendCommandLock(queryCmd, "+CLCK", 0, ppResponse);
25311fccf17Sopenharmony_ci    if (ret != 0 || ppResponse == NULL || *ppResponse == NULL || !(*ppResponse)->success) {
25411fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CLCK failed");
25511fccf17Sopenharmony_ci        return HRIL_ERR_CMD_SEND_FAILURE;
25611fccf17Sopenharmony_ci    }
25711fccf17Sopenharmony_ci    char *pLine = (*ppResponse)->last == NULL ? (*ppResponse)->result : (*ppResponse)->last->data;
25811fccf17Sopenharmony_ci    SkipATPrefix(&pLine);
25911fccf17Sopenharmony_ci    int32_t clckRes = VENDOR_FAIL;
26011fccf17Sopenharmony_ci    NextInt(&pLine, &clckRes);
26111fccf17Sopenharmony_ci    clckRes = (clckRes > 0) ? 1 : 0;
26211fccf17Sopenharmony_ci    TELEPHONY_LOGD("FDN had got FDN clck res:%{public}d", clckRes);
26311fccf17Sopenharmony_ci    int32_t writeRet = ReqGetSimIOFDNWrite(pSim, ppResponse, dataLen);
26411fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
26511fccf17Sopenharmony_ci    int32_t tmp = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",%d,\"%s\"", "FD", clckRes, pSim->pin2);
26611fccf17Sopenharmony_ci    if (tmp < 0) {
26711fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed");
26811fccf17Sopenharmony_ci        return VENDOR_FAIL;
26911fccf17Sopenharmony_ci    }
27011fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CLCK", 0, ppResponse);
27111fccf17Sopenharmony_ci    if (ret != 0 || (ppResponse != NULL && !(*ppResponse)->success)) {
27211fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CLCK failed");
27311fccf17Sopenharmony_ci        return HRIL_ERR_CMD_SEND_FAILURE;
27411fccf17Sopenharmony_ci    }
27511fccf17Sopenharmony_ci    return writeRet;
27611fccf17Sopenharmony_ci}
27711fccf17Sopenharmony_ci
27811fccf17Sopenharmony_cistatic void HandlerSimIOResult(ResponseInfo *pResponse, HRilSimIOResponse *simResponse,
27911fccf17Sopenharmony_ci    const ReqDataInfo *requestInfo, char *pLine, int32_t *ret)
28011fccf17Sopenharmony_ci{
28111fccf17Sopenharmony_ci    if (ret == NULL) {
28211fccf17Sopenharmony_ci        TELEPHONY_LOGE("ret is NULL");
28311fccf17Sopenharmony_ci        return;
28411fccf17Sopenharmony_ci    }
28511fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, *ret, HRIL_RESPONSE, 0);
28611fccf17Sopenharmony_ci    if (pResponse == NULL) {
28711fccf17Sopenharmony_ci        TELEPHONY_LOGE("pResponse is NULL");
28811fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
28911fccf17Sopenharmony_ci        return;
29011fccf17Sopenharmony_ci    }
29111fccf17Sopenharmony_ci
29211fccf17Sopenharmony_ci    if (*ret != HRIL_ERR_SUCCESS) {
29311fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
29411fccf17Sopenharmony_ci            pLine = pResponse->result;
29511fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
29611fccf17Sopenharmony_ci            NextInt(&pLine, ret);
29711fccf17Sopenharmony_ci        } else {
29811fccf17Sopenharmony_ci            *ret = HRIL_ERR_GENERIC_FAILURE;
29911fccf17Sopenharmony_ci        }
30011fccf17Sopenharmony_ci    }
30111fccf17Sopenharmony_ci    if (simResponse == NULL) {
30211fccf17Sopenharmony_ci        TELEPHONY_LOGE("simResponse is NULL");
30311fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
30411fccf17Sopenharmony_ci    } else {
30511fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)simResponse, sizeof(HRilSimIOResponse));
30611fccf17Sopenharmony_ci    }
30711fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
30811fccf17Sopenharmony_ci}
30911fccf17Sopenharmony_ci
31011fccf17Sopenharmony_civoid ReqGetSimIO(const ReqDataInfo *requestInfo, const HRilSimIO *data, size_t dataLen)
31111fccf17Sopenharmony_ci{
31211fccf17Sopenharmony_ci    char *pLine = NULL;
31311fccf17Sopenharmony_ci    int32_t ret;
31411fccf17Sopenharmony_ci    const int32_t FILEID = 0x6F3B;
31511fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
31611fccf17Sopenharmony_ci    HRilSimIOResponse simResponse = {0};
31711fccf17Sopenharmony_ci    HRilSimIO *pSim = (HRilSimIO *)data;
31811fccf17Sopenharmony_ci    if (pSim == NULL) {
31911fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
32011fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
32111fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
32211fccf17Sopenharmony_ci        return;
32311fccf17Sopenharmony_ci    }
32411fccf17Sopenharmony_ci    if (pSim->pin2 != NULL && strcmp(pSim->pin2, "") != 0 && pSim->fileid == FILEID) {
32511fccf17Sopenharmony_ci        ret = ReqGetSimIOFDN(pSim, &pResponse, dataLen);
32611fccf17Sopenharmony_ci        if (ret != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
32711fccf17Sopenharmony_ci            TELEPHONY_LOGE("FDN is failed");
32811fccf17Sopenharmony_ci            HandlerSimIOResult(pResponse, NULL, requestInfo, pLine, &ret);
32911fccf17Sopenharmony_ci            return;
33011fccf17Sopenharmony_ci        }
33111fccf17Sopenharmony_ci        TELEPHONY_LOGE("FDN is success");
33211fccf17Sopenharmony_ci        HandlerSimIOResult(pResponse, &simResponse, requestInfo, pLine, &ret);
33311fccf17Sopenharmony_ci        return;
33411fccf17Sopenharmony_ci    }
33511fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
33611fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CRSM=%d,%d,%d,%d,%d,\"%s\",\"%s\"", pSim->command,
33711fccf17Sopenharmony_ci        pSim->fileid, pSim->p1, pSim->p2, pSim->p3, ((pSim->data == NULL) ? "" : (pSim->data)), pSim->pathid);
33811fccf17Sopenharmony_ci    TELEPHONY_LOGI("GenerateCommand result is %{public}d", result);
33911fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CRSM", 0, &pResponse);
34011fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS || pResponse == NULL || !pResponse->success) {
34111fccf17Sopenharmony_ci        TELEPHONY_LOGE("send failed dataLen:%{public}zu", dataLen);
34211fccf17Sopenharmony_ci        HandlerSimIOResult(pResponse, NULL, requestInfo, pLine, &ret);
34311fccf17Sopenharmony_ci        return;
34411fccf17Sopenharmony_ci    }
34511fccf17Sopenharmony_ci    if (pResponse->head) {
34611fccf17Sopenharmony_ci        pLine = pResponse->head->data;
34711fccf17Sopenharmony_ci    }
34811fccf17Sopenharmony_ci    ret = ParseSimResponseResult(pLine, &simResponse);
34911fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
35011fccf17Sopenharmony_ci        HandlerSimIOResult(pResponse, NULL, requestInfo, pLine, &ret);
35111fccf17Sopenharmony_ci        return;
35211fccf17Sopenharmony_ci    }
35311fccf17Sopenharmony_ci    if (GetSimType() == HRIL_SIM_TYPE_USIM && pSim->command == CMD_GET_RESPONSE) {
35411fccf17Sopenharmony_ci        ConvertUsimFcpToSimRsp((unsigned char **)&(simResponse.response));
35511fccf17Sopenharmony_ci    }
35611fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
35711fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&simResponse, sizeof(HRilSimIOResponse));
35811fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
35911fccf17Sopenharmony_ci}
36011fccf17Sopenharmony_ci
36111fccf17Sopenharmony_cistatic void HandlerSimImsiResult(
36211fccf17Sopenharmony_ci    ResponseInfo *pResponse, struct ReportInfo reportInfo, const ReqDataInfo *requestInfo, char *pLine, int32_t *ret)
36311fccf17Sopenharmony_ci{
36411fccf17Sopenharmony_ci    if (pResponse == NULL || ret == NULL) {
36511fccf17Sopenharmony_ci        TELEPHONY_LOGE("pResponse is NULL");
36611fccf17Sopenharmony_ci        return;
36711fccf17Sopenharmony_ci    }
36811fccf17Sopenharmony_ci    if (pResponse && pResponse->result) {
36911fccf17Sopenharmony_ci        pLine = pResponse->result;
37011fccf17Sopenharmony_ci        SkipATPrefix(&pLine);
37111fccf17Sopenharmony_ci        NextInt(&pLine, ret);
37211fccf17Sopenharmony_ci    } else {
37311fccf17Sopenharmony_ci        *ret = HRIL_ERR_GENERIC_FAILURE;
37411fccf17Sopenharmony_ci    }
37511fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, *ret, HRIL_RESPONSE, 0);
37611fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
37711fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
37811fccf17Sopenharmony_ci}
37911fccf17Sopenharmony_ci
38011fccf17Sopenharmony_civoid ReqGetSimImsi(const ReqDataInfo *requestInfo)
38111fccf17Sopenharmony_ci{
38211fccf17Sopenharmony_ci    char *pLine = NULL;
38311fccf17Sopenharmony_ci    char *result = NULL;
38411fccf17Sopenharmony_ci    int32_t ret;
38511fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
38611fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
38711fccf17Sopenharmony_ci
38811fccf17Sopenharmony_ci    ret = SendCommandLock("AT+CIMI", NULL, 0, &pResponse);
38911fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
39011fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CIMI send failed");
39111fccf17Sopenharmony_ci        HandlerSimImsiResult(pResponse, reportInfo, requestInfo, pLine, &ret);
39211fccf17Sopenharmony_ci        return;
39311fccf17Sopenharmony_ci    }
39411fccf17Sopenharmony_ci    if (pResponse->head) {
39511fccf17Sopenharmony_ci        result = pResponse->head->data;
39611fccf17Sopenharmony_ci    } else {
39711fccf17Sopenharmony_ci        HandlerSimImsiResult(pResponse, reportInfo, requestInfo, pLine, &ret);
39811fccf17Sopenharmony_ci        return;
39911fccf17Sopenharmony_ci    }
40011fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
40111fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)result, 0);
40211fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
40311fccf17Sopenharmony_ci}
40411fccf17Sopenharmony_ci
40511fccf17Sopenharmony_cistatic void HandlerSimLockStatusResult(
40611fccf17Sopenharmony_ci    ResponseInfo *pResponse, struct ReportInfo reportInfo, const ReqDataInfo *requestInfo, char *pLine, int32_t *ret)
40711fccf17Sopenharmony_ci{
40811fccf17Sopenharmony_ci    if (pResponse == NULL || ret == NULL) {
40911fccf17Sopenharmony_ci        TELEPHONY_LOGE("pResponse is NULL");
41011fccf17Sopenharmony_ci        return;
41111fccf17Sopenharmony_ci    }
41211fccf17Sopenharmony_ci    if (pResponse && pResponse->result) {
41311fccf17Sopenharmony_ci        pLine = pResponse->result;
41411fccf17Sopenharmony_ci        SkipATPrefix(&pLine);
41511fccf17Sopenharmony_ci        NextInt(&pLine, ret);
41611fccf17Sopenharmony_ci    } else {
41711fccf17Sopenharmony_ci        *ret = HRIL_ERR_GENERIC_FAILURE;
41811fccf17Sopenharmony_ci    }
41911fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, *ret, HRIL_RESPONSE, 0);
42011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
42111fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
42211fccf17Sopenharmony_ci}
42311fccf17Sopenharmony_ci
42411fccf17Sopenharmony_civoid ReqGetSimLockStatus(const ReqDataInfo *requestInfo, const HRilSimClock *data, size_t dataLen)
42511fccf17Sopenharmony_ci{
42611fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
42711fccf17Sopenharmony_ci    int32_t ret;
42811fccf17Sopenharmony_ci    char *pLine = NULL;
42911fccf17Sopenharmony_ci    int32_t status = 0;
43011fccf17Sopenharmony_ci    HRilSimClock *pSimClck = NULL;
43111fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
43211fccf17Sopenharmony_ci    struct ReportInfo reportInfo = {0};
43311fccf17Sopenharmony_ci
43411fccf17Sopenharmony_ci    pSimClck = (HRilSimClock *)data;
43511fccf17Sopenharmony_ci    if (pSimClck == NULL) {
43611fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
43711fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
43811fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
43911fccf17Sopenharmony_ci        return;
44011fccf17Sopenharmony_ci    }
44111fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",%d", pSimClck->fac, pSimClck->mode);
44211fccf17Sopenharmony_ci    if (result <= 0) {
44311fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
44411fccf17Sopenharmony_ci    }
44511fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CLCK", 0, &pResponse);
44611fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
44711fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CLCK send failed dataLen:%{public}zu", dataLen);
44811fccf17Sopenharmony_ci        HandlerSimLockStatusResult(pResponse, reportInfo, requestInfo, pLine, &ret);
44911fccf17Sopenharmony_ci        return;
45011fccf17Sopenharmony_ci    }
45111fccf17Sopenharmony_ci    if (pResponse->head) {
45211fccf17Sopenharmony_ci        pLine = pResponse->head->data;
45311fccf17Sopenharmony_ci    }
45411fccf17Sopenharmony_ci    ret = SkipATPrefix(&pLine);
45511fccf17Sopenharmony_ci    if (ret != 0) {
45611fccf17Sopenharmony_ci        HandlerSimLockStatusResult(pResponse, reportInfo, requestInfo, pLine, &ret);
45711fccf17Sopenharmony_ci        return;
45811fccf17Sopenharmony_ci    }
45911fccf17Sopenharmony_ci
46011fccf17Sopenharmony_ci    ret = NextInt(&pLine, &status);
46111fccf17Sopenharmony_ci    if (ret != 0) {
46211fccf17Sopenharmony_ci        HandlerSimLockStatusResult(pResponse, reportInfo, requestInfo, pLine, &ret);
46311fccf17Sopenharmony_ci        return;
46411fccf17Sopenharmony_ci    }
46511fccf17Sopenharmony_ci    reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
46611fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&status, sizeof(int32_t));
46711fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
46811fccf17Sopenharmony_ci}
46911fccf17Sopenharmony_ci
47011fccf17Sopenharmony_civoid ReqSetSimLock(const ReqDataInfo *requestInfo, const HRilSimClock *data, size_t dataLen)
47111fccf17Sopenharmony_ci{
47211fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
47311fccf17Sopenharmony_ci    char *pLine = NULL;
47411fccf17Sopenharmony_ci    int32_t ret;
47511fccf17Sopenharmony_ci    HRilSimClock *pSimClck = (HRilSimClock *)data;
47611fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
47711fccf17Sopenharmony_ci    if (pSimClck == NULL) {
47811fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
47911fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
48011fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
48111fccf17Sopenharmony_ci        return;
48211fccf17Sopenharmony_ci    }
48311fccf17Sopenharmony_ci    int32_t result = GenerateCommand(
48411fccf17Sopenharmony_ci        cmd, MAX_CMD_LENGTH, "AT+CLCK=\"%s\",%d,\"%s\"", pSimClck->fac, pSimClck->mode, pSimClck->passwd);
48511fccf17Sopenharmony_ci    TELEPHONY_LOGI("GenerateCommand result is %{public}d", result);
48611fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CLCK", 0, &pResponse);
48711fccf17Sopenharmony_ci    HRilLockStatus lockStatus = { HRIL_UNLOCK_OTHER_ERR, -1 };
48811fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
48911fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CLCK send failed dataLen:%{public}zu", dataLen);
49011fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
49111fccf17Sopenharmony_ci            pLine = pResponse->result;
49211fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
49311fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
49411fccf17Sopenharmony_ci            HRilPinInputTimes pinInputTimes = { 0 };
49511fccf17Sopenharmony_ci            if (ret == AT_RESPONSE_INCORRECT_PASSWORD) {
49611fccf17Sopenharmony_ci                ReqGetSimPinInputTimesRemain(requestInfo, &pinInputTimes);
49711fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_PASSWORD_ERR;
49811fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pinTimes;
49911fccf17Sopenharmony_ci            }
50011fccf17Sopenharmony_ci            if (strcmp(pSimClck->fac, "FD") == 0) {
50111fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pin2Times;
50211fccf17Sopenharmony_ci            }
50311fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
50411fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
50511fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
50611fccf17Sopenharmony_ci        } else {
50711fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
50811fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
50911fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
51011fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
51111fccf17Sopenharmony_ci        }
51211fccf17Sopenharmony_ci        return;
51311fccf17Sopenharmony_ci    }
51411fccf17Sopenharmony_ci    lockStatus.result = HRIL_UNLOCK_SUCCESS;
51511fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
51611fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
51711fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
51811fccf17Sopenharmony_ci}
51911fccf17Sopenharmony_ci
52011fccf17Sopenharmony_civoid ReqChangeSimPassword(const ReqDataInfo *requestInfo, const HRilSimPassword *data, size_t dataLen)
52111fccf17Sopenharmony_ci{
52211fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
52311fccf17Sopenharmony_ci    char *pLine = NULL;
52411fccf17Sopenharmony_ci    HRilSimPassword *pSimPassword = NULL;
52511fccf17Sopenharmony_ci    int32_t ret;
52611fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
52711fccf17Sopenharmony_ci    pSimPassword = (HRilSimPassword *)data;
52811fccf17Sopenharmony_ci    if (pSimPassword == NULL) {
52911fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
53011fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
53111fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
53211fccf17Sopenharmony_ci        return;
53311fccf17Sopenharmony_ci    }
53411fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPWD=\"%s\",\"%s\",\"%s\"", pSimPassword->fac,
53511fccf17Sopenharmony_ci        pSimPassword->oldPassword, pSimPassword->newPassword);
53611fccf17Sopenharmony_ci    TELEPHONY_LOGI("GenerateCommand result is %{public}d", result);
53711fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CPWD", 0, &pResponse);
53811fccf17Sopenharmony_ci    HRilLockStatus lockStatus = { HRIL_UNLOCK_OTHER_ERR, -1 };
53911fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
54011fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CPWD send failed dataLen:%{public}zu", dataLen);
54111fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
54211fccf17Sopenharmony_ci            pLine = pResponse->result;
54311fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
54411fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
54511fccf17Sopenharmony_ci            HRilPinInputTimes pinInputTimes = {0};
54611fccf17Sopenharmony_ci            if (ret == AT_RESPONSE_INCORRECT_PASSWORD) {
54711fccf17Sopenharmony_ci                ReqGetSimPinInputTimesRemain(requestInfo, &pinInputTimes);
54811fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_PASSWORD_ERR;
54911fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pinTimes;
55011fccf17Sopenharmony_ci            }
55111fccf17Sopenharmony_ci            if (strcmp(pSimPassword->fac, "P2") == 0) {
55211fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pin2Times;
55311fccf17Sopenharmony_ci            }
55411fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
55511fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
55611fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
55711fccf17Sopenharmony_ci        } else {
55811fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
55911fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
56011fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
56111fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
56211fccf17Sopenharmony_ci        }
56311fccf17Sopenharmony_ci        return;
56411fccf17Sopenharmony_ci    }
56511fccf17Sopenharmony_ci    lockStatus.result = HRIL_UNLOCK_SUCCESS;
56611fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
56711fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
56811fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
56911fccf17Sopenharmony_ci}
57011fccf17Sopenharmony_ci
57111fccf17Sopenharmony_civoid ReqUnlockPin(const ReqDataInfo *requestInfo, const char *pin)
57211fccf17Sopenharmony_ci{
57311fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
57411fccf17Sopenharmony_ci    char *pLine = NULL;
57511fccf17Sopenharmony_ci    int32_t ret;
57611fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
57711fccf17Sopenharmony_ci
57811fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPIN=\"%s\"", pin);
57911fccf17Sopenharmony_ci    if (result <= 0) {
58011fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
58111fccf17Sopenharmony_ci    }
58211fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CPIN", 0, &pResponse);
58311fccf17Sopenharmony_ci    HRilLockStatus lockStatus = {0};
58411fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
58511fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CPIN send failed");
58611fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
58711fccf17Sopenharmony_ci            pLine = pResponse->result;
58811fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT+CPIN send failed pLine1:%{public}s", pLine);
58911fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
59011fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT+CPIN send failed pLine2:%{public}s", pLine);
59111fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
59211fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT+CPIN send failed ret:%{public}d", ret);
59311fccf17Sopenharmony_ci            if (ret == AT_RESPONSE_INCORRECT_PASSWORD) {
59411fccf17Sopenharmony_ci                HRilPinInputTimes pinInputTimes = {0};
59511fccf17Sopenharmony_ci                ReqGetSimPinInputTimesRemain(requestInfo, &pinInputTimes);
59611fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_PASSWORD_ERR;
59711fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pinTimes;
59811fccf17Sopenharmony_ci            } else {
59911fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
60011fccf17Sopenharmony_ci                lockStatus.remain = -1;
60111fccf17Sopenharmony_ci                TELEPHONY_LOGE("AT+CPWD send failed");
60211fccf17Sopenharmony_ci            }
60311fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
60411fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
60511fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
60611fccf17Sopenharmony_ci            return;
60711fccf17Sopenharmony_ci        } else {
60811fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
60911fccf17Sopenharmony_ci            lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
61011fccf17Sopenharmony_ci            lockStatus.remain = -1;
61111fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
61211fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
61311fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
61411fccf17Sopenharmony_ci            return;
61511fccf17Sopenharmony_ci        }
61611fccf17Sopenharmony_ci    }
61711fccf17Sopenharmony_ci
61811fccf17Sopenharmony_ci    lockStatus.result = HRIL_UNLOCK_SUCCESS;
61911fccf17Sopenharmony_ci    lockStatus.remain = -1;
62011fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
62111fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
62211fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
62311fccf17Sopenharmony_ci}
62411fccf17Sopenharmony_ci
62511fccf17Sopenharmony_civoid ReqUnlockPuk(const ReqDataInfo *requestInfo, const char *puk, const char *pin)
62611fccf17Sopenharmony_ci{
62711fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
62811fccf17Sopenharmony_ci    char *pLine = NULL;
62911fccf17Sopenharmony_ci    int32_t ret;
63011fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
63111fccf17Sopenharmony_ci
63211fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CPIN=\"%s\",\"%s\"", puk, pin);
63311fccf17Sopenharmony_ci    if (result <= 0) {
63411fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
63511fccf17Sopenharmony_ci    }
63611fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CPIN", 0, &pResponse);
63711fccf17Sopenharmony_ci    HRilLockStatus lockStatus = {0};
63811fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
63911fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CPIN send failed");
64011fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
64111fccf17Sopenharmony_ci            pLine = pResponse->result;
64211fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT+CPIN send failed pLine1:%{public}s", pLine);
64311fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
64411fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT+CPIN send failed pLine2:%{public}s", pLine);
64511fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
64611fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT+CPIN send failed ret:%{public}d", ret);
64711fccf17Sopenharmony_ci            if (ret == AT_RESPONSE_INCORRECT_PASSWORD) {
64811fccf17Sopenharmony_ci                HRilPinInputTimes pinInputTimes = {0};
64911fccf17Sopenharmony_ci                ReqGetSimPinInputTimesRemain(requestInfo, &pinInputTimes);
65011fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_PASSWORD_ERR;
65111fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pukTimes;
65211fccf17Sopenharmony_ci            } else {
65311fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
65411fccf17Sopenharmony_ci                lockStatus.remain = -1;
65511fccf17Sopenharmony_ci                TELEPHONY_LOGE("AT+CPIN send failed");
65611fccf17Sopenharmony_ci            }
65711fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
65811fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
65911fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
66011fccf17Sopenharmony_ci            return;
66111fccf17Sopenharmony_ci        } else {
66211fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
66311fccf17Sopenharmony_ci            lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
66411fccf17Sopenharmony_ci            lockStatus.remain = -1;
66511fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
66611fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
66711fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
66811fccf17Sopenharmony_ci            return;
66911fccf17Sopenharmony_ci        }
67011fccf17Sopenharmony_ci    }
67111fccf17Sopenharmony_ci
67211fccf17Sopenharmony_ci    lockStatus.result = HRIL_UNLOCK_SUCCESS;
67311fccf17Sopenharmony_ci    lockStatus.remain = -1;
67411fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
67511fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
67611fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
67711fccf17Sopenharmony_ci}
67811fccf17Sopenharmony_ci
67911fccf17Sopenharmony_civoid ReqGetSimPinInputTimes(const ReqDataInfo *requestInfo)
68011fccf17Sopenharmony_ci{
68111fccf17Sopenharmony_ci    char *pLine = NULL;
68211fccf17Sopenharmony_ci    int32_t ret;
68311fccf17Sopenharmony_ci    HRilPinInputTimes pinInputTimes = {0};
68411fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
68511fccf17Sopenharmony_ci
68611fccf17Sopenharmony_ci    ret = SendCommandLock("AT^CPIN?", "^CPIN", 0, &pResponse);
68711fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
68811fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^CPIN? send failed");
68911fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
69011fccf17Sopenharmony_ci            pLine = pResponse->result;
69111fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
69211fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
69311fccf17Sopenharmony_ci        } else {
69411fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
69511fccf17Sopenharmony_ci        }
69611fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
69711fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
69811fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
69911fccf17Sopenharmony_ci        return;
70011fccf17Sopenharmony_ci    }
70111fccf17Sopenharmony_ci    if (pResponse->head) {
70211fccf17Sopenharmony_ci        pLine = pResponse->head->data;
70311fccf17Sopenharmony_ci    }
70411fccf17Sopenharmony_ci    ret = ParseSimPinInputTimesResult(pLine, &pinInputTimes);
70511fccf17Sopenharmony_ci    if (ret != 0) {
70611fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
70711fccf17Sopenharmony_ci            pLine = pResponse->result;
70811fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
70911fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
71011fccf17Sopenharmony_ci        } else {
71111fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
71211fccf17Sopenharmony_ci        }
71311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
71411fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
71511fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
71611fccf17Sopenharmony_ci        return;
71711fccf17Sopenharmony_ci    }
71811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
71911fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&pinInputTimes, sizeof(HRilPinInputTimes));
72011fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
72111fccf17Sopenharmony_ci}
72211fccf17Sopenharmony_ci
72311fccf17Sopenharmony_civoid ReqGetSimPinInputTimesRemain(const ReqDataInfo *requestInfo, HRilPinInputTimes *pinInputTimes)
72411fccf17Sopenharmony_ci{
72511fccf17Sopenharmony_ci    char *pLine = NULL;
72611fccf17Sopenharmony_ci    int32_t ret;
72711fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
72811fccf17Sopenharmony_ci
72911fccf17Sopenharmony_ci    ret = SendCommandLock("AT^CPIN?", "^CPIN", 0, &pResponse);
73011fccf17Sopenharmony_ci    TELEPHONY_LOGI("AT+^CPIN send failed ret:%{public}d", ret);
73111fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
73211fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^CPIN? send failed");
73311fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
73411fccf17Sopenharmony_ci            pLine = pResponse->result;
73511fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
73611fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
73711fccf17Sopenharmony_ci        } else {
73811fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
73911fccf17Sopenharmony_ci        }
74011fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
74111fccf17Sopenharmony_ci        return;
74211fccf17Sopenharmony_ci    }
74311fccf17Sopenharmony_ci    if (pResponse && pResponse->head) {
74411fccf17Sopenharmony_ci        pLine = pResponse->head->data;
74511fccf17Sopenharmony_ci    }
74611fccf17Sopenharmony_ci    TELEPHONY_LOGD("ReqGetSimPinInputTimesRemain pLine:%{public}s, result:%{public}s, success:%{public}d", pLine,
74711fccf17Sopenharmony_ci        pResponse->result, pResponse->success);
74811fccf17Sopenharmony_ci    if (pinInputTimes == NULL) {
74911fccf17Sopenharmony_ci        return;
75011fccf17Sopenharmony_ci    }
75111fccf17Sopenharmony_ci    ret = ParseSimPinInputTimesResult(pLine, pinInputTimes);
75211fccf17Sopenharmony_ci    TELEPHONY_LOGD("code:%{public}s, times:%{public}d, puk:%{public}d,"
75311fccf17Sopenharmony_ci        " pin:%{public}d, puk2:%{public}d, pin2:%{public}d",
75411fccf17Sopenharmony_ci        pinInputTimes->code, pinInputTimes->times, pinInputTimes->pukTimes,
75511fccf17Sopenharmony_ci        pinInputTimes->pinTimes, pinInputTimes->puk2Times, pinInputTimes->pin2Times);
75611fccf17Sopenharmony_ci    if (ret != 0) {
75711fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
75811fccf17Sopenharmony_ci            pLine = pResponse->result;
75911fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
76011fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
76111fccf17Sopenharmony_ci        } else {
76211fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
76311fccf17Sopenharmony_ci        }
76411fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+^CPIN send failed ret3:%{public}d", ret);
76511fccf17Sopenharmony_ci        return;
76611fccf17Sopenharmony_ci    }
76711fccf17Sopenharmony_ci    return;
76811fccf17Sopenharmony_ci}
76911fccf17Sopenharmony_ci
77011fccf17Sopenharmony_civoid ReqUnlockPin2(const ReqDataInfo *requestInfo, const char *pin2)
77111fccf17Sopenharmony_ci{
77211fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
77311fccf17Sopenharmony_ci    char *pLine = NULL;
77411fccf17Sopenharmony_ci    int32_t ret;
77511fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
77611fccf17Sopenharmony_ci
77711fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^CPIN2=\"%s\"", pin2);
77811fccf17Sopenharmony_ci    if (result <= 0) {
77911fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
78011fccf17Sopenharmony_ci    }
78111fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "^CPIN2", 0, &pResponse);
78211fccf17Sopenharmony_ci    HRilLockStatus lockStatus = {0};
78311fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
78411fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^CPIN2 send failed");
78511fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
78611fccf17Sopenharmony_ci            pLine = pResponse->result;
78711fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT^CPIN2 send failed pLine1:%{public}s", pLine);
78811fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
78911fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT^CPIN2 send failed pLine2:%{public}s", pLine);
79011fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
79111fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT^CPIN2 send failed ret:%{public}d", ret);
79211fccf17Sopenharmony_ci            if (ret == AT_RESPONSE_INCORRECT_PASSWORD) {
79311fccf17Sopenharmony_ci                HRilPinInputTimes pinInputTimes = {0};
79411fccf17Sopenharmony_ci                ReqGetSimPinInputTimesRemain(requestInfo, &pinInputTimes);
79511fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_PASSWORD_ERR;
79611fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.pin2Times;
79711fccf17Sopenharmony_ci            } else {
79811fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
79911fccf17Sopenharmony_ci                lockStatus.remain = -1;
80011fccf17Sopenharmony_ci                TELEPHONY_LOGE("AT+^CPIN2 send failed");
80111fccf17Sopenharmony_ci            }
80211fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
80311fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
80411fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
80511fccf17Sopenharmony_ci            return;
80611fccf17Sopenharmony_ci        } else {
80711fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
80811fccf17Sopenharmony_ci            lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
80911fccf17Sopenharmony_ci            lockStatus.remain = -1;
81011fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
81111fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
81211fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
81311fccf17Sopenharmony_ci            return;
81411fccf17Sopenharmony_ci        }
81511fccf17Sopenharmony_ci    }
81611fccf17Sopenharmony_ci
81711fccf17Sopenharmony_ci    lockStatus.result = HRIL_UNLOCK_SUCCESS;
81811fccf17Sopenharmony_ci    lockStatus.remain = -1;
81911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
82011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
82111fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
82211fccf17Sopenharmony_ci}
82311fccf17Sopenharmony_ci
82411fccf17Sopenharmony_civoid ReqUnlockPuk2(const ReqDataInfo *requestInfo, const char *puk2, const char *pin2)
82511fccf17Sopenharmony_ci{
82611fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
82711fccf17Sopenharmony_ci    char *pLine = NULL;
82811fccf17Sopenharmony_ci    int32_t ret;
82911fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
83011fccf17Sopenharmony_ci
83111fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^CPIN2=\"%s\",\"%s\"", puk2, pin2);
83211fccf17Sopenharmony_ci    if (result <= 0) {
83311fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
83411fccf17Sopenharmony_ci    }
83511fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "^CPIN2", 0, &pResponse);
83611fccf17Sopenharmony_ci    HRilLockStatus lockStatus = {0};
83711fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
83811fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^CPIN2 send failed");
83911fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
84011fccf17Sopenharmony_ci            pLine = pResponse->result;
84111fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT^CPIN2 send failed pLine1:%{public}s", pLine);
84211fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
84311fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT^CPIN2 send failed pLine2:%{public}s", pLine);
84411fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
84511fccf17Sopenharmony_ci            TELEPHONY_LOGD("AT^CPIN2 send failed ret:%{public}d", ret);
84611fccf17Sopenharmony_ci            if (ret == AT_RESPONSE_INCORRECT_PASSWORD) {
84711fccf17Sopenharmony_ci                HRilPinInputTimes pinInputTimes = {0};
84811fccf17Sopenharmony_ci                ReqGetSimPinInputTimesRemain(requestInfo, &pinInputTimes);
84911fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_PASSWORD_ERR;
85011fccf17Sopenharmony_ci                lockStatus.remain = pinInputTimes.puk2Times;
85111fccf17Sopenharmony_ci            } else {
85211fccf17Sopenharmony_ci                lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
85311fccf17Sopenharmony_ci                lockStatus.remain = -1;
85411fccf17Sopenharmony_ci                TELEPHONY_LOGE("AT+^CPIN2 send failed");
85511fccf17Sopenharmony_ci            }
85611fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
85711fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
85811fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
85911fccf17Sopenharmony_ci            return;
86011fccf17Sopenharmony_ci        } else {
86111fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
86211fccf17Sopenharmony_ci            lockStatus.result = HRIL_UNLOCK_OTHER_ERR;
86311fccf17Sopenharmony_ci            lockStatus.remain = -1;
86411fccf17Sopenharmony_ci            struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
86511fccf17Sopenharmony_ci            OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
86611fccf17Sopenharmony_ci            FreeResponseInfo(pResponse);
86711fccf17Sopenharmony_ci            return;
86811fccf17Sopenharmony_ci        }
86911fccf17Sopenharmony_ci    }
87011fccf17Sopenharmony_ci
87111fccf17Sopenharmony_ci    lockStatus.result = HRIL_UNLOCK_SUCCESS;
87211fccf17Sopenharmony_ci    lockStatus.remain = -1;
87311fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
87411fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(lockStatus));
87511fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
87611fccf17Sopenharmony_ci}
87711fccf17Sopenharmony_ci
87811fccf17Sopenharmony_civoid ReqGetSimPin2InputTimes(const ReqDataInfo *requestInfo)
87911fccf17Sopenharmony_ci{
88011fccf17Sopenharmony_ci    char *pLine = NULL;
88111fccf17Sopenharmony_ci    int32_t ret;
88211fccf17Sopenharmony_ci    HRilPinInputTimes pin2InputTimes = {0};
88311fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
88411fccf17Sopenharmony_ci
88511fccf17Sopenharmony_ci    ret = SendCommandLock("AT^CPIN2?", "^CPIN2", 0, &pResponse);
88611fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
88711fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^CPIN2? send failed");
88811fccf17Sopenharmony_ci    }
88911fccf17Sopenharmony_ci    if (pResponse != NULL && pResponse->head != NULL) {
89011fccf17Sopenharmony_ci        pLine = pResponse->head->data;
89111fccf17Sopenharmony_ci    }
89211fccf17Sopenharmony_ci    ret = ParseSimPinInputTimesResult(pLine, &pin2InputTimes);
89311fccf17Sopenharmony_ci    if (ret != 0) {
89411fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
89511fccf17Sopenharmony_ci            pLine = pResponse->result;
89611fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
89711fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
89811fccf17Sopenharmony_ci        } else {
89911fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
90011fccf17Sopenharmony_ci        }
90111fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
90211fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
90311fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
90411fccf17Sopenharmony_ci        return;
90511fccf17Sopenharmony_ci    }
90611fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
90711fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&pin2InputTimes, 0);
90811fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
90911fccf17Sopenharmony_ci}
91011fccf17Sopenharmony_ci
91111fccf17Sopenharmony_civoid ReqSetActiveSim(const ReqDataInfo *requestInfo, int32_t index, int32_t enable)
91211fccf17Sopenharmony_ci{
91311fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
91411fccf17Sopenharmony_ci    char *pLine = NULL;
91511fccf17Sopenharmony_ci    int32_t ret;
91611fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
91711fccf17Sopenharmony_ci
91811fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^HVSST=%d,%d", index, enable);
91911fccf17Sopenharmony_ci    if (result <= 0) {
92011fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
92111fccf17Sopenharmony_ci    }
92211fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "^HVSST", 0, &pResponse);
92311fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
92411fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^HVSST send failed");
92511fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
92611fccf17Sopenharmony_ci            pLine = pResponse->result;
92711fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
92811fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
92911fccf17Sopenharmony_ci        } else {
93011fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
93111fccf17Sopenharmony_ci        }
93211fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
93311fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
93411fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
93511fccf17Sopenharmony_ci        return;
93611fccf17Sopenharmony_ci    }
93711fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
93811fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
93911fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
94011fccf17Sopenharmony_ci}
94111fccf17Sopenharmony_ci
94211fccf17Sopenharmony_civoid ReqSimStkSendTerminalResponse(const ReqDataInfo *requestInfo, const char *strCmd)
94311fccf17Sopenharmony_ci{
94411fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
94511fccf17Sopenharmony_ci    char *pLine = NULL;
94611fccf17Sopenharmony_ci    int32_t ret;
94711fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
94811fccf17Sopenharmony_ci
94911fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+SPUSATTERMINAL=\"%s\"", strCmd);
95011fccf17Sopenharmony_ci    if (result < 0) {
95111fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", result);
95211fccf17Sopenharmony_ci    }
95311fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+SPUSATTERMINAL", 0, &pResponse);
95411fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
95511fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+SPUSATTERMINAL send failed");
95611fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
95711fccf17Sopenharmony_ci            pLine = pResponse->result;
95811fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
95911fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
96011fccf17Sopenharmony_ci        } else {
96111fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
96211fccf17Sopenharmony_ci        }
96311fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
96411fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
96511fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
96611fccf17Sopenharmony_ci        return;
96711fccf17Sopenharmony_ci    }
96811fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
96911fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
97011fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
97111fccf17Sopenharmony_ci}
97211fccf17Sopenharmony_ci
97311fccf17Sopenharmony_civoid ReqSimStkSendEnvelope(const ReqDataInfo *requestInfo, const char *strCmd)
97411fccf17Sopenharmony_ci{
97511fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
97611fccf17Sopenharmony_ci    char *pLine = NULL;
97711fccf17Sopenharmony_ci    int32_t ret;
97811fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
97911fccf17Sopenharmony_ci
98011fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+SPUSATENVECMD=\"%s\"", strCmd);
98111fccf17Sopenharmony_ci    if (result < 0) {
98211fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand failed, err = %{public}d\n", result);
98311fccf17Sopenharmony_ci    }
98411fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+SPUSATENVECMD", 0, &pResponse);
98511fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
98611fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+SPUSATENVECMD send failed");
98711fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
98811fccf17Sopenharmony_ci            pLine = pResponse->result;
98911fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
99011fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
99111fccf17Sopenharmony_ci        } else {
99211fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
99311fccf17Sopenharmony_ci        }
99411fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
99511fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
99611fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
99711fccf17Sopenharmony_ci        return;
99811fccf17Sopenharmony_ci    }
99911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
100011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
100111fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
100211fccf17Sopenharmony_ci}
100311fccf17Sopenharmony_ci
100411fccf17Sopenharmony_civoid ReqSimStkSendCallSetupRequestResult(const ReqDataInfo *requestInfo, int32_t accept)
100511fccf17Sopenharmony_ci{
100611fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
100711fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
100811fccf17Sopenharmony_ci}
100911fccf17Sopenharmony_ci
101011fccf17Sopenharmony_civoid ReqSimStkIsReady(const ReqDataInfo *requestInfo)
101111fccf17Sopenharmony_ci{
101211fccf17Sopenharmony_ci    char *pLine = NULL;
101311fccf17Sopenharmony_ci    int32_t ret;
101411fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
101511fccf17Sopenharmony_ci
101611fccf17Sopenharmony_ci    ret = SendCommandLock("AT+SPUSATPROFILE?", "+SPUSATPROFILE", 0, &pResponse);
101711fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
101811fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+SPUSATPROFILE send failed");
101911fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
102011fccf17Sopenharmony_ci            pLine = pResponse->result;
102111fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
102211fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
102311fccf17Sopenharmony_ci        } else {
102411fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
102511fccf17Sopenharmony_ci        }
102611fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
102711fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
102811fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
102911fccf17Sopenharmony_ci        return;
103011fccf17Sopenharmony_ci    }
103111fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
103211fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
103311fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
103411fccf17Sopenharmony_ci}
103511fccf17Sopenharmony_ci
103611fccf17Sopenharmony_civoid ReqGetRadioProtocol(const ReqDataInfo *requestInfo)
103711fccf17Sopenharmony_ci{
103811fccf17Sopenharmony_ci    TELEPHONY_LOGD("ReqGetRadioProtocol");
103911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
104011fccf17Sopenharmony_ci    HRilRadioProtocol radioProtocol = {};
104111fccf17Sopenharmony_ci    radioProtocol.sessionId = 0;
104211fccf17Sopenharmony_ci    radioProtocol.phase = HRIL_RADIO_PROTOCOL_PHASE_INITIAL;
104311fccf17Sopenharmony_ci    radioProtocol.technology = HRIL_RADIO_PROTOCOL_TECH_GSM | HRIL_RADIO_PROTOCOL_TECH_WCDMA |
104411fccf17Sopenharmony_ci                               HRIL_RADIO_PROTOCOL_TECH_HSPA | HRIL_RADIO_PROTOCOL_TECH_HSPAP |
104511fccf17Sopenharmony_ci                               HRIL_RADIO_PROTOCOL_TECH_LTE | HRIL_RADIO_PROTOCOL_TECH_LTE_CA;
104611fccf17Sopenharmony_ci    radioProtocol.modemId = 0;
104711fccf17Sopenharmony_ci    radioProtocol.status = HRIL_RADIO_PROTOCOL_STATUS_NONE;
104811fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&radioProtocol, sizeof(HRilRadioProtocol));
104911fccf17Sopenharmony_ci}
105011fccf17Sopenharmony_ci
105111fccf17Sopenharmony_civoid ReqSetRadioProtocol(const ReqDataInfo *requestInfo, const HRilRadioProtocol *data)
105211fccf17Sopenharmony_ci{
105311fccf17Sopenharmony_ci    HRilRadioProtocol *radioProtocol = (HRilRadioProtocol *)data;
105411fccf17Sopenharmony_ci    struct ReportInfo reportInfo = { 0 };
105511fccf17Sopenharmony_ci    if (radioProtocol == NULL) {
105611fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
105711fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
105811fccf17Sopenharmony_ci        return;
105911fccf17Sopenharmony_ci    }
106011fccf17Sopenharmony_ci
106111fccf17Sopenharmony_ci    if (radioProtocol->phase != HRIL_RADIO_PROTOCOL_PHASE_UPDATE) {
106211fccf17Sopenharmony_ci        reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
106311fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)radioProtocol, sizeof(HRilRadioProtocol));
106411fccf17Sopenharmony_ci        return;
106511fccf17Sopenharmony_ci    }
106611fccf17Sopenharmony_ci    radioProtocol->phase = HRIL_RADIO_PROTOCOL_PHASE_NOTIFY;
106711fccf17Sopenharmony_ci    radioProtocol->status = HRIL_RADIO_PROTOCOL_STATUS_SUCCESS;
106811fccf17Sopenharmony_ci    reportInfo.error = HRIL_ERR_SUCCESS;
106911fccf17Sopenharmony_ci    reportInfo.type = HRIL_NOTIFICATION;
107011fccf17Sopenharmony_ci    reportInfo.notifyId = HNOTI_SIM_RADIO_PROTOCOL_UPDATED;
107111fccf17Sopenharmony_ci    OnSimReport(GetSlotId(NULL), reportInfo, (const uint8_t *)radioProtocol, sizeof(HRilRadioProtocol));
107211fccf17Sopenharmony_ci}
107311fccf17Sopenharmony_ci
107411fccf17Sopenharmony_civoid ReqSimOpenLogicalChannel(const ReqDataInfo *requestInfo, const char *appID, int32_t p2)
107511fccf17Sopenharmony_ci{
107611fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
107711fccf17Sopenharmony_ci    char *pLine = NULL;
107811fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
107911fccf17Sopenharmony_ci
108011fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+SPCCHO=\"%s\",%d", appID, p2);
108111fccf17Sopenharmony_ci    if (result <= 0) {
108211fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
108311fccf17Sopenharmony_ci    }
108411fccf17Sopenharmony_ci    int32_t ret = SendCommandLock(cmd, "+SPCCHO", 0, &pResponse);
108511fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
108611fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+SPCCHO send failed");
108711fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
108811fccf17Sopenharmony_ci            pLine = pResponse->result;
108911fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
109011fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
109111fccf17Sopenharmony_ci        } else {
109211fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
109311fccf17Sopenharmony_ci        }
109411fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
109511fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
109611fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
109711fccf17Sopenharmony_ci        return;
109811fccf17Sopenharmony_ci    }
109911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
110011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
110111fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
110211fccf17Sopenharmony_ci}
110311fccf17Sopenharmony_ci
110411fccf17Sopenharmony_civoid ReqSimCloseLogicalChannel(const ReqDataInfo *requestInfo, int32_t channelId)
110511fccf17Sopenharmony_ci{
110611fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
110711fccf17Sopenharmony_ci    char *pLine = NULL;
110811fccf17Sopenharmony_ci    int32_t ret;
110911fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
111011fccf17Sopenharmony_ci
111111fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CCHC=%d", channelId);
111211fccf17Sopenharmony_ci    if (result <= 0) {
111311fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
111411fccf17Sopenharmony_ci    }
111511fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CCHC", 0, &pResponse);
111611fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
111711fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CCHC send failed");
111811fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
111911fccf17Sopenharmony_ci            pLine = pResponse->result;
112011fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
112111fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
112211fccf17Sopenharmony_ci        } else {
112311fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
112411fccf17Sopenharmony_ci        }
112511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
112611fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
112711fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
112811fccf17Sopenharmony_ci        return;
112911fccf17Sopenharmony_ci    }
113011fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
113111fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
113211fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
113311fccf17Sopenharmony_ci}
113411fccf17Sopenharmony_ci
113511fccf17Sopenharmony_civoid ReqSimTransmitApduLogicalChannel(const ReqDataInfo *requestInfo, HRilApduSimIO *data, size_t dataLen)
113611fccf17Sopenharmony_ci{
113711fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
113811fccf17Sopenharmony_ci    char *pLine = NULL;
113911fccf17Sopenharmony_ci    int32_t ret;
114011fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
114111fccf17Sopenharmony_ci    HRilSimIOResponse apduSimResponse = {0};
114211fccf17Sopenharmony_ci    HRilApduSimIO *pApduSimIO = (HRilApduSimIO *)data;
114311fccf17Sopenharmony_ci
114411fccf17Sopenharmony_ci    if (pApduSimIO == NULL) {
114511fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
114611fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
114711fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
114811fccf17Sopenharmony_ci        return;
114911fccf17Sopenharmony_ci    }
115011fccf17Sopenharmony_ci
115111fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT+CGLA=%d,%d,%d,%d,%d,%d,\"%s\"", pApduSimIO->channelId,
115211fccf17Sopenharmony_ci        pApduSimIO->type, pApduSimIO->instruction, pApduSimIO->p1, pApduSimIO->p2, pApduSimIO->p3, pApduSimIO->data);
115311fccf17Sopenharmony_ci    if (result <= 0) {
115411fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
115511fccf17Sopenharmony_ci    }
115611fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "+CGLA", 0, &pResponse);
115711fccf17Sopenharmony_ci    if (ret != 0 || pResponse == NULL || !pResponse->success) {
115811fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT+CGLA send failed  dataLen:%{public}zu", dataLen);
115911fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
116011fccf17Sopenharmony_ci            pLine = pResponse->result;
116111fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
116211fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
116311fccf17Sopenharmony_ci        } else {
116411fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
116511fccf17Sopenharmony_ci        }
116611fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
116711fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
116811fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
116911fccf17Sopenharmony_ci        return;
117011fccf17Sopenharmony_ci    }
117111fccf17Sopenharmony_ci    if (pResponse->head) {
117211fccf17Sopenharmony_ci        pLine = pResponse->head->data;
117311fccf17Sopenharmony_ci    }
117411fccf17Sopenharmony_ci    ret = ParseSimResponseResult(pLine, &apduSimResponse);
117511fccf17Sopenharmony_ci    if (ret != HRIL_ERR_SUCCESS) {
117611fccf17Sopenharmony_ci        HandlerSimIOResult(pResponse, NULL, requestInfo, pLine, &ret);
117711fccf17Sopenharmony_ci        return;
117811fccf17Sopenharmony_ci    }
117911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
118011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&apduSimResponse, sizeof(HRilSimIOResponse));
118111fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
118211fccf17Sopenharmony_ci}
118311fccf17Sopenharmony_ci
118411fccf17Sopenharmony_civoid ReqSimAuthentication(const ReqDataInfo *requestInfo, HRilSimAuthenticationRequestInfo *data, size_t dataLen)
118511fccf17Sopenharmony_ci{
118611fccf17Sopenharmony_ci    HRilSimAuthenticationRequestInfo *HRilSimAuthInfo = (HRilSimAuthenticationRequestInfo *)data;
118711fccf17Sopenharmony_ci    if (HRilSimAuthInfo == NULL) {
118811fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_INVALID_RESPONSE, HRIL_RESPONSE, 0);
118911fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
119011fccf17Sopenharmony_ci        return;
119111fccf17Sopenharmony_ci    }
119211fccf17Sopenharmony_ci    TELEPHONY_LOGD("ReqSimAuthentication serial = %{public}d, aid = %{public}s, data = %{public}s",
119311fccf17Sopenharmony_ci        HRilSimAuthInfo->serial, HRilSimAuthInfo->aid, HRilSimAuthInfo->data);
119411fccf17Sopenharmony_ci    HRilSimIOResponse simAuthResponse = { 0 };
119511fccf17Sopenharmony_ci    simAuthResponse.sw1 = (int32_t)0x90;
119611fccf17Sopenharmony_ci    simAuthResponse.sw2 = (int32_t)0x00;
119711fccf17Sopenharmony_ci    simAuthResponse.response = ("FFFFFFFFFFFFFF");
119811fccf17Sopenharmony_ci    int32_t ret = 0;
119911fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
120011fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&simAuthResponse, sizeof(HRilSimIOResponse));
120111fccf17Sopenharmony_ci}
120211fccf17Sopenharmony_ci
120311fccf17Sopenharmony_civoid ReqUnlockSimLock(const ReqDataInfo *requestInfo, int32_t lockType, const char *password)
120411fccf17Sopenharmony_ci{
120511fccf17Sopenharmony_ci    char cmd[MAX_CMD_LENGTH] = {0};
120611fccf17Sopenharmony_ci    char *pLine = NULL;
120711fccf17Sopenharmony_ci    int32_t ret;
120811fccf17Sopenharmony_ci    ResponseInfo *pResponse = NULL;
120911fccf17Sopenharmony_ci
121011fccf17Sopenharmony_ci    int32_t result = GenerateCommand(cmd, MAX_CMD_LENGTH, "AT^UNLOCKSIMLOCK=\"%d\",%s", lockType, password);
121111fccf17Sopenharmony_ci    if (result <= 0) {
121211fccf17Sopenharmony_ci        TELEPHONY_LOGE("GenerateCommand is failed");
121311fccf17Sopenharmony_ci    }
121411fccf17Sopenharmony_ci    ret = SendCommandLock(cmd, "^UNLOCKSIMLOCK", 0, &pResponse);
121511fccf17Sopenharmony_ci    if (ret != 0 || (pResponse != NULL && !pResponse->success)) {
121611fccf17Sopenharmony_ci        TELEPHONY_LOGE("AT^UNLOCKSIMLOCK send failed");
121711fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
121811fccf17Sopenharmony_ci            pLine = pResponse->result;
121911fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
122011fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
122111fccf17Sopenharmony_ci        } else {
122211fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
122311fccf17Sopenharmony_ci        }
122411fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
122511fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
122611fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
122711fccf17Sopenharmony_ci        return;
122811fccf17Sopenharmony_ci    }
122911fccf17Sopenharmony_ci    if (pResponse && pResponse->head) {
123011fccf17Sopenharmony_ci        pLine = pResponse->head->data;
123111fccf17Sopenharmony_ci    }
123211fccf17Sopenharmony_ci    HRilLockStatus lockStatus = {0};
123311fccf17Sopenharmony_ci    ret = ParseUnlockSimLockResult(pLine, &lockStatus);
123411fccf17Sopenharmony_ci    if (ret != 0) {
123511fccf17Sopenharmony_ci        if (pResponse && pResponse->result) {
123611fccf17Sopenharmony_ci            pLine = pResponse->result;
123711fccf17Sopenharmony_ci            SkipATPrefix(&pLine);
123811fccf17Sopenharmony_ci            NextInt(&pLine, &ret);
123911fccf17Sopenharmony_ci        } else {
124011fccf17Sopenharmony_ci            ret = HRIL_ERR_GENERIC_FAILURE;
124111fccf17Sopenharmony_ci        }
124211fccf17Sopenharmony_ci        struct ReportInfo reportInfo = CreateReportInfo(requestInfo, ret, HRIL_RESPONSE, 0);
124311fccf17Sopenharmony_ci        OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
124411fccf17Sopenharmony_ci        FreeResponseInfo(pResponse);
124511fccf17Sopenharmony_ci        return;
124611fccf17Sopenharmony_ci    }
124711fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
124811fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, (const uint8_t *)&lockStatus, sizeof(HRilLockStatus));
124911fccf17Sopenharmony_ci    FreeResponseInfo(pResponse);
125011fccf17Sopenharmony_ci}
125111fccf17Sopenharmony_ci
125211fccf17Sopenharmony_civoid ReqSendSimMatchedOperatorInfo(const ReqDataInfo *requestInfo, HRilNcfgOperatorInfo *data, size_t dataLen)
125311fccf17Sopenharmony_ci{
125411fccf17Sopenharmony_ci    struct ReportInfo reportInfo = CreateReportInfo(requestInfo, HRIL_ERR_SUCCESS, HRIL_RESPONSE, 0);
125511fccf17Sopenharmony_ci    OnSimReport(GetSlotId(requestInfo), reportInfo, NULL, 0);
125611fccf17Sopenharmony_ci}
125711fccf17Sopenharmony_ci
125811fccf17Sopenharmony_civoid ConvertUsimFcpToSimRsp(uint8_t **simResponse)
125911fccf17Sopenharmony_ci{
126011fccf17Sopenharmony_ci    uint16_t fcpLen = strlen((char *)*simResponse) / HALF_LEN;
126111fccf17Sopenharmony_ci    uint8_t *fcpByte = malloc(fcpLen);
126211fccf17Sopenharmony_ci    UsimFileDescriptor fDescriptor = { 0 };
126311fccf17Sopenharmony_ci    UsimFileIdentifier fId = { 0 };
126411fccf17Sopenharmony_ci    uint8_t simRspByte[GET_RESPONSE_EF_SIZE_BYTES] = { 0 };
126511fccf17Sopenharmony_ci    if (fcpByte == NULL) {
126611fccf17Sopenharmony_ci        TELEPHONY_LOGE("fcpByte is NULL");
126711fccf17Sopenharmony_ci        free(fcpByte);
126811fccf17Sopenharmony_ci        return;
126911fccf17Sopenharmony_ci    }
127011fccf17Sopenharmony_ci    if (memset_s(fcpByte, fcpLen, 0, fcpLen) != EOK) {
127111fccf17Sopenharmony_ci        TELEPHONY_LOGE("ConvertUsimFcpToSimRsp memset_s failed");
127211fccf17Sopenharmony_ci        free(fcpByte);
127311fccf17Sopenharmony_ci        return;
127411fccf17Sopenharmony_ci    }
127511fccf17Sopenharmony_ci    ConvertHexStringToByteArray(*simResponse, strlen((char *)*simResponse), fcpByte, fcpLen);
127611fccf17Sopenharmony_ci    if (FcpFileDescriptorQuery(fcpByte, fcpLen, (UsimFileDescriptor *)&fDescriptor) == FALSE) {
127711fccf17Sopenharmony_ci        TELEPHONY_LOGE("FcpFileDescriptorQuery failed");
127811fccf17Sopenharmony_ci        free(fcpByte);
127911fccf17Sopenharmony_ci        return;
128011fccf17Sopenharmony_ci    }
128111fccf17Sopenharmony_ci    if (FcpFileIdentifierQuery(fcpByte, fcpLen, (UsimFileIdentifier *)&fId) == FALSE) {
128211fccf17Sopenharmony_ci        TELEPHONY_LOGE("FcpFileIdentifierQuery failed");
128311fccf17Sopenharmony_ci        free(fcpByte);
128411fccf17Sopenharmony_ci        return;
128511fccf17Sopenharmony_ci    }
128611fccf17Sopenharmony_ci    if (IsDedicatedFile(fDescriptor.fd)) {
128711fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_FILE_TYPE] = TYPE_DF;
128811fccf17Sopenharmony_ci        *simResponse = ConvertByteArrayToHexString(simRspByte, fcpLen);
128911fccf17Sopenharmony_ci        free(fcpByte);
129011fccf17Sopenharmony_ci        return;
129111fccf17Sopenharmony_ci    }
129211fccf17Sopenharmony_ci    CreateSimRspByte(simRspByte, GET_RESPONSE_EF_SIZE_BYTES, &fId, &fDescriptor);
129311fccf17Sopenharmony_ci    *simResponse = ConvertByteArrayToHexString(simRspByte, GET_RESPONSE_EF_SIZE_BYTES);
129411fccf17Sopenharmony_ci    free(fcpByte);
129511fccf17Sopenharmony_ci}
129611fccf17Sopenharmony_ci
129711fccf17Sopenharmony_civoid CreateSimRspByte(uint8_t simRspByte[], int responseLen, UsimFileIdentifier *fId, UsimFileDescriptor *fDescriptor)
129811fccf17Sopenharmony_ci{
129911fccf17Sopenharmony_ci    if (responseLen < RESPONSE_DATA_RECORD_LENGTH + 1) {
130011fccf17Sopenharmony_ci        TELEPHONY_LOGE("simRspByte size error");
130111fccf17Sopenharmony_ci        return;
130211fccf17Sopenharmony_ci    }
130311fccf17Sopenharmony_ci    if (fId == NULL || fDescriptor == NULL) {
130411fccf17Sopenharmony_ci        TELEPHONY_LOGE("fId or  fDescriptor is null");
130511fccf17Sopenharmony_ci        return;
130611fccf17Sopenharmony_ci    }
130711fccf17Sopenharmony_ci    simRspByte[RESPONSE_DATA_FILE_TYPE] = TYPE_EF;
130811fccf17Sopenharmony_ci    simRspByte[RESPONSE_DATA_FILE_ID_1] = (fId->fileId & BYTE_NUM_1) >> ADDR_OFFSET_8BIT;
130911fccf17Sopenharmony_ci    simRspByte[RESPONSE_DATA_FILE_ID_2] = fId->fileId & BYTE_NUM_2;
131011fccf17Sopenharmony_ci    simRspByte[RESPONSE_DATA_LENGTH] = (GET_RESPONSE_EF_SIZE_BYTES - RESPONSE_DATA_LENGTH - 1);
131111fccf17Sopenharmony_ci    if (IsLinearFixedFile(fDescriptor->fd)) {
131211fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_STRUCTURE] = EF_TYPE_LINEAR_FIXED;
131311fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_RECORD_LENGTH] = fDescriptor->recLen;
131411fccf17Sopenharmony_ci        fDescriptor->dataSize = (fDescriptor->numRec & BYTE_NUM_0) * (fDescriptor->recLen);
131511fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_FILE_SIZE_1] = (fDescriptor->dataSize & BYTE_NUM_1) >> ADDR_OFFSET_8BIT;
131611fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_FILE_SIZE_2] = fDescriptor->dataSize & BYTE_NUM_2;
131711fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_FILE_STATUS] = VALID_FILE_STATUS;
131811fccf17Sopenharmony_ci        return;
131911fccf17Sopenharmony_ci    }
132011fccf17Sopenharmony_ci    if (IsTransparentFile(fDescriptor->fd)) {
132111fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_STRUCTURE] = EF_TYPE_TRANSPARENT;
132211fccf17Sopenharmony_ci        return;
132311fccf17Sopenharmony_ci    }
132411fccf17Sopenharmony_ci    if (IsCyclicFile(fDescriptor->fd)) {
132511fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_STRUCTURE] = EF_TYPE_CYCLIC;
132611fccf17Sopenharmony_ci        simRspByte[RESPONSE_DATA_RECORD_LENGTH] = fDescriptor->recLen;
132711fccf17Sopenharmony_ci        return;
132811fccf17Sopenharmony_ci    }
132911fccf17Sopenharmony_ci}
133011fccf17Sopenharmony_ci
133111fccf17Sopenharmony_ciuint8_t FcpTlvSearchTag(uint8_t *dataPtr, uint16_t len, UsimFcpTag tag, uint8_t **outPtr)
133211fccf17Sopenharmony_ci{
133311fccf17Sopenharmony_ci    uint8_t tagLen = 0;
133411fccf17Sopenharmony_ci    uint16_t lenVar = len;
133511fccf17Sopenharmony_ci    for (*outPtr = dataPtr; lenVar > 0; *outPtr += tagLen) {
133611fccf17Sopenharmony_ci        tagLen = (*(*outPtr + 1) + HALF_LEN);
133711fccf17Sopenharmony_ci        if (**outPtr == (uint8_t)tag) {
133811fccf17Sopenharmony_ci            *outPtr += HALF_LEN;
133911fccf17Sopenharmony_ci            return *(*outPtr - 1);
134011fccf17Sopenharmony_ci        }
134111fccf17Sopenharmony_ci        lenVar -= tagLen;
134211fccf17Sopenharmony_ci    }
134311fccf17Sopenharmony_ci    *outPtr = NULL;
134411fccf17Sopenharmony_ci    return FALSE;
134511fccf17Sopenharmony_ci}
134611fccf17Sopenharmony_ci
134711fccf17Sopenharmony_ciuint8_t FcpFileDescriptorQuery(uint8_t *fcpByte, uint16_t fcpLen, UsimFileDescriptor *filledStructPtr)
134811fccf17Sopenharmony_ci{
134911fccf17Sopenharmony_ci    if (fcpByte == NULL || fcpLen < HALF_LEN + 1) {
135011fccf17Sopenharmony_ci        TELEPHONY_LOGE("fcpByte size error");
135111fccf17Sopenharmony_ci        return FALSE;
135211fccf17Sopenharmony_ci    }
135311fccf17Sopenharmony_ci    uint8_t valueLen = fcpByte[1];
135411fccf17Sopenharmony_ci    uint8_t *dataPtr = &fcpByte[HALF_LEN];
135511fccf17Sopenharmony_ci    if (fcpByte[0] != FCP_TEMP_T) {
135611fccf17Sopenharmony_ci        TELEPHONY_LOGE("fcpByte data error");
135711fccf17Sopenharmony_ci        return FALSE;
135811fccf17Sopenharmony_ci    }
135911fccf17Sopenharmony_ci    uint8_t resultLen = 0;
136011fccf17Sopenharmony_ci    uint8_t *outPtr = NULL;
136111fccf17Sopenharmony_ci    UsimFileDescriptor *queryPtr = filledStructPtr;
136211fccf17Sopenharmony_ci    resultLen = FcpTlvSearchTag(dataPtr, valueLen, FCP_FILE_DES_T, &outPtr);
136311fccf17Sopenharmony_ci    if (!((outPtr != NULL) && ((resultLen == HALF_LEN) || (resultLen == FIVE_LEN)))) {
136411fccf17Sopenharmony_ci        TELEPHONY_LOGE("resultLen value error");
136511fccf17Sopenharmony_ci        return FALSE;
136611fccf17Sopenharmony_ci    }
136711fccf17Sopenharmony_ci    if (queryPtr == NULL) {
136811fccf17Sopenharmony_ci        return FALSE;
136911fccf17Sopenharmony_ci    }
137011fccf17Sopenharmony_ci    queryPtr->fd = outPtr[0];
137111fccf17Sopenharmony_ci    queryPtr->dataCoding = outPtr[1];
137211fccf17Sopenharmony_ci    if (resultLen == FIVE_LEN) {
137311fccf17Sopenharmony_ci        queryPtr->recLen = (short)((outPtr[HALF_LEN] << ADDR_OFFSET_8BIT) | outPtr[THIRD_INDEX]);
137411fccf17Sopenharmony_ci        queryPtr->numRec = outPtr[HALF_BYTE_LEN];
137511fccf17Sopenharmony_ci        return TRUE;
137611fccf17Sopenharmony_ci    }
137711fccf17Sopenharmony_ci    queryPtr->recLen = 0;
137811fccf17Sopenharmony_ci    queryPtr->numRec = 0;
137911fccf17Sopenharmony_ci    return TRUE;
138011fccf17Sopenharmony_ci}
138111fccf17Sopenharmony_ci
138211fccf17Sopenharmony_ciuint8_t FcpFileIdentifierQuery(uint8_t *fcpByte, uint16_t fcpLen, UsimFileIdentifier *filledStructPtr)
138311fccf17Sopenharmony_ci{
138411fccf17Sopenharmony_ci    if (fcpByte == NULL || fcpLen < HALF_LEN + 1) {
138511fccf17Sopenharmony_ci        TELEPHONY_LOGE("fcpByte size error");
138611fccf17Sopenharmony_ci        return FALSE;
138711fccf17Sopenharmony_ci    }
138811fccf17Sopenharmony_ci    uint8_t valueLen = fcpByte[1];
138911fccf17Sopenharmony_ci    uint8_t *dataPtr = &fcpByte[HALF_LEN];
139011fccf17Sopenharmony_ci    if (fcpByte[0] != FCP_TEMP_T) {
139111fccf17Sopenharmony_ci        TELEPHONY_LOGE("fcpByte data error");
139211fccf17Sopenharmony_ci        return FALSE;
139311fccf17Sopenharmony_ci    }
139411fccf17Sopenharmony_ci    uint8_t resultLen = 0;
139511fccf17Sopenharmony_ci    uint8_t *outPtr = NULL;
139611fccf17Sopenharmony_ci    UsimFileIdentifier *queryPtr = (UsimFileIdentifier *)filledStructPtr;
139711fccf17Sopenharmony_ci    if (queryPtr == NULL) {
139811fccf17Sopenharmony_ci        return FALSE;
139911fccf17Sopenharmony_ci    }
140011fccf17Sopenharmony_ci    resultLen = FcpTlvSearchTag(dataPtr, valueLen, FCP_FILE_ID_T, &outPtr);
140111fccf17Sopenharmony_ci    if (outPtr == NULL) {
140211fccf17Sopenharmony_ci        queryPtr->fileId = 0;
140311fccf17Sopenharmony_ci        return FALSE;
140411fccf17Sopenharmony_ci    }
140511fccf17Sopenharmony_ci    if (resultLen != HALF_LEN) {
140611fccf17Sopenharmony_ci        TELEPHONY_LOGE("resultLen size error");
140711fccf17Sopenharmony_ci        return FALSE;
140811fccf17Sopenharmony_ci    }
140911fccf17Sopenharmony_ci    queryPtr->fileId = (short)((outPtr[0] << ADDR_OFFSET_8BIT) | outPtr[1]);
141011fccf17Sopenharmony_ci    return TRUE;
141111fccf17Sopenharmony_ci}
141211fccf17Sopenharmony_ci
141311fccf17Sopenharmony_ciuint8_t IsCyclicFile(uint8_t fd)
141411fccf17Sopenharmony_ci{
141511fccf17Sopenharmony_ci    return (0x07 & (fd)) == 0x06;
141611fccf17Sopenharmony_ci}
141711fccf17Sopenharmony_ci
141811fccf17Sopenharmony_ciuint8_t IsDedicatedFile(uint8_t fd)
141911fccf17Sopenharmony_ci{
142011fccf17Sopenharmony_ci    return (0x38 & (fd)) == 0x38;
142111fccf17Sopenharmony_ci}
142211fccf17Sopenharmony_ci
142311fccf17Sopenharmony_ciuint8_t IsLinearFixedFile(uint8_t fd)
142411fccf17Sopenharmony_ci{
142511fccf17Sopenharmony_ci    return (0x07 & (fd)) == 0x02;
142611fccf17Sopenharmony_ci}
142711fccf17Sopenharmony_ci
142811fccf17Sopenharmony_ciuint8_t IsTransparentFile(uint8_t fd)
142911fccf17Sopenharmony_ci{
143011fccf17Sopenharmony_ci    return (0x07 & (fd)) == 0x01;
143111fccf17Sopenharmony_ci}
143211fccf17Sopenharmony_ci
143311fccf17Sopenharmony_civoid ConvertHexStringToByteArray(uint8_t *originHexString, int responseLen, uint8_t *byteArray, int fcpLen)
143411fccf17Sopenharmony_ci{
143511fccf17Sopenharmony_ci    if (responseLen <= 0 || fcpLen <= 0) {
143611fccf17Sopenharmony_ci        TELEPHONY_LOGE("originHexString is error, size=%{public}d", responseLen);
143711fccf17Sopenharmony_ci        return;
143811fccf17Sopenharmony_ci    }
143911fccf17Sopenharmony_ci    for (int i = 0; i < fcpLen; i++) {
144011fccf17Sopenharmony_ci        int hexIndex = i * HALF_LEN;
144111fccf17Sopenharmony_ci        if (hexIndex + 1 >= responseLen) {
144211fccf17Sopenharmony_ci            break;
144311fccf17Sopenharmony_ci        }
144411fccf17Sopenharmony_ci        byteArray[i] = (ToByte(originHexString[hexIndex]) << HALF_BYTE_LEN) | ToByte(originHexString[hexIndex + 1]);
144511fccf17Sopenharmony_ci    }
144611fccf17Sopenharmony_ci}
144711fccf17Sopenharmony_ci
144811fccf17Sopenharmony_ciuint8_t *ConvertByteArrayToHexString(uint8_t *byteArray, int byteArrayLen)
144911fccf17Sopenharmony_ci{
145011fccf17Sopenharmony_ci    uint8_t *buf = malloc(byteArrayLen * HALF_LEN + 1);
145111fccf17Sopenharmony_ci    if (buf == NULL) {
145211fccf17Sopenharmony_ci        TELEPHONY_LOGE("buf is NULL");
145311fccf17Sopenharmony_ci        return NULL;
145411fccf17Sopenharmony_ci    }
145511fccf17Sopenharmony_ci    int bufIndex = 0;
145611fccf17Sopenharmony_ci    const char HEX_DIGITS[HEX_DIGITS_LEN] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
145711fccf17Sopenharmony_ci        'F' };
145811fccf17Sopenharmony_ci    for (int i = 0; i < byteArrayLen; i++) {
145911fccf17Sopenharmony_ci        uint8_t b = byteArray[i];
146011fccf17Sopenharmony_ci        buf[bufIndex++] = HEX_DIGITS[(b >> HALF_BYTE_LEN) & BYTE_NUM_4];
146111fccf17Sopenharmony_ci        buf[bufIndex++] = HEX_DIGITS[b & BYTE_NUM_4];
146211fccf17Sopenharmony_ci    }
146311fccf17Sopenharmony_ci    buf[bufIndex] = '\0';
146411fccf17Sopenharmony_ci    return buf;
146511fccf17Sopenharmony_ci}
146611fccf17Sopenharmony_ci
146711fccf17Sopenharmony_ciuint8_t ToByte(char c)
146811fccf17Sopenharmony_ci{
146911fccf17Sopenharmony_ci    if (c >= '0' && c <= '9') {
147011fccf17Sopenharmony_ci        return (c - '0');
147111fccf17Sopenharmony_ci    }
147211fccf17Sopenharmony_ci    if (c >= 'A' && c <= 'F') {
147311fccf17Sopenharmony_ci        return (c - 'A' + DECIMAL_MAX);
147411fccf17Sopenharmony_ci    }
147511fccf17Sopenharmony_ci    if (c >= 'a' && c <= 'f') {
147611fccf17Sopenharmony_ci        return (c - 'a' + DECIMAL_MAX);
147711fccf17Sopenharmony_ci    }
147811fccf17Sopenharmony_ci    TELEPHONY_LOGE("ToByte Error: %{public}c", c);
147911fccf17Sopenharmony_ci    return 0;
148011fccf17Sopenharmony_ci}
1481