Add Multiple AT channels supported for ril api v2

Change-Id: I53f574c85d07bd7b8e0dd15d2e596d23c8772907
diff --git a/mbtk/mbtk_rild_v2/src/ril_ecall.c b/mbtk/mbtk_rild_v2/src/ril_ecall.c
index 3c61159..60b64c5 100755
--- a/mbtk/mbtk_rild_v2/src/ril_ecall.c
+++ b/mbtk/mbtk_rild_v2/src/ril_ecall.c
@@ -19,9 +19,9 @@
 
 static mbtk_ecall_mode_type_enum ecall_mode = MBTK_ECALL_MODE_TYPE_EU;
 
-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);
 
-static int cfg_ecalldata_get(mbtk_ecall_cfg_item_enum type, uint32 *value, int *cme_err)
+static int cfg_ecalldata_get(ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 *value, int *cme_err)
 {
     ATResponse *response = NULL;
 //    char *tmp_ptr = NULL;
@@ -30,7 +30,7 @@
     int err = 0;
 
     snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d", type);
-    err = at_send_command_singleline(cmd, "*ECALLDATA:", &response);
+    err = at_send_command_singleline(port, cmd, "*ECALLDATA:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -70,14 +70,14 @@
     return err;
 }
 
-static int cfg_ecalldata_set(mbtk_ecall_cfg_item_enum type, uint32 value, int *cme_err)
+static int cfg_ecalldata_set(ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 value, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     int err = 0;
 
     snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d,%d", type, value / 20);
-    err = at_send_command(cmd, &response);
+    err = at_send_command(port, cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -89,14 +89,14 @@
     return err;
 }
 
-static int cfg_ecalltimer_set(const char* type, uint32 value, int *cme_err)
+static int cfg_ecalltimer_set(ATPortType_enum port, const char* type, uint32 value, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     int err = 0;
 
     snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=%s,%d", type, value);
-    err = at_send_command(cmd, &response);
+    err = at_send_command(port, cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -108,12 +108,12 @@
     return err;
 }
 
-static int req_ecall_msdcfg(mbtk_ecall_msd_cfg_info_t *cfg_info, int *cme_err)
+static int req_ecall_msdcfg(ATPortType_enum port, mbtk_ecall_msd_cfg_info_t *cfg_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT*ECALLMSDCFG=%d,\"%s\",0", cfg_info->item_type, cfg_info->data);
-    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;
@@ -124,10 +124,10 @@
     return err;
 }
 
-static int req_ecall_msdgen(int *cme_err)
+static int req_ecall_msdgen(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command("AT*ECALLMSDGEN", &response);
+    int err = at_send_command(port, "AT*ECALLMSDGEN", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -138,12 +138,12 @@
     return err;
 }
 
-static int req_ecall_msd_set(const uint8 *msd, int *cme_err)
+static int req_ecall_msd_set(ATPortType_enum port, const uint8 *msd, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT*ECALLMSD=\"%s\"", msd);
-    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;
@@ -154,11 +154,11 @@
     return err;
 }
 
-static int req_ecall_msd_get(uint8 *msd, int *cme_err)
+static int req_ecall_msd_get(ATPortType_enum port, uint8 *msd, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline("AT*ECALLMSD?", "*ECALLMSD:", &response);
+    int err = at_send_command_singleline(port, "AT*ECALLMSD?", "*ECALLMSD:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -188,10 +188,10 @@
     return err;
 }
 
-static int req_ecall_push(int *cme_err)
+static int req_ecall_push(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command("AT*ECALLPUSH", &response);
+    int err = at_send_command(port, "AT*ECALLPUSH", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -209,12 +209,12 @@
 OK
 
 */
-static int req_ecall_only_get(mbtk_ecall_only_info_t *only_info, int *cme_err)
+static int req_ecall_only_get(ATPortType_enum port, mbtk_ecall_only_info_t *only_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
     int tmp_int;
-    int err = at_send_command_singleline("AT*ECALLONLY?", "*ECALLONLY:", &response);
+    int err = at_send_command_singleline(port, "AT*ECALLONLY?", "*ECALLONLY:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -275,12 +275,12 @@
 OK
 
 */
-static int req_ecall_only_set(const mbtk_ecall_only_info_t *only_info, int *cme_err)
+static int req_ecall_only_set(ATPortType_enum port, const mbtk_ecall_only_info_t *only_info, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT*ECALLONLY=%d,%s,%s", only_info->active,only_info->test_num,only_info->reconfig_num);
-    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;
@@ -295,12 +295,12 @@
 AT*ECALLREG=0/1
 
 */
-static int req_ecall_reg_set(uint8 reg, int *cme_err)
+static int req_ecall_reg_set(ATPortType_enum port, uint8 reg, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[30] = {0};
     sprintf(cmd, "AT*ECALLREG=%d", reg);
-    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;
@@ -318,11 +318,11 @@
 OK
 
 */
-static int req_ecall_dial_state_get(mbtk_ecall_dial_type_enum *type, int *cme_err)
+static int req_ecall_dial_state_get(ATPortType_enum port, mbtk_ecall_dial_type_enum *type, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
-    int err = at_send_command_singleline("AT+CECALL?", "+CECALL:", &response);
+    int err = at_send_command_singleline(port, "AT+CECALL?", "+CECALL:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -353,12 +353,12 @@
 AT+CECALL=<ecalltype>
 OK
 */
-static int req_ecall_dial_start(mbtk_ecall_dial_type_enum type, int *cme_err)
+static int req_ecall_dial_start(ATPortType_enum port, mbtk_ecall_dial_type_enum type, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
     sprintf(cmd, "AT+CECALL=%d", type);
-    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;
@@ -377,11 +377,11 @@
 OK
 
 */
-static int req_ecall_mode_get(mbtk_ecall_mode_type_enum *mode, int *cme_err)
+static int req_ecall_mode_get(ATPortType_enum port, mbtk_ecall_mode_type_enum *mode, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline("AT*ECALLMODE?", "*ECALLMODE:", &response);
+    int err = at_send_command_singleline(port, "AT*ECALLMODE?", "*ECALLMODE:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -424,7 +424,7 @@
 OK
 
 */
-static int req_ecall_mode_set(mbtk_ecall_mode_type_enum mode, int *cme_err)
+static int req_ecall_mode_set(ATPortType_enum port, mbtk_ecall_mode_type_enum mode, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[1024] = {0};
@@ -433,7 +433,7 @@
     } else {
         sprintf(cmd, "AT*ECALLMODE=\"ERA\"");
     }
-    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;
@@ -458,7 +458,7 @@
 OK
 
 */
-static int req_ecall_cfg_get(uint32 type, mbtk_ecall_cfg_info_t *cfg, int *cme_err)
+static int req_ecall_cfg_get(ATPortType_enum port, uint32 type, mbtk_ecall_cfg_info_t *cfg, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
@@ -468,7 +468,7 @@
     cfg->type = type;
 
     if(type & MBTK_ECALL_CFG_T3) {
-        if(cfg_ecalldata_get(MBTK_ECALL_CFG_ITEM_T3, &(cfg->data[MBTK_ECALL_CFG_ITEM_T3]), cme_err)
+        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T3, &(cfg->data[MBTK_ECALL_CFG_ITEM_T3]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -477,7 +477,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_T5) {
-        if(cfg_ecalldata_get(MBTK_ECALL_CFG_ITEM_T5, &(cfg->data[MBTK_ECALL_CFG_ITEM_T5]), cme_err)
+        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T5, &(cfg->data[MBTK_ECALL_CFG_ITEM_T5]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -486,7 +486,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_T6) {
-        if(cfg_ecalldata_get(MBTK_ECALL_CFG_ITEM_T6, &(cfg->data[MBTK_ECALL_CFG_ITEM_T6]), cme_err)
+        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T6, &(cfg->data[MBTK_ECALL_CFG_ITEM_T6]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -495,7 +495,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_T7) {
-        if(cfg_ecalldata_get(MBTK_ECALL_CFG_ITEM_T7, &(cfg->data[MBTK_ECALL_CFG_ITEM_T7]), cme_err)
+        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_T7, &(cfg->data[MBTK_ECALL_CFG_ITEM_T7]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -504,7 +504,7 @@
     }
 
     if(type & MBTK_ECALL_CFG_TH) {
-        if(cfg_ecalldata_get(MBTK_ECALL_CFG_ITEM_TH, &(cfg->data[MBTK_ECALL_CFG_ITEM_TH]), cme_err)
+        if(cfg_ecalldata_get(port, MBTK_ECALL_CFG_ITEM_TH, &(cfg->data[MBTK_ECALL_CFG_ITEM_TH]), cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -515,7 +515,7 @@
     if(type & (MBTK_ECALL_CFG_TIMER_CALLBACK | MBTK_ECALL_CFG_TIMER_CLEARDOWN | MBTK_ECALL_CFG_TIMER_DEREG
                 | MBTK_ECALL_CFG_TIMER_DIAL | MBTK_ECALL_CFG_TIMER_REDIAL | MBTK_ECALL_CFG_TIMER_SMS
                 | MBTK_ECALL_CFG_REDIALCNT | MBTK_ECALL_CFG_SMSPROCESS | MBTK_ECALL_CFG_SMSMSDCNT)) {
-        err = at_send_command_singleline("AT*ECALLTIMER?", "*ECALLTIMER:", &response);
+        err = at_send_command_singleline(port, "AT*ECALLTIMER?", "*ECALLTIMER:", &response);
         if (err < 0 || response->success == 0 || !response->p_intermediates){
             *cme_err = at_get_cme_error(response);
             goto exit;
@@ -632,7 +632,7 @@
 AT*ECALLTIMER=dereg,300
 OK
 */
-static int req_ecall_cfg_set(const mbtk_ecall_cfg_info_t *cfg_info, int *cme_err)
+static int req_ecall_cfg_set(ATPortType_enum port, const mbtk_ecall_cfg_info_t *cfg_info, int *cme_err)
 {
     int err = 0;
     if(ecall_mode == MBTK_ECALL_MODE_TYPE_EU) {
@@ -647,7 +647,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T3) {
-        if(cfg_ecalldata_set(MBTK_ECALL_CFG_ITEM_T3, cfg_info->data[MBTK_ECALL_CFG_ITEM_T3], cme_err)
+        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T3, cfg_info->data[MBTK_ECALL_CFG_ITEM_T3], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -655,7 +655,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T5) {
-        if(cfg_ecalldata_set(MBTK_ECALL_CFG_ITEM_T5, cfg_info->data[MBTK_ECALL_CFG_ITEM_T5], cme_err)
+        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T5, cfg_info->data[MBTK_ECALL_CFG_ITEM_T5], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -663,7 +663,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T6) {
-        if(cfg_ecalldata_set(MBTK_ECALL_CFG_ITEM_T6, cfg_info->data[MBTK_ECALL_CFG_ITEM_T6], cme_err)
+        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T6, cfg_info->data[MBTK_ECALL_CFG_ITEM_T6], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -671,7 +671,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_T7) {
-        if(cfg_ecalldata_set(MBTK_ECALL_CFG_ITEM_T7, cfg_info->data[MBTK_ECALL_CFG_ITEM_T7], cme_err)
+        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_T7, cfg_info->data[MBTK_ECALL_CFG_ITEM_T7], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -679,7 +679,7 @@
     }
 
     if(cfg_info->type & MBTK_ECALL_CFG_TH) {
-        if(cfg_ecalldata_set(MBTK_ECALL_CFG_ITEM_TH, cfg_info->data[MBTK_ECALL_CFG_ITEM_TH], cme_err)
+        if(cfg_ecalldata_set(port, MBTK_ECALL_CFG_ITEM_TH, cfg_info->data[MBTK_ECALL_CFG_ITEM_TH], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON)
         {
             goto exit;
@@ -688,63 +688,63 @@
 
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_CALLBACK)
     {
-        if(cfg_ecalltimer_set("callback", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] / 1000, cme_err)
+        if(cfg_ecalltimer_set(port, "callback", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_TIMER_CLEARDOWN)
     {
-        if(cfg_ecalltimer_set("cleardown", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] / 1000, cme_err)
+        if(cfg_ecalltimer_set(port, "cleardown", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_TIMER_DEREG)
     {
-        if(cfg_ecalltimer_set("dereg", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] / 1000, cme_err)
+        if(cfg_ecalltimer_set(port, "dereg", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_TIMER_DIAL)
     {
-        if(cfg_ecalltimer_set("dial", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] / 1000, cme_err)
+        if(cfg_ecalltimer_set(port, "dial", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_TIMER_REDIAL)
     {
-        if(cfg_ecalltimer_set("redialtmr", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] / 1000, cme_err)
+        if(cfg_ecalltimer_set(port, "redialtmr", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_TIMER_SMS)
     {
-        if(cfg_ecalltimer_set("sms", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] / 1000, cme_err)
+        if(cfg_ecalltimer_set(port, "sms", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] / 1000, cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_REDIALCNT)
     {
-        if(cfg_ecalltimer_set("redialcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_REDIALCNT], cme_err)
+        if(cfg_ecalltimer_set(port, "redialcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_REDIALCNT], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_SMSPROCESS)
     {
-        if(cfg_ecalltimer_set("smsprocess", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSPROCESS], cme_err)
+        if(cfg_ecalltimer_set(port, "smsprocess", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSPROCESS], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
     }
     if(cfg_info->type & MBTK_ECALL_CFG_ITEM_SMSMSDCNT)
     {
-        if(cfg_ecalltimer_set("smsmsdcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSMSDCNT], cme_err)
+        if(cfg_ecalltimer_set(port, "smsmsdcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSMSDCNT], cme_err)
             || *cme_err != MBTK_RIL_ERR_CME_NON) {
             goto exit;
         }
@@ -759,12 +759,12 @@
 OK
 
 */
-static int req_ecall_spkmute_set(int mute, int *cme_err)
+static int req_ecall_spkmute_set(ATPortType_enum port, int mute, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT*ECALLMUTESPK=%d", mute);
-    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;
@@ -783,11 +783,11 @@
 OK
 
 */
-static int req_ecall_sms_num_get(uint8 *number, int *cme_err)
+static int req_ecall_sms_num_get(ATPortType_enum port, uint8 *number, int *cme_err)
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline("AT*ECALLSMSNUM?", "*ECALLSMSNUM:", &response);
+    int err = at_send_command_singleline(port, "AT*ECALLSMSNUM?", "*ECALLSMSNUM:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
@@ -822,12 +822,12 @@
 OK
 
 */
-static int req_ecall_sms_num_set(const uint8 *number, int *cme_err)
+static int req_ecall_sms_num_set(ATPortType_enum port, const uint8 *number, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT*ECALLSMSNUM=%s", 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;
@@ -843,12 +843,12 @@
 OK
 
 */
-static int req_ecall_gain_set(mbtk_ecall_gain_info_t *gain, int *cme_err)
+static int req_ecall_gain_set(ATPortType_enum port, mbtk_ecall_gain_info_t *gain, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "AT*AUDGAIN=%d,%d", gain->gain, gain->mode);
-    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;
@@ -877,7 +877,7 @@
             else     // Set
             {
                 mbtk_ecall_msd_cfg_info_t *cfg_info = (mbtk_ecall_msd_cfg_info_t*)(pack->data);
-                if(req_ecall_msdcfg(cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msdcfg(cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -888,7 +888,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;
@@ -897,7 +897,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_msdgen(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msdgen(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;
@@ -908,7 +908,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
@@ -923,7 +923,7 @@
             memset(msd, 0, sizeof(msd));
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_msd_get(msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msd_get(cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -934,13 +934,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen((char*)msd));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen((char*)msd));
                 }
             }
             else     // Set
             {
                 memcpy(msd, pack->data, pack->data_len);
-                if(req_ecall_msd_set(msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_msd_set(cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -951,7 +951,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;
@@ -960,7 +960,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_push(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_push(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;
@@ -971,7 +971,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
@@ -986,7 +986,7 @@
             {
                 mbtk_ecall_only_info_t only_info;
                 memset(&only_info, 0, sizeof(mbtk_ecall_only_info_t));
-                if(req_ecall_only_get(&only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_only_get(cli_info->port, &only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -997,13 +997,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &only_info, sizeof(mbtk_ecall_only_info_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &only_info, sizeof(mbtk_ecall_only_info_t));
                 }
             }
             else     // Set
             {
                 mbtk_ecall_only_info_t *only_info = (mbtk_ecall_only_info_t*)(pack->data);
-                if(req_ecall_only_set(only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_only_set(cli_info->port, only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1014,7 +1014,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;
@@ -1028,7 +1028,7 @@
             else
             {
                 uint8 reg = pack->data[0];
-                if(req_ecall_reg_set(reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_reg_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;
@@ -1039,7 +1039,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;
@@ -1049,7 +1049,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 mbtk_ecall_dial_type_enum type;
-                if(req_ecall_dial_state_get(&type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_dial_state_get(cli_info->port, &type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1060,13 +1060,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &type, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &type, sizeof(uint8));
                 }
             }
             else
             {
                 mbtk_ecall_dial_type_enum type = (mbtk_ecall_dial_type_enum)pack->data[0];
-                if(req_ecall_dial_start(type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_dial_start(cli_info->port, type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1077,7 +1077,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;
@@ -1087,7 +1087,7 @@
             if(pack->data_len == 0 || pack->data == NULL)
             {
                 mbtk_ecall_mode_type_enum mode;
-                if(req_ecall_mode_get(&mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_mode_get(cli_info->port, &mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1098,13 +1098,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &mode, sizeof(uint8));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &mode, sizeof(uint8));
                 }
             }
             else
             {
                 mbtk_ecall_mode_type_enum mode = (mbtk_ecall_mode_type_enum)pack->data[0];
-                if(req_ecall_mode_set(mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_mode_set(cli_info->port, mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1115,7 +1115,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;
@@ -1130,7 +1130,7 @@
             {
                 if(pack->data_len == sizeof(mbtk_ecall_cfg_info_t)) { // Set
                     mbtk_ecall_cfg_info_t *cfg_info = (mbtk_ecall_cfg_info_t*)pack->data;
-                    if(req_ecall_cfg_set(cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_ecall_cfg_set(cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -1141,13 +1141,13 @@
                     }
                     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 { // Get
                     mbtk_ecall_cfg_info_t cfg_info;
                     memset(&cfg_info, 0, sizeof(mbtk_ecall_cfg_info_t));
                     uint32 *type = (uint32*)(pack->data);
-                    if(req_ecall_cfg_get(*type, &cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_ecall_cfg_get(cli_info->port, *type, &cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -1158,7 +1158,7 @@
                     }
                     else
                     {
-                        ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &cfg_info, sizeof(mbtk_ecall_cfg_info_t));
+                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cfg_info, sizeof(mbtk_ecall_cfg_info_t));
                     }
                 }
             }
@@ -1170,7 +1170,7 @@
             memset(number, 0, sizeof(number));
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_sms_num_get(number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_sms_num_get(cli_info->port, number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1181,13 +1181,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, number, strlen((char*)number));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, number, strlen((char*)number));
                 }
             }
             else     // Set
             {
                 memcpy(number, pack->data, pack->data_len);
-                if(req_ecall_sms_num_set(number, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_sms_num_set(cli_info->port, number, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1198,7 +1198,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;
@@ -1219,7 +1219,7 @@
                     break;
                 }
 
-                if(req_ecall_spkmute_set(mute, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_spkmute_set(cli_info->port, mute, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1230,7 +1230,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;
@@ -1244,7 +1244,7 @@
             else     // Set
             {
                 mbtk_ecall_gain_info_t *gain_info = (mbtk_ecall_gain_info_t *)pack->data;
-                if(req_ecall_gain_set(gain_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_gain_set(cli_info->port, gain_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1255,7 +1255,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;