[Feature][ZXW-41] merged 0601 version

Change-Id: I667af6bb09d65581d455b73f8984c160b2c67ad8
diff --git a/ap/lib/libvsim/ght_vsim_api.c b/ap/lib/libvsim/ght_vsim_api.c
index 12a5afa..11b7bd1 100755
--- a/ap/lib/libvsim/ght_vsim_api.c
+++ b/ap/lib/libvsim/ght_vsim_api.c
@@ -47,7 +47,7 @@
 

 extern int32_t zte_GetRegInfobySimid(RegInfo_t *reg_info, uint8_t nSimID);

 

-extern int32_t zte_GetCellInfobySimId(CellInfo_t *pcellinfo, uint8_t nSimID);

+extern int32_t zte_GetCellInfobySimId(uint8_t nSimID);

 

 extern int32_t zte_GetNetInfobySimId(NetInfo_t *pNetInfo, uint8_t nSimID);

 

@@ -340,9 +340,9 @@
 **

 ***********************************************************/

 

-int32_t fibo_get_CellInfo_by_simid(CellInfo_t *pcellinfo, uint8_t nSimID)

+int32_t fibo_get_CellInfo_by_simid(uint8_t nSimID)

 {

-    return zte_GetCellInfobySimId(pcellinfo, nSimID);

+    return zte_GetCellInfobySimId(nSimID);

 }

 

 

diff --git a/ap/lib/libvsim/ght_vsim_api.h b/ap/lib/libvsim/ght_vsim_api.h
index b381421..5fd8568 100755
--- a/ap/lib/libvsim/ght_vsim_api.h
+++ b/ap/lib/libvsim/ght_vsim_api.h
@@ -48,10 +48,8 @@
 

 typedef enum {

     E_NW_STATUS_SRV_NONE = 0,

-    E_NW_STATUS_CURRENT_SERVING = 1,

-    E_NW_STATUS_SRV_LIMITED = 2,

-    E_NW_STATUS_SRV_AVAILABLE = 3,

-    E_NW_STATUS_SRV_FORBIDDEN = 4,

+    E_NW_STATUS_SRV_LIMITED = 1,

+    E_NW_STATUS_SRV_AVAILABLE = 2,

 }e_nw_srv_status_t;

 

 

@@ -59,6 +57,7 @@
 {

 	uint32_t tac;

 	uint32_t cell_id;

+	uint32_t roamingFlag; ///< 1:roaming,0:non roaming

 }lte_scell_info_t;

 

 typedef struct

@@ -83,15 +82,14 @@
 	uint32_t tac;

 	uint32_t cell_id;

     uint16_t bandwidth;

-    int16_t  rxlev;

+    uint16_t pcid;//int16_t  rxlev;

     uint32_t arfcn;

-    uint16_t pcid;

 }base_cell_info_t;//Hex format

 

 

 typedef struct

 {

-    uint8_t  roamingFlag; ///< 1:roaming,0:non roaming

+    uint16_t  roamingFlag; ///< 1:roaming,0:non roaming

     int16_t  rsrp;

     int16_t  rsrq;

     uint16_t SINR;

@@ -227,6 +225,7 @@
   E_RF_RESOURCE_CALLBACK_EVENT = 0x00,   /**< É䯵×ÊÔ´Çл». */

   E_NW_ATTACH_COMMPLETE_EVENT  = 0x32,   /**< ×¢ÍøÍê³É. */

   E_DATA_PDN_ACT_SUCC_EVENT = 0x64,      /**< PDN¼¤»îÍê³É ,ind_dataÖÐЯ´øZGIPDNS:µØÖ·ÐÅÏ¢  */

+  E_GET_CELLINFO_BY_SIMID_EVENT  = 0x65,	 /**< É¨ÍøÍê³É. */

 }E_MODEM_EVENT_ID;

 

 typedef enum

@@ -470,7 +469,7 @@
 **

 ***********************************************************/

 

-extern int32_t fibo_get_CellInfo_by_simid(CellInfo_t *pcellinfo, uint8_t nSimID);

