Add Multiple AT channels supported for ril api v2

Change-Id: I53f574c85d07bd7b8e0dd15d2e596d23c8772907
diff --git a/mbtk/mbtk_rild_v2/src/ril_call.c b/mbtk/mbtk_rild_v2/src/ril_call.c
index 3891143..e35775a 100755
--- a/mbtk/mbtk_rild_v2/src/ril_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_call.c
@@ -17,21 +17,21 @@
 #include "mbtk_utils.h"
 #include "ril_info.h"
 
-void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len);
+void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
 
 /*
 ATDXXXXXXX;
 OK
 
 */
-static int req_call_start(char *phont_number, int *cme_err)
+static int req_call_start(ATPortType_enum port, char *phont_number, int *cme_err)
 {
     ATResponse *response = NULL;
 //    int tmp_int;
 //    char *tmp_str = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "ATD%s;", phont_number);
-    int err = at_send_command(cmd, &response);
+    int err = at_send_command(port, cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -48,10 +48,10 @@
 OK
 
 */
-static int req_answer_call(int *cme_err)
+static int req_answer_call(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command("AT+CHLD=2", &response);
+    int err = at_send_command(port, "AT+CHLD=2", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -67,10 +67,10 @@
 OK
 
 */
-static int req_hangup_call(int *cme_err)
+static int req_hangup_call(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command("ATH", &response);
+    int err = at_send_command(port, "ATH", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -86,12 +86,12 @@
 OK
 
 */
-static int req_hangup_a_call(int phone_id, int *cme_err)
+static int req_hangup_a_call(ATPortType_enum port, int phone_id, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+CHLD=1%d", phone_id);
-    int err = at_send_command(cmd, &response);
+    int err = at_send_command(port, cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -107,10 +107,10 @@
 OK
 
 */
-static int req_hangup_waiting_or_background_call(int *cme_err)
+static int req_hangup_waiting_or_background_call(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command("AT+CHLD=0", &response);
+    int err = at_send_command(port, "AT+CHLD=0", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -126,10 +126,10 @@
 OK
 
 */
-static int req_hangup_foreground_resume_background_call(int *cme_err)
+static int req_hangup_foreground_resume_background_call(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command("AT+CHLD=1", &response);
+    int err = at_send_command(port, "AT+CHLD=1", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -145,13 +145,13 @@
 OK
 
 */
-static int req_waitin_call(mbtk_call_info_t *reg, int *cme_err)
+static int req_waitin_call(ATPortType_enum port, mbtk_call_info_t *reg, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_str = NULL;
 
-    int err = at_send_command_multiline("AT+CLCC", "+CLCC:", &response);
+    int err = at_send_command_multiline(port, "AT+CLCC", "+CLCC:", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -224,11 +224,11 @@
 
 OK
 */
-static int req_mute_get(int *state, int *cme_err)
+static int req_mute_get(ATPortType_enum port, int *state, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
-    int err = at_send_command_singleline("AT+CMUT?", "+CMUT:", &response);
+    int err = at_send_command_singleline(port, "AT+CMUT?", "+CMUT:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -258,13 +258,13 @@
 OK
 
 */
-static int req_mute_set(int state, int *cme_err)
+static int req_mute_set(ATPortType_enum port, int state, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+CMUT=%d", state);
     LOG("Set the mute command is = %s.\n", cmd);
-    int err = at_send_command(cmd, &response);
+    int err = at_send_command(port, cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -280,13 +280,13 @@
 OK
 
 */
-static int req_dtmf_set(mbtk_call_dtmf_info_t *state, int *cme_err)
+static int req_dtmf_set(ATPortType_enum port, mbtk_call_dtmf_info_t *state, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT+VTS=%c,%d", state->character, state->duration);
     LOG("Set the DTMF command is = %s.\n", cmd);
-    int err = at_send_command(cmd, &response);
+    int err = at_send_command(port, cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -315,7 +315,7 @@
             else     // Set
             {
                 char *pn = (char*)(pack->data);
-                if(req_call_start(pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_call_start(cli_info->port, pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -326,7 +326,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             break;
@@ -335,7 +335,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-               if(req_answer_call(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+               if(req_answer_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -346,7 +346,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             else     // Set
@@ -360,7 +360,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_hangup_call(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -371,7 +371,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             else     // Set
@@ -391,7 +391,7 @@
             else
             {
                 uint8 phone_id = *(pack->data);
-                if(req_hangup_a_call(phone_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_a_call(cli_info->port, phone_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -402,7 +402,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             break;
@@ -411,7 +411,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_hangup_waiting_or_background_call(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_waiting_or_background_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -422,7 +422,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             else
@@ -436,7 +436,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_hangup_foreground_resume_background_call(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_hangup_foreground_resume_background_call(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -447,7 +447,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             else
@@ -463,7 +463,7 @@
             {
                 mbtk_call_info_t reg;
                 memset(&reg, 0, sizeof(mbtk_call_info_t));
-                if(req_waitin_call(&reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_waitin_call(cli_info->port, &reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -474,7 +474,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &reg, sizeof(mbtk_call_info_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &reg, sizeof(mbtk_call_info_t));
                 }
             }
             else     // Set
@@ -489,7 +489,7 @@
             if(pack->data_len == 0 || pack->data == NULL)   // Get VoLTE state.
             {
                 int state;
-                if(req_mute_get(&state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_mute_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;
@@ -500,7 +500,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8));
                 }
             }
             else     // Set mute state.
@@ -513,7 +513,7 @@
                     break;
                 }
 
-                if(req_mute_set(on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_mute_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;
@@ -524,7 +524,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             break;
@@ -539,7 +539,7 @@
             else     // Set
             {
                 mbtk_call_dtmf_info_t *reg = (mbtk_call_dtmf_info_t *)pack->data;
-                if(req_dtmf_set(reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_dtmf_set(cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -550,7 +550,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
                 }
             }
             break;