[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/lib/libvsim/libvsim.c b/ap/lib/libvsim/libvsim.c
new file mode 100755
index 0000000..22067cd
--- /dev/null
+++ b/ap/lib/libvsim/libvsim.c
@@ -0,0 +1,722 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <asm/unistd.h>
+#include "softap_api.h"
+#include "zte_vsim_api.h"
+
+#define VSIM_MAX_MSG_LEN 1024
+#define vsim_debug_printf printf
+
+enum{
+ MSG_CMD_VSIM_GET_SWITCH = 1,//ATÔÚÄÄÒ»´ý·¢
+ MSG_CMD_VSIM_SET_SWITCH,
+ MSG_CMD_VSIM_GET_STANDBY,//¿Í»§ÉèÖôý»ú²à,¿ÉÄܲ»Êǵ±Ç°µ±Ç°´ý»ú²à,±ÈÈçTAU
+ MSG_CMD_VSIM_SET_STANDBY,
+ MSG_CMD_VSIM_GET_TAUING,//ÕýÔÚ×öTAU,ÓÃÓÚ¼øÈ¨Á÷³ÌÇлØÊµÌ忨ÅжÏ
+ MSG_CMD_VSIM_SET_TAUING,
+ MSG_CMD_VSIM_GET_AUTHING,//ÕýÔÚ×ö¼øÈ¨,´Ëʱ½ûÖ¹TAU
+ MSG_CMD_VSIM_SET_AUTHING,
+ MSG_CMD_VSIM_GET_CARD_STAT,//»ñÈ¡µ±Ç°µ×²ãʵ¼Ê´ý»ú²à
+ MSG_CMD_VSIM_APDU,
+ MSG_CMD_VSIM_GET_FLOW_STATISTIC,//»ñÈ¡µ±Ç°Á÷Á¿Í³¼Æ
+ MSG_CMD_VSIM_RESET_FLOW_STATISTIC,//ÖØÖõ±Ç°Á÷Á¿Í³¼Æ
+ MSG_CMD_VSIM_MAX,
+};
+
+typedef struct {
+ unsigned short usMsgCmd; /* ÏûÏ¢ÀàÐÍ */
+ unsigned short usDataLen; /* ÏûÏ¢³¤¶È£¬°üÀ¨Í·²¿ */
+ unsigned char aucDataBuf[VSIM_MAX_MSG_LEN]; /* ÏûÏ¢ÕýÎÄ */
+} VSIM_MSG_BUF;
+
+pthread_t read_thread_tid;
+pthread_t msg_thread_tid;
+int g_read_thread_state = -1;
+int g_msg_thread_state = -1;
+VSIM_COMMAND g_vsim_apdu_process_cb;
+zte_mdm_event_ind_callback g_vsim_event_ind_cb;
+
+int32_t zte_mdm_event_ind_cb(E_MODEM_EVENT_ID event_id, void *ind_data, uint32_t 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)
+{
+ char addr[64] = {0};
+ char cmd[128] = {0};
+
+ sc_cfg_get("vsim_debug_ip",addr,sizeof(addr));
+ if(strlen(addr)){
+ snprintf(cmd, sizeof(cmd), "ping %s -w 5", addr);
+ system(cmd);
+ }else
+ system("ping 192.168.30.110 -w 5");
+ return 0;
+}
+
+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);
+ else
+ ret = get_modem_info("AT+ZCARDSWITCHREQ=1,0\r\n", NULL, NULL);
+ if(ret != 0){
+ printf("##vsim## [%s] sim=%d ret=%d err\n", __FUNCTION__, sim, ret);
+ }
+ vsim_debug_printf("##vsim## [%s] sim=%d ret=%d\n", __FUNCTION__, sim, ret);
+ return ret;
+}
+
+static int vsim_set(unsigned short msg, unsigned char param)
+{
+ VSIM_MSG_BUF msg_in = {0};
+ VSIM_MSG_BUF msg_out = {0};
+ int ret = 0;
+
+ msg_in.usMsgCmd = msg;
+ msg_in.aucDataBuf[0] = param;
+ vsim_debug_printf("##vsim## [%s] msg=%d param=%d start\n", __FUNCTION__, msg, param);
+ ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
+ if(ret == 0){
+ printf("##vsim## [%s] msg=%d param=%d err\n", __FUNCTION__, msg, param);
+ }
+ return ret;
+}
+
+static unsigned char vsim_get(unsigned short msg)
+{
+ VSIM_MSG_BUF msg_in = {0};
+ VSIM_MSG_BUF msg_out = {0};
+ int ret = 0;
+
+ msg_in.usMsgCmd = msg;
+ vsim_debug_printf("##vsim## [%s] msg=%d start\n", __FUNCTION__, msg);
+ ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
+ if(ret == 0){
+ printf("##vsim## [%s] msg=%d err\n", __FUNCTION__, msg);
+ }
+ return msg_out.aucDataBuf[0];
+}
+
+static int vsim_get_cardstat_fromps(void)
+{
+ VSIM_MSG_BUF msg_in = {0};
+ VSIM_MSG_BUF msg_out = {0};
+ int ret = 0;
+
+ msg_in.usMsgCmd = MSG_CMD_VSIM_GET_CARD_STAT;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
+ if(ret == 0 || msg_out.aucDataBuf[0] == msg_out.aucDataBuf[1] || msg_out.aucDataBuf[2]){
+ printf("##vsim## [%s] err ret=%d sim1=%d sim2=%d busy=%d\n", __FUNCTION__, ret, msg_out.aucDataBuf[0], msg_out.aucDataBuf[1], msg_out.aucDataBuf[2]);
+ return -1;
+ }
+ if(msg_out.aucDataBuf[0])
+ return 0;
+ if(msg_out.aucDataBuf[1])
+ return 1;
+ return -1;
+}
+
+static void read_thread_entry(void *arg)
+{
+ prctl(PR_SET_NAME, "vsim_read", 0, 0, 0);
+ while(g_vsim_apdu_process_cb)
+ {
+ VSIM_MSG_BUF msg_in = {0};
+ VSIM_MSG_BUF msg_out = {0};
+ int ret = 0;
+ int is_auth = 0;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ ret = syscall(__NR_vsim_read,(unsigned char *)&msg_out);
+ if(ret == 0){
+ printf("##vsim## read fail\n");
+ }
+ vsim_debug_printf("##vsim## read msg=%d\n", msg_out.usMsgCmd);
+ if(msg_out.usMsgCmd != MSG_CMD_VSIM_APDU || ret == 0){
+ printf("##vsim## read msg=%d ret=%d err\n", msg_out.usMsgCmd, ret);
+ }
+ is_auth = msg_out.aucDataBuf[1];
+ //ÇÐʵÌ忨
+ if(is_auth){
+ 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»Ø¸´¸øÍø²à
+ vsim_card_switch_req(0);//´ËʱʵÌ忨¿ÉÄÜ´æÔÚÍøÂçÁ´½Ó£¬ÏÈÇÐÍøÔÙÇÐÊý¾Ý
+ vsim_set(MSG_CMD_VSIM_SET_STANDBY,0);
+ }
+ msg_in.usDataLen = sizeof(msg_in.aucDataBuf);
+ ret = g_vsim_apdu_process_cb(&msg_out.aucDataBuf[2], msg_out.usDataLen, msg_in.aucDataBuf,
+ &msg_in.usDataLen, msg_out.aucDataBuf[0]);
+ vsim_debug_printf("##vsim## g_vsim_apdu_process_cb ret=0x%x len=%d\n", ret, msg_in.usDataLen);
+ //ÇÐÐéÄ⿨
+ if(is_auth){
+ vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Ó¦¸Ãδ½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
+ vsim_card_switch_req(1);
+ vsim_set(MSG_CMD_VSIM_SET_AUTHING,0);
+ }
+ //msg_in.usDataLen = ret;·µ»Ø²»Êdz¤¶ÈÊÇ״̬×Ö
+ msg_in.usMsgCmd = MSG_CMD_VSIM_APDU;
+ ret = syscall(__NR_vsim_write,(unsigned char *)&msg_in);
+ if(ret == 0){
+ printf("##vsim## write fail\n");
+ }
+ }
+ printf("##vsim## read_thread quit\n");
+ g_read_thread_state = -1;
+ pthread_exit(0);
+}
+
+static void msg_thread_entry(void *arg)
+{
+ int iMsgHandle = msgget(MODULE_ID_VSIM, IPC_CREAT|0600);
+ LONG msgSize = sizeof(MSG_BUF)-sizeof(LONG);
+ unsigned char SwitchStat;
+
+ prctl(PR_SET_NAME, "vsim_msg", 0, 0, 0);
+ while(g_vsim_event_ind_cb)
+ {
+ MSG_BUF stMsg = {0};
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if (msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0) >= 0)
+ {
+ switch (stMsg.usMsgCmd)
+ {
+ case MSG_CMD_ZCARDSWITCHIND_IND:
+ //callback todo
+ SwitchStat = stMsg.aucDataBuf[1];
+ if(vsim_get(MSG_CMD_VSIM_GET_AUTHING)){
+ printf("##vsim## ZCARDSWITCHIND AUTHING abort\n");
+ if(SwitchStat)
+ vsim_set(MSG_CMD_VSIM_SET_TAUING,0);
+ break;
+ }
+ if(SwitchStat == 0){
+ vsim_set(MSG_CMD_VSIM_SET_TAUING,1);
+ vsim_card_switch_req(stMsg.aucDataBuf[0]);
+ }else{
+ if(vsim_get(MSG_CMD_VSIM_GET_STANDBY) == stMsg.aucDataBuf[0])
+ vsim_card_switch_req(stMsg.aucDataBuf[0]);
+ vsim_set(MSG_CMD_VSIM_SET_TAUING,0);
+ }
+ break;
+ case MSG_CMD_CREG_IND:
+ if(vsim_get(MSG_CMD_VSIM_GET_STANDBY) == 1){
+ //callback todo
+ }
+ break;
+ case MSG_CMD_VSIMDEBUG_IND:
+ if(stMsg.aucDataBuf[0] == 1){
+ char imei[]="862769025435956";
+ fibo_set_IMEI_by_simid(imei,sizeof(imei),1);
+ fibo_mdm_event_regist(zte_mdm_event_ind_cb);
+ fibo_vsim_init(zte_vsim_ind_cb,1);
+ }
+ if(stMsg.aucDataBuf[0] == 2){
+ fibo_vsim_close(zte_vsim_ind_cb,1);
+ }
+ if(stMsg.aucDataBuf[0] == 10){
+ zte_SetGTDATASIM(0);
+ }
+ if(stMsg.aucDataBuf[0] == 11){
+ zte_SetGTDATASIM(1);
+ }
+ if(stMsg.aucDataBuf[0] == 20){
+ zte_SetGTDUALSIM(0);
+ }
+ if(stMsg.aucDataBuf[0] == 21){
+ zte_SetGTDUALSIM(1);
+ }
+ break;
+ default:
+ printf("##vsim## rcv_msg err msgid 0x%x\n",stMsg.usMsgCmd);
+ break;
+ }
+ }
+ vsim_debug_printf("##vsim## rcv_msg msgid 0x%x param=%d end\n",stMsg.usMsgCmd, stMsg.aucDataBuf[0]);
+ }
+ printf("##vsim## msg_thread quit\n");
+ g_msg_thread_state = -1;
+ pthread_exit(0);
+}
+
+int32_t zte_atVsimInit(VSIM_COMMAND vsim_apdu_process_fn, uint8_t nSimID)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(vsim_apdu_process_fn == NULL || nSimID != 1){
+ printf("##vsim## init param err fn=0x%x sim=%d\n", vsim_apdu_process_fn, nSimID);
+ return -1;
+ }
+ g_vsim_apdu_process_cb = vsim_apdu_process_fn;
+ if(g_read_thread_state != 0)
+ g_read_thread_state = pthread_create(&read_thread_tid, NULL, (void *)read_thread_entry, NULL);
+ if(g_msg_thread_state != 0)
+ g_msg_thread_state = pthread_create(&msg_thread_tid, NULL, (void *)msg_thread_entry, NULL);
+ if(g_read_thread_state != 0 || g_msg_thread_state != 0){
+ printf("##vsim## init fail read=%d msg=%d\n", g_read_thread_state, g_msg_thread_state);
+ return -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);
+ return 0;
+}
+
+int32_t zte_atVsimClose(VSIM_COMMAND vsim_apdu_process_fn, uint8_t nSimID)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ zte_SetGTDATASIM(1);
+ get_modem_info("AT+CFUN=0\r\n", NULL, NULL);
+ vsim_card_switch_req(0);
+ zte_SetGTDUALSIM(0);
+ return 0;
+}
+
+int32_t zte_SetGTDATASIM(uint8_t nSimID)
+{
+ int ret = 0;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(vsim_get(MSG_CMD_VSIM_GET_AUTHING)){
+ printf("##vsim## [%s]->%d fail AUTHING\n", __FUNCTION__, nSimID);
+ return -1;
+ }
+ vsim_set(MSG_CMD_VSIM_SET_STANDBY,nSimID);
+ ret = vsim_get_cardstat_fromps();
+ if(ret >= 0){
+ if(nSimID != ret){
+ //Èç¹ûÉèÖú͵±Ç°µ×²ã´ý»ú²à²»Ò»Ö²ÅÇÐ,forTAUING
+ vsim_card_switch_req(nSimID);
+ }
+ }else
+ vsim_card_switch_req(nSimID);
+ vsim_set(MSG_CMD_VSIM_SET_SWITCH, nSimID);
+ printf("##vsim## [%s] cardstat=%d sim=%d\n", __FUNCTION__, ret, nSimID);
+ return 0;
+}
+
+int32_t zte_GetGTDATASIM(uint8_t *nSimID)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ *nSimID = vsim_get(MSG_CMD_VSIM_GET_STANDBY);
+ return 0;
+}
+
+int32_t zte_SetGTDUALSIM(uint8_t nSimID)
+{
+ int ret = 0;
+ unsigned char standby = vsim_get(MSG_CMD_VSIM_GET_STANDBY);
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ ret = vsim_set(MSG_CMD_VSIM_SET_SWITCH,nSimID);
+ if(ret == 0){
+ printf("##vsim## [%s] err sim=%d\n", __FUNCTION__, nSimID);
+ return -1;
+ }
+ //ATÒѾÇкã¬ÏÂÃæÊÇÅжÏÊÇ·ñÒªÇп¨
+ if(vsim_get(MSG_CMD_VSIM_GET_TAUING)){//TAUµÄ¹ý³ÌÖÐ,²»Çп¨
+ printf("##vsim## [%s] TAUING\n", __FUNCTION__);
+ return 0;
+ }
+ ret = vsim_get_cardstat_fromps();
+ if(ret >= 0 && standby != ret && standby == nSimID){
+ //µ±Çл»ATµÄÄ¿±ê´ý»ú²àºÍÉϲã֮ǰÉ趨µÄ´ý»ú²àÏàͬ,ÇҺ͵ײãʵ¼ÊµÄ´ý»ú²à²»Í¬,ÓÖ²»ÊÇTAUµÄ¹ý³ÌÖÐ,¾Í´¥·¢Çп¨
+ vsim_card_switch_req(nSimID);
+ }
+ printf("##vsim## [%s] cardstat=%d standby=%d sim=%d\n", __FUNCTION__, ret, standby, nSimID);
+ return 0;
+}
+
+int32_t zte_GetGTDUALSIM(uint8_t *nSimID)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ *nSimID = vsim_get(MSG_CMD_VSIM_GET_SWITCH);
+ return 0;
+}
+
+int32_t zte_mdm_event_regist(zte_mdm_event_ind_callback ind_cb)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ g_vsim_event_ind_cb = ind_cb;
+ return 0;
+}
+
+void zte_vsim_debug(void)
+{
+ g_vsim_event_ind_cb = zte_mdm_event_ind_cb;
+ g_vsim_apdu_process_cb = zte_vsim_ind_cb;
+ if(g_read_thread_state != 0)
+ g_read_thread_state = pthread_create(&read_thread_tid, NULL, (void *)read_thread_entry, NULL);
+ if(g_msg_thread_state != 0)
+ g_msg_thread_state = pthread_create(&msg_thread_tid, NULL, (void *)msg_thread_entry, NULL);
+ if(g_read_thread_state != 0 || g_msg_thread_state != 0){
+ printf("##vsim## debug fail read=%d msg=%d\n", g_read_thread_state, g_msg_thread_state);
+ }
+}
+
+int32_t zte_atVsimReset(void)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ return restart_request(MODULE_ID_VSIM);
+}
+
+int32_t zte_SetCfunMode(uint8_t mode)
+{
+ 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);
+}
+
+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 -1;
+}
+
+int32_t zte_SetIMEIbySimId(uint8_t *imei, uint8_t imei_len, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(imei){
+ char at_cmd[64] = {0};
+ uint8_t sim = 0;
+ zte_GetGTDUALSIM(&sim);
+ 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);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ }
+ return ret;
+}
+
+int32_t zte_GetIMEIbySimId(uint8_t *imei, uint8_t imei_len, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(imei){
+ uint8_t sim = 0;
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info("AT+CGSN\r\n", "%s", (void**)&imei);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ }
+ return ret;
+}
+
+
+int32_t zte_GetCCIDbySimId(uint8_t *ccid, uint8_t ccid_len, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(ccid){
+ uint8_t sim = 0;
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info("AT+ZICCID?\r\n", "%s", (void**)&ccid);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ }
+ return ret;
+}
+
+int32_t zte_GetMCCMNCbySimId(char *mcc, char *mnc, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(mcc && mnc){
+#if 0
+ int sw1=0;
+ int sw2=-1;
+ char response[513] = {0};//³¤¶È·¶Î§0-256×Ö½Ú£¬7F205F70±íʾ4¸ö×Ö½Ú³¤¶È
+ void *p[] = {&sw1,&sw2,response};
+ uint8_t sim = 0;
+ 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);
+ 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);
+ strncpy(strPlmnLast, &response[strlen(response)-2], 2);
+ memset(mcc, 0, 4);
+ memset(mnc, 0, 4);
+ memcpy(mcc, imsi, 3);
+ if(0 == strcmp("03", strPlmnLast))
+ memcpy(mnc, imsi+3, 3);
+ else
+ memcpy(mnc, imsi+3, 2);
+ }
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ return !(sw1 == 144 && sw2 == 0);
+#else
+ int i1,i2,i3,i4,i5;
+ char plmn[8] = {0};
+ void *p[] = {&i1,&i2,&i3,&i4,&i5,plmn};
+ uint8_t sim = 0;
+ 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);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ memset(mcc, 0, 4);
+ memset(mnc, 0, 4);
+ memcpy(mcc, plmn, 3);
+ memcpy(mnc, plmn+3, 3);
+#endif
+ }
+ return ret;
+}
+
+int32_t zte_SwitchSimHandle(uint8_t mode)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ return 0;
+}
+
+int32_t zte_GetCSQbySimId(int32_t *rssi, int32_t *ber, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(rssi && ber){
+ void *p[] = {rssi,ber};
+ uint8_t sim = 0;
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info("AT+CSQ\r\n", "%d,%d", (void**)p);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ }
+ return ret;
+}
+
+int32_t zte_GetRegInfobySimid(RegInfo_t *reg_info, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(reg_info){
+ int i,act,rac;
+ void *p[] = {&i,&act,®_info->lte_scell_info.cell_id,&rac,®_info->lte_scell_info.tac};
+ void *p1[] = {®_info->nStatus};
+ 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);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ if(ret || reg_info->nStatus != 2)
+ return -1;
+ if(act == 16){
+ reg_info->curr_rat = E_NW_RADIO_IF_LTE;
+ } else {
+ if(act == 1)
+ reg_info->curr_rat = E_NW_RADIO_IF_TDSCDMA;
+ else if(act == 2)
+ reg_info->curr_rat = E_NW_RADIO_IF_WCDMA;
+ else if(act == 4)
+ reg_info->curr_rat = E_NW_RADIO_IF_GSM;
+ else
+ printf("##vsim## [%s] act=%d ???\n", __FUNCTION__, act);
+ }
+ }
+ return ret;
+}
+
+int32_t zte_GetCellInfobySimId(CellInfo_t *pcellinfo, uint8_t nSimID)
+{
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ return 0;
+}
+
+int32_t zte_GetNetInfobySimId(NetInfo_t *pNetInfo, uint8_t nSimID)
+{
+ VSIM_MSG_BUF msg_in = {0};
+ VSIM_MSG_BUF msg_out = {0};
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(pNetInfo && nSimID < 2){
+ msg_in.usMsgCmd = MSG_CMD_VSIM_GET_FLOW_STATISTIC;
+ msg_in.aucDataBuf[0] = nSimID;
+ ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
+ if(ret == 0){
+ printf("##vsim## [%s] vsim_proc err\n", __FUNCTION__);
+ }
+ if(sizeof(NetInfo_t) > msg_out.usDataLen)
+ memcpy(pNetInfo, msg_out.aucDataBuf, msg_out.usDataLen);
+ else
+ memcpy(pNetInfo, msg_out.aucDataBuf, sizeof(NetInfo_t));
+ }
+ return ret;
+}
+
+int32_t zte_SetAPNbySimID(Data_call_config_info_t *data_call, uint8_t nSimID)
+{
+ return 0;
+}
+
+int32_t zte_StartDataCallbySimId(Data_call_config_info_t *data_call, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(data_call){
+ uint8_t sim = 0;
+ char at_cmd[128] = {0};
+ void *p[] = {&data_call->profile_id};
+ char reservecid[30] = {0};
+ unsigned char cid_reserved = 0;
+ unsigned char cid_reserved_vsim = 0;
+
+ zte_GetGTDATASIM(&sim);
+ if(sim != nSimID){
+ printf("##vsim## [%s] nSimID=%d standby=%d err\n", __FUNCTION__, nSimID, sim);
+ return ret;
+ }
+ if(nSimID){
+ sc_cfg_get("cid_reserved",reservecid,sizeof(reservecid));
+ if(strlen(reservecid))
+ 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);
+ }
+ 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);
+ else if(data_call->ip_family == E_DATA_IP_FAMILY_IPV6)
+ snprintf(at_cmd,sizeof(at_cmd),"AT+ZPDPACT=0,\"IPV6\",\"%s\",,,,%d,\"%s\",\"%s\"\r\n", data_call->apn_name, data_call->auth_pref, data_call->user_name, data_call->password);
+ else if(data_call->ip_family == E_DATA_IP_FAMILY_IPV4V6)
+ snprintf(at_cmd,sizeof(at_cmd),"AT+ZPDPACT=0,\"IPV4V6\",\"%s\",,,,%d,\"%s\",\"%s\"\r\n", data_call->apn_name, data_call->auth_pref, data_call->user_name, data_call->password);
+ else {
+ printf("##vsim## [%s] ip_family=%d ???\n", __FUNCTION__, data_call->ip_family);
+ 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);
+ }
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info(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);
+ }
+ }
+ return ret;
+}
+
+int32_t zte_StopDataCallbySimId(uint8_t profile_id, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(profile_id > 0 && profile_id < 9){
+ uint8_t sim = 0;
+ char at_cmd[64] = {0};
+
+ snprintf(at_cmd,sizeof(at_cmd),"AT+ZPDPDEACT=%d\r\n", profile_id);
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info(at_cmd, NULL, NULL);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ }
+ return ret;
+}
+
+int32_t zte_GetDataAddrbySimID(uint8_t profile_id, Data_call_addr_info_list_t *addr_list, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(profile_id > 0 && profile_id < 9 && addr_list){
+ uint8_t sim = 0;
+ char at_cmd[64] = {0};
+ int cid = 0;
+ void *p[] = {&cid, addr_list};
+
+ snprintf(at_cmd,sizeof(at_cmd),"AT+CGPADDR=%d\r\n", profile_id);
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info(at_cmd, "%d,%17s", (void**)p);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ }
+ return ret;
+}
+
+int32_t zte_GetSimStatusbySimId(E_SIM_STATUS *sim_status, uint8_t nSimID)
+{
+ int ret = -1;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ if(sim_status){
+ uint8_t sim = 0;
+ char at_paras[64] = {0};
+ void *p[] = {at_paras};
+ zte_GetGTDUALSIM(&sim);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(nSimID);
+ ret = get_modem_info("AT+CPIN?\r\n", "%s", (void**)p);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ if(ret == 0){
+ if (strncmp("READY", at_paras, strlen("READY")) == 0)
+ {
+ *sim_status = E_SIM_STAT_READY;
+ }
+ /*Èç¹ûµ±Ç°ÃÜÂëÊäÈëÇëÇóΪPIN»òPIN2£¬ÔòÊäÈë+CPIN=<pin>½øÐÐУÑé*/
+ else if(strncmp("SIM PIN",at_paras, strlen("SIM PIN")) == 0)
+ {
+ *sim_status = E_SIM_STAT_PIN;
+ }
+ /*Èç¹ûµ±Ç°ÃÜÂëÊäÈëÇëÇóΪPUK»òPUK2£¬ÔòÊäÈë+CPIN=<pin>,<newpin>½øÐнâËø*/
+ else if(strncmp("SIM PUK",at_paras, strlen("SIM PUK")) == 0)
+ {
+ *sim_status = E_SIM_STAT_PUK;
+ }
+ } else if(ret == 10){
+ *sim_status = E_SIM_STAT_NOT_INSERTED;
+ } else if(ret == 14){
+ *sim_status = E_SIM_STAT_BUSY;
+ } else {
+ *sim_status = E_SIM_STAT_UNKNOWN;
+ }
+ return 0;
+ }
+ return -1;
+}
+
+int32_t zte_SendATbySimId(char *req_at, char *info_fmt, void **pval, uint8_t nSimID)
+{
+ int ret = -1;
+ uint8_t sim = 0;
+ vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
+ zte_GetGTDUALSIM(&sim);
+ 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);
+ if(sim != nSimID)
+ zte_SetGTDUALSIM(sim);
+ return ret;
+}
+
+