+extern int32_t fibo_get_CellInfo_by_simid(uint8_t nSimID);

 

 /**********************************************************

 ** Function Name: fibo_get_NetInfo_by_simid

diff --git a/ap/lib/libvsim/libvsim.c b/ap/lib/libvsim/libvsim.c
index e0f275b..210e3e6 100755
--- a/ap/lib/libvsim/libvsim.c
+++ b/ap/lib/libvsim/libvsim.c
@@ -9,6 +9,7 @@
 
 #define VSIM_MAX_MSG_LEN	1024
 #define vsim_debug_printf printf 
+uint8_t bWithVsimApp = 1; //  0 ²»´øÓ¦ÓÃ    1 ´øÓ¦ÓÃ
 
 enum{
 	MSG_CMD_VSIM_GET_SWITCH = 1,//ATÔÚÄÄÒ»´ý·¢
@@ -23,6 +24,8 @@
 	MSG_CMD_VSIM_APDU,
 	MSG_CMD_VSIM_GET_FLOW_STATISTIC,//»ñÈ¡µ±Ç°Á÷Á¿Í³¼Æ
 	MSG_CMD_VSIM_RESET_FLOW_STATISTIC,//ÖØÖõ±Ç°Á÷Á¿Í³¼Æ
+	MSG_CMD_VSIM_GET_SCANING,//Õýscan,´Ëʱ½ûÖ¹TAU
+	MSG_CMD_VSIM_SET_SCANING,
 	MSG_CMD_VSIM_MAX,
 };
 
@@ -32,6 +35,7 @@
     unsigned char aucDataBuf[VSIM_MAX_MSG_LEN];  /* ÏûÏ¢ÕýÎÄ */  
 } VSIM_MSG_BUF;
 
+pthread_mutex_t vsim_at_mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_t read_thread_tid;
 pthread_t msg_thread_tid;
 int g_read_thread_state = -1;
@@ -40,9 +44,11 @@
 SoftSim_COMMAND g_softsim_apdu_process_cb;
 zte_mdm_event_ind_callback g_vsim_event_ind_cb;
 unsigned char g_vsim_slot[2];
+int g_sim_status[2] = {-1,-1};
 
 int32_t zte_mdm_event_ind_cb(E_MODEM_EVENT_ID event_id, void *ind_data, uint32_t  ind_data_len)
 {
+	printf("##vsim## [%s] event_id=%d len=%d \n", __FUNCTION__, event_id, ind_data_len);
 	return 0;
 }
 int zte_vsim_ind_cb(uint8_t *apdu_req, uint16_t apdu_req_len,uint8_t *apdu_rsp, uint16_t *apdu_rsp_len, uint8_t slot)
@@ -59,13 +65,23 @@
 	return 0;
 }
 
