Add Multiple AT channels supported for ril api v2

Change-Id: I53f574c85d07bd7b8e0dd15d2e596d23c8772907
diff --git a/mbtk/mbtk_rild_v2/src/ril_net.c b/mbtk/mbtk_rild_v2/src/ril_net.c
index 8aacb7c..837f1cc 100755
--- a/mbtk/mbtk_rild_v2/src/ril_net.c
+++ b/mbtk/mbtk_rild_v2/src/ril_net.c
@@ -23,7 +23,7 @@
 mbtk_cell_pack_info_t cell_info;
 
 extern ril_band_info_t band_info;
-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);
 
 /*
 AT+COPS=?
@@ -32,10 +32,10 @@
 
 OK
 */
-static int req_available_net_get(mbtk_net_info_array_t* nets, int *cme_err)
+static int req_available_net_get(ATPortType_enum port, mbtk_net_info_array_t* nets, int *cme_err)
 {
     ATResponse *response = NULL;
-    int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
+    int err = at_send_command_singleline(port, "AT+COPS=?", "+COPS:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
@@ -130,14 +130,14 @@
 OK
 
 */
-static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err)
+static int req_net_sel_mode_get(ATPortType_enum port, mbtk_net_info_t *net, int *cme_err)
 {
     //LOG("req_net_sel_mode_get() 0");
     //sleep(1);
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_ptr = NULL;
-    int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
+    int err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response);
     //LOG("req_net_sel_mode_get() 00");
     //sleep(1);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -216,7 +216,7 @@
 OK
 
 */
-static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err)
+static int req_net_sel_mode_set(ATPortType_enum port, mbtk_net_info_t* net, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[50] = {0};
@@ -233,7 +233,7 @@
         }
      }
 
