Fix IMS set error

Change-Id: I0085e8bc553092c821bea9e46aabd1a9bd484366
diff --git a/mbtk/include/mbtk/mbtk_info_api.h b/mbtk/include/mbtk/mbtk_info_api.h
old mode 100644
new mode 100755
index 5943c2e..6bff940
--- a/mbtk/include/mbtk/mbtk_info_api.h
+++ b/mbtk/include/mbtk/mbtk_info_api.h
@@ -695,14 +695,19 @@
 int mbtk_net_reg_get(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg);
 
 /*
-* Get current network IMS information.
+* Get current IMS enable or not.
 */
-int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* reg);
+int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* enable);
 
 /*
-* Set current network IMS information.
+* Set IMS enable or not. This function takes effect after starting the device.
 */
-int mbtk_net_ims_set(mbtk_info_handle_t* handle, int reg);
+int mbtk_net_ims_set(mbtk_info_handle_t* handle, int enable);
+
+/*
+* Get current network IMS register state.
+*/
+int mbtk_net_ims_reg_state_get(mbtk_info_handle_t* handle, int* reg);
 
 /*
 * Get radio state.
diff --git a/mbtk/liblynq_lib/src/lynq_network.c b/mbtk/liblynq_lib/src/lynq_network.c
old mode 100644
new mode 100755
index 795539c..d550efd
--- a/mbtk/liblynq_lib/src/lynq_network.c
+++ b/mbtk/liblynq_lib/src/lynq_network.c
@@ -1176,7 +1176,7 @@
         return -1;
     }
 
-    ret = mbtk_net_ims_get(lynq_nw_info_handle, &tmp_pt);
+    ret = mbtk_net_ims_reg_state_get(lynq_nw_info_handle, &tmp_pt);
     if (ret != 0)
     {
         LOGE("mbtk_net_ims_get fail.");
diff --git a/mbtk/libmbtk_ril/mbtk_info.h b/mbtk/libmbtk_ril/mbtk_info.h
index 9d90690..573ba84 100755
--- a/mbtk/libmbtk_ril/mbtk_info.h
+++ b/mbtk/libmbtk_ril/mbtk_info.h
@@ -151,6 +151,9 @@
     MBTK_INFO_ID_NET_IMS_REQ,
     MBTK_INFO_ID_NET_IMS_RSP,
 
+    MBTK_INFO_ID_NET_IMS_REG_STATE_REQ,
+    MBTK_INFO_ID_NET_IMS_REG_STATE_RSP,
+
 
     MBTK_INFO_ID_NET_END,
 
diff --git a/mbtk/libmbtk_ril/mbtk_info_api.c b/mbtk/libmbtk_ril/mbtk_info_api.c
old mode 100644
new mode 100755
index ce9cc9c..608f9b0
--- a/mbtk/libmbtk_ril/mbtk_info_api.c
+++ b/mbtk/libmbtk_ril/mbtk_info_api.c
@@ -1590,9 +1590,9 @@
 }
 
 /*
-* Get current network IMS information.
+* Get current IMS enable or not.
 */
-int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* reg)
+int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* enable)
 {
     uint8 state;
     if(handle == NULL)
@@ -1601,8 +1601,8 @@
         return -1;
     }
     if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, NULL, 0, &state) > 0) {
-        LOG("reg type : %d", state);
-        *reg = state;
+        LOG("IMS enable : %d", state);
+        *enable = state;
         return 0;
     } else {
         return handle->info_err;
@@ -1611,9 +1611,9 @@
 }
 
 /*
-* Set current network IMS information.
+* Set IMS enable or not. This function takes effect after starting the device.
 */
-int mbtk_net_ims_set(mbtk_info_handle_t* handle, int reg)
+int mbtk_net_ims_set(mbtk_info_handle_t* handle, int enable)
 {
     if(handle == NULL)
     {
@@ -1621,10 +1621,30 @@
         return -1;
     }
 
-    return info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, (uint8*)&reg, sizeof(uint8), NULL) ? handle->info_err : 0;
+    return info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, (uint8*)&enable, sizeof(uint8), NULL) ? handle->info_err : 0;
 
 }
 