+
+static int vsim_send_at(char *req_at, char *info_fmt, void **pval)
+{
+	int ret;
+	pthread_mutex_lock(&vsim_at_mutex);
+	ret = get_modem_info(req_at,info_fmt,pval);
+	pthread_mutex_unlock(&vsim_at_mutex);
+	return ret;
+}
+
 static int vsim_card_switch_req(unsigned char sim)
 {
 	int ret = 0;
 	if(sim)
-		ret = get_modem_info("AT+ZCARDSWITCHREQ=0,1\r\n", NULL, NULL);
+		ret = vsim_send_at("AT+ZCARDSWITCHREQ=0,1\r\n", NULL, NULL);
 	else
-		ret = get_modem_info("AT+ZCARDSWITCHREQ=1,0\r\n", NULL, NULL);
+		ret = vsim_send_at("AT+ZCARDSWITCHREQ=1,0\r\n", NULL, NULL);
 	if(ret != 0){
 		printf("##vsim## [%s] sim=%d ret=%d err\n", __FUNCTION__, sim, ret);
 	}
@@ -82,7 +98,11 @@
 	msg_in.usMsgCmd = msg;
 	msg_in.aucDataBuf[0] = param;
 	vsim_debug_printf("##vsim## [%s] msg=%d param=%d start\n", __FUNCTION__, msg, param);
+	if(msg == MSG_CMD_VSIM_SET_SWITCH)
+		pthread_mutex_lock(&vsim_at_mutex);
 	ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
+	if(msg == MSG_CMD_VSIM_SET_SWITCH)
+		pthread_mutex_unlock(&vsim_at_mutex);
 	if(ret == 0){
 		printf("##vsim## [%s] msg=%d param=%d err\n", __FUNCTION__, msg, param);
 	}
@@ -133,6 +153,7 @@
 		VSIM_MSG_BUF msg_out = {0};
 		int ret = 0;
 		int is_auth = 0;
+		int is_slot1 = 0;
 		vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
 		ret = syscall(__NR_vsim_read,(unsigned char *)&msg_out);
 		if(ret == 0){
@@ -143,8 +164,9 @@
 			printf("##vsim## read msg=%d ret=%d err\n", msg_out.usMsgCmd, ret);
 		}
 		is_auth = msg_out.aucDataBuf[1];
+		is_slot1 = msg_out.aucDataBuf[0];
 		//ÇÐʵÌ忨
-		if(is_auth){
+		if(is_auth && g_vsim_slot[msg_out.aucDataBuf[0]] && is_slot1){
 			printf("##vsim## vsim_apdu_auth standby=%d\n", vsim_get(MSG_CMD_VSIM_GET_STANDBY));
 			vsim_set(MSG_CMD_VSIM_SET_AUTHING,1);
 			usleep(20000);//±£»¤´ëÊ©,ÑÓ³Ù20ºÁÃëÔÙÏ·¢Çп¨£¬±£Ö¤¼øÈ¨ÇëÇóµÄrlc ack»Ø¸´¸øÍø²à
@@ -162,7 +184,7 @@
 		}
 		vsim_debug_printf("##vsim## g_vsim_apdu_process_cb ret=0x%x len=%d\n", ret, msg_in.usDataLen);
 		//ÇÐÐéÄ⿨
-		if(is_auth){
+		if(is_auth && g_vsim_slot[msg_out.aucDataBuf[0]] && is_slot1){
 			vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Ó¦¸Ãδ½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
 			vsim_card_switch_req(1);
 			vsim_set(MSG_CMD_VSIM_SET_AUTHING,0);
@@ -197,7 +219,7 @@
 			case MSG_CMD_ZCARDSWITCHIND_IND:
 				//callback todo
 				SwitchStat = stMsg.aucDataBuf[1];
-				if(vsim_get(MSG_CMD_VSIM_GET_AUTHING)){
+				if(vsim_get(MSG_CMD_VSIM_GET_AUTHING) || vsim_get(MSG_CMD_VSIM_GET_SCANING)){
 					printf("##vsim## ZCARDSWITCHIND AUTHING abort\n");
 					if(SwitchStat)
 						vsim_set(MSG_CMD_VSIM_SET_TAUING,0);
@@ -213,8 +235,64 @@
 				}
 				break;
 			case MSG_CMD_CREG_IND:
-				if(vsim_get(MSG_CMD_VSIM_GET_STANDBY) == 1){
-				//callback todo
+				{
+					uint8_t nSimID = vsim_get(MSG_CMD_VSIM_GET_STANDBY);
+					if(nSimID == vsim_get_cardstat_fromps())
+						g_vsim_event_ind_cb(E_NW_ATTACH_COMMPLETE_EVENT, nSimID, 1);
+				}
+				break;
+			case MSG_CMD_ZSCISCAN_IND:
+				{
+					uint8_t nSimID = vsim_get(MSG_CMD_VSIM_GET_SCANING);
+					RegInfo_t reg_info = {0};
+					lte_cellinfo_t cell_info = {0};
+					lte_Scell_t cell[20] = {0};
+					lte_Scell_t cell_order[20] = {0};
+					int reg_ret = 0;
+					int i = 0;
+					int j = 0;
+					memcpy(cell, stMsg.aucDataBuf, sizeof(lte_Scell_t)*20);
+					if(nSimID != 0){
+						nSimID--;
+						reg_ret = zte_GetRegInfobySimid(&reg_info, nSimID);
+						vsim_set(MSG_CMD_VSIM_SET_SCANING,0);
+						for(i = 0; i < 20; i++){
+							for(j = 0; j < 20; j++){
+								if((cell_order[j].base_Scell_info.mcc == 0 && cell_order[j].base_Scell_info.mnc == 0)
+								||(cell_order[j].base_Scell_info.mcc == cell[i].base_Scell_info.mcc 
+									&& cell_order[j].base_Scell_info.mnc == cell[i].base_Scell_info.mnc 
+									&& cell_order[j].netMode == cell[i].netMode)){
+									if(cell[i].rsrp > cell_order[j].rsrp)
+										memcpy(&cell_order[j], &cell[i], sizeof(lte_Scell_t));
+								}
+							}
+							if(reg_ret == 0 && cell[i].base_Scell_info.cell_id == reg_info.lte_scell_info.cell_id){
+								memcpy(&cell_info.lteScell, &cell[i], sizeof(lte_Scell_t));
+								cell_info.lteScell.roamingFlag = reg_info.lte_scell_info.roamingFlag;
+							}
+						}
+						for(i = 0; i < 20; i++){
+							for(j = 0; j < 6; j++){
+								if(cell_info.lteNcell[j].base_Ncell_info.mcc == 0 && cell_info.lteNcell[j].base_Ncell_info.mnc == 0 
+									&& (cell_order[i].base_Scell_info.mcc != 0 || cell_order[i].base_Scell_info.mnc != 0)){
+									memcpy(&cell_info.lteNcell[j].base_Ncell_info, &cell_order[i].base_Scell_info, sizeof(base_cell_info_t));
+									cell_info.lteNcell[j].rsrp = cell_order[i].rsrp;
+									cell_info.lteNcell[j].rsrq = cell_order[i].rsrq;
+									cell_info.lteNcell[j].netMode = cell_order[i].netMode;
+									cell_info.lteNcellNum++;
+								}
+								if(cell_info.lteNcellNum == 6){
+									if(cell_order[i].rsrp > cell_info.lteNcell[j].rsrp){
+										memcpy(&cell_info.lteNcell[j].base_Ncell_info, &cell_order[i].base_Scell_info, sizeof(base_cell_info_t));
+										cell_info.lteNcell[j].rsrp = cell_order[i].rsrp;
+										cell_info.lteNcell[j].rsrq = cell_order[i].rsrq;
+										cell_info.lteNcell[j].netMode = cell_order[i].netMode;
+									}
+								}
+							}
+						}
+						g_vsim_event_ind_cb(E_GET_CELLINFO_BY_SIMID_EVENT, &cell_info, sizeof(cell_info));
+					}
 				}
 				break;
 			case MSG_CMD_VSIMDEBUG_IND:
@@ -222,10 +300,10 @@
 					char imei[]="862769025435956";
 					fibo_set_IMEI_by_simid(imei,sizeof(imei),1);
 					fibo_mdm_event_regist(zte_mdm_event_ind_cb);
-					vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);
+					vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
 					vsim_card_switch_req(1);
 					vsim_set(MSG_CMD_VSIM_SET_SWITCH,1);
-					get_modem_info("AT+CFUN=1\r\n", NULL, NULL);
+					vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
 					g_vsim_slot[1] = 1;
 				}
 				if(stMsg.aucDataBuf[0] == 2){
@@ -243,6 +321,26 @@
 				if(stMsg.aucDataBuf[0] == 21){
 					zte_SetGTDUALSIM(1);
 				}
+				if(stMsg.aucDataBuf[0] == 30){
+					bWithVsimApp = 0;
+				    fibo_SoftSim_init(zte_vsim_ind_cb,0);
+				}
+				if(stMsg.aucDataBuf[0] == 40){
+					fibo_SoftSim_close(zte_vsim_ind_cb,0);
+				}
+				if(stMsg.aucDataBuf[0] == 31){
+					bWithVsimApp = 0;
+					fibo_SoftSim_init(zte_vsim_ind_cb,1);
+				}
+				if(stMsg.aucDataBuf[0] == 41){
+					fibo_SoftSim_close(zte_vsim_ind_cb,1);
+				}
+				if(stMsg.aucDataBuf[0] == 50){
+					fibo_get_CellInfo_by_simid(0);
+				}
+				if(stMsg.aucDataBuf[0] == 51){
+					fibo_get_CellInfo_by_simid(1);
+				}
 				break;
 			default:
 				printf("##vsim## rcv_msg err msgid 0x%x\n",stMsg.usMsgCmd);
@@ -277,16 +375,17 @@
 		return -1;
 	}
 	g_vsim_slot[1] = 1;
+	g_sim_status[1] = -1;
 	sc_cfg_set("vsim_stat","1");
 	vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
 	vsim_card_switch_req(1);
 	vsim_set(MSG_CMD_VSIM_SET_SWITCH,1);
-	get_modem_info("AT+ZCARDSWITCH=1,1\r\n", NULL, NULL);
-	get_modem_info("AT+CFUN=1\r\n", NULL, NULL);
+	vsim_send_at("AT+ZCARDSWITCH=1,1\r\n", NULL, NULL);
+	vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
 	return 0;
 }
 
-int32_t zte_atSoftSimInit(SoftSim_COMMAND softssim_apdu_process_fn, uint8_t nSimID)
+int32_t zte_atSoftSimInit(SoftSim_COMMAND softssim_apdu_process_fn,  uint8_t nSimID)
 {
 	char stat[4] = {0};
 	
@@ -298,14 +397,22 @@
 		return -1;
 	}
 	g_vsim_slot[nSimID] = 2;
+	g_sim_status[nSimID] = -1;
 	sc_cfg_set("softsim_stat","1");
 	g_softsim_apdu_process_cb = softssim_apdu_process_fn;
 	if(nSimID){
 		vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
 		vsim_card_switch_req(1);
 		vsim_set(MSG_CMD_VSIM_SET_SWITCH,1);
-		get_modem_info("AT+ZCARDSWITCH=2,1\r\n", NULL, NULL);
-		get_modem_info("AT+CFUN=1\r\n", NULL, NULL);
+		if(bWithVsimApp == 1)
+		{
+			vsim_send_at("AT+ZCARDSWITCH=2,1\r\n", NULL, NULL);
+		}
+		else
+		{
+			vsim_send_at("AT+ZCARDSWITCH=3,1\r\n", NULL, NULL);
+		}
+		vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
 	}else{
 		uint8_t sim = 0;
 		uint8_t ret = 0;
@@ -315,10 +422,17 @@
 		ret = vsim_get_cardstat_fromps();
 		if(ret >= 0 && nSimID != ret)
 			vsim_card_switch_req(nSimID);
-		get_modem_info("AT+CFUN=0\r\n", NULL, NULL);
-		get_modem_info("AT+CFUN=5\r\n", NULL, NULL);
-		get_modem_info("AT+ZCARDSWITCH=2,0\r\n", NULL, NULL);
-		get_modem_info("AT+CFUN=1\r\n", NULL, NULL);
+		if(bWithVsimApp == 1)
+		{
+			vsim_send_at("AT+ZCARDSWITCH=2,0\r\n", NULL, NULL);
+		}
+		else
+		{
+			vsim_send_at("AT+ZCARDSWITCH=3,0\r\n", NULL, NULL);
+		}
+		vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
+//		vsim_send_at("AT+CFUN=5\r\n", NULL, NULL);		
+		vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 		if(ret >= 0 && nSimID != ret)
@@ -334,9 +448,12 @@
 		printf("##vsim## soft close param err sim=%d\n", nSimID);
 		return -1;
 	}
+	g_vsim_slot[nSimID] = 0;
+	g_sim_status[nSimID] = -1;
 	if(nSimID){
+		vsim_card_switch_req(1);
 		zte_SetGTDATASIM(1);
-		get_modem_info("AT+CFUN=0\r\n", NULL, NULL);
+		vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
 		vsim_card_switch_req(0);
 		zte_SetGTDUALSIM(0);
 		vsim_set(MSG_CMD_VSIM_RESET_FLOW_STATISTIC,1);
@@ -349,17 +466,16 @@
 		ret = vsim_get_cardstat_fromps();
 		if(ret >= 0 && nSimID != ret)
 			vsim_card_switch_req(nSimID);
-		get_modem_info("AT+CFUN=0\r\n", NULL, NULL);
-		get_modem_info("AT+CFUN=5\r\n", NULL, NULL);
-		get_modem_info("AT+ZCARDSWITCH=0,0\r\n", NULL, NULL);
-		get_modem_info("AT+CFUN=1\r\n", NULL, NULL);
+	//	vsim_send_at("AT+CFUN=5\r\n", NULL, NULL);
+		vsim_send_at("AT+ZCARDSWITCH=0,0\r\n", NULL, NULL);
+		vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
+		vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 		if(ret >= 0 && nSimID != ret)
 			vsim_card_switch_req(ret);
 	}
 	g_vsim_apdu_process_cb = NULL;
-	g_vsim_slot[nSimID] = 0;
 	sc_cfg_set("softsim_stat","0");
 	return 0;
 }
@@ -371,13 +487,15 @@
 		printf("##vsim## close param err sim=%d\n", nSimID);
 		return -1;
 	}
+	g_vsim_slot[1] = 0;
+	g_sim_status[1] = -1;
+	vsim_card_switch_req(1);
 	zte_SetGTDATASIM(1);
-	get_modem_info("AT+CFUN=0\r\n", NULL, NULL);
+	vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
 	vsim_card_switch_req(0);
 	zte_SetGTDUALSIM(0);
 	vsim_set(MSG_CMD_VSIM_RESET_FLOW_STATISTIC,1);
 	g_vsim_apdu_process_cb = NULL;
-	g_vsim_slot[1] = 0;
 	sc_cfg_set("vsim_stat","0");
 	return 0;
 }
