add centric

Change-Id: I6ff1dd3d2fdce306574b59882ca62d2fd9114b6a
diff --git a/mbtk/include/mbtk/mbtk_ril_api.h b/mbtk/include/mbtk/mbtk_ril_api.h
old mode 100755
new mode 100644
index 6c3a197..98dc338
--- a/mbtk/include/mbtk/mbtk_ril_api.h
+++ b/mbtk/include/mbtk/mbtk_ril_api.h
@@ -1395,6 +1395,12 @@
 */
 mbtk_ril_err_enum mbtk_dtmf_send(mbtk_ril_handle* handle, mbtk_call_dtmf_info_t *dtmf_character);
 
+mbtk_ril_err_enum mbtk_centric_set(mbtk_ril_handle* handle, int centric);
+
+mbtk_ril_err_enum mbtk_centric_get(mbtk_ril_handle* handle, int *centric);
+
+
+
 /*
 * Set msd item.
 *
diff --git a/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h b/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h
old mode 100755
new mode 100644
index efd67fc..cd70839
--- a/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h
+++ b/mbtk/libmbtk_lib/ril/inc/mbtk_ril.h
@@ -143,6 +143,8 @@
     RIL_MSG_ID_CALL_MUTE,
     //dtmf call
     RIL_MSG_ID_CALL_DTMF,
+    //centric
+    RIL_MSG_ID_CALL_CENTRIC,
     RIL_MSG_ID_CALL_END,
 
     // SMS Information
diff --git a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
old mode 100755
new mode 100644
index 8ef6b98..a2eab56
--- a/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
+++ b/mbtk/libmbtk_lib/ril/v2/mbtk_ril_api.c
@@ -2624,6 +2624,50 @@
     return ril_req_process(port_info->port, RIL_MSG_ID_CALL_DTMF, dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL, FALSE);
 }
 
+mbtk_ril_err_enum mbtk_centric_set(mbtk_ril_handle* handle, int centric)
+{
+    if(!ril_cli.ril_ready)
+    {
+        return MBTK_RIL_ERR_NOT_INIT;
+    }
+
+    if((0 != centric && 1 != centric) || handle == NULL)
+    {
+        LOGE("ARG error.");
+        return MBTK_RIL_ERR_PARAMETER;
+    }
+
+    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_CALL_CENTRIC, &centric, 1, NULL, FALSE);
+}
+
+mbtk_ril_err_enum mbtk_centric_get(mbtk_ril_handle* handle, int *centric)
+{
+    if(!ril_cli.ril_ready)
+    {
+        return MBTK_RIL_ERR_NOT_INIT;
+    }
+
+    if(centric == NULL || handle == NULL)
+    {
+        LOGE("ARG error.");
+        return MBTK_RIL_ERR_PARAMETER;
+    }
+
+    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_CALL_CENTRIC, NULL, 0, centric, FALSE);
+}
+
+
+
 /*
 * Set msd item.
 *
diff --git a/mbtk/mbtk_rild_v2/src/ril_call.c b/mbtk/mbtk_rild_v2/src/ril_call.c
old mode 100755
new mode 100644
index e35775a..ca80871
--- a/mbtk/mbtk_rild_v2/src/ril_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_call.c
@@ -297,6 +297,58 @@
     return err;
 }
 
+static int req_centric_get(ATPortType_enum port, int *state, int *cme_err)
+{
+    ATResponse *response = NULL;
+    int tmp_int = 0;
+    int err = at_send_command_singleline(port, "AT+CEUS?", "+CEUS:", &response);
+
+    if (err < 0 || response->success == 0 || !response->p_intermediates){
+        *cme_err = at_get_cme_error(response);
+        goto exit;
+    }
+
+    char *line = response->p_intermediates->line;
+    err = at_tok_start(&line);
+    if (err < 0)
+    {
+        goto exit;
+    }
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+    *state = tmp_int;
+
+exit:
+    at_response_free(response);
+    return err;
+}
+
+/*
+AT+CMUT=0;
+OK
+
+*/
+static int req_centric_set(ATPortType_enum port, int state, int *cme_err)
+{
+    ATResponse *response = NULL;
+    char cmd[100] = {0};
+    sprintf(cmd, "AT+CEUS=%d", state);
+    LOG("Set the centric command is = %s.\n", cmd);
+    int err = at_send_command(port, cmd, &response);
+    if (err < 0 || response->success == 0){
+        *cme_err = at_get_cme_error(response);
+        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.
 // Otherwise, do not call pack_error_send().
@@ -555,6 +607,51 @@
             }
             break;
         }
+        case RIL_MSG_ID_CALL_CENTRIC:
+        {
+            if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
+            {
+                int state;
+                if(req_centric_get(cli_info->port, &state, &cme_err) || 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 mute state fail.");
+                }
+                else
+                {
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(int));
+                }
+            }
+            else     // Set mute state.
+            {
+                uint8 on = *(pack->data);
+                if(pack->data_len != sizeof(uint8) || (on != 0 && on != 1))
+                {
+                    err = MBTK_RIL_ERR_REQ_PARAMETER;
+                    LOG("Set mute parameter error.");
+                    break;
+                }
+
+                if(req_centric_set(cli_info->port, on, &cme_err) || 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("Set mute state fail.");
+                }
+                else
+                {
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                }
+            }
+            break;
+        }
         default:
         {
             err = MBTK_RIL_ERR_REQ_UNKNOWN;