+/*
+* Get current network IMS register state.
+*/
+int mbtk_net_ims_reg_state_get(mbtk_info_handle_t* handle, int* reg)
+{
+    uint8 state;
+    if(handle == NULL)
+    {
+        LOGE("ARG error.");
+        return -1;
+    }
+    if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REG_STATE_REQ, NULL, 0, &state) > 0) {
+        LOG("reg type : %d", state);
+        *reg = state;
+        return 0;
+    } else {
+        return handle->info_err;
+    }
+}
+
 
 /*
 * Get radio state.
diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 8417c19..78938dc 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -2981,7 +2981,7 @@
     char cmd[30] = {0};
     int err = -1;
 
-    sprintf(cmd, "AT+CIREG=%d", reg);
+    sprintf(cmd, "AT+ACONFIG=\"IMSD=%d\"", reg);
     err = at_send_command(cmd, &response);
     LOG("cmd : %s", cmd);
 
@@ -2999,7 +2999,35 @@
 static int net_ims_get(int *reg, int *cme_err)
 {
     ATResponse *response = NULL;
-    int tmp_int, tmp_reg;
+    int tmp_int, tmp_reg = 0;
+    int err;
+    char *tmp_str = NULL;
+
+    err = at_send_command_singleline("AT+ACONFIG?", "", &response);
+    if (err < 0 || response->success == 0 || !response->p_intermediates){
+        tmp_reg = 0;
+        err = 0;
+        goto exit;
+    }
+    if(response->p_intermediates->line) {
+        char *ptr = strstr(response->p_intermediates->line, "IMSD=");
+        if(ptr) {
+            tmp_reg = atoi(ptr + strlen("IMSD="));
+        }
+    }
+
+    LOG("net_ims_get reg : %u", tmp_reg);
+
+exit:
+    at_response_free(response);
+    *reg = tmp_reg;
+    return err;
+}
+
+static int net_ims_reg_state_get(int *reg, int *cme_err)
+{
+    ATResponse *response = NULL;
+    int tmp_int, tmp_reg = -1;
     int err;
     char *tmp_str = NULL;
 
@@ -3021,7 +3049,16 @@
         goto exit;
     }
 
-    tmp_reg = tmp_int;
+    if(at_tok_hasmore(&line)) {
+        err = at_tok_nextint(&line, &tmp_int);// stat
+        if (err < 0)
+        {
+            goto exit;
+        }
+        tmp_reg = tmp_int;
+    } else {
+        tmp_reg = tmp_int;
+    }
 
     LOG("net_ims_get reg : %u", tmp_reg);
 
@@ -3032,6 +3069,7 @@
 }
 
 
+
 /*
 AT+CGDCONT?
 +CGDCONT: 1,"IPV4V6","cmnet.MNC000.MCC460.GPRS","10.131.67.146 254.128.0.0.0.0.0.0.0.1.0.2.200.2.158.0",0,0,,,,
@@ -5531,6 +5569,32 @@
                 }
                 break;
             }
+            case MBTK_INFO_ID_NET_IMS_REG_STATE_REQ:
+            {
+                if(pack->data_len == 0 || pack->data == NULL) //Get
+                {
+                    int reg = -1;
+                    if(net_ims_reg_state_get(&reg, &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;
+                        }
+                        LOG("Get net ims fail.");
+                    }
+                    else
+                    {
+                        uint8 reg_type = (uint8)reg;
+                        pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_REG_STATE_RSP, &reg_type, sizeof(uint8));
+                    }
+                }
+                else
+                {
+                    err = MBTK_INFO_ERR_UNSUPPORTED;
+                }
+                break;
+            }
             case MBTK_INFO_ID_WAKEUP_STA_REQ:
             {
                 if(pack->data_len == 0 || pack->data == NULL)