@@ -387,7 +505,7 @@
 {
 	int ret = 0;
 	vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
-	if(vsim_get(MSG_CMD_VSIM_GET_AUTHING)){
+	if(vsim_get(MSG_CMD_VSIM_GET_AUTHING) || vsim_get(MSG_CMD_VSIM_GET_SCANING)){
 		printf("##vsim## [%s]->%d fail AUTHING\n", __FUNCTION__, nSimID);
 		return -1;
 	}
@@ -474,14 +592,14 @@
 	char at_cmd[64] = {0};
 	vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
 	snprintf(at_cmd,sizeof(at_cmd),"AT+CFUN=%d\r\n", mode);
-	return get_modem_info(at_cmd, NULL, NULL);
+	return vsim_send_at(at_cmd, NULL, NULL);
 }
 
 int32_t zte_GetCfunMode(uint8_t *mode)
 {
 	vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
 	if(mode)
-		return get_modem_info("AT+CFUN?\r\n", "%1d", (void**)&mode);
+		return vsim_send_at("AT+CFUN?\r\n", "%1d", (void**)&mode);
 	return -1;
 }
 
@@ -496,7 +614,7 @@
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
 		snprintf(at_cmd,sizeof(at_cmd),"AT+CGSN=%s\r\n",imei);
-		ret = get_modem_info(at_cmd, NULL, NULL);
+		ret = vsim_send_at(at_cmd, NULL, NULL);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 	}
@@ -512,7 +630,7 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info("AT+CGSN\r\n", "%s", (void**)&imei);
+		ret = vsim_send_at("AT+CGSN\r\n", "%s", (void**)&imei);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 	}
@@ -529,7 +647,7 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info("AT+ZICCID?\r\n", "%s", (void**)&ccid);
+		ret = vsim_send_at("AT+ZICCID?\r\n", "%s", (void**)&ccid);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 	}
@@ -550,13 +668,13 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		get_modem_info("AT+CRSM=176,28589,0,0,4\r\n", "%d,%d,%s", (void**)p);
+		vsim_send_at("AT+CRSM=176,28589,0,0,4\r\n", "%d,%d,%s", (void**)p);
 		if(sw1 == 144 && sw2 == 0){
 			char imsi[64] = {0};
 			char strPlmnLast[10] = {0};
 			void *p1[] = {imsi};
 		
-			get_modem_info("AT+CIMI\r\n", "%s", (void**)p1);
+			vsim_send_at("AT+CIMI\r\n", "%s", (void**)p1);
 			strncpy(strPlmnLast, &response[strlen(response)-2], 2);
 			memset(mcc, 0, 4);
 			memset(mnc, 0, 4);
@@ -577,7 +695,7 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d,%s", (void**)p);
+		ret = vsim_send_at("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d,%s", (void**)p);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 		memset(mcc, 0, 4);
@@ -605,7 +723,7 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info("AT+CSQ\r\n", "%d,%d", (void**)p);
+		ret = vsim_send_at("AT+CSQ\r\n", "%d,%d", (void**)p);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 	}
@@ -617,19 +735,19 @@
 	int ret = -1;
 	vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
 	if(reg_info){
-		int i,act,rac;
+		int i,act,rac,srv_domain;
 		void *p[] = {&i,&act,&reg_info->lte_scell_info.cell_id,&rac,&reg_info->lte_scell_info.tac};
-		void *p1[] = {&reg_info->nStatus};
+		void *p1[] = {&reg_info->nStatus,&srv_domain,&reg_info->lte_scell_info.roamingFlag};
 		uint8_t sim = 0;
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
 		reg_info->nStatus = 0;
-		get_modem_info("AT^SYSINFO\r\n", "%d", (void**)p1);
-		ret = get_modem_info("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d", (void**)p);
+		vsim_send_at("AT^SYSINFO\r\n", "%d,%d,%d", (void**)p1);
+		ret = vsim_send_at("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d", (void**)p);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
-		if(ret || reg_info->nStatus != 2)
+		if(ret || reg_info->nStatus != E_NW_STATUS_SRV_AVAILABLE)
 			return -1;
 		if(act == 16){
 			reg_info->curr_rat = E_NW_RADIO_IF_LTE;
@@ -647,9 +765,11 @@
 	return ret;
 }
 
-int32_t zte_GetCellInfobySimId(CellInfo_t *pcellinfo, uint8_t nSimID)
+int32_t zte_GetCellInfobySimId(uint8_t nSimID)
 {
 	vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+	vsim_set(MSG_CMD_VSIM_SET_SCANING, 1+nSimID);
+	ipc_send_message(MODULE_ID_VSIM, MODULE_ID_AT_CTL, MSG_CMD_ZSCISCAN_REQ, 0, NULL, 0);
 	return 0;
 }
 
@@ -702,7 +822,7 @@
 				cid_reserved = atoi(reservecid);
 			cid_reserved_vsim = cid_reserved|15;
 			snprintf(at_cmd,sizeof(at_cmd),"AT+CIDRESERVED=%d\r\n", cid_reserved_vsim);
-			get_modem_info(at_cmd, NULL, NULL);
+			vsim_send_at(at_cmd, NULL, NULL);
 		}
 		if(data_call->ip_family == E_DATA_IP_FAMILY_IPV4)
 			snprintf(at_cmd,sizeof(at_cmd),"AT+ZPDPACT=0,\"IP\",\"%s\",,,,%d,\"%s\",\"%s\"\r\n", data_call->apn_name, data_call->auth_pref, data_call->user_name, data_call->password);
