|
@@ -2,9 +2,9 @@
|
|
|
* Module_4g.c
|
|
|
*
|
|
|
* Created on: 2019-11-29
|
|
|
- * Update on: 2020-09-16
|
|
|
+ * Update on: 2020-11-26
|
|
|
* Author: Eason Yang
|
|
|
- * Version: V0.06
|
|
|
+ * Version: V0.07
|
|
|
*/
|
|
|
|
|
|
#include <sys/types.h>
|
|
@@ -80,7 +80,7 @@ void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
|
|
|
|
|
|
char *portName[3] = {"/dev/ttyUSB2", "/dev/ttyUSB2", "/dev/ttyACM2"};
|
|
|
char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
|
|
|
-char *Version_And_Date[2] = {"V0.06","2020-09-16"};
|
|
|
+char *Version_And_Date[2] = {"V0.07","2020-11-26"};
|
|
|
pid_t pid;
|
|
|
|
|
|
struct dongle_info
|
|
@@ -303,7 +303,7 @@ int isReadInfo(void)
|
|
|
int uart;
|
|
|
char rx[512];
|
|
|
char tmp[512];
|
|
|
- char Lenght;
|
|
|
+ char Length;
|
|
|
int modeStatus;
|
|
|
|
|
|
if((uart = openPort(portName[Dongle.Model])) != FAIL)
|
|
@@ -315,20 +315,36 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Set don't echo command
|
|
|
//==============================
|
|
|
- if(at_command(uart, "ate0\r", rx) <= 0)
|
|
|
+ Length = at_command(uart, "ate0\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
+ {
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+ else
|
|
|
result = FAIL;
|
|
|
|
|
|
//==============================
|
|
|
// Read Manufacturer
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+gmi\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+gmi\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,"OK"));
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
- trim_s(tmp,Lenght);
|
|
|
- strcpy(Dongle.MANUFACTURER, tmp);
|
|
|
+ trim_s(tmp,Length);
|
|
|
+
|
|
|
+ if(strstr(tmp, "atgmi") != NULL)
|
|
|
+ {
|
|
|
+ substr(tmp, tmp, 5, strlen(tmp)-5);
|
|
|
+ }
|
|
|
+
|
|
|
+ strncpy(Dongle.MANUFACTURER, tmp, strlen(tmp));
|
|
|
}
|
|
|
else
|
|
|
result = FAIL;
|
|
@@ -336,13 +352,19 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read Model
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+gmm\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+gmm\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,"OK"));
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
- trim_s(tmp,Lenght);
|
|
|
+ trim_s(tmp,Length);
|
|
|
+
|
|
|
+ if(strstr(tmp, "atgmm") != NULL)
|
|
|
+ {
|
|
|
+ substr(tmp, tmp, 5, strlen(tmp)-5);
|
|
|
+ }
|
|
|
+
|
|
|
strncpy(Dongle.MODELNAME, tmp, strlen(tmp));
|
|
|
}
|
|
|
else
|
|
@@ -351,13 +373,19 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read Revision
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+gmr\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+gmr\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx, "OK"));
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
- trim_s(tmp,Lenght);
|
|
|
+ trim_s(tmp,Length);
|
|
|
+
|
|
|
+ if(strstr(tmp, "atgmr") != NULL)
|
|
|
+ {
|
|
|
+ substr(tmp, tmp, 5, strlen(tmp)-5);
|
|
|
+ }
|
|
|
+
|
|
|
strncpy(Dongle.REVISION, tmp, strlen(tmp));
|
|
|
}
|
|
|
else
|
|
@@ -366,13 +394,19 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read IMEI
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+gsn\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+gsn\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx, "OK"));
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
- trim_s(tmp,Lenght);
|
|
|
+ trim_s(tmp,Length);
|
|
|
+
|
|
|
+ if(strstr(tmp, "atgsn") != NULL)
|
|
|
+ {
|
|
|
+ substr(tmp, tmp, 5, strlen(tmp)-5);
|
|
|
+ }
|
|
|
+
|
|
|
strncpy(Dongle.IMEI, tmp, strlen(tmp));
|
|
|
}
|
|
|
else
|
|
@@ -381,8 +415,8 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read CSQ
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+csq\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+csq\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,","));
|
|
@@ -395,8 +429,8 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read Mode
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+qcfg= \"nwscanmode\"\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+qcfg= \"nwscanmode\"\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,"OK"));
|
|
@@ -429,14 +463,24 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Set don't echo command
|
|
|
//==============================
|
|
|
- if(at_command(uart, "ate0\r", rx) <= 0)
|
|
|
+ Length = at_command(uart, "ate0\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
+ {
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+ else
|
|
|
result = FAIL;
|
|
|
|
|
|
//==============================
|
|
|
// Read Manufacturer
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+cgmi\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+cgmi\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,"OK"));
|
|
@@ -449,8 +493,8 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read Model
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+cgmm\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+cgmm\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,"OK"));
|
|
@@ -463,8 +507,8 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read Revision
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+cgmr\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+cgmr\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx, "OK"));
|
|
@@ -477,13 +521,13 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read IMEI
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+cgsn\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+cgsn\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx, "OK"));
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
- trim_s(tmp,Lenght);
|
|
|
+ trim_s(tmp,Length);
|
|
|
strncpy(Dongle.IMEI, tmp, strlen(tmp));
|
|
|
}
|
|
|
else
|
|
@@ -492,8 +536,8 @@ int isReadInfo(void)
|
|
|
//==============================
|
|
|
// Read CSQ
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+csq\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+csq\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
memcpy(tmp, rx, strcspn(rx,","));
|
|
@@ -528,7 +572,7 @@ int isReadSimInfo(void)
|
|
|
int uart;
|
|
|
char rx[512];
|
|
|
char tmp[512];
|
|
|
- char Lenght;
|
|
|
+ char Length;
|
|
|
|
|
|
if((uart = openPort(portName[Dongle.Model])) != FAIL)
|
|
|
{
|
|
@@ -539,17 +583,27 @@ int isReadSimInfo(void)
|
|
|
//==============================
|
|
|
// Set don't echo command
|
|
|
//==============================
|
|
|
- if(at_command(uart, "ate0\r", rx) <= 0)
|
|
|
+ Length = at_command(uart, "ate0\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
+ {
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+ else
|
|
|
result = FAIL;
|
|
|
|
|
|
//==============================
|
|
|
// Read IMSI
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+cimi\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+cimi\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
- if (strstr(rx, "ERROR"))
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
{
|
|
|
memset(Dongle.IMSI, 0, sizeof Dongle.IMSI);
|
|
|
result = FAIL;
|
|
@@ -557,8 +611,14 @@ int isReadSimInfo(void)
|
|
|
else
|
|
|
{
|
|
|
memcpy(tmp, rx, strcspn(rx, "OK"));
|
|
|
- trim_s(tmp, Lenght);
|
|
|
+ trim_s(tmp, Length);
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
+
|
|
|
+ if(strstr(tmp, "atcimi") != NULL)
|
|
|
+ {
|
|
|
+ substr(tmp, tmp, 6, strlen(tmp)-6);
|
|
|
+ }
|
|
|
+
|
|
|
strncpy(Dongle.IMSI, tmp, strlen(tmp));
|
|
|
}
|
|
|
}
|
|
@@ -568,11 +628,11 @@ int isReadSimInfo(void)
|
|
|
//==============================
|
|
|
// Read CCID
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+qccid\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+qccid\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
- if (strstr(rx, "ERROR"))
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
{
|
|
|
memset(Dongle.ICCID, 0, sizeof Dongle.ICCID);
|
|
|
result = FAIL;
|
|
@@ -592,14 +652,24 @@ int isReadSimInfo(void)
|
|
|
//==============================
|
|
|
// Set don't echo command
|
|
|
//==============================
|
|
|
- if(at_command(uart, "ate0\r", rx) <= 0)
|
|
|
+ Length = at_command(uart, "ate0\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
+ {
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+ else
|
|
|
result = FAIL;
|
|
|
|
|
|
//==============================
|
|
|
// Read IMSI
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+cimi\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+cimi\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
if(strstr(rx, "ERROR"))
|
|
@@ -611,8 +681,14 @@ int isReadSimInfo(void)
|
|
|
{
|
|
|
memcpy(tmp, rx, strcspn(rx,"OK"));
|
|
|
memset(rx, 0, sizeof rx);
|
|
|
- trim_s(tmp,Lenght);
|
|
|
- strncpy(Dongle.IMSI , tmp, strlen(tmp));
|
|
|
+ trim_s(tmp,Length);
|
|
|
+
|
|
|
+ if(strstr(tmp, "atcimi") != NULL)
|
|
|
+ {
|
|
|
+ substr(tmp, tmp, 6, strlen(tmp)-6);
|
|
|
+ }
|
|
|
+
|
|
|
+ strncpy(Dongle.IMSI, tmp, strlen(tmp));
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -621,8 +697,8 @@ int isReadSimInfo(void)
|
|
|
//==============================
|
|
|
// Read CCID
|
|
|
//==============================
|
|
|
- Lenght = at_command(uart, "at+ccid\r", rx);
|
|
|
- if(Lenght > 0)
|
|
|
+ Length = at_command(uart, "at+ccid\r", rx);
|
|
|
+ if(Length > 0)
|
|
|
{
|
|
|
memset(tmp, 0, sizeof tmp);
|
|
|
if(strstr(rx, "ERROR"))
|
|
@@ -675,7 +751,17 @@ int CheckSignalRssi(void)
|
|
|
//==============================
|
|
|
// Set don't echo command
|
|
|
//==============================
|
|
|
- if(at_command(uart, "ate0\r", rx) <= 0)
|
|
|
+ Lenght = at_command(uart, "ate0\r", rx);
|
|
|
+ if(Lenght > 0)
|
|
|
+ {
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+ else
|
|
|
result = FAIL;
|
|
|
|
|
|
//==============================
|
|
@@ -699,7 +785,17 @@ int CheckSignalRssi(void)
|
|
|
//==============================
|
|
|
// Set don't echo command
|
|
|
//==============================
|
|
|
- if(at_command(uart, "ate0\r", rx) <= 0)
|
|
|
+ Lenght = at_command(uart, "ate0\r", rx);
|
|
|
+ if(Lenght > 0)
|
|
|
+ {
|
|
|
+ if(strstr(rx, "ERROR"))
|
|
|
+ {
|
|
|
+ result = FAIL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
+ }
|
|
|
+ else
|
|
|
result = FAIL;
|
|
|
|
|
|
//==============================
|
|
@@ -944,11 +1040,13 @@ int at_command(int uart, char* cmd, char* rx)
|
|
|
{
|
|
|
int len;
|
|
|
//sleep(2); //required to make flush work, for some reason
|
|
|
+ //DEBUG_INFO("cmd : %s \n", cmd);
|
|
|
tcflush(uart,TCIOFLUSH);
|
|
|
if(write(uart, cmd, strlen(cmd)) >= sizeof(cmd))
|
|
|
{
|
|
|
usleep(500000);
|
|
|
len = read(uart, rx, 512);
|
|
|
+ //DEBUG_INFO("rx : %s \n", rx);
|
|
|
}
|
|
|
else
|
|
|
{
|