add pin mode get api
Change-Id: I8ebf1e5e9ad5ad8274d4ff657863e0eb7fecff07
diff --git a/mbtk/include/mbtk/mbtk_info_api.h b/mbtk/include/mbtk/mbtk_info_api.h
index 1b1d88c..2983371 100755
--- a/mbtk/include/mbtk/mbtk_info_api.h
+++ b/mbtk/include/mbtk/mbtk_info_api.h
@@ -264,6 +264,11 @@
} mbtk_sim_state_enum;
typedef enum {
+ MBTK_PIN_DISABLE = 0,
+ MBTK_PIN_ENABLE = 1,
+}mbtk_pin_state_enum;
+
+typedef enum {
MBTK_IP_TYPE_IP,
MBTK_IP_TYPE_IPV6,
MBTK_IP_TYPE_IPV4V6,
@@ -922,6 +927,11 @@
int mbtk_enable_pin(mbtk_info_handle_t* handle, mbtk_enable_pin_info *pin);
/*
+* GET PIN STATE
+*/
+int mbtk_get_pin_state(mbtk_info_handle_t* handle, mbtk_pin_state_enum *pin_state);
+
+/*
*Verify PIN
*/
int mbtk_verify_pin(mbtk_info_handle_t* handle, char *pin);
diff --git a/mbtk/libmbtk_lib/ril/mbtk_info_api.c b/mbtk/libmbtk_lib/ril/mbtk_info_api.c
index e355cce..99fb91f 100755
--- a/mbtk/libmbtk_lib/ril/mbtk_info_api.c
+++ b/mbtk/libmbtk_lib/ril/mbtk_info_api.c
@@ -833,6 +833,26 @@
}
/*
+* GET PIN STATE
+*/
+int mbtk_get_pin_state(mbtk_info_handle_t* handle, mbtk_pin_state_enum *pin_state)
+{
+ if(handle == NULL)
+ {
+ LOGE("ARG error.");
+ return -1;
+ }
+ if(info_item_process(handle, MBTK_INFO_ID_SIM_ENABLE_PIN_REQ, NULL, 0, pin_state) >= 0) {
+ LOGD("pin state: %d", *pin_state);
+ return 0;
+ } else {
+ return handle->info_err;
+ }
+
+}
+
+
+/*
* Verify PIN
*/
int mbtk_verify_pin(mbtk_info_handle_t* handle, char *pin)
diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 57dc6ac..d582fb4 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -579,24 +579,24 @@
if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
{
+ switch (at_get_cme_error(p_response))
+ {
+ case CME_SUCCESS:
+ break;
+
+ case CME_SIM_NOT_INSERTED:
+ case 13: //sim fail,as "sim absent"
+ ret = MBTK_SIM_ABSENT;
+ goto done;
+
+ default:
+ ret = MBTK_SIM_NOT_READY;
+ goto done;
+ }
ret = MBTK_SIM_NOT_READY;
goto done;
}
-
- switch (at_get_cme_error(p_response))
- {
- case CME_SUCCESS:
- break;
-
- case CME_SIM_NOT_INSERTED:
- ret = MBTK_SIM_ABSENT;
- goto done;
-
- default:
- ret = MBTK_SIM_NOT_READY;
- goto done;
- }
-
+
/* CPIN? has succeeded, now look at the result */
cpinLine = p_response->p_intermediates->line;
@@ -1798,6 +1798,64 @@
}
/*
+AT+CLCK=SC,2
++CLCK: 1
+
+OK
+*/
+static int req_get_pin_state(mbtk_enable_pin_info *state, int *cme_err)
+{
+ ATResponse *response = NULL;
+ char cmd[64]={0};
+
+ int err = at_send_command_singleline("AT+CLCK=SC,2", "+CLCK:", &response);
+ if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates)
+ {
+ if(response)
+ {
+ *cme_err = at_get_cme_error(response);
+ }
+ LOGE("[req_get_pin_state] AT+CLCK fail.");
+ goto exit;
+ }
+
+ char *line = response->p_intermediates->line;
+ if(line == NULL)
+ {
+ LOGE("[req_get_pin_state] line is NULL");
+ goto exit;
+ }
+ err = at_tok_start(&line);
+ if (err < 0)
+ {
+ LOGE("[req_get_pin_state] at_tok_start fail.[%d]", err);
+ goto exit;
+ }
+
+ int clck;
+ err = at_tok_nextint(&line, &clck);
+ if (err < 0)
+ {
+ LOGE("[req_get_pin_state] at_tok_nextint fail.[%d]", err);
+ goto exit;
+ }
+
+ if(clck == 1)
+ {
+ state = MBTK_PIN_ENABLE;
+ }
+ else
+ {
+ state = MBTK_PIN_DISABLE;
+ }
+exit:
+ at_response_free(response);
+ response = NULL;
+ return err;
+}
+
+
+/*
AT+CPIN=1234
OK
@@ -4471,8 +4529,20 @@
{
if(pack->data_len == 0 || pack->data == NULL) // Enable PIN
{
- err = MBTK_INFO_ERR_UNSUPPORTED;
- LOG("Unsupport GET PIN.");
+ mbtk_pin_state_enum pin_state = MBTK_PIN_DISABLE;
+ if(req_get_pin_state(&pin_state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
+ {
+ if(cme_err != MBTK_INFO_ERR_CME_NON) {
+ err = MBTK_INFO_ERR_CME + cme_err;
+ } else {
+ err = MBTK_INFO_ERR_UNKNOWN;
+ }
+ LOGE("Get pin state fail.");
+ }
+ else
+ {
+ pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ENABLE_PIN_RSP, &pin_state, sizeof(mbtk_pin_state_enum));
+ }
}
else // Enable PIN
{