@@ -717,13 +837,13 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info(at_cmd, "%d", (void**)p);
+		ret = vsim_send_at(at_cmd, "%d", (void**)p);
 		vsim_debug_printf("##vsim## [%s] ret=%d cid=%d\n", __FUNCTION__, ret, data_call->profile_id);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 		if(nSimID){
 			snprintf(at_cmd,sizeof(at_cmd),"AT+CIDRESERVED=%d\r\n", cid_reserved);
-			get_modem_info(at_cmd, NULL, NULL);
+			vsim_send_at(at_cmd, NULL, NULL);
 		}
 	}
 	return ret;
@@ -741,7 +861,7 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info(at_cmd, NULL, NULL);
+		ret = vsim_send_at(at_cmd, NULL, NULL);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 	}
@@ -762,7 +882,7 @@
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info(at_cmd, "%d,%17s", (void**)p);
+		ret = vsim_send_at(at_cmd, "%d,%17s", (void**)p);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 	}
@@ -777,10 +897,16 @@
 		uint8_t sim = 0;
 		char at_paras[64] = {0};
 		void *p[] = {at_paras};
+
+		vsim_debug_printf("##vsim## [%s] simid=%d sim_stat=%d\n", __FUNCTION__, nSimID, g_sim_status[nSimID]);
+		if(g_vsim_slot[nSimID] && g_sim_status[nSimID] == E_SIM_STAT_READY){
+			*sim_status = E_SIM_STAT_READY;
+			return 0;
+		}
 		zte_GetGTDUALSIM(&sim);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(nSimID);