-    int err = at_send_command(cmd, &response);
+    int err = at_send_command(port, cmd, &response);
 
     if (err < 0 || response->success == 0) {
         if(cme_err) {
@@ -252,7 +252,7 @@
 OK
 
 */
-static int req_band_set(mbtk_band_info_t* band, int *cme_err)
+static int req_band_set(ATPortType_enum port, mbtk_band_info_t* band, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
@@ -305,7 +305,7 @@
 
         if(band->net_pref == 0xFF) { // No change net_pref.
             int tmp_int;
-            err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
+            err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response);
             if (err < 0 || response->success == 0 || !response->p_intermediates){
                 if(cme_err) {
                     *cme_err = at_get_cme_error(response);
@@ -336,7 +336,7 @@
             sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
         }
     }
-    err = at_send_command(cmd, &response);
+    err = at_send_command(port, cmd, &response);
 
     if (err < 0 || response->success == 0){
         if(cme_err) {
@@ -417,13 +417,13 @@
     65536 ?C FDDLTE _BAND_17
     524288 ?C FDDLTE _BAND_20
 */
-static int req_band_get(mbtk_band_info_t *band, int *cme_err)
+static int req_band_get(ATPortType_enum port, mbtk_band_info_t *band, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
 
     log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
-    int err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
+    int err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -533,13 +533,13 @@
 OK
 
 */
-static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err)
+static int req_net_signal_get(ATPortType_enum port, mbtk_signal_info_t *signal, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_ptr = NULL;
     // AT+EEMOPT=1 in the first.
-    int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response);
+    int err = at_send_command_singleline(port, "AT+CSQ", "+CSQ:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -561,7 +561,7 @@
     signal->rssi = (uint8)tmp_int;
     at_response_free(response);
 
-    err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response);
+    err = at_send_command_singleline(port, "AT+CESQ", "+CESQ:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -618,7 +618,7 @@
     signal->rsrp = (uint8)tmp_int;
 
     at_response_free(response);
-    err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
+    err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -693,12 +693,12 @@
 
 
 */
-static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err)
+static int req_net_reg_get(ATPortType_enum port, mbtk_net_reg_info_t *reg, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_str = NULL;
-    int err = at_send_command("AT+CREG=3", &response);
+    int err = at_send_command(port, "AT+CREG=3", &response);
     if (err < 0 || response->success == 0){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -707,7 +707,7 @@
     }
     at_response_free(response);
 
-    err = at_send_command_multiline("AT+CREG?", "+CREG:", &response);
+    err = at_send_command_multiline(port, "AT+CREG?", "+CREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -757,7 +757,7 @@
     }
     at_response_free(response);
 
-    err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response);
+    err = at_send_command_multiline(port, "AT+CEREG?", "+CEREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err) {
             *cme_err = at_get_cme_error(response);
@@ -807,7 +807,7 @@
     }
     at_response_free(response);
 
-    err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
+    err = at_send_command_multiline(port, "AT+CIREG?", "+CIREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         reg->ims_state = (uint8)0;
         err = 0;
@@ -1039,13 +1039,13 @@
 OK
 
 */
-static int req_cell_info_get(int *cme_err)
+static int req_cell_info_get(ATPortType_enum port, int *cme_err)
 {
     ATResponse *response = NULL;
     int tmp_int;
     int buff_size = 0;
     // AT+EEMOPT=1 in the first.
-    int err = at_send_command("AT+EEMOPT=1", &response);
+    int err = at_send_command(port, "AT+EEMOPT=1", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -1056,7 +1056,7 @@
     cell_info.running = true;
     cell_info.cell_list.num = 0;
 
-    err = at_send_command_singleline("AT+EEMGINFO?", "+EEMGINFO:", &response);
+    err = at_send_command_singleline(port, "AT+EEMGINFO?", "+EEMGINFO:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -1147,7 +1147,7 @@
     return buff_size;
 }
 
-static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err)
+static int req_cell_info_set(ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
 {
     ATResponse *response = NULL;
     char cmd[500] = {0};
@@ -1160,7 +1160,7 @@
 
 	if(strlen(cmd) > 0)
 	{
-        err = at_send_command_multiline(cmd, "", &response);
+        err = at_send_command_multiline(port, cmd, "", &response);
 		if (err < 0 || response->success == 0 || !response->p_intermediates){
 			*cme_err = at_get_cme_error(response);
 			goto exit;
@@ -1202,7 +1202,7 @@
             {
                 mbtk_net_info_array_t net_array;
                 memset(&net_array, 0, sizeof(mbtk_net_info_array_t));
-                if(req_available_net_get(&net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_available_net_get(cli_info->port, &net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1213,7 +1213,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t));
                 }
             }
             else     // Set
@@ -1229,7 +1229,7 @@
             {
                 mbtk_net_info_t info;
                 memset(&info, 0, sizeof(mbtk_net_info_t));
-                if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_sel_mode_get(cli_info->port, &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;
@@ -1240,13 +1240,13 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t));
                 }
             }
             else     // Set
             {
                 mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data;
-                if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_sel_mode_set(cli_info->port, 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;
@@ -1257,7 +1257,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;
@@ -1275,7 +1275,7 @@
                     if(*(pack->data)) { // Get current bands.
                         mbtk_band_info_t band;
                         memset(&band, 0x0, sizeof(mbtk_band_info_t));
-                        if(req_band_get(&band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                        if(req_band_get(cli_info->port, &band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                         {
                             if(cme_err != MBTK_RIL_ERR_CME_NON) {
                                 err = MBTK_RIL_ERR_CME + cme_err;
@@ -1286,10 +1286,10 @@
                         }
                         else
                         {
-                            ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t));
+                            ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t));
                         }
                     } else { // Get support bands.
-                        ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support , sizeof(mbtk_band_info_t));
+                        ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support , sizeof(mbtk_band_info_t));
                     }
                 } else { // Set current bands.
                     mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
@@ -1300,7 +1300,7 @@
                         break;
                     }
 
-                    if(req_band_set(band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                    if(req_band_set(cli_info->port, band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_RIL_ERR_CME_NON) {
                             err = MBTK_RIL_ERR_CME + cme_err;
@@ -1311,7 +1311,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);
                     }
                 }
             }
@@ -1323,7 +1323,7 @@
             {
                 mbtk_signal_info_t signal;
                 memset(&signal, 0, sizeof(mbtk_signal_info_t));
-                if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_signal_get(cli_info->port, &signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1334,7 +1334,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t));
                 }
             }
             else     // Set
@@ -1350,7 +1350,7 @@
             {
                 mbtk_net_reg_info_t net_reg;
                 memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t));
-                if(req_net_reg_get(&net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_net_reg_get(cli_info->port, &net_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;
@@ -1361,7 +1361,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t));
                 }
             }
             else     // Set
@@ -1375,7 +1375,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)   // Get net cell.
             {
-                if(req_cell_info_get(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cell_info_get(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;
@@ -1387,7 +1387,7 @@
                 else
                 {
                     LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num);
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &cell_info.cell_list, sizeof(mbtk_cell_info_array_t));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cell_info.cell_list, sizeof(mbtk_cell_info_array_t));
                 }
             }
             else     // Lock cell
@@ -1395,7 +1395,7 @@
                 char *mem = (char*)(pack->data);
                 int len = pack->data_len;
                 char reg[100] = {0};
-                if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_cell_info_set(cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1405,7 +1405,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
+                    ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
                 }
             }
             break;