blob: 210e3e64259716e2792b25bb4da6dd15b4274907 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include <unistd.h>
5#include <pthread.h>
6#include <asm/unistd.h>
7#include "softap_api.h"
8#include "zte_vsim_api.h"
9
10#define VSIM_MAX_MSG_LEN 1024
11#define vsim_debug_printf printf
xf.li742dd022023-06-08 01:43:32 -070012uint8_t bWithVsimApp = 1; // 0 ²»´øÓ¦ÓÃ 1 ´øÓ¦ÓÃ
lh9ed821d2023-04-07 01:36:19 -070013
14enum{
15 MSG_CMD_VSIM_GET_SWITCH = 1,//ATÔÚÄÄÒ»´ý·¢
16 MSG_CMD_VSIM_SET_SWITCH,
17 MSG_CMD_VSIM_GET_STANDBY,//¿Í»§ÉèÖôý»ú²à,¿ÉÄܲ»Êǵ±Ç°µ±Ç°´ý»ú²à,±ÈÈçTAU
18 MSG_CMD_VSIM_SET_STANDBY,
19 MSG_CMD_VSIM_GET_TAUING,//ÕýÔÚ×öTAU,ÓÃÓÚ¼øÈ¨Á÷³ÌÇлØÊµÌ忨ÅжÏ
20 MSG_CMD_VSIM_SET_TAUING,
21 MSG_CMD_VSIM_GET_AUTHING,//ÕýÔÚ×ö¼øÈ¨,´Ëʱ½ûÖ¹TAU
22 MSG_CMD_VSIM_SET_AUTHING,
23 MSG_CMD_VSIM_GET_CARD_STAT,//»ñÈ¡µ±Ç°µ×²ãʵ¼Ê´ý»ú²à
24 MSG_CMD_VSIM_APDU,
25 MSG_CMD_VSIM_GET_FLOW_STATISTIC,//»ñÈ¡µ±Ç°Á÷Á¿Í³¼Æ
26 MSG_CMD_VSIM_RESET_FLOW_STATISTIC,//ÖØÖõ±Ç°Á÷Á¿Í³¼Æ
xf.li742dd022023-06-08 01:43:32 -070027 MSG_CMD_VSIM_GET_SCANING,//Õýscan,´Ëʱ½ûÖ¹TAU
28 MSG_CMD_VSIM_SET_SCANING,
lh9ed821d2023-04-07 01:36:19 -070029 MSG_CMD_VSIM_MAX,
30};
31
32typedef struct {
33 unsigned short usMsgCmd; /* ÏûÏ¢ÀàÐÍ */
34 unsigned short usDataLen; /* ÏûÏ¢³¤¶È£¬°üÀ¨Í·²¿ */
35 unsigned char aucDataBuf[VSIM_MAX_MSG_LEN]; /* ÏûÏ¢ÕýÎÄ */
36} VSIM_MSG_BUF;
37
xf.li742dd022023-06-08 01:43:32 -070038pthread_mutex_t vsim_at_mutex = PTHREAD_MUTEX_INITIALIZER;
lh9ed821d2023-04-07 01:36:19 -070039pthread_t read_thread_tid;
40pthread_t msg_thread_tid;
41int g_read_thread_state = -1;
42int g_msg_thread_state = -1;
43VSIM_COMMAND g_vsim_apdu_process_cb;
xf.libdd93d52023-05-12 07:10:14 -070044SoftSim_COMMAND g_softsim_apdu_process_cb;
lh9ed821d2023-04-07 01:36:19 -070045zte_mdm_event_ind_callback g_vsim_event_ind_cb;
xf.libdd93d52023-05-12 07:10:14 -070046unsigned char g_vsim_slot[2];
xf.li742dd022023-06-08 01:43:32 -070047int g_sim_status[2] = {-1,-1};
lh9ed821d2023-04-07 01:36:19 -070048
49int32_t zte_mdm_event_ind_cb(E_MODEM_EVENT_ID event_id, void *ind_data, uint32_t ind_data_len)
50{
xf.li742dd022023-06-08 01:43:32 -070051 printf("##vsim## [%s] event_id=%d len=%d \n", __FUNCTION__, event_id, ind_data_len);
lh9ed821d2023-04-07 01:36:19 -070052 return 0;
53}
54int 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)
55{
56 char addr[64] = {0};
57 char cmd[128] = {0};
58
59 sc_cfg_get("vsim_debug_ip",addr,sizeof(addr));
60 if(strlen(addr)){
61 snprintf(cmd, sizeof(cmd), "ping %s -w 5", addr);
62 system(cmd);
63 }else
64 system("ping 192.168.30.110 -w 5");
65 return 0;
66}
67
xf.li742dd022023-06-08 01:43:32 -070068
69static int vsim_send_at(char *req_at, char *info_fmt, void **pval)
70{
71 int ret;
72 pthread_mutex_lock(&vsim_at_mutex);
73 ret = get_modem_info(req_at,info_fmt,pval);
74 pthread_mutex_unlock(&vsim_at_mutex);
75 return ret;
76}
77
lh9ed821d2023-04-07 01:36:19 -070078static int vsim_card_switch_req(unsigned char sim)
79{
80 int ret = 0;
81 if(sim)
xf.li742dd022023-06-08 01:43:32 -070082 ret = vsim_send_at("AT+ZCARDSWITCHREQ=0,1\r\n", NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -070083 else
xf.li742dd022023-06-08 01:43:32 -070084 ret = vsim_send_at("AT+ZCARDSWITCHREQ=1,0\r\n", NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -070085 if(ret != 0){
86 printf("##vsim## [%s] sim=%d ret=%d err\n", __FUNCTION__, sim, ret);
87 }
88 vsim_debug_printf("##vsim## [%s] sim=%d ret=%d\n", __FUNCTION__, sim, ret);
89 return ret;
90}
91
92static int vsim_set(unsigned short msg, unsigned char param)
93{
94 VSIM_MSG_BUF msg_in = {0};
95 VSIM_MSG_BUF msg_out = {0};
96 int ret = 0;
97
98 msg_in.usMsgCmd = msg;
99 msg_in.aucDataBuf[0] = param;
100 vsim_debug_printf("##vsim## [%s] msg=%d param=%d start\n", __FUNCTION__, msg, param);
xf.li742dd022023-06-08 01:43:32 -0700101 if(msg == MSG_CMD_VSIM_SET_SWITCH)
102 pthread_mutex_lock(&vsim_at_mutex);
lh9ed821d2023-04-07 01:36:19 -0700103 ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
xf.li742dd022023-06-08 01:43:32 -0700104 if(msg == MSG_CMD_VSIM_SET_SWITCH)
105 pthread_mutex_unlock(&vsim_at_mutex);
lh9ed821d2023-04-07 01:36:19 -0700106 if(ret == 0){
107 printf("##vsim## [%s] msg=%d param=%d err\n", __FUNCTION__, msg, param);
108 }
109 return ret;
110}
111
112static unsigned char vsim_get(unsigned short msg)
113{
114 VSIM_MSG_BUF msg_in = {0};
115 VSIM_MSG_BUF msg_out = {0};
116 int ret = 0;
117
118 msg_in.usMsgCmd = msg;
119 vsim_debug_printf("##vsim## [%s] msg=%d start\n", __FUNCTION__, msg);
120 ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
121 if(ret == 0){
122 printf("##vsim## [%s] msg=%d err\n", __FUNCTION__, msg);
123 }
124 return msg_out.aucDataBuf[0];
125}
126
127static int vsim_get_cardstat_fromps(void)
128{
129 VSIM_MSG_BUF msg_in = {0};
130 VSIM_MSG_BUF msg_out = {0};
131 int ret = 0;
132
133 msg_in.usMsgCmd = MSG_CMD_VSIM_GET_CARD_STAT;
134 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
135 ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
136 if(ret == 0 || msg_out.aucDataBuf[0] == msg_out.aucDataBuf[1] || msg_out.aucDataBuf[2]){
137 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]);
138 return -1;
139 }
140 if(msg_out.aucDataBuf[0])
141 return 0;
142 if(msg_out.aucDataBuf[1])
143 return 1;
144 return -1;
145}
146
147static void read_thread_entry(void *arg)
148{
149 prctl(PR_SET_NAME, "vsim_read", 0, 0, 0);
xf.libdd93d52023-05-12 07:10:14 -0700150 while(g_vsim_event_ind_cb)
lh9ed821d2023-04-07 01:36:19 -0700151 {
152 VSIM_MSG_BUF msg_in = {0};
153 VSIM_MSG_BUF msg_out = {0};
154 int ret = 0;
155 int is_auth = 0;
xf.li742dd022023-06-08 01:43:32 -0700156 int is_slot1 = 0;
lh9ed821d2023-04-07 01:36:19 -0700157 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
158 ret = syscall(__NR_vsim_read,(unsigned char *)&msg_out);
159 if(ret == 0){
160 printf("##vsim## read fail\n");
161 }
162 vsim_debug_printf("##vsim## read msg=%d\n", msg_out.usMsgCmd);
163 if(msg_out.usMsgCmd != MSG_CMD_VSIM_APDU || ret == 0){
164 printf("##vsim## read msg=%d ret=%d err\n", msg_out.usMsgCmd, ret);
165 }
166 is_auth = msg_out.aucDataBuf[1];
xf.li742dd022023-06-08 01:43:32 -0700167 is_slot1 = msg_out.aucDataBuf[0];
lh9ed821d2023-04-07 01:36:19 -0700168 //ÇÐʵÌ忨
xf.li742dd022023-06-08 01:43:32 -0700169 if(is_auth && g_vsim_slot[msg_out.aucDataBuf[0]] && is_slot1){
lh9ed821d2023-04-07 01:36:19 -0700170 printf("##vsim## vsim_apdu_auth standby=%d\n", vsim_get(MSG_CMD_VSIM_GET_STANDBY));
171 vsim_set(MSG_CMD_VSIM_SET_AUTHING,1);
172 usleep(20000);//±£»¤´ëÊ©,ÑÓ³Ù20ºÁÃëÔÙÏ·¢Çп¨£¬±£Ö¤¼øÈ¨ÇëÇóµÄrlc ack»Ø¸´¸øÍø²à
173 vsim_card_switch_req(0);//´ËʱʵÌ忨¿ÉÄÜ´æÔÚÍøÂçÁ´½Ó£¬ÏÈÇÐÍøÔÙÇÐÊý¾Ý
174 vsim_set(MSG_CMD_VSIM_SET_STANDBY,0);
175 }
176 msg_in.usDataLen = sizeof(msg_in.aucDataBuf);
xf.libdd93d52023-05-12 07:10:14 -0700177 if(g_vsim_apdu_process_cb && msg_out.aucDataBuf[0] < 2 && g_vsim_slot[msg_out.aucDataBuf[0]] == 1){
178 ret = g_vsim_apdu_process_cb(&msg_out.aucDataBuf[2], msg_out.usDataLen, msg_in.aucDataBuf,
179 &msg_in.usDataLen, msg_out.aucDataBuf[0]);
180 }
181 if(g_softsim_apdu_process_cb && msg_out.aucDataBuf[0] < 2 && g_vsim_slot[msg_out.aucDataBuf[0]] == 2){
182 ret = g_softsim_apdu_process_cb(&msg_out.aucDataBuf[2], msg_out.usDataLen, msg_in.aucDataBuf,
183 &msg_in.usDataLen, msg_out.aucDataBuf[0]);
184 }
lh9ed821d2023-04-07 01:36:19 -0700185 vsim_debug_printf("##vsim## g_vsim_apdu_process_cb ret=0x%x len=%d\n", ret, msg_in.usDataLen);
186 //ÇÐÐéÄ⿨
xf.li742dd022023-06-08 01:43:32 -0700187 if(is_auth && g_vsim_slot[msg_out.aucDataBuf[0]] && is_slot1){
lh9ed821d2023-04-07 01:36:19 -0700188 vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Ó¦¸Ãδ½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
189 vsim_card_switch_req(1);
190 vsim_set(MSG_CMD_VSIM_SET_AUTHING,0);
191 }
192 //msg_in.usDataLen = ret;·µ»Ø²»Êdz¤¶ÈÊÇ״̬×Ö
193 msg_in.usMsgCmd = MSG_CMD_VSIM_APDU;
194 ret = syscall(__NR_vsim_write,(unsigned char *)&msg_in);
195 if(ret == 0){
196 printf("##vsim## write fail\n");
197 }
198 }
199 printf("##vsim## read_thread quit\n");
200 g_read_thread_state = -1;
201 pthread_exit(0);
202}
203
204static void msg_thread_entry(void *arg)
205{
206 int iMsgHandle = msgget(MODULE_ID_VSIM, IPC_CREAT|0600);
207 LONG msgSize = sizeof(MSG_BUF)-sizeof(LONG);
208 unsigned char SwitchStat;
209
210 prctl(PR_SET_NAME, "vsim_msg", 0, 0, 0);
211 while(g_vsim_event_ind_cb)
212 {
213 MSG_BUF stMsg = {0};
214 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
215 if (msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0) >= 0)
216 {
217 switch (stMsg.usMsgCmd)
218 {
219 case MSG_CMD_ZCARDSWITCHIND_IND:
220 //callback todo
221 SwitchStat = stMsg.aucDataBuf[1];
xf.li742dd022023-06-08 01:43:32 -0700222 if(vsim_get(MSG_CMD_VSIM_GET_AUTHING) || vsim_get(MSG_CMD_VSIM_GET_SCANING)){
lh9ed821d2023-04-07 01:36:19 -0700223 printf("##vsim## ZCARDSWITCHIND AUTHING abort\n");
224 if(SwitchStat)
225 vsim_set(MSG_CMD_VSIM_SET_TAUING,0);
226 break;
227 }
228 if(SwitchStat == 0){
229 vsim_set(MSG_CMD_VSIM_SET_TAUING,1);
230 vsim_card_switch_req(stMsg.aucDataBuf[0]);
231 }else{
232 if(vsim_get(MSG_CMD_VSIM_GET_STANDBY) == stMsg.aucDataBuf[0])
233 vsim_card_switch_req(stMsg.aucDataBuf[0]);
234 vsim_set(MSG_CMD_VSIM_SET_TAUING,0);
235 }
236 break;
237 case MSG_CMD_CREG_IND:
xf.li742dd022023-06-08 01:43:32 -0700238 {
239 uint8_t nSimID = vsim_get(MSG_CMD_VSIM_GET_STANDBY);
240 if(nSimID == vsim_get_cardstat_fromps())
241 g_vsim_event_ind_cb(E_NW_ATTACH_COMMPLETE_EVENT, nSimID, 1);
242 }
243 break;
244 case MSG_CMD_ZSCISCAN_IND:
245 {
246 uint8_t nSimID = vsim_get(MSG_CMD_VSIM_GET_SCANING);
247 RegInfo_t reg_info = {0};
248 lte_cellinfo_t cell_info = {0};
249 lte_Scell_t cell[20] = {0};
250 lte_Scell_t cell_order[20] = {0};
251 int reg_ret = 0;
252 int i = 0;
253 int j = 0;
254 memcpy(cell, stMsg.aucDataBuf, sizeof(lte_Scell_t)*20);
255 if(nSimID != 0){
256 nSimID--;
257 reg_ret = zte_GetRegInfobySimid(&reg_info, nSimID);
258 vsim_set(MSG_CMD_VSIM_SET_SCANING,0);
259 for(i = 0; i < 20; i++){
260 for(j = 0; j < 20; j++){
261 if((cell_order[j].base_Scell_info.mcc == 0 && cell_order[j].base_Scell_info.mnc == 0)
262 ||(cell_order[j].base_Scell_info.mcc == cell[i].base_Scell_info.mcc
263 && cell_order[j].base_Scell_info.mnc == cell[i].base_Scell_info.mnc
264 && cell_order[j].netMode == cell[i].netMode)){
265 if(cell[i].rsrp > cell_order[j].rsrp)
266 memcpy(&cell_order[j], &cell[i], sizeof(lte_Scell_t));
267 }
268 }
269 if(reg_ret == 0 && cell[i].base_Scell_info.cell_id == reg_info.lte_scell_info.cell_id){
270 memcpy(&cell_info.lteScell, &cell[i], sizeof(lte_Scell_t));
271 cell_info.lteScell.roamingFlag = reg_info.lte_scell_info.roamingFlag;
272 }
273 }
274 for(i = 0; i < 20; i++){
275 for(j = 0; j < 6; j++){
276 if(cell_info.lteNcell[j].base_Ncell_info.mcc == 0 && cell_info.lteNcell[j].base_Ncell_info.mnc == 0
277 && (cell_order[i].base_Scell_info.mcc != 0 || cell_order[i].base_Scell_info.mnc != 0)){
278 memcpy(&cell_info.lteNcell[j].base_Ncell_info, &cell_order[i].base_Scell_info, sizeof(base_cell_info_t));
279 cell_info.lteNcell[j].rsrp = cell_order[i].rsrp;
280 cell_info.lteNcell[j].rsrq = cell_order[i].rsrq;
281 cell_info.lteNcell[j].netMode = cell_order[i].netMode;
282 cell_info.lteNcellNum++;
283 }
284 if(cell_info.lteNcellNum == 6){
285 if(cell_order[i].rsrp > cell_info.lteNcell[j].rsrp){
286 memcpy(&cell_info.lteNcell[j].base_Ncell_info, &cell_order[i].base_Scell_info, sizeof(base_cell_info_t));
287 cell_info.lteNcell[j].rsrp = cell_order[i].rsrp;
288 cell_info.lteNcell[j].rsrq = cell_order[i].rsrq;
289 cell_info.lteNcell[j].netMode = cell_order[i].netMode;
290 }
291 }
292 }
293 }
294 g_vsim_event_ind_cb(E_GET_CELLINFO_BY_SIMID_EVENT, &cell_info, sizeof(cell_info));
295 }
lh9ed821d2023-04-07 01:36:19 -0700296 }
297 break;
298 case MSG_CMD_VSIMDEBUG_IND:
299 if(stMsg.aucDataBuf[0] == 1){
300 char imei[]="862769025435956";
301 fibo_set_IMEI_by_simid(imei,sizeof(imei),1);
302 fibo_mdm_event_regist(zte_mdm_event_ind_cb);
xf.li742dd022023-06-08 01:43:32 -0700303 vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
xf.libdd93d52023-05-12 07:10:14 -0700304 vsim_card_switch_req(1);
305 vsim_set(MSG_CMD_VSIM_SET_SWITCH,1);
xf.li742dd022023-06-08 01:43:32 -0700306 vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
xf.libdd93d52023-05-12 07:10:14 -0700307 g_vsim_slot[1] = 1;
lh9ed821d2023-04-07 01:36:19 -0700308 }
309 if(stMsg.aucDataBuf[0] == 2){
310 fibo_vsim_close(zte_vsim_ind_cb,1);
311 }
312 if(stMsg.aucDataBuf[0] == 10){
313 zte_SetGTDATASIM(0);
314 }
315 if(stMsg.aucDataBuf[0] == 11){
316 zte_SetGTDATASIM(1);
317 }
318 if(stMsg.aucDataBuf[0] == 20){
319 zte_SetGTDUALSIM(0);
320 }
321 if(stMsg.aucDataBuf[0] == 21){
322 zte_SetGTDUALSIM(1);
323 }
xf.li742dd022023-06-08 01:43:32 -0700324 if(stMsg.aucDataBuf[0] == 30){
325 bWithVsimApp = 0;
326 fibo_SoftSim_init(zte_vsim_ind_cb,0);
327 }
328 if(stMsg.aucDataBuf[0] == 40){
329 fibo_SoftSim_close(zte_vsim_ind_cb,0);
330 }
331 if(stMsg.aucDataBuf[0] == 31){
332 bWithVsimApp = 0;
333 fibo_SoftSim_init(zte_vsim_ind_cb,1);
334 }
335 if(stMsg.aucDataBuf[0] == 41){
336 fibo_SoftSim_close(zte_vsim_ind_cb,1);
337 }
338 if(stMsg.aucDataBuf[0] == 50){
339 fibo_get_CellInfo_by_simid(0);
340 }
341 if(stMsg.aucDataBuf[0] == 51){
342 fibo_get_CellInfo_by_simid(1);
343 }
lh9ed821d2023-04-07 01:36:19 -0700344 break;
345 default:
346 printf("##vsim## rcv_msg err msgid 0x%x\n",stMsg.usMsgCmd);
347 break;
348 }
349 }
350 vsim_debug_printf("##vsim## rcv_msg msgid 0x%x param=%d end\n",stMsg.usMsgCmd, stMsg.aucDataBuf[0]);
351 }
352 printf("##vsim## msg_thread quit\n");
353 g_msg_thread_state = -1;
354 pthread_exit(0);
355}
356
357int32_t zte_atVsimInit(VSIM_COMMAND vsim_apdu_process_fn, uint8_t nSimID)
358{
xf.libdd93d52023-05-12 07:10:14 -0700359 char stat[4] = {0};
360
361 sc_cfg_get("vsim_stat",stat,sizeof(stat));
lh9ed821d2023-04-07 01:36:19 -0700362 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
xf.libdd93d52023-05-12 07:10:14 -0700363 if(vsim_apdu_process_fn == NULL || nSimID != 1 || g_vsim_apdu_process_cb || atoi(stat)){
364 printf("##vsim## init param err fn=0x%x old=0x%x sim=%d stat=%d\n",
365 vsim_apdu_process_fn, g_vsim_apdu_process_cb, nSimID, atoi(stat));
lh9ed821d2023-04-07 01:36:19 -0700366 return -1;
367 }
368 g_vsim_apdu_process_cb = vsim_apdu_process_fn;
369 if(g_read_thread_state != 0)
370 g_read_thread_state = pthread_create(&read_thread_tid, NULL, (void *)read_thread_entry, NULL);
371 if(g_msg_thread_state != 0)
372 g_msg_thread_state = pthread_create(&msg_thread_tid, NULL, (void *)msg_thread_entry, NULL);
373 if(g_read_thread_state != 0 || g_msg_thread_state != 0){
374 printf("##vsim## init fail read=%d msg=%d\n", g_read_thread_state, g_msg_thread_state);
375 return -1;
376 }
xf.libdd93d52023-05-12 07:10:14 -0700377 g_vsim_slot[1] = 1;
xf.li742dd022023-06-08 01:43:32 -0700378 g_sim_status[1] = -1;
xf.libdd93d52023-05-12 07:10:14 -0700379 sc_cfg_set("vsim_stat","1");
lh9ed821d2023-04-07 01:36:19 -0700380 vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
381 vsim_card_switch_req(1);
382 vsim_set(MSG_CMD_VSIM_SET_SWITCH,1);
xf.li742dd022023-06-08 01:43:32 -0700383 vsim_send_at("AT+ZCARDSWITCH=1,1\r\n", NULL, NULL);
384 vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700385 return 0;
386}
387
xf.li742dd022023-06-08 01:43:32 -0700388int32_t zte_atSoftSimInit(SoftSim_COMMAND softssim_apdu_process_fn, uint8_t nSimID)
xf.libdd93d52023-05-12 07:10:14 -0700389{
390 char stat[4] = {0};
391
392 sc_cfg_get("softsim_stat",stat,sizeof(stat));
393 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
394 if(softssim_apdu_process_fn == NULL || (nSimID != 1 && nSimID != 0) || g_softsim_apdu_process_cb || atoi(stat)){
395 printf("##vsim## soft init param err fn=0x%x old=0x%x sim=%d\n",
396 softssim_apdu_process_fn, g_softsim_apdu_process_cb, nSimID, atoi(stat));
397 return -1;
398 }
399 g_vsim_slot[nSimID] = 2;
xf.li742dd022023-06-08 01:43:32 -0700400 g_sim_status[nSimID] = -1;
xf.libdd93d52023-05-12 07:10:14 -0700401 sc_cfg_set("softsim_stat","1");
402 g_softsim_apdu_process_cb = softssim_apdu_process_fn;
403 if(nSimID){
404 vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø
405 vsim_card_switch_req(1);
406 vsim_set(MSG_CMD_VSIM_SET_SWITCH,1);
xf.li742dd022023-06-08 01:43:32 -0700407 if(bWithVsimApp == 1)
408 {
409 vsim_send_at("AT+ZCARDSWITCH=2,1\r\n", NULL, NULL);
410 }
411 else
412 {
413 vsim_send_at("AT+ZCARDSWITCH=3,1\r\n", NULL, NULL);
414 }
415 vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
xf.libdd93d52023-05-12 07:10:14 -0700416 }else{
417 uint8_t sim = 0;
418 uint8_t ret = 0;
419 zte_GetGTDUALSIM(&sim);
420 if(sim != nSimID)
421 zte_SetGTDUALSIM(nSimID);
422 ret = vsim_get_cardstat_fromps();
423 if(ret >= 0 && nSimID != ret)
424 vsim_card_switch_req(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700425 if(bWithVsimApp == 1)
426 {
427 vsim_send_at("AT+ZCARDSWITCH=2,0\r\n", NULL, NULL);
428 }
429 else
430 {
431 vsim_send_at("AT+ZCARDSWITCH=3,0\r\n", NULL, NULL);
432 }
433 vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
434// vsim_send_at("AT+CFUN=5\r\n", NULL, NULL);
435 vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
xf.libdd93d52023-05-12 07:10:14 -0700436 if(sim != nSimID)
437 zte_SetGTDUALSIM(sim);
438 if(ret >= 0 && nSimID != ret)
439 vsim_card_switch_req(ret);
440 }
441 return 0;
442}
443
444int32_t zte_atSoftSimClose(VSIM_COMMAND vsim_apdu_process_fn, uint8_t nSimID)
lh9ed821d2023-04-07 01:36:19 -0700445{
446 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
xf.libdd93d52023-05-12 07:10:14 -0700447 if(nSimID != 1 && nSimID != 0){
448 printf("##vsim## soft close param err sim=%d\n", nSimID);
449 return -1;
450 }
xf.li742dd022023-06-08 01:43:32 -0700451 g_vsim_slot[nSimID] = 0;
452 g_sim_status[nSimID] = -1;
xf.libdd93d52023-05-12 07:10:14 -0700453 if(nSimID){
xf.li742dd022023-06-08 01:43:32 -0700454 vsim_card_switch_req(1);
xf.libdd93d52023-05-12 07:10:14 -0700455 zte_SetGTDATASIM(1);
xf.li742dd022023-06-08 01:43:32 -0700456 vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
xf.libdd93d52023-05-12 07:10:14 -0700457 vsim_card_switch_req(0);
458 zte_SetGTDUALSIM(0);
459 vsim_set(MSG_CMD_VSIM_RESET_FLOW_STATISTIC,1);
460 }else{
461 uint8_t sim = 0;
462 uint8_t ret = 0;
463 zte_GetGTDUALSIM(&sim);
464 if(sim != nSimID)
465 zte_SetGTDUALSIM(nSimID);
466 ret = vsim_get_cardstat_fromps();
467 if(ret >= 0 && nSimID != ret)
468 vsim_card_switch_req(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700469 // vsim_send_at("AT+CFUN=5\r\n", NULL, NULL);
470 vsim_send_at("AT+ZCARDSWITCH=0,0\r\n", NULL, NULL);
471 vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
472 vsim_send_at("AT+CFUN=1\r\n", NULL, NULL);
xf.libdd93d52023-05-12 07:10:14 -0700473 if(sim != nSimID)
474 zte_SetGTDUALSIM(sim);
475 if(ret >= 0 && nSimID != ret)
476 vsim_card_switch_req(ret);
477 }
478 g_vsim_apdu_process_cb = NULL;
xf.libdd93d52023-05-12 07:10:14 -0700479 sc_cfg_set("softsim_stat","0");
480 return 0;
481}
482
483int32_t zte_atVsimClose(SoftSim_COMMAND softssim_apdu_process_fn, uint8_t nSimID)
484{
485 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
486 if(nSimID != 1 && nSimID != 0){
487 printf("##vsim## close param err sim=%d\n", nSimID);
488 return -1;
489 }
xf.li742dd022023-06-08 01:43:32 -0700490 g_vsim_slot[1] = 0;
491 g_sim_status[1] = -1;
492 vsim_card_switch_req(1);
lh9ed821d2023-04-07 01:36:19 -0700493 zte_SetGTDATASIM(1);
xf.li742dd022023-06-08 01:43:32 -0700494 vsim_send_at("AT+CFUN=0\r\n", NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700495 vsim_card_switch_req(0);
496 zte_SetGTDUALSIM(0);
xf.libdd93d52023-05-12 07:10:14 -0700497 vsim_set(MSG_CMD_VSIM_RESET_FLOW_STATISTIC,1);
498 g_vsim_apdu_process_cb = NULL;
xf.libdd93d52023-05-12 07:10:14 -0700499 sc_cfg_set("vsim_stat","0");
lh9ed821d2023-04-07 01:36:19 -0700500 return 0;
501}
502
xf.libdd93d52023-05-12 07:10:14 -0700503
lh9ed821d2023-04-07 01:36:19 -0700504int32_t zte_SetGTDATASIM(uint8_t nSimID)
505{
506 int ret = 0;
507 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
xf.li742dd022023-06-08 01:43:32 -0700508 if(vsim_get(MSG_CMD_VSIM_GET_AUTHING) || vsim_get(MSG_CMD_VSIM_GET_SCANING)){
lh9ed821d2023-04-07 01:36:19 -0700509 printf("##vsim## [%s]->%d fail AUTHING\n", __FUNCTION__, nSimID);
510 return -1;
511 }
512 vsim_set(MSG_CMD_VSIM_SET_STANDBY,nSimID);
513 ret = vsim_get_cardstat_fromps();
514 if(ret >= 0){
515 if(nSimID != ret){
516 //Èç¹ûÉèÖú͵±Ç°µ×²ã´ý»ú²à²»Ò»Ö²ÅÇÐ,forTAUING
517 vsim_card_switch_req(nSimID);
518 }
519 }else
520 vsim_card_switch_req(nSimID);
521 vsim_set(MSG_CMD_VSIM_SET_SWITCH, nSimID);
522 printf("##vsim## [%s] cardstat=%d sim=%d\n", __FUNCTION__, ret, nSimID);
523 return 0;
524}
525
526int32_t zte_GetGTDATASIM(uint8_t *nSimID)
527{
528 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
529 *nSimID = vsim_get(MSG_CMD_VSIM_GET_STANDBY);
530 return 0;
531}
532
533int32_t zte_SetGTDUALSIM(uint8_t nSimID)
534{
535 int ret = 0;
536 unsigned char standby = vsim_get(MSG_CMD_VSIM_GET_STANDBY);
537 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
538 ret = vsim_set(MSG_CMD_VSIM_SET_SWITCH,nSimID);
539 if(ret == 0){
540 printf("##vsim## [%s] err sim=%d\n", __FUNCTION__, nSimID);
541 return -1;
542 }
543 //ATÒѾ­Çкã¬ÏÂÃæÊÇÅжÏÊÇ·ñÒªÇп¨
544 if(vsim_get(MSG_CMD_VSIM_GET_TAUING)){//TAUµÄ¹ý³ÌÖÐ,²»Çп¨
545 printf("##vsim## [%s] TAUING\n", __FUNCTION__);
546 return 0;
547 }
548 ret = vsim_get_cardstat_fromps();
549 if(ret >= 0 && standby != ret && standby == nSimID){
550 //µ±Çл»ATµÄÄ¿±ê´ý»ú²àºÍÉϲã֮ǰÉ趨µÄ´ý»ú²àÏàͬ,ÇҺ͵ײãʵ¼ÊµÄ´ý»ú²à²»Í¬,ÓÖ²»ÊÇTAUµÄ¹ý³ÌÖÐ,¾Í´¥·¢Çп¨
551 vsim_card_switch_req(nSimID);
552 }
553 printf("##vsim## [%s] cardstat=%d standby=%d sim=%d\n", __FUNCTION__, ret, standby, nSimID);
554 return 0;
555}
556
557int32_t zte_GetGTDUALSIM(uint8_t *nSimID)
558{
559 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
560 *nSimID = vsim_get(MSG_CMD_VSIM_GET_SWITCH);
561 return 0;
562}
563
564int32_t zte_mdm_event_regist(zte_mdm_event_ind_callback ind_cb)
565{
566 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
567 g_vsim_event_ind_cb = ind_cb;
568 return 0;
569}
570
571void zte_vsim_debug(void)
572{
573 g_vsim_event_ind_cb = zte_mdm_event_ind_cb;
574 g_vsim_apdu_process_cb = zte_vsim_ind_cb;
575 if(g_read_thread_state != 0)
576 g_read_thread_state = pthread_create(&read_thread_tid, NULL, (void *)read_thread_entry, NULL);
577 if(g_msg_thread_state != 0)
578 g_msg_thread_state = pthread_create(&msg_thread_tid, NULL, (void *)msg_thread_entry, NULL);
579 if(g_read_thread_state != 0 || g_msg_thread_state != 0){
580 printf("##vsim## debug fail read=%d msg=%d\n", g_read_thread_state, g_msg_thread_state);
581 }
582}
583
584int32_t zte_atVsimReset(void)
585{
586 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
587 return restart_request(MODULE_ID_VSIM);
588}
589
590int32_t zte_SetCfunMode(uint8_t mode)
591{
592 char at_cmd[64] = {0};
593 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
594 snprintf(at_cmd,sizeof(at_cmd),"AT+CFUN=%d\r\n", mode);
xf.li742dd022023-06-08 01:43:32 -0700595 return vsim_send_at(at_cmd, NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700596}
597
598int32_t zte_GetCfunMode(uint8_t *mode)
599{
600 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
601 if(mode)
xf.li742dd022023-06-08 01:43:32 -0700602 return vsim_send_at("AT+CFUN?\r\n", "%1d", (void**)&mode);
lh9ed821d2023-04-07 01:36:19 -0700603 return -1;
604}
605
606int32_t zte_SetIMEIbySimId(uint8_t *imei, uint8_t imei_len, uint8_t nSimID)
607{
608 int ret = -1;
609 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
610 if(imei){
611 char at_cmd[64] = {0};
612 uint8_t sim = 0;
613 zte_GetGTDUALSIM(&sim);
614 if(sim != nSimID)
615 zte_SetGTDUALSIM(nSimID);
616 snprintf(at_cmd,sizeof(at_cmd),"AT+CGSN=%s\r\n",imei);
xf.li742dd022023-06-08 01:43:32 -0700617 ret = vsim_send_at(at_cmd, NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700618 if(sim != nSimID)
619 zte_SetGTDUALSIM(sim);
620 }
621 return ret;
622}
623
624int32_t zte_GetIMEIbySimId(uint8_t *imei, uint8_t imei_len, uint8_t nSimID)
625{
626 int ret = -1;
627 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
628 if(imei){
629 uint8_t sim = 0;
630 zte_GetGTDUALSIM(&sim);
631 if(sim != nSimID)
632 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700633 ret = vsim_send_at("AT+CGSN\r\n", "%s", (void**)&imei);
lh9ed821d2023-04-07 01:36:19 -0700634 if(sim != nSimID)
635 zte_SetGTDUALSIM(sim);
636 }
637 return ret;
638}
639
640
641int32_t zte_GetCCIDbySimId(uint8_t *ccid, uint8_t ccid_len, uint8_t nSimID)
642{
643 int ret = -1;
644 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
645 if(ccid){
646 uint8_t sim = 0;
647 zte_GetGTDUALSIM(&sim);
648 if(sim != nSimID)
649 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700650 ret = vsim_send_at("AT+ZICCID?\r\n", "%s", (void**)&ccid);
lh9ed821d2023-04-07 01:36:19 -0700651 if(sim != nSimID)
652 zte_SetGTDUALSIM(sim);
653 }
654 return ret;
655}
656
657int32_t zte_GetMCCMNCbySimId(char *mcc, char *mnc, uint8_t nSimID)
658{
659 int ret = -1;
660 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
661 if(mcc && mnc){
662#if 0
663 int sw1=0;
664 int sw2=-1;
665 char response[513] = {0};//³¤¶È·¶Î§0-256×Ö½Ú£¬7F205F70±íʾ4¸ö×Ö½Ú³¤¶È
666 void *p[] = {&sw1,&sw2,response};
667 uint8_t sim = 0;
668 zte_GetGTDUALSIM(&sim);
669 if(sim != nSimID)
670 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700671 vsim_send_at("AT+CRSM=176,28589,0,0,4\r\n", "%d,%d,%s", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700672 if(sw1 == 144 && sw2 == 0){
673 char imsi[64] = {0};
674 char strPlmnLast[10] = {0};
675 void *p1[] = {imsi};
676
xf.li742dd022023-06-08 01:43:32 -0700677 vsim_send_at("AT+CIMI\r\n", "%s", (void**)p1);
lh9ed821d2023-04-07 01:36:19 -0700678 strncpy(strPlmnLast, &response[strlen(response)-2], 2);
679 memset(mcc, 0, 4);
680 memset(mnc, 0, 4);
681 memcpy(mcc, imsi, 3);
682 if(0 == strcmp("03", strPlmnLast))
683 memcpy(mnc, imsi+3, 3);
684 else
685 memcpy(mnc, imsi+3, 2);
686 }
687 if(sim != nSimID)
688 zte_SetGTDUALSIM(sim);
689 return !(sw1 == 144 && sw2 == 0);
690#else
691 int i1,i2,i3,i4,i5;
692 char plmn[8] = {0};
693 void *p[] = {&i1,&i2,&i3,&i4,&i5,plmn};
694 uint8_t sim = 0;
695 zte_GetGTDUALSIM(&sim);
696 if(sim != nSimID)
697 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700698 ret = vsim_send_at("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d,%s", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700699 if(sim != nSimID)
700 zte_SetGTDUALSIM(sim);
701 memset(mcc, 0, 4);
702 memset(mnc, 0, 4);
703 memcpy(mcc, plmn, 3);
704 memcpy(mnc, plmn+3, 3);
705#endif
706 }
707 return ret;
708}
709
710int32_t zte_SwitchSimHandle(uint8_t mode)
711{
712 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
713 return 0;
714}
715
716int32_t zte_GetCSQbySimId(int32_t *rssi, int32_t *ber, uint8_t nSimID)
717{
718 int ret = -1;
719 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
720 if(rssi && ber){
721 void *p[] = {rssi,ber};
722 uint8_t sim = 0;
723 zte_GetGTDUALSIM(&sim);
724 if(sim != nSimID)
725 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700726 ret = vsim_send_at("AT+CSQ\r\n", "%d,%d", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700727 if(sim != nSimID)
728 zte_SetGTDUALSIM(sim);
729 }
730 return ret;
731}
732
733int32_t zte_GetRegInfobySimid(RegInfo_t *reg_info, uint8_t nSimID)
734{
735 int ret = -1;
736 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
737 if(reg_info){
xf.li742dd022023-06-08 01:43:32 -0700738 int i,act,rac,srv_domain;
lh9ed821d2023-04-07 01:36:19 -0700739 void *p[] = {&i,&act,&reg_info->lte_scell_info.cell_id,&rac,&reg_info->lte_scell_info.tac};
xf.li742dd022023-06-08 01:43:32 -0700740 void *p1[] = {&reg_info->nStatus,&srv_domain,&reg_info->lte_scell_info.roamingFlag};
lh9ed821d2023-04-07 01:36:19 -0700741 uint8_t sim = 0;
742 zte_GetGTDUALSIM(&sim);
743 if(sim != nSimID)
744 zte_SetGTDUALSIM(nSimID);
745 reg_info->nStatus = 0;
xf.li742dd022023-06-08 01:43:32 -0700746 vsim_send_at("AT^SYSINFO\r\n", "%d,%d,%d", (void**)p1);
747 ret = vsim_send_at("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700748 if(sim != nSimID)
749 zte_SetGTDUALSIM(sim);
xf.li742dd022023-06-08 01:43:32 -0700750 if(ret || reg_info->nStatus != E_NW_STATUS_SRV_AVAILABLE)
lh9ed821d2023-04-07 01:36:19 -0700751 return -1;
752 if(act == 16){
753 reg_info->curr_rat = E_NW_RADIO_IF_LTE;
754 } else {
755 if(act == 1)
756 reg_info->curr_rat = E_NW_RADIO_IF_TDSCDMA;
757 else if(act == 2)
758 reg_info->curr_rat = E_NW_RADIO_IF_WCDMA;
759 else if(act == 4)
760 reg_info->curr_rat = E_NW_RADIO_IF_GSM;
761 else
762 printf("##vsim## [%s] act=%d ???\n", __FUNCTION__, act);
763 }
764 }
765 return ret;
766}
767
xf.li742dd022023-06-08 01:43:32 -0700768int32_t zte_GetCellInfobySimId(uint8_t nSimID)
lh9ed821d2023-04-07 01:36:19 -0700769{
770 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
xf.li742dd022023-06-08 01:43:32 -0700771 vsim_set(MSG_CMD_VSIM_SET_SCANING, 1+nSimID);
772 ipc_send_message(MODULE_ID_VSIM, MODULE_ID_AT_CTL, MSG_CMD_ZSCISCAN_REQ, 0, NULL, 0);
lh9ed821d2023-04-07 01:36:19 -0700773 return 0;
774}
775
776int32_t zte_GetNetInfobySimId(NetInfo_t *pNetInfo, uint8_t nSimID)
777{
778 VSIM_MSG_BUF msg_in = {0};
779 VSIM_MSG_BUF msg_out = {0};
780 int ret = -1;
781 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
782 if(pNetInfo && nSimID < 2){
783 msg_in.usMsgCmd = MSG_CMD_VSIM_GET_FLOW_STATISTIC;
784 msg_in.aucDataBuf[0] = nSimID;
785 ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out);
786 if(ret == 0){
787 printf("##vsim## [%s] vsim_proc err\n", __FUNCTION__);
788 }
789 if(sizeof(NetInfo_t) > msg_out.usDataLen)
790 memcpy(pNetInfo, msg_out.aucDataBuf, msg_out.usDataLen);
791 else
792 memcpy(pNetInfo, msg_out.aucDataBuf, sizeof(NetInfo_t));
793 }
794 return ret;
795}
796
797int32_t zte_SetAPNbySimID(Data_call_config_info_t *data_call, uint8_t nSimID)
798{
799 return 0;
800}
801
802int32_t zte_StartDataCallbySimId(Data_call_config_info_t *data_call, uint8_t nSimID)
803{
804 int ret = -1;
805 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
806 if(data_call){
807 uint8_t sim = 0;
808 char at_cmd[128] = {0};
809 void *p[] = {&data_call->profile_id};
810 char reservecid[30] = {0};
811 unsigned char cid_reserved = 0;
812 unsigned char cid_reserved_vsim = 0;
813
814 zte_GetGTDATASIM(&sim);
815 if(sim != nSimID){
816 printf("##vsim## [%s] nSimID=%d standby=%d err\n", __FUNCTION__, nSimID, sim);
817 return ret;
818 }
819 if(nSimID){
820 sc_cfg_get("cid_reserved",reservecid,sizeof(reservecid));
821 if(strlen(reservecid))
822 cid_reserved = atoi(reservecid);
823 cid_reserved_vsim = cid_reserved|15;
824 snprintf(at_cmd,sizeof(at_cmd),"AT+CIDRESERVED=%d\r\n", cid_reserved_vsim);
xf.li742dd022023-06-08 01:43:32 -0700825 vsim_send_at(at_cmd, NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700826 }
827 if(data_call->ip_family == E_DATA_IP_FAMILY_IPV4)
828 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);
829 else if(data_call->ip_family == E_DATA_IP_FAMILY_IPV6)
830 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);
831 else if(data_call->ip_family == E_DATA_IP_FAMILY_IPV4V6)
832 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);
833 else {
834 printf("##vsim## [%s] ip_family=%d ???\n", __FUNCTION__, data_call->ip_family);
835 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);
836 }
837 zte_GetGTDUALSIM(&sim);
838 if(sim != nSimID)
839 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700840 ret = vsim_send_at(at_cmd, "%d", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700841 vsim_debug_printf("##vsim## [%s] ret=%d cid=%d\n", __FUNCTION__, ret, data_call->profile_id);
842 if(sim != nSimID)
843 zte_SetGTDUALSIM(sim);
844 if(nSimID){
845 snprintf(at_cmd,sizeof(at_cmd),"AT+CIDRESERVED=%d\r\n", cid_reserved);
xf.li742dd022023-06-08 01:43:32 -0700846 vsim_send_at(at_cmd, NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700847 }
848 }
849 return ret;
850}
851
852int32_t zte_StopDataCallbySimId(uint8_t profile_id, uint8_t nSimID)
853{
854 int ret = -1;
855 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
856 if(profile_id > 0 && profile_id < 9){
857 uint8_t sim = 0;
858 char at_cmd[64] = {0};
859
860 snprintf(at_cmd,sizeof(at_cmd),"AT+ZPDPDEACT=%d\r\n", profile_id);
861 zte_GetGTDUALSIM(&sim);
862 if(sim != nSimID)
863 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700864 ret = vsim_send_at(at_cmd, NULL, NULL);
lh9ed821d2023-04-07 01:36:19 -0700865 if(sim != nSimID)
866 zte_SetGTDUALSIM(sim);
867 }
868 return ret;
869}
870
871int32_t zte_GetDataAddrbySimID(uint8_t profile_id, Data_call_addr_info_list_t *addr_list, uint8_t nSimID)
872{
873 int ret = -1;
874 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
875 if(profile_id > 0 && profile_id < 9 && addr_list){
876 uint8_t sim = 0;
877 char at_cmd[64] = {0};
878 int cid = 0;
879 void *p[] = {&cid, addr_list};
880
881 snprintf(at_cmd,sizeof(at_cmd),"AT+CGPADDR=%d\r\n", profile_id);
882 zte_GetGTDUALSIM(&sim);
883 if(sim != nSimID)
884 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700885 ret = vsim_send_at(at_cmd, "%d,%17s", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700886 if(sim != nSimID)
887 zte_SetGTDUALSIM(sim);
888 }
889 return ret;
890}
891
892int32_t zte_GetSimStatusbySimId(E_SIM_STATUS *sim_status, uint8_t nSimID)
893{
894 int ret = -1;
895 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
896 if(sim_status){
897 uint8_t sim = 0;
898 char at_paras[64] = {0};
899 void *p[] = {at_paras};
xf.li742dd022023-06-08 01:43:32 -0700900
901 vsim_debug_printf("##vsim## [%s] simid=%d sim_stat=%d\n", __FUNCTION__, nSimID, g_sim_status[nSimID]);
902 if(g_vsim_slot[nSimID] && g_sim_status[nSimID] == E_SIM_STAT_READY){
903 *sim_status = E_SIM_STAT_READY;
904 return 0;
905 }
lh9ed821d2023-04-07 01:36:19 -0700906 zte_GetGTDUALSIM(&sim);
907 if(sim != nSimID)
908 zte_SetGTDUALSIM(nSimID);
xf.li742dd022023-06-08 01:43:32 -0700909 ret = vsim_send_at("AT+CPIN?\r\n", "%s", (void**)p);
lh9ed821d2023-04-07 01:36:19 -0700910 if(sim != nSimID)
911 zte_SetGTDUALSIM(sim);
912 if(ret == 0){
913 if (strncmp("READY", at_paras, strlen("READY")) == 0)
914 {
915 *sim_status = E_SIM_STAT_READY;
916 }
917 /*Èç¹ûµ±Ç°ÃÜÂëÊäÈëÇëÇóΪPIN»òPIN2£¬ÔòÊäÈë+CPIN=<pin>½øÐÐУÑé*/
918 else if(strncmp("SIM PIN",at_paras, strlen("SIM PIN")) == 0)
919 {
920 *sim_status = E_SIM_STAT_PIN;
921 }
922 /*Èç¹ûµ±Ç°ÃÜÂëÊäÈëÇëÇóΪPUK»òPUK2£¬ÔòÊäÈë+CPIN=<pin>,<newpin>½øÐнâËø*/
923 else if(strncmp("SIM PUK",at_paras, strlen("SIM PUK")) == 0)
924 {
925 *sim_status = E_SIM_STAT_PUK;
926 }
927 } else if(ret == 10){
928 *sim_status = E_SIM_STAT_NOT_INSERTED;
929 } else if(ret == 14){
930 *sim_status = E_SIM_STAT_BUSY;
931 } else {
932 *sim_status = E_SIM_STAT_UNKNOWN;
933 }
xf.li742dd022023-06-08 01:43:32 -0700934 if(g_vsim_slot[nSimID]){
935 g_sim_status[nSimID] = *sim_status;
936 }
lh9ed821d2023-04-07 01:36:19 -0700937 return 0;
938 }
939 return -1;
940}
941
942int32_t zte_SendATbySimId(char *req_at, char *info_fmt, void **pval, uint8_t nSimID)
943{
944 int ret = -1;
945 uint8_t sim = 0;
946 vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__);
947 zte_GetGTDUALSIM(&sim);
948 if(sim != nSimID)
949 zte_SetGTDUALSIM(nSimID);
950 printf("##vsim## [%s] nSimID=%d sw=%d at=%s\n", __FUNCTION__, nSimID, sim, req_at);
xf.li742dd022023-06-08 01:43:32 -0700951 ret = vsim_send_at(req_at, info_fmt, pval);
lh9ed821d2023-04-07 01:36:19 -0700952 if(sim != nSimID)
953 zte_SetGTDUALSIM(sim);
954 return ret;
955}
956
957