summaryrefslogtreecommitdiff
path: root/src/atcmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/atcmd.c')
-rw-r--r--src/atcmd.c88
1 files changed, 82 insertions, 6 deletions
diff --git a/src/atcmd.c b/src/atcmd.c
index 595a91a..a216ab6 100644
--- a/src/atcmd.c
+++ b/src/atcmd.c
@@ -1229,8 +1229,7 @@ int atcmd_plus_gmm_read(int fd)
log_debug("atcmd_value_tok model");
return -1;
}
- free(Global.core.model);
- Global.core.model = strdup(token);
+ strncpy(Global.core.model, token, MODEL_LEN);
log_debug("model: %s", Global.core.model);
@@ -1243,6 +1242,49 @@ int atcmd_plus_gmm_read(int fd)
return 0;
}
+/* Manufacturer identification is needed to pick proper manufacturer-specific commands.
+ * For example, in atcmd_plus_iccid_read() function. */
+int atcmd_plus_gmi_read(int fd)
+{
+ char buf[ATCMD_LINE_SIZE];
+ char *save;
+ char *token;
+ int tmp;
+
+ atcmd_writeline(fd, "AT+GMI");
+ //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 manufacturer string
+ tmp = atcmd_readline(fd, buf, sizeof(buf));
+ if (tmp <= 0) {
+ log_debug("expected manufacturer but it was not received");
+ return -1;
+ }
+
+ save = buf;
+ token = atcmd_value_tok(&save);
+ if (!token) {
+ log_debug("atcmd_value_tok manufacturer");
+ return -1;
+ }
+ strncpy(Global.core.manufacturer, token, MANUFACTURER_LEN);
+
+ log_debug("manufacturer: %s", Global.core.manufacturer);
+
+ 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;
+}
+
/* ICCID needed for LNA3 to determine carrier */
int atcmd_plus_iccid_read(int fd)
{
@@ -1250,8 +1292,18 @@ int atcmd_plus_iccid_read(int fd)
char *save;
char *token;
int tmp;
+ char* command;
- atcmd_writeline(fd, "AT#CCID");
+ if (is_telit_model()) {
+ command = "AT#CCID";
+ } else if (is_quectel_model()) {
+ command = "AT+QCCID";
+ } else {
+ log_error("unsupported modem manufacturer, unable to detect ICCID");
+ return -1;
+ }
+
+ atcmd_writeline(fd, command);
//Swallow extra "\r\n"
tmp = atcmd_readline(fd, buf, sizeof(buf));
if (tmp <= 0) {
@@ -1286,8 +1338,7 @@ int atcmd_plus_iccid_read(int fd)
token = ++tmp;
}
log_debug("token[0]=%2.2x token[1]=%2.2x",token[0],token[1]);
- free(Global.core.iccid);
- Global.core.iccid = strdup(token);
+ strncpy(Global.core.iccid, token, ICCID_LEN);
log_debug("iccid: %s", Global.core.iccid);
@@ -1348,12 +1399,18 @@ static int sms_atcmd_init(int fd)
return -1;
}
- tmp = atcmd_plus_gmm_read(fd);
+ tmp = atcmd_plus_gmm_read(fd);
if (tmp < 0) {
log_error("failed to read radio model");
return -1;
}
+ tmp = atcmd_plus_gmi_read(fd);
+ if (tmp < 0) {
+ log_error("failed to read radio manufacturer");
+ return -1;
+ }
+
tmp = atcmd_plus_iccid_read(fd);
if (tmp < 0) {
log_error("failed to read SIM ICCID");
@@ -1494,3 +1551,22 @@ int isCdmaTypeModel()
!strcmp(Global.core.model, "CE910-DUAL"));
}
+int is_telit_model()
+{
+ if (!strncmp(Global.core.manufacturer, "Telit", MANUFACTURER_LEN)) {
+ log_debug("Found Telit model");
+ return 1;
+ }
+
+ return 0;
+}
+
+int is_quectel_model()
+{
+ if (!strncmp(Global.core.manufacturer, "Quectel", MANUFACTURER_LEN)) {
+ log_debug("Found Quectel model");
+ return 1;
+ }
+
+ return 0;
+}