Fix IMS set error

Change-Id: I0085e8bc553092c821bea9e46aabd1a9bd484366
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)