-		ret = get_modem_info("AT+CPIN?\r\n", "%s", (void**)p);
+		ret = vsim_send_at("AT+CPIN?\r\n", "%s", (void**)p);
 		if(sim != nSimID)
 			zte_SetGTDUALSIM(sim);
 		if(ret == 0){
@@ -805,6 +931,9 @@
 		} else {
 			*sim_status = E_SIM_STAT_UNKNOWN;
 		}
+		if(g_vsim_slot[nSimID]){
+			g_sim_status[nSimID] = *sim_status;
+		}
 		return 0;
 	}
 	return -1;
@@ -819,7 +948,7 @@
 	if(sim != nSimID)
 		zte_SetGTDUALSIM(nSimID);
 	printf("##vsim## [%s] nSimID=%d sw=%d at=%s\n", __FUNCTION__, nSimID, sim, req_at);
-	ret = get_modem_info(req_at, info_fmt, pval);
+	ret = vsim_send_at(req_at, info_fmt, pval);
 	if(sim != nSimID)
 		zte_SetGTDUALSIM(sim);
 	return ret;
diff --git a/ap/lib/libvsim/zte_vsim_api.h b/ap/lib/libvsim/zte_vsim_api.h
index c3821dd..a549035 100755
--- a/ap/lib/libvsim/zte_vsim_api.h
+++ b/ap/lib/libvsim/zte_vsim_api.h
@@ -36,10 +36,8 @@
 

 typedef enum {

     E_NW_STATUS_SRV_NONE = 0,

-    E_NW_STATUS_CURRENT_SERVING = 1,

-    E_NW_STATUS_SRV_LIMITED = 2,

-    E_NW_STATUS_SRV_AVAILABLE = 3,

-    E_NW_STATUS_SRV_FORBIDDEN = 4,

+    E_NW_STATUS_SRV_LIMITED = 1,

+    E_NW_STATUS_SRV_AVAILABLE = 2,

 }e_nw_srv_status_t;

 

 

