diff options
Diffstat (limited to 'src/atcmd.c')
-rw-r--r-- | src/atcmd.c | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/src/atcmd.c b/src/atcmd.c index 0c4860a..d17c03f 100644 --- a/src/atcmd.c +++ b/src/atcmd.c @@ -1300,7 +1300,7 @@ int atcmd_plus_gmi_read(int fd) return 0; } -/* ICCID needed for LNA3 to determine carrier */ +/* ICCID needed to detect Verizon on multi-carrier radios */ int atcmd_plus_iccid_read(int fd) { char buf[ATCMD_LINE_SIZE]; @@ -1342,7 +1342,7 @@ int atcmd_plus_iccid_read(int fd) log_debug("buf=%s for %d", buf,strlen(buf)); token = atcmd_value_tok(&save); if (!token) { - log_debug("atcmd_value_tok model"); + log_debug("atcmd_value_tok iccid"); return -1; } else { log_debug("token is %s",token); @@ -1371,6 +1371,65 @@ int atcmd_plus_iccid_read(int fd) return 0; } +/* IMSI needed to detect Verizon when the ICCID is unrecognized */ +int atcmd_plus_imsi_read(int fd) +{ + char buf[ATCMD_LINE_SIZE]; + char *save; + char *token; + int tmp; + char *tmp_buf; + char* command = "AT+CIMI"; + + atcmd_writeline(fd, command); + //Swallow extra "\r\n" + tmp = atcmd_readline(fd, buf, sizeof(buf)); + if (tmp <= 0) { + log_debug("expected \\r\\n but it was not received"); + return -1; + } + + //Read imsi string + tmp = atcmd_readline(fd, buf, sizeof(buf)); + if (tmp <= 0) { + log_debug("expected IMSI but it was not received"); + /* Currently only LNA7/LNA7D/L4G1 models will need the IMSI */ + return -1; + } + + save = buf; + log_debug("buf=%s for %d", buf,strlen(buf)); + token = atcmd_value_tok(&save); + if (!token) { + log_debug("atcmd_value_tok imsi"); + return -1; + } else { + log_debug("token is %s",token); + } + tmp_buf = strrchr(token,' '); + if (tmp_buf) { + token = ++tmp_buf; + log_debug("Found blank, incrementing tmp"); + } else { + tmp_buf = strrchr(token,'\t'); + log_debug("Found tab, incrementing tmp"); + if(tmp_buf) + token = ++tmp_buf; + } + log_debug("token[0]=%2.2x token[1]=%2.2x",token[0],token[1]); + strncpy(Global.core.imsi, token, IMSI_LEN); + + log_debug("imsi: %s", Global.core.imsi); + + tmp = atcmd_expect_line(fd, buf, sizeof(buf), "OK"); + if (tmp <= 0) { + log_debug("expected OK but it was not received"); + return -1; + } + + return 0; +} + int atcmd_init(int fd, int read_timeout) { int tmp; @@ -1437,6 +1496,12 @@ static int sms_atcmd_init(int fd) return -1; } + tmp = atcmd_plus_imsi_read(fd); + if (tmp < 0) { + log_error("failed to read SIM IMSI"); + return -1; + } + tmp = atcmd_plus_cmgf_write(fd, SMS_PDU_MODE); if (tmp < 0) { return -1; @@ -1566,11 +1631,35 @@ int is_quectel_dual_format(void) !strncmp(Global.core.model, "EG25", MODEL_LEN)) { log_debug("Found Quectel radio with dual SMS format support"); - /* Verizon Wireless SIM */ + + /* Verizon Wireless SIM ICCID */ if (strncmp(Global.core.iccid,"891480",6) == 0) { - log_debug("Found VZW SIM"); + log_debug("Found VZW SIM by ICCID"); return 1; } + + /* Extract PLMN ID - the first 5 or 6 digits of IMSI. + Assume 6 digits for Verizon. + NOTE: Other carriers may use shorter codes */ + char plmn_id_str[PLMN_ID_SIZE_VZW] = {0}; + strncpy(plmn_id_str, Global.core.imsi, PLMN_ID_LEN_VZW); + + /* Parse as integer for easier comparison */ + int plmn_id_num = atoi(plmn_id_str); + + /* Verizon Wireless SIM MCC/MNC */ + switch (plmn_id_num) { + case 310590: + case 310890: + case 311270: + case 311480: + case 312770: + log_debug("Found VZW SIM by IMSI"); + return 1; + default: + /* ignore, not Verizon */ + break; + }; } return 0; } |