lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #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 |
| 12 | |
| 13 | enum{ |
| 14 | MSG_CMD_VSIM_GET_SWITCH = 1,//ATÔÚÄÄÒ»´ý·¢ |
| 15 | MSG_CMD_VSIM_SET_SWITCH, |
| 16 | MSG_CMD_VSIM_GET_STANDBY,//¿Í»§ÉèÖôý»ú²à,¿ÉÄܲ»Êǵ±Ç°µ±Ç°´ý»ú²à,±ÈÈçTAU |
| 17 | MSG_CMD_VSIM_SET_STANDBY, |
| 18 | MSG_CMD_VSIM_GET_TAUING,//ÕýÔÚ×öTAU,ÓÃÓÚ¼øÈ¨Á÷³ÌÇлØÊµÌ忨ÅÐ¶Ï |
| 19 | MSG_CMD_VSIM_SET_TAUING, |
| 20 | MSG_CMD_VSIM_GET_AUTHING,//ÕýÔÚ×ö¼øÈ¨,´Ëʱ½ûÖ¹TAU |
| 21 | MSG_CMD_VSIM_SET_AUTHING, |
| 22 | MSG_CMD_VSIM_GET_CARD_STAT,//»ñÈ¡µ±Ç°µ×²ãʵ¼Ê´ý»ú²à |
| 23 | MSG_CMD_VSIM_APDU, |
| 24 | MSG_CMD_VSIM_GET_FLOW_STATISTIC,//»ñÈ¡µ±Ç°Á÷Á¿Í³¼Æ |
| 25 | MSG_CMD_VSIM_RESET_FLOW_STATISTIC,//ÖØÖõ±Ç°Á÷Á¿Í³¼Æ |
| 26 | MSG_CMD_VSIM_MAX, |
| 27 | }; |
| 28 | |
| 29 | typedef struct { |
| 30 | unsigned short usMsgCmd; /* ÏûÏ¢ÀàÐÍ */ |
| 31 | unsigned short usDataLen; /* ÏûÏ¢³¤¶È£¬°üÀ¨Í·²¿ */ |
| 32 | unsigned char aucDataBuf[VSIM_MAX_MSG_LEN]; /* ÏûÏ¢ÕýÎÄ */ |
| 33 | } VSIM_MSG_BUF; |
| 34 | |
| 35 | pthread_t read_thread_tid; |
| 36 | pthread_t msg_thread_tid; |
| 37 | int g_read_thread_state = -1; |
| 38 | int g_msg_thread_state = -1; |
| 39 | VSIM_COMMAND g_vsim_apdu_process_cb; |
| 40 | zte_mdm_event_ind_callback g_vsim_event_ind_cb; |
| 41 | |
| 42 | int32_t zte_mdm_event_ind_cb(E_MODEM_EVENT_ID event_id, void *ind_data, uint32_t ind_data_len) |
| 43 | { |
| 44 | return 0; |
| 45 | } |
| 46 | 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) |
| 47 | { |
| 48 | char addr[64] = {0}; |
| 49 | char cmd[128] = {0}; |
| 50 | |
| 51 | sc_cfg_get("vsim_debug_ip",addr,sizeof(addr)); |
| 52 | if(strlen(addr)){ |
| 53 | snprintf(cmd, sizeof(cmd), "ping %s -w 5", addr); |
| 54 | system(cmd); |
| 55 | }else |
| 56 | system("ping 192.168.30.110 -w 5"); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int vsim_card_switch_req(unsigned char sim) |
| 61 | { |
| 62 | int ret = 0; |
| 63 | if(sim) |
| 64 | ret = get_modem_info("AT+ZCARDSWITCHREQ=0,1\r\n", NULL, NULL); |
| 65 | else |
| 66 | ret = get_modem_info("AT+ZCARDSWITCHREQ=1,0\r\n", NULL, NULL); |
| 67 | if(ret != 0){ |
| 68 | printf("##vsim## [%s] sim=%d ret=%d err\n", __FUNCTION__, sim, ret); |
| 69 | } |
| 70 | vsim_debug_printf("##vsim## [%s] sim=%d ret=%d\n", __FUNCTION__, sim, ret); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | static int vsim_set(unsigned short msg, unsigned char param) |
| 75 | { |
| 76 | VSIM_MSG_BUF msg_in = {0}; |
| 77 | VSIM_MSG_BUF msg_out = {0}; |
| 78 | int ret = 0; |
| 79 | |
| 80 | msg_in.usMsgCmd = msg; |
| 81 | msg_in.aucDataBuf[0] = param; |
| 82 | vsim_debug_printf("##vsim## [%s] msg=%d param=%d start\n", __FUNCTION__, msg, param); |
| 83 | ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out); |
| 84 | if(ret == 0){ |
| 85 | printf("##vsim## [%s] msg=%d param=%d err\n", __FUNCTION__, msg, param); |
| 86 | } |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | static unsigned char vsim_get(unsigned short msg) |
| 91 | { |
| 92 | VSIM_MSG_BUF msg_in = {0}; |
| 93 | VSIM_MSG_BUF msg_out = {0}; |
| 94 | int ret = 0; |
| 95 | |
| 96 | msg_in.usMsgCmd = msg; |
| 97 | vsim_debug_printf("##vsim## [%s] msg=%d start\n", __FUNCTION__, msg); |
| 98 | ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out); |
| 99 | if(ret == 0){ |
| 100 | printf("##vsim## [%s] msg=%d err\n", __FUNCTION__, msg); |
| 101 | } |
| 102 | return msg_out.aucDataBuf[0]; |
| 103 | } |
| 104 | |
| 105 | static int vsim_get_cardstat_fromps(void) |
| 106 | { |
| 107 | VSIM_MSG_BUF msg_in = {0}; |
| 108 | VSIM_MSG_BUF msg_out = {0}; |
| 109 | int ret = 0; |
| 110 | |
| 111 | msg_in.usMsgCmd = MSG_CMD_VSIM_GET_CARD_STAT; |
| 112 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 113 | ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out); |
| 114 | if(ret == 0 || msg_out.aucDataBuf[0] == msg_out.aucDataBuf[1] || msg_out.aucDataBuf[2]){ |
| 115 | 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]); |
| 116 | return -1; |
| 117 | } |
| 118 | if(msg_out.aucDataBuf[0]) |
| 119 | return 0; |
| 120 | if(msg_out.aucDataBuf[1]) |
| 121 | return 1; |
| 122 | return -1; |
| 123 | } |
| 124 | |
| 125 | static void read_thread_entry(void *arg) |
| 126 | { |
| 127 | prctl(PR_SET_NAME, "vsim_read", 0, 0, 0); |
| 128 | while(g_vsim_apdu_process_cb) |
| 129 | { |
| 130 | VSIM_MSG_BUF msg_in = {0}; |
| 131 | VSIM_MSG_BUF msg_out = {0}; |
| 132 | int ret = 0; |
| 133 | int is_auth = 0; |
| 134 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 135 | ret = syscall(__NR_vsim_read,(unsigned char *)&msg_out); |
| 136 | if(ret == 0){ |
| 137 | printf("##vsim## read fail\n"); |
| 138 | } |
| 139 | vsim_debug_printf("##vsim## read msg=%d\n", msg_out.usMsgCmd); |
| 140 | if(msg_out.usMsgCmd != MSG_CMD_VSIM_APDU || ret == 0){ |
| 141 | printf("##vsim## read msg=%d ret=%d err\n", msg_out.usMsgCmd, ret); |
| 142 | } |
| 143 | is_auth = msg_out.aucDataBuf[1]; |
| 144 | //ÇÐʵÌ忨 |
| 145 | if(is_auth){ |
| 146 | printf("##vsim## vsim_apdu_auth standby=%d\n", vsim_get(MSG_CMD_VSIM_GET_STANDBY)); |
| 147 | vsim_set(MSG_CMD_VSIM_SET_AUTHING,1); |
| 148 | usleep(20000);//±£»¤´ëÊ©,ÑÓ³Ù20ºÁÃëÔÙÏ·¢Çп¨£¬±£Ö¤¼øÈ¨ÇëÇóµÄrlc ack»Ø¸´¸øÍø²à |
| 149 | vsim_card_switch_req(0);//´ËʱʵÌ忨¿ÉÄÜ´æÔÚÍøÂçÁ´½Ó£¬ÏÈÇÐÍøÔÙÇÐÊý¾Ý |
| 150 | vsim_set(MSG_CMD_VSIM_SET_STANDBY,0); |
| 151 | } |
| 152 | msg_in.usDataLen = sizeof(msg_in.aucDataBuf); |
| 153 | ret = g_vsim_apdu_process_cb(&msg_out.aucDataBuf[2], msg_out.usDataLen, msg_in.aucDataBuf, |
| 154 | &msg_in.usDataLen, msg_out.aucDataBuf[0]); |
| 155 | vsim_debug_printf("##vsim## g_vsim_apdu_process_cb ret=0x%x len=%d\n", ret, msg_in.usDataLen); |
| 156 | //ÇÐÐéÄ⿨ |
| 157 | if(is_auth){ |
| 158 | vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Ó¦¸Ãδ½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø |
| 159 | vsim_card_switch_req(1); |
| 160 | vsim_set(MSG_CMD_VSIM_SET_AUTHING,0); |
| 161 | } |
| 162 | //msg_in.usDataLen = ret;·µ»Ø²»Êdz¤¶ÈÊÇ״̬×Ö |
| 163 | msg_in.usMsgCmd = MSG_CMD_VSIM_APDU; |
| 164 | ret = syscall(__NR_vsim_write,(unsigned char *)&msg_in); |
| 165 | if(ret == 0){ |
| 166 | printf("##vsim## write fail\n"); |
| 167 | } |
| 168 | } |
| 169 | printf("##vsim## read_thread quit\n"); |
| 170 | g_read_thread_state = -1; |
| 171 | pthread_exit(0); |
| 172 | } |
| 173 | |
| 174 | static void msg_thread_entry(void *arg) |
| 175 | { |
| 176 | int iMsgHandle = msgget(MODULE_ID_VSIM, IPC_CREAT|0600); |
| 177 | LONG msgSize = sizeof(MSG_BUF)-sizeof(LONG); |
| 178 | unsigned char SwitchStat; |
| 179 | |
| 180 | prctl(PR_SET_NAME, "vsim_msg", 0, 0, 0); |
| 181 | while(g_vsim_event_ind_cb) |
| 182 | { |
| 183 | MSG_BUF stMsg = {0}; |
| 184 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 185 | if (msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0) >= 0) |
| 186 | { |
| 187 | switch (stMsg.usMsgCmd) |
| 188 | { |
| 189 | case MSG_CMD_ZCARDSWITCHIND_IND: |
| 190 | //callback todo |
| 191 | SwitchStat = stMsg.aucDataBuf[1]; |
| 192 | if(vsim_get(MSG_CMD_VSIM_GET_AUTHING)){ |
| 193 | printf("##vsim## ZCARDSWITCHIND AUTHING abort\n"); |
| 194 | if(SwitchStat) |
| 195 | vsim_set(MSG_CMD_VSIM_SET_TAUING,0); |
| 196 | break; |
| 197 | } |
| 198 | if(SwitchStat == 0){ |
| 199 | vsim_set(MSG_CMD_VSIM_SET_TAUING,1); |
| 200 | vsim_card_switch_req(stMsg.aucDataBuf[0]); |
| 201 | }else{ |
| 202 | if(vsim_get(MSG_CMD_VSIM_GET_STANDBY) == stMsg.aucDataBuf[0]) |
| 203 | vsim_card_switch_req(stMsg.aucDataBuf[0]); |
| 204 | vsim_set(MSG_CMD_VSIM_SET_TAUING,0); |
| 205 | } |
| 206 | break; |
| 207 | case MSG_CMD_CREG_IND: |
| 208 | if(vsim_get(MSG_CMD_VSIM_GET_STANDBY) == 1){ |
| 209 | //callback todo |
| 210 | } |
| 211 | break; |
| 212 | case MSG_CMD_VSIMDEBUG_IND: |
| 213 | if(stMsg.aucDataBuf[0] == 1){ |
| 214 | char imei[]="862769025435956"; |
| 215 | fibo_set_IMEI_by_simid(imei,sizeof(imei),1); |
| 216 | fibo_mdm_event_regist(zte_mdm_event_ind_cb); |
| 217 | fibo_vsim_init(zte_vsim_ind_cb,1); |
| 218 | } |
| 219 | if(stMsg.aucDataBuf[0] == 2){ |
| 220 | fibo_vsim_close(zte_vsim_ind_cb,1); |
| 221 | } |
| 222 | if(stMsg.aucDataBuf[0] == 10){ |
| 223 | zte_SetGTDATASIM(0); |
| 224 | } |
| 225 | if(stMsg.aucDataBuf[0] == 11){ |
| 226 | zte_SetGTDATASIM(1); |
| 227 | } |
| 228 | if(stMsg.aucDataBuf[0] == 20){ |
| 229 | zte_SetGTDUALSIM(0); |
| 230 | } |
| 231 | if(stMsg.aucDataBuf[0] == 21){ |
| 232 | zte_SetGTDUALSIM(1); |
| 233 | } |
| 234 | break; |
| 235 | default: |
| 236 | printf("##vsim## rcv_msg err msgid 0x%x\n",stMsg.usMsgCmd); |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | vsim_debug_printf("##vsim## rcv_msg msgid 0x%x param=%d end\n",stMsg.usMsgCmd, stMsg.aucDataBuf[0]); |
| 241 | } |
| 242 | printf("##vsim## msg_thread quit\n"); |
| 243 | g_msg_thread_state = -1; |
| 244 | pthread_exit(0); |
| 245 | } |
| 246 | |
| 247 | int32_t zte_atVsimInit(VSIM_COMMAND vsim_apdu_process_fn, uint8_t nSimID) |
| 248 | { |
| 249 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 250 | if(vsim_apdu_process_fn == NULL || nSimID != 1){ |
| 251 | printf("##vsim## init param err fn=0x%x sim=%d\n", vsim_apdu_process_fn, nSimID); |
| 252 | return -1; |
| 253 | } |
| 254 | g_vsim_apdu_process_cb = vsim_apdu_process_fn; |
| 255 | if(g_read_thread_state != 0) |
| 256 | g_read_thread_state = pthread_create(&read_thread_tid, NULL, (void *)read_thread_entry, NULL); |
| 257 | if(g_msg_thread_state != 0) |
| 258 | g_msg_thread_state = pthread_create(&msg_thread_tid, NULL, (void *)msg_thread_entry, NULL); |
| 259 | if(g_read_thread_state != 0 || g_msg_thread_state != 0){ |
| 260 | printf("##vsim## init fail read=%d msg=%d\n", g_read_thread_state, g_msg_thread_state); |
| 261 | return -1; |
| 262 | } |
| 263 | vsim_set(MSG_CMD_VSIM_SET_STANDBY,1);//´ËÊ±ÔÆ¿¨Î´½¨ÍøÂçÁ´½Ó£¬ÏÈÇÐÊý¾ÝÔÙÇÐÍø |
| 264 | vsim_card_switch_req(1); |
| 265 | vsim_set(MSG_CMD_VSIM_SET_SWITCH,1); |
| 266 | get_modem_info("AT+CFUN=1\r\n", NULL, NULL); |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | int32_t zte_atVsimClose(VSIM_COMMAND vsim_apdu_process_fn, uint8_t nSimID) |
| 271 | { |
| 272 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 273 | zte_SetGTDATASIM(1); |
| 274 | get_modem_info("AT+CFUN=0\r\n", NULL, NULL); |
| 275 | vsim_card_switch_req(0); |
| 276 | zte_SetGTDUALSIM(0); |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | int32_t zte_SetGTDATASIM(uint8_t nSimID) |
| 281 | { |
| 282 | int ret = 0; |
| 283 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 284 | if(vsim_get(MSG_CMD_VSIM_GET_AUTHING)){ |
| 285 | printf("##vsim## [%s]->%d fail AUTHING\n", __FUNCTION__, nSimID); |
| 286 | return -1; |
| 287 | } |
| 288 | vsim_set(MSG_CMD_VSIM_SET_STANDBY,nSimID); |
| 289 | ret = vsim_get_cardstat_fromps(); |
| 290 | if(ret >= 0){ |
| 291 | if(nSimID != ret){ |
| 292 | //Èç¹ûÉèÖú͵±Ç°µ×²ã´ý»ú²à²»Ò»Ö²ÅÇÐ,forTAUING |
| 293 | vsim_card_switch_req(nSimID); |
| 294 | } |
| 295 | }else |
| 296 | vsim_card_switch_req(nSimID); |
| 297 | vsim_set(MSG_CMD_VSIM_SET_SWITCH, nSimID); |
| 298 | printf("##vsim## [%s] cardstat=%d sim=%d\n", __FUNCTION__, ret, nSimID); |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | int32_t zte_GetGTDATASIM(uint8_t *nSimID) |
| 303 | { |
| 304 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 305 | *nSimID = vsim_get(MSG_CMD_VSIM_GET_STANDBY); |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | int32_t zte_SetGTDUALSIM(uint8_t nSimID) |
| 310 | { |
| 311 | int ret = 0; |
| 312 | unsigned char standby = vsim_get(MSG_CMD_VSIM_GET_STANDBY); |
| 313 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 314 | ret = vsim_set(MSG_CMD_VSIM_SET_SWITCH,nSimID); |
| 315 | if(ret == 0){ |
| 316 | printf("##vsim## [%s] err sim=%d\n", __FUNCTION__, nSimID); |
| 317 | return -1; |
| 318 | } |
| 319 | //ATÒѾÇкã¬ÏÂÃæÊÇÅжÏÊÇ·ñÒªÇп¨ |
| 320 | if(vsim_get(MSG_CMD_VSIM_GET_TAUING)){//TAUµÄ¹ý³ÌÖÐ,²»Çп¨ |
| 321 | printf("##vsim## [%s] TAUING\n", __FUNCTION__); |
| 322 | return 0; |
| 323 | } |
| 324 | ret = vsim_get_cardstat_fromps(); |
| 325 | if(ret >= 0 && standby != ret && standby == nSimID){ |
| 326 | //µ±Çл»ATµÄÄ¿±ê´ý»ú²àºÍÉϲã֮ǰÉ趨µÄ´ý»ú²àÏàͬ,ÇҺ͵ײãʵ¼ÊµÄ´ý»ú²à²»Í¬,ÓÖ²»ÊÇTAUµÄ¹ý³ÌÖÐ,¾Í´¥·¢Çп¨ |
| 327 | vsim_card_switch_req(nSimID); |
| 328 | } |
| 329 | printf("##vsim## [%s] cardstat=%d standby=%d sim=%d\n", __FUNCTION__, ret, standby, nSimID); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | int32_t zte_GetGTDUALSIM(uint8_t *nSimID) |
| 334 | { |
| 335 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 336 | *nSimID = vsim_get(MSG_CMD_VSIM_GET_SWITCH); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | int32_t zte_mdm_event_regist(zte_mdm_event_ind_callback ind_cb) |
| 341 | { |
| 342 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 343 | g_vsim_event_ind_cb = ind_cb; |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | void zte_vsim_debug(void) |
| 348 | { |
| 349 | g_vsim_event_ind_cb = zte_mdm_event_ind_cb; |
| 350 | g_vsim_apdu_process_cb = zte_vsim_ind_cb; |
| 351 | if(g_read_thread_state != 0) |
| 352 | g_read_thread_state = pthread_create(&read_thread_tid, NULL, (void *)read_thread_entry, NULL); |
| 353 | if(g_msg_thread_state != 0) |
| 354 | g_msg_thread_state = pthread_create(&msg_thread_tid, NULL, (void *)msg_thread_entry, NULL); |
| 355 | if(g_read_thread_state != 0 || g_msg_thread_state != 0){ |
| 356 | printf("##vsim## debug fail read=%d msg=%d\n", g_read_thread_state, g_msg_thread_state); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | int32_t zte_atVsimReset(void) |
| 361 | { |
| 362 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 363 | return restart_request(MODULE_ID_VSIM); |
| 364 | } |
| 365 | |
| 366 | int32_t zte_SetCfunMode(uint8_t mode) |
| 367 | { |
| 368 | char at_cmd[64] = {0}; |
| 369 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 370 | snprintf(at_cmd,sizeof(at_cmd),"AT+CFUN=%d\r\n", mode); |
| 371 | return get_modem_info(at_cmd, NULL, NULL); |
| 372 | } |
| 373 | |
| 374 | int32_t zte_GetCfunMode(uint8_t *mode) |
| 375 | { |
| 376 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 377 | if(mode) |
| 378 | return get_modem_info("AT+CFUN?\r\n", "%1d", (void**)&mode); |
| 379 | return -1; |
| 380 | } |
| 381 | |
| 382 | int32_t zte_SetIMEIbySimId(uint8_t *imei, uint8_t imei_len, uint8_t nSimID) |
| 383 | { |
| 384 | int ret = -1; |
| 385 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 386 | if(imei){ |
| 387 | char at_cmd[64] = {0}; |
| 388 | uint8_t sim = 0; |
| 389 | zte_GetGTDUALSIM(&sim); |
| 390 | if(sim != nSimID) |
| 391 | zte_SetGTDUALSIM(nSimID); |
| 392 | snprintf(at_cmd,sizeof(at_cmd),"AT+CGSN=%s\r\n",imei); |
| 393 | ret = get_modem_info(at_cmd, NULL, NULL); |
| 394 | if(sim != nSimID) |
| 395 | zte_SetGTDUALSIM(sim); |
| 396 | } |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | int32_t zte_GetIMEIbySimId(uint8_t *imei, uint8_t imei_len, uint8_t nSimID) |
| 401 | { |
| 402 | int ret = -1; |
| 403 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 404 | if(imei){ |
| 405 | uint8_t sim = 0; |
| 406 | zte_GetGTDUALSIM(&sim); |
| 407 | if(sim != nSimID) |
| 408 | zte_SetGTDUALSIM(nSimID); |
| 409 | ret = get_modem_info("AT+CGSN\r\n", "%s", (void**)&imei); |
| 410 | if(sim != nSimID) |
| 411 | zte_SetGTDUALSIM(sim); |
| 412 | } |
| 413 | return ret; |
| 414 | } |
| 415 | |
| 416 | |
| 417 | int32_t zte_GetCCIDbySimId(uint8_t *ccid, uint8_t ccid_len, uint8_t nSimID) |
| 418 | { |
| 419 | int ret = -1; |
| 420 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 421 | if(ccid){ |
| 422 | uint8_t sim = 0; |
| 423 | zte_GetGTDUALSIM(&sim); |
| 424 | if(sim != nSimID) |
| 425 | zte_SetGTDUALSIM(nSimID); |
| 426 | ret = get_modem_info("AT+ZICCID?\r\n", "%s", (void**)&ccid); |
| 427 | if(sim != nSimID) |
| 428 | zte_SetGTDUALSIM(sim); |
| 429 | } |
| 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | int32_t zte_GetMCCMNCbySimId(char *mcc, char *mnc, uint8_t nSimID) |
| 434 | { |
| 435 | int ret = -1; |
| 436 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 437 | if(mcc && mnc){ |
| 438 | #if 0 |
| 439 | int sw1=0; |
| 440 | int sw2=-1; |
| 441 | char response[513] = {0};//³¤¶È·¶Î§0-256×Ö½Ú£¬7F205F70±íʾ4¸ö×Ö½Ú³¤¶È |
| 442 | void *p[] = {&sw1,&sw2,response}; |
| 443 | uint8_t sim = 0; |
| 444 | zte_GetGTDUALSIM(&sim); |
| 445 | if(sim != nSimID) |
| 446 | zte_SetGTDUALSIM(nSimID); |
| 447 | get_modem_info("AT+CRSM=176,28589,0,0,4\r\n", "%d,%d,%s", (void**)p); |
| 448 | if(sw1 == 144 && sw2 == 0){ |
| 449 | char imsi[64] = {0}; |
| 450 | char strPlmnLast[10] = {0}; |
| 451 | void *p1[] = {imsi}; |
| 452 | |
| 453 | get_modem_info("AT+CIMI\r\n", "%s", (void**)p1); |
| 454 | strncpy(strPlmnLast, &response[strlen(response)-2], 2); |
| 455 | memset(mcc, 0, 4); |
| 456 | memset(mnc, 0, 4); |
| 457 | memcpy(mcc, imsi, 3); |
| 458 | if(0 == strcmp("03", strPlmnLast)) |
| 459 | memcpy(mnc, imsi+3, 3); |
| 460 | else |
| 461 | memcpy(mnc, imsi+3, 2); |
| 462 | } |
| 463 | if(sim != nSimID) |
| 464 | zte_SetGTDUALSIM(sim); |
| 465 | return !(sw1 == 144 && sw2 == 0); |
| 466 | #else |
| 467 | int i1,i2,i3,i4,i5; |
| 468 | char plmn[8] = {0}; |
| 469 | void *p[] = {&i1,&i2,&i3,&i4,&i5,plmn}; |
| 470 | uint8_t sim = 0; |
| 471 | zte_GetGTDUALSIM(&sim); |
| 472 | if(sim != nSimID) |
| 473 | zte_SetGTDUALSIM(nSimID); |
| 474 | ret = get_modem_info("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d,%s", (void**)p); |
| 475 | if(sim != nSimID) |
| 476 | zte_SetGTDUALSIM(sim); |
| 477 | memset(mcc, 0, 4); |
| 478 | memset(mnc, 0, 4); |
| 479 | memcpy(mcc, plmn, 3); |
| 480 | memcpy(mnc, plmn+3, 3); |
| 481 | #endif |
| 482 | } |
| 483 | return ret; |
| 484 | } |
| 485 | |
| 486 | int32_t zte_SwitchSimHandle(uint8_t mode) |
| 487 | { |
| 488 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | int32_t zte_GetCSQbySimId(int32_t *rssi, int32_t *ber, uint8_t nSimID) |
| 493 | { |
| 494 | int ret = -1; |
| 495 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 496 | if(rssi && ber){ |
| 497 | void *p[] = {rssi,ber}; |
| 498 | uint8_t sim = 0; |
| 499 | zte_GetGTDUALSIM(&sim); |
| 500 | if(sim != nSimID) |
| 501 | zte_SetGTDUALSIM(nSimID); |
| 502 | ret = get_modem_info("AT+CSQ\r\n", "%d,%d", (void**)p); |
| 503 | if(sim != nSimID) |
| 504 | zte_SetGTDUALSIM(sim); |
| 505 | } |
| 506 | return ret; |
| 507 | } |
| 508 | |
| 509 | int32_t zte_GetRegInfobySimid(RegInfo_t *reg_info, uint8_t nSimID) |
| 510 | { |
| 511 | int ret = -1; |
| 512 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 513 | if(reg_info){ |
| 514 | int i,act,rac; |
| 515 | void *p[] = {&i,&act,®_info->lte_scell_info.cell_id,&rac,®_info->lte_scell_info.tac}; |
| 516 | void *p1[] = {®_info->nStatus}; |
| 517 | uint8_t sim = 0; |
| 518 | zte_GetGTDUALSIM(&sim); |
| 519 | if(sim != nSimID) |
| 520 | zte_SetGTDUALSIM(nSimID); |
| 521 | reg_info->nStatus = 0; |
| 522 | get_modem_info("AT^SYSINFO\r\n", "%d", (void**)p1); |
| 523 | ret = get_modem_info("AT+ZEMSCIQ=1\r\n", "%d,%d,%d,%d,%d", (void**)p); |
| 524 | if(sim != nSimID) |
| 525 | zte_SetGTDUALSIM(sim); |
| 526 | if(ret || reg_info->nStatus != 2) |
| 527 | return -1; |
| 528 | if(act == 16){ |
| 529 | reg_info->curr_rat = E_NW_RADIO_IF_LTE; |
| 530 | } else { |
| 531 | if(act == 1) |
| 532 | reg_info->curr_rat = E_NW_RADIO_IF_TDSCDMA; |
| 533 | else if(act == 2) |
| 534 | reg_info->curr_rat = E_NW_RADIO_IF_WCDMA; |
| 535 | else if(act == 4) |
| 536 | reg_info->curr_rat = E_NW_RADIO_IF_GSM; |
| 537 | else |
| 538 | printf("##vsim## [%s] act=%d ???\n", __FUNCTION__, act); |
| 539 | } |
| 540 | } |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | int32_t zte_GetCellInfobySimId(CellInfo_t *pcellinfo, uint8_t nSimID) |
| 545 | { |
| 546 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | int32_t zte_GetNetInfobySimId(NetInfo_t *pNetInfo, uint8_t nSimID) |
| 551 | { |
| 552 | VSIM_MSG_BUF msg_in = {0}; |
| 553 | VSIM_MSG_BUF msg_out = {0}; |
| 554 | int ret = -1; |
| 555 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 556 | if(pNetInfo && nSimID < 2){ |
| 557 | msg_in.usMsgCmd = MSG_CMD_VSIM_GET_FLOW_STATISTIC; |
| 558 | msg_in.aucDataBuf[0] = nSimID; |
| 559 | ret = syscall(__NR_vsim_proc,(unsigned char *)&msg_in, (unsigned char *)&msg_out); |
| 560 | if(ret == 0){ |
| 561 | printf("##vsim## [%s] vsim_proc err\n", __FUNCTION__); |
| 562 | } |
| 563 | if(sizeof(NetInfo_t) > msg_out.usDataLen) |
| 564 | memcpy(pNetInfo, msg_out.aucDataBuf, msg_out.usDataLen); |
| 565 | else |
| 566 | memcpy(pNetInfo, msg_out.aucDataBuf, sizeof(NetInfo_t)); |
| 567 | } |
| 568 | return ret; |
| 569 | } |
| 570 | |
| 571 | int32_t zte_SetAPNbySimID(Data_call_config_info_t *data_call, uint8_t nSimID) |
| 572 | { |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | int32_t zte_StartDataCallbySimId(Data_call_config_info_t *data_call, uint8_t nSimID) |
| 577 | { |
| 578 | int ret = -1; |
| 579 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 580 | if(data_call){ |
| 581 | uint8_t sim = 0; |
| 582 | char at_cmd[128] = {0}; |
| 583 | void *p[] = {&data_call->profile_id}; |
| 584 | char reservecid[30] = {0}; |
| 585 | unsigned char cid_reserved = 0; |
| 586 | unsigned char cid_reserved_vsim = 0; |
| 587 | |
| 588 | zte_GetGTDATASIM(&sim); |
| 589 | if(sim != nSimID){ |
| 590 | printf("##vsim## [%s] nSimID=%d standby=%d err\n", __FUNCTION__, nSimID, sim); |
| 591 | return ret; |
| 592 | } |
| 593 | if(nSimID){ |
| 594 | sc_cfg_get("cid_reserved",reservecid,sizeof(reservecid)); |
| 595 | if(strlen(reservecid)) |
| 596 | cid_reserved = atoi(reservecid); |
| 597 | cid_reserved_vsim = cid_reserved|15; |
| 598 | snprintf(at_cmd,sizeof(at_cmd),"AT+CIDRESERVED=%d\r\n", cid_reserved_vsim); |
| 599 | get_modem_info(at_cmd, NULL, NULL); |
| 600 | } |
| 601 | if(data_call->ip_family == E_DATA_IP_FAMILY_IPV4) |
| 602 | 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); |
| 603 | else if(data_call->ip_family == E_DATA_IP_FAMILY_IPV6) |
| 604 | 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); |
| 605 | else if(data_call->ip_family == E_DATA_IP_FAMILY_IPV4V6) |
| 606 | 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); |
| 607 | else { |
| 608 | printf("##vsim## [%s] ip_family=%d ???\n", __FUNCTION__, data_call->ip_family); |
| 609 | 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); |
| 610 | } |
| 611 | zte_GetGTDUALSIM(&sim); |
| 612 | if(sim != nSimID) |
| 613 | zte_SetGTDUALSIM(nSimID); |
| 614 | ret = get_modem_info(at_cmd, "%d", (void**)p); |
| 615 | vsim_debug_printf("##vsim## [%s] ret=%d cid=%d\n", __FUNCTION__, ret, data_call->profile_id); |
| 616 | if(sim != nSimID) |
| 617 | zte_SetGTDUALSIM(sim); |
| 618 | if(nSimID){ |
| 619 | snprintf(at_cmd,sizeof(at_cmd),"AT+CIDRESERVED=%d\r\n", cid_reserved); |
| 620 | get_modem_info(at_cmd, NULL, NULL); |
| 621 | } |
| 622 | } |
| 623 | return ret; |
| 624 | } |
| 625 | |
| 626 | int32_t zte_StopDataCallbySimId(uint8_t profile_id, uint8_t nSimID) |
| 627 | { |
| 628 | int ret = -1; |
| 629 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 630 | if(profile_id > 0 && profile_id < 9){ |
| 631 | uint8_t sim = 0; |
| 632 | char at_cmd[64] = {0}; |
| 633 | |
| 634 | snprintf(at_cmd,sizeof(at_cmd),"AT+ZPDPDEACT=%d\r\n", profile_id); |
| 635 | zte_GetGTDUALSIM(&sim); |
| 636 | if(sim != nSimID) |
| 637 | zte_SetGTDUALSIM(nSimID); |
| 638 | ret = get_modem_info(at_cmd, NULL, NULL); |
| 639 | if(sim != nSimID) |
| 640 | zte_SetGTDUALSIM(sim); |
| 641 | } |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | int32_t zte_GetDataAddrbySimID(uint8_t profile_id, Data_call_addr_info_list_t *addr_list, uint8_t nSimID) |
| 646 | { |
| 647 | int ret = -1; |
| 648 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 649 | if(profile_id > 0 && profile_id < 9 && addr_list){ |
| 650 | uint8_t sim = 0; |
| 651 | char at_cmd[64] = {0}; |
| 652 | int cid = 0; |
| 653 | void *p[] = {&cid, addr_list}; |
| 654 | |
| 655 | snprintf(at_cmd,sizeof(at_cmd),"AT+CGPADDR=%d\r\n", profile_id); |
| 656 | zte_GetGTDUALSIM(&sim); |
| 657 | if(sim != nSimID) |
| 658 | zte_SetGTDUALSIM(nSimID); |
| 659 | ret = get_modem_info(at_cmd, "%d,%17s", (void**)p); |
| 660 | if(sim != nSimID) |
| 661 | zte_SetGTDUALSIM(sim); |
| 662 | } |
| 663 | return ret; |
| 664 | } |
| 665 | |
| 666 | int32_t zte_GetSimStatusbySimId(E_SIM_STATUS *sim_status, uint8_t nSimID) |
| 667 | { |
| 668 | int ret = -1; |
| 669 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 670 | if(sim_status){ |
| 671 | uint8_t sim = 0; |
| 672 | char at_paras[64] = {0}; |
| 673 | void *p[] = {at_paras}; |
| 674 | zte_GetGTDUALSIM(&sim); |
| 675 | if(sim != nSimID) |
| 676 | zte_SetGTDUALSIM(nSimID); |
| 677 | ret = get_modem_info("AT+CPIN?\r\n", "%s", (void**)p); |
| 678 | if(sim != nSimID) |
| 679 | zte_SetGTDUALSIM(sim); |
| 680 | if(ret == 0){ |
| 681 | if (strncmp("READY", at_paras, strlen("READY")) == 0) |
| 682 | { |
| 683 | *sim_status = E_SIM_STAT_READY; |
| 684 | } |
| 685 | /*Èç¹ûµ±Ç°ÃÜÂëÊäÈëÇëÇóΪPIN»òPIN2£¬ÔòÊäÈë+CPIN=<pin>½øÐÐУÑé*/ |
| 686 | else if(strncmp("SIM PIN",at_paras, strlen("SIM PIN")) == 0) |
| 687 | { |
| 688 | *sim_status = E_SIM_STAT_PIN; |
| 689 | } |
| 690 | /*Èç¹ûµ±Ç°ÃÜÂëÊäÈëÇëÇóΪPUK»òPUK2£¬ÔòÊäÈë+CPIN=<pin>,<newpin>½øÐнâËø*/ |
| 691 | else if(strncmp("SIM PUK",at_paras, strlen("SIM PUK")) == 0) |
| 692 | { |
| 693 | *sim_status = E_SIM_STAT_PUK; |
| 694 | } |
| 695 | } else if(ret == 10){ |
| 696 | *sim_status = E_SIM_STAT_NOT_INSERTED; |
| 697 | } else if(ret == 14){ |
| 698 | *sim_status = E_SIM_STAT_BUSY; |
| 699 | } else { |
| 700 | *sim_status = E_SIM_STAT_UNKNOWN; |
| 701 | } |
| 702 | return 0; |
| 703 | } |
| 704 | return -1; |
| 705 | } |
| 706 | |
| 707 | int32_t zte_SendATbySimId(char *req_at, char *info_fmt, void **pval, uint8_t nSimID) |
| 708 | { |
| 709 | int ret = -1; |
| 710 | uint8_t sim = 0; |
| 711 | vsim_debug_printf("##vsim## [%s] start\n", __FUNCTION__); |
| 712 | zte_GetGTDUALSIM(&sim); |
| 713 | if(sim != nSimID) |
| 714 | zte_SetGTDUALSIM(nSimID); |
| 715 | printf("##vsim## [%s] nSimID=%d sw=%d at=%s\n", __FUNCTION__, nSimID, sim, req_at); |
| 716 | ret = get_modem_info(req_at, info_fmt, pval); |
| 717 | if(sim != nSimID) |
| 718 | zte_SetGTDUALSIM(sim); |
| 719 | return ret; |
| 720 | } |
| 721 | |
| 722 | |