@@ -47,6 +45,7 @@
 {

 	uint32_t tac;

 	uint32_t cell_id;

+	uint32_t roamingFlag; ///< 1:roaming,0:non roaming

 }lte_scell_info_t;

 

 typedef struct

@@ -71,15 +70,14 @@
 	uint32_t tac;

 	uint32_t cell_id;

     uint16_t bandwidth;

-    int16_t  rxlev;

+    uint16_t pcid;//int16_t  rxlev;

     uint32_t arfcn;

-    uint16_t pcid;

 }base_cell_info_t;//Hex format

 

 

 typedef struct

 {

-    uint8_t  roamingFlag; ///< 1:roaming,0:non roaming

+    uint16_t  roamingFlag; ///< 1:roaming,0:non roaming

     int16_t  rsrp;

     int16_t  rsrq;

     uint16_t SINR;

@@ -215,6 +213,7 @@
   E_RF_RESOURCE_CALLBACK_EVENT = 0x00,   /**< É䯵×ÊÔ´Çл». */

   E_NW_ATTACH_COMMPLETE_EVENT  = 0x32,   /**< ×¢ÍøÍê³É. */

   E_DATA_PDN_ACT_SUCC_EVENT = 0x64,      /**< PDN¼¤»îÍê³É ,ind_dataÖÐЯ´øZGIPDNS:µØÖ·ÐÅÏ¢  */

+  E_GET_CELLINFO_BY_SIMID_EVENT  = 0x65,	 /**< É¨ÍøÍê³É. */

 }E_MODEM_EVENT_ID;

 

 typedef enum

@@ -294,7 +293,7 @@
 

 extern int32_t zte_GetRegInfobySimid(RegInfo_t *reg_info, uint8_t nSimID);

 

-extern int32_t zte_GetCellInfobySimId(CellInfo_t *pcellinfo, uint8_t nSimID);

+extern int32_t zte_GetCellInfobySimId(uint8_t nSimID);

 

 extern int32_t zte_GetNetInfobySimId(NetInfo_t *pNetInfo, uint8_t nSimID);