优化sim部分的demo的代码,解决涉及unlock生效但是会报错的问题,优化sim的状态返回,优化电话长度的判断
Change-Id: I61c3e1b7027cc8671ff16d50e046a1e34b82fea5
diff --git a/mbtk/liblynq_lib/src/lynq_sim.c b/mbtk/liblynq_lib/src/lynq_sim.c
index 2f9c1c7..777ea46 100755
--- a/mbtk/liblynq_lib/src/lynq_sim.c
+++ b/mbtk/liblynq_lib/src/lynq_sim.c
@@ -118,7 +118,7 @@
return QSER_RESULT_FAIL;
}
- if(iccid == NULL || iccidLen < 15)
+ if(iccid == NULL || iccidLen < QSER_SIM_ICCID_LEN_MAX)
{
LOGE("[qser_data_call] iccid is NULL.");
return QSER_RESULT_FAIL;
@@ -403,7 +403,7 @@
pt_info->e_card_state = QSER_SIM_CARD_STATE_ABSENT;
break;
case 1: //NOT READY
- pt_info->e_card_state = QSER_SIM_CARD_STATE_UNKNOWN;
+ pt_info->e_card_state = QSER_SIM_CARD_STATE_ABSENT;
break;
case 2: //READY
pt_info->e_card_state = QSER_SIM_CARD_STATE_PRESENT;
diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 81633e1..5345fa9 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -1942,14 +1942,14 @@
return err;
#else
sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value);
- int err = at_send_command_singleline(cmd, "+CPIN: READY:", &response);
- if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
- if(response) {
+ int err = at_send_command(cmd, &response);
+ if (err < 0 || response->success == 0){
+ if(cme_err) {
*cme_err = at_get_cme_error(response);
}
- LOGD("AT+CPIN fail.");
goto exit;
}
+
#endif
exit:
at_response_free(response);
diff --git a/mbtk/test/liblynq_lib/qser_sim_test.c b/mbtk/test/liblynq_lib/qser_sim_test.c
index d6478c4..cae4530 100755
--- a/mbtk/test/liblynq_lib/qser_sim_test.c
+++ b/mbtk/test/liblynq_lib/qser_sim_test.c
@@ -18,420 +18,304 @@
sim_client_handle_type ph_sim = 2023;
sim_client_handle_type h_sim = 2023;
-int flag_init = 0;
-typedef struct
-{
- int cmdIdx;
- const char *funcName;
-} st_api_test_case;
-
-//for server test
-st_api_test_case at_api_testcases[] =
-{
- {0, "qser_sim_init"},
- {1, "qser_get_imsi"},
- {2, "qser_get_iccid"},
- {3, "qser_get_phonenumber"},
- {4, "qser_verify_pin"},
- {5, "qser_change_pin"},
- {6, "qser_unlock_pin"},
- {7, "qser_enable_pin"},
- {8, "qser_disable_pin"},
- {9, "qser_get_sim_status"},
- {10, "qser_get_imei"},
- {11, "qser_get_imei_and_sv"},
- {12, "qser_reset_modem"},
- {13, "qser_get_version"},
- {14, "qser_reset_sim"},
- {15, "qser_deinit_sim"},
- {-1, NULL}
-};
-
-void print_help(void)
-{
- int i;
- printf("Supported test cases:\n");
- for(i = 0; ; i++)
- {
- if(at_api_testcases[i].cmdIdx == -1)
- {
- break;
- }
- printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
- }
-}
int main(int argc, char const *argv[])
{
- int cmdIdx = 0;
- int res = 0;
+ printf("=========sim main=========\n"
+ "\t0 qser_sim_init\n"
+ "\t1 qser_get_imsi\n"
+ "\t2 qser_get_iccid\n"
+ "\t3 qser_get_phonenumber\n"
+ "\t4 qser_verify_pin\n"
+ "\t5 qser_change_pin\n"
+ "\t6 qser_unlock_pin\n"
+ "\t7 qser_enable_pin\n"
+ "\t8 qser_disable_pin\n"
+ "\t9 qser_get_sim_status\n"
+ "\t10 qser_get_imei\n"
+ "\t11 qser_get_imei_and_sv\n"
+ "\t12 qser_reset_modem\n"
+ "\t13 qser_get_version\n"
+ "\t14 qser_reset_sim\n"
+ "\t15 qser_deinit_sim\n"
+ "\t16 exit\n");
- print_help();
while(1)
{
- printf("\nplease input cmd index(-1 exit): ");
+ int cmdIdx = -1;
+ int res = -1;
+
+ printf("operator: >> \n");
+
scanf("%d", &cmdIdx);
- if(cmdIdx == -1)
- {
- break;
- }
+ fflush(stdin);
switch(cmdIdx)
{
//"qser_sim_init"
case 0:
{
- if(flag_init == 1)
+ //int token;
+ //printf("input token\n");
+ //scanf("%d", &token);
+ res = qser_sim_client_init(&h_sim);
+ if(res == 0)
{
- printf("init is already\n");
- break;
- }
- else{
- //int token;
- //printf("input token\n");
- //scanf("%d", &token);
- res = qser_sim_client_init(&h_sim);
- if(res == 0)
- {
- printf("Run qser_sim_client_init\n");
- flag_init = 1;
- }else{
- printf("qser_sim_client_init error\n");
- }
-
- break;
+ printf("Run qser_sim_client_init\n");
+ }else{
+ printf("qser_sim_client_init error\n");
}
}
-
+ break;
//"qser_sim_getimsi"
case 1:
{
- if(flag_init == 0){
- printf("must init first\n");
+ char imsi[BUF_SIZE] = {0};
+ QSER_SIM_APP_ID_INFO_T pt_info;
+ res = qser_sim_getimsi(h_sim, &pt_info, imsi, BUF_SIZE);
+ if(res == 0)
+ {
+ printf("imsi is %s!!!\n",imsi);
+ }else{
+ printf("get imsi error, res = %d\n", res);
}
- else{
- char imsi[BUF_SIZE] = {0};
- QSER_SIM_APP_ID_INFO_T pt_info;
- res = qser_sim_getimsi(h_sim, &pt_info, imsi, 32);
- if(res == 0)
- {
- printf("imsi is %s!!!\n",imsi);
- }else{
- printf("get imsi error, res = %d\n", res);
- }
- }
- break;
}
-
+ break;
//"qser_get_iccid"
case 2:
{
- if(flag_init == 0){
- printf("must init first\n");
+ char iccid[BUF_SIZE] = {0};
+ res = qser_sim_geticcid(h_sim, QSER_SIM_SLOT_ID_1, iccid, BUF_SIZE);
+ if(res == 0)
+ {
+ printf("get iccid success!!! iccid is %s\n",iccid);
+ }else{
+ printf("get iccid error, res = %d\n", res);
}
- else{
- char iccid[BUF_SIZE] = {0};
- res = qser_sim_geticcid(h_sim, QSER_SIM_SLOT_ID_1, iccid, 32);
- if(res == 0)
- {
- printf("get iccid success!!! iccid is %s\n",iccid);
- }else{
- printf("get iccid error, res = %d\n", res);
- }
- }
- break;
}
+ break;
//qser_get_phonenumber
case 3:
{
- if(flag_init == 0){
- printf("must init first\n");
+ char phonenumber[BUF_SIZE] = "";
+ QSER_SIM_APP_ID_INFO_T pt_info;
+ res = qser_sim_getphonenumber(h_sim, &pt_info, phonenumber, BUF_SIZE);
+ if(res == 0)
+ {
+ printf("get phonenumber success!!! phonenumber is %s\n",phonenumber);
+ }else{
+ printf("get phonenumber error, res = %d\n", res);
}
- else{
- char phonenumber[BUF_SIZE] = "";
- QSER_SIM_APP_ID_INFO_T pt_info;
- res = qser_sim_getphonenumber(h_sim, &pt_info, phonenumber, 32);
- if(res == 0)
- {
- printf("get phonenumber success!!! phonenumber is %s\n",phonenumber);
- }else{
- printf("get phonenumber error, res = %d\n", res);
- }
- }
- break;
- }
- //qser_verify_pin
+ }
+ break;
+ //qser_verify_pin
case 4:
{
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- char pin[BUF_PIN] = {0};
- QSER_SIM_VERIFY_PIN_INFO_T pt_info;
- printf("input pin\n");
- scanf("%s", pin);
- strncpy(pt_info.pin_value, pin, BUF_PIN);
- printf("pin_value = %s , pin = %s\n", pt_info.pin_value, pin);
- pt_info.pin_value_len = strlen(pt_info.pin_value);
-
- res = qser_sim_verifypin(h_sim, &pt_info);
- if(res == 0)
- {
- printf("verify pin success!!!\n");
- }else{
- printf("verify pin error, res = %d\n", res);
- }
+ char pin[BUF_PIN] = {0};
+ QSER_SIM_VERIFY_PIN_INFO_T pt_info;
+ printf("input pin\n");
+ scanf("%s", pin);
+ strncpy(pt_info.pin_value, pin, BUF_PIN);
+ printf("pin_value = %s , pin = %s\n", pt_info.pin_value, pin);
+ pt_info.pin_value_len = strlen(pt_info.pin_value);
+ res = qser_sim_verifypin(h_sim, &pt_info);
+ if(res == 0)
+ {
+ printf("verify pin success!!!\n");
+ }else{
+ printf("verify pin error, res = %d\n", res);
}
- break;
}
+ break;
//qser_change_pin
case 5:
{
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- char old_pin[BUF_PIN] = {0};
- QSER_SIM_CHANGE_PIN_INFO_T pt_info;
- printf("input old pin\n");
- scanf("%s", old_pin);
- char new_pin[BUF_PIN] = {0};
- printf("input new pin\n");
- scanf("%s", new_pin);
- strncpy(pt_info.old_pin_value, old_pin, BUF_PIN);
- strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
- printf("pt_info.old_pin_value = %s, old_pin = %s\n", pt_info.old_pin_value, old_pin);
- printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
- pt_info.old_pin_value_len = strlen(pt_info.old_pin_value);
- pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
+ char old_pin[BUF_PIN] = {0};
+ QSER_SIM_CHANGE_PIN_INFO_T pt_info;
+ printf("input old pin\n");
+ scanf("%s", old_pin);
+ char new_pin[BUF_PIN] = {0};
+ printf("input new pin\n");
+ scanf("%s", new_pin);
+ strncpy(pt_info.old_pin_value, old_pin, BUF_PIN);
+ strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
+ printf("pt_info.old_pin_value = %s, old_pin = %s\n", pt_info.old_pin_value, old_pin);
+ printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
+ pt_info.old_pin_value_len = strlen(pt_info.old_pin_value);
+ pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
- res = qser_sim_changepin(h_sim, &pt_info);
- if(res == 0)
- {
- printf("change pin success!!!\n");
- }else{
- printf("change pin error, res = %d\n", res);
- }
+ res = qser_sim_changepin(h_sim, &pt_info);
+ if(res == 0)
+ {
+ printf("change pin success!!!\n");
+ }else{
+ printf("change pin error, res = %d\n", res);
}
- break;
}
+ break;
//qser_unlock_pin
case 6:
{
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- char puk[BUF_PIN] = {0};
- QSER_SIM_UNBLOCK_PIN_INFO_T pt_info;
- printf("input puk\n");
- scanf("%s", puk);
- char new_pin[BUF_PIN] = {0};
- printf("input new pin\n");
- scanf("%s", new_pin);
+ char puk[BUF_PIN] = {0};
+ QSER_SIM_UNBLOCK_PIN_INFO_T pt_info;
+ printf("input puk\n");
+ scanf("%s", puk);
+ char new_pin[BUF_PIN] = {0};
+ printf("input new pin\n");
+ scanf("%s", new_pin);
- strncpy(pt_info.puk_value, puk, BUF_PIN);
- strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
- printf("pt_info.puk_value = %s, puk = %s\n", pt_info.puk_value, puk);
- printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
- pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
- pt_info.puk_value_len = strlen(pt_info.puk_value);
-
- res = qser_sim_unblockpin(h_sim, &pt_info);
- if(res == 0)
- {
- printf("unlock pin success!!!\n");
- }else{
- printf("unlock pin error, res = %d\n", res);
- }
+ strncpy(pt_info.puk_value, puk, BUF_PIN);
+ strncpy(pt_info.new_pin_value, new_pin, BUF_PIN);
+ printf("pt_info.puk_value = %s, puk = %s\n", pt_info.puk_value, puk);
+ printf("pt_info.new_pin_value = %s, new_pin = %s\n", pt_info.new_pin_value, new_pin);
+ pt_info.new_pin_value_len = strlen(pt_info.new_pin_value);
+ pt_info.puk_value_len = strlen(pt_info.puk_value);
+
+ res = qser_sim_unblockpin(h_sim, &pt_info);
+ if(res == 0)
+ {
+ printf("unlock pin success!!!\n");
+ }else{
+ printf("unlock pin error, res = %d\n", res);
}
- break;
}
+ break;
//qser_enable_pin
case 7:
- {
- if(flag_init == 0){
- printf("must init first\n");
+ {
+ char pin[BUF_PIN] = {0};
+ QSER_SIM_ENABLE_PIN_INFO_T pt_info;
+ printf("input pin\n");
+ scanf("%s", pin);
+ strncpy(pt_info.pin_value, pin, BUF_PIN);
+ pt_info.pin_value_len = strlen(pt_info.pin_value);
+
+ res = qser_sim_enablepin(h_sim, &pt_info);
+ if(res == 0)
+ {
+ printf("pin enabled!!!\n");
+ }else{
+ printf("pin enable error, res =%d\n", res);
}
- else{
- char pin[BUF_PIN] = {0};
- QSER_SIM_ENABLE_PIN_INFO_T pt_info;
- printf("input pin\n");
- scanf("%s", pin);
- strncpy(pt_info.pin_value, pin, BUF_PIN);
- pt_info.pin_value_len = strlen(pt_info.pin_value);
-
- res = qser_sim_enablepin(h_sim, &pt_info);
- if(res == 0)
- {
- printf("pin enabled!!!\n");
- }else{
- printf("pin enable error, res =%d\n", res);
- }
- }
- break;
}
+ break;
//qser_disable_pin
case 8:
{
- if(flag_init == 0){
- printf("must init first\n");
+ char pin[BUF_PIN] = {0};
+ QSER_SIM_ENABLE_PIN_INFO_T pt_info;
+ printf("input pin\n");
+ scanf("%s", pin);
+ strncpy(pt_info.pin_value, pin, BUF_PIN);
+ pt_info.pin_value_len = strlen(pt_info.pin_value);
+
+ res = qser_sim_disablepin(h_sim, &pt_info);
+ if(res == 0)
+ {
+ printf("pin disnabled!!!\n");
+ }else{
+ printf("pin disable error,res = %d\n", res);
}
- else{
- char pin[BUF_PIN] = {0};
- QSER_SIM_ENABLE_PIN_INFO_T pt_info;
- printf("input pin\n");
- scanf("%s", pin);
- strncpy(pt_info.pin_value, pin, BUF_PIN);
- pt_info.pin_value_len = strlen(pt_info.pin_value);
-
- res = qser_sim_disablepin(h_sim, &pt_info);
- if(res == 0)
- {
- printf("pin disnabled!!!\n");
- }else{
- printf("pin disable error,res = %d\n", res);
- }
- }
- break;
}
- //qser_get_sim_status
+ break;
+ //qser_get_sim_status
case 9:
{
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- QSER_SIM_CARD_STATUS_INFO_T pt_info;
+ QSER_SIM_CARD_STATUS_INFO_T pt_info;
- res = qser_sim_getcardstatus(h_sim, QSER_SIM_SLOT_ID_1, &pt_info);
- if(res == 0)
- {
- printf("state is %d !!!\n",pt_info.e_card_state);
- }else{
- printf("get imsi error,res = %d\n", res);
- }
+ res = qser_sim_getcardstatus(h_sim, QSER_SIM_SLOT_ID_1, &pt_info);
+ if(res == 0)
+ {
+ printf("state is %d !!!\n",pt_info.e_card_state);
+ }else{
+ printf("get imsi error,res = %d\n", res);
}
- break;
}
+ break;
//qser_get_imei
case 10:
{
- if(flag_init == 0){
- printf("must init first\n");
+ char imei[BUF_SIZE]="";
+ res = qser_sim_getimei(h_sim, imei);
+ if(res == 0)
+ {
+ printf("get imei success!!! imei = %s\n", imei);
+ }else{
+ printf("get imei error, res = %d\n", res);
}
- else{
- char imei[BUF_SIZE]="";
- res = qser_sim_getimei(h_sim, imei);
- if(res == 0)
- {
- printf("get imei success!!! imei = %s\n", imei);
- }else{
- printf("get imei error, res = %d\n", res);
- }
- }
- //flag_init = 0;
- break;
}
+ break;
//qser_get_imei_and_sv
case 11:
{
char imei[BUF_SIZE]="";
char sv[BUF_SIZE]="";
- if(flag_init == 0){
- printf("must init first\n");
+ res = qser_get_imei_and_sv(h_sim, imei, sv);
+ if(res == 0)
+ {
+ printf("get imei and sv success!!!imei = %s sv = %s\n", imei, sv);
+ }else{
+ printf("get imei and sv error, res = %d\n", res);
}
- else{
- res = qser_get_imei_and_sv(h_sim, imei, sv);
- if(res == 0)
- {
- printf("get imei and sv success!!!imei = %s sv = %s\n", imei, sv);
- }else{
- printf("get imei and sv error, res = %d\n", res);
- }
- }
- //flag_init = 0;
- break;
}
+ break;
//qser_reset_modem
case 12:
{
- if(flag_init == 0){
- printf("must init first\n");
+ res = qser_reset_modem(h_sim);
+ if(res == 0)
+ {
+ printf("reset modem success!!!\n");
+ }else{
+ printf("reset modem error, res = %d\n", res);
}
- else{
- res = qser_reset_modem(h_sim);
- if(res == 0)
- {
- printf("reset modem success!!!\n");
- }else{
- printf("reset modem error, res = %d\n", res);
- }
- }
- //flag_init = 0;
- break;
}
+ break;
//qser_get_version
case 13:
{
char buf[VER_SIZE]="";
- if(flag_init == 0){
- printf("must init first\n");
+
+ res = qser_get_version(h_sim, buf);
+ if(res == 0)
+ {
+ printf("get version success!!! ver = %s\n", buf);
+ }else{
+ printf("get version error, res = %d\n", res);
}
- else{
- res = qser_get_version(h_sim, buf);
- if(res == 0)
- {
- printf("get version success!!! ver = %s\n", buf);
- }else{
- printf("get version error, res = %d\n", res);
- }
- }
- //flag_init = 0;
- break;
}
+ break;
//qser_reset_sim
case 14:
{
- if(flag_init == 0){
- printf("must init first\n");
+ res = qser_reset_sim(h_sim);
+ if(res == 0)
+ {
+ printf("reset sim success!!!\n");
+ }else{
+ printf("reset sim error, res = %d\n", res);
}
- else{
- res = qser_reset_sim(h_sim);
- if(res == 0)
- {
- printf("reset sim success!!!\n");
- }else{
- printf("reset sim error, res = %d\n", res);
- }
- }
- //flag_init = 0;
- break;
}
+ break;
//qser_deinit_sim
case 15:
{
- if(flag_init == 0){
- printf("must init first\n");
+ res = qser_sim_client_deinit(h_sim);
+ if(res == 0)
+ {
+ printf("sim deinit success is!!!\n");
+ }else{
+ printf("sim deint errors, res = %d\n", res);
}
- else{
- res = qser_sim_client_deinit(h_sim);
- if(res == 0)
- {
- printf("sim deinit success is!!!\n");
- }else{
- printf("sim deint errors, res = %d\n", res);
- }
- }
- flag_init = 0;
- break;
}
- default:
- print_help();
+ break;
+ case 16:
+ printf("main exit\n");
+ return 0;
+ default :
break;
}