Add API:mbtk_get_modem_version from v2.

Change-Id: I5df09ddfaf0b7d55822e1b0b559b014a36bfdc48
diff --git a/mbtk/include/mbtk/mbtk_ril_api.h b/mbtk/include/mbtk/mbtk_ril_api.h
index bf5523d..80548cd 100755
--- a/mbtk/include/mbtk/mbtk_ril_api.h
+++ b/mbtk/include/mbtk/mbtk_ril_api.h
@@ -1637,6 +1637,10 @@
 */
 mbtk_ril_err_enum mbtk_ecall_state_change_cb_reg(mbtk_ril_callback_func cb);
 
+/*
+* get md version 
+*/
+int mbtk_get_modem_version(mbtk_ril_handle* handle, void *modem_version);
 
 
 #endif /* _MBTK_INFO_API_2_H */
diff --git a/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h b/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h
index d4664d9..3ad1dd4 100755
--- a/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h
+++ b/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h
@@ -57,7 +57,7 @@
     RIL_MSG_ID_DEV_MODEM,
     // <uint8>
     RIL_MSG_ID_DEV_POWERIND,
-
+    RIL_MSG_ID_DEV_MD_VERSION_REQ,
     RIL_MSG_ID_DEV_END,
 
     // Sim Information
diff --git a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
index 710173e..ddebb76 100755
--- a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
+++ b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
@@ -3285,6 +3285,27 @@
     return ril_req_process(port_info->port, RIL_MSG_ID_ECALL_DSP_GAIN, gain_info, sizeof(mbtk_ecall_gain_info_t), NULL, FALSE, 0);
 }
 
+int mbtk_get_modem_version(mbtk_ril_handle* handle, void *modem_version)
+{
+    if(!ril_cli.ril_ready)
+    {
+        return MBTK_RIL_ERR_NOT_INIT;
+    }
+    
+    if(handle == NULL || modem_version == NULL)
+    {
+        LOGE("ARG error.");
+        return -1;
+    }
+    ril_at_port_info_t *port_info = (ril_at_port_info_t*)handle;
+    if(!at_port_check(port_info->port)) {
+        return MBTK_RIL_ERR_PORT;
+    }
+    
+    return ril_req_process(port_info->port, RIL_MSG_ID_DEV_MD_VERSION_REQ, NULL, 0, modem_version,FALSE, 0);
+        
+}
+
 #if 0
 /*
 * Set wakeup state.
diff --git a/mbtk/libmbtk_lib/ril/v2/ril_utils.c b/mbtk/libmbtk_lib/ril/v2/ril_utils.c
index b3f3fdd..33b25a8 100755
--- a/mbtk/libmbtk_lib/ril/v2/ril_utils.c
+++ b/mbtk/libmbtk_lib/ril/v2/ril_utils.c
@@ -226,7 +226,8 @@
         case RIL_MSG_ID_DEV_POWERIND:
             return "POWERIND";
         // Sim Information
-
+        case RIL_MSG_ID_DEV_MD_VERSION_REQ:
+            return "MD_VERSION";
         // <uint8> 0:NOT_EXIST 1:READY ...
         case RIL_MSG_ID_SIM_STATE:
             return "SIM_STATE";
diff --git a/mbtk/mbtk_rild_v2/src/ril_dev.c b/mbtk/mbtk_rild_v2/src/ril_dev.c
index f2de0f1..763ed41 100755
--- a/mbtk/mbtk_rild_v2/src/ril_dev.c
+++ b/mbtk/mbtk_rild_v2/src/ril_dev.c
@@ -474,6 +474,58 @@
     return err;
 }
 
+static int req_md_version_get(ATPortType_enum port,void *data, int *cme_err)
+{
+    ATResponse *response = NULL;
+    int err = at_send_command_multiline(port,"AT*CGMR", "", &response);
+
+    if (err < 0 || response->success == 0 || !response->p_intermediates)
+    {
+        *cme_err = at_get_cme_error(response);
+        goto exit;
+    }
+
+    ATLine* lines_ptr = response->p_intermediates;
+    char *line = NULL;
+    while(lines_ptr)
+    {
+        line = lines_ptr->line;
+        char *start = strstr(line, "FALCON_CP_SDK");
+        if(start)
+        {
+            char *end = strstr(start, "_Linux");
+            if(end)
+            {
+                end += strlen("_Linux");
+                int length = end - start;
+                if (length)
+                {
+                    strncpy(data, start, length);
+                    ((char*)data)[length] = '\0';
+                    break;
+                }
+                else
+                {
+                    err = -1;
+                    goto exit;
+
+                }
+            }
+            else
+            {
+                err = -1;
+                goto exit;
+            }
+        }
+        lines_ptr = lines_ptr->p_next;
+    }
+
+    goto exit;
+exit:
+    at_response_free(response);
+    return err;
+}
+
 
 //void net_list_free(void *data);
 // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
@@ -759,6 +811,28 @@
             }
             break;
         }
+        case RIL_MSG_ID_DEV_MD_VERSION_REQ:
+            {
+                if(pack->data_len == 0 || pack->data == NULL)   // Get VERSION
+                {
+                    char version[50] = {0};
+                    if(req_md_version_get(cli_info->port,version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                    {
+                        if(cme_err != MBTK_RIL_ERR_CME_NON) {
+                            err = MBTK_RIL_ERR_CME + cme_err;
+                        } else {
+                            err = MBTK_RIL_ERR_UNKNOWN;
+                        }
+                        LOG("Get MD Version fail.");
+                    }
+                    else
+                    {
+                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen((char*)version));
+                    }
+                }
+                break;
+
+            }
         default:
         {
             err = MBTK_RIL_ERR_REQ_UNKNOWN;