summaryrefslogtreecommitdiffstats
path: root/package/query3g/src
diff options
context:
space:
mode:
Diffstat (limited to 'package/query3g/src')
-rw-r--r--package/query3g/src/Makefile6
-rwxr-xr-xpackage/query3g/src/apnproviderbin0 -> 48352 bytes
-rw-r--r--package/query3g/src/apnprovider.c91
-rwxr-xr-xpackage/query3g/src/modemnamebin0 -> 50332 bytes
-rw-r--r--package/query3g/src/modemname.c97
5 files changed, 194 insertions, 0 deletions
diff --git a/package/query3g/src/Makefile b/package/query3g/src/Makefile
new file mode 100644
index 000000000..36b8d40c4
--- /dev/null
+++ b/package/query3g/src/Makefile
@@ -0,0 +1,6 @@
+CC=gcc
+CFLAGS=-Wall -g3
+LDFLAGS=-ljson-c -lc
+make:
+ $(CC) apnprovider.c -o apnprovider $(CFLAGS) $(LDFLAGS)
+ $(CC) modemname.c -o modemname $(CFLAGS) $(LDFLAGS)
diff --git a/package/query3g/src/apnprovider b/package/query3g/src/apnprovider
new file mode 100755
index 000000000..7fee85c8a
--- /dev/null
+++ b/package/query3g/src/apnprovider
Binary files differ
diff --git a/package/query3g/src/apnprovider.c b/package/query3g/src/apnprovider.c
new file mode 100644
index 000000000..c5f812073
--- /dev/null
+++ b/package/query3g/src/apnprovider.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <json/json.h>
+
+#define FNAME "/usr/share/3gmodem/apn.json"
+
+int main( int argc, char **argv )
+{
+ int ret=0;
+ int cnt_apn=0;
+ if ( argc != 2 )
+ {
+ printf(" %s [APN_Provider_5_symbols]\n", argv[0]);
+ printf("%s 12345\n", argv[0]);
+ return -1;
+ } else if ( strlen(argv[1]) != 5 )
+ {
+ printf("ERR: Only 5 number apn supported\n");
+ return -1;
+ }
+
+ char *apnnumber = argv[1];
+ char mcc[4];
+ char mnc[3];
+ memcpy( mcc, apnnumber, 3 );
+ mcc[3] = 0;
+ memcpy( mnc, apnnumber+3 , 2 );
+ mnc[2] = 0;
+
+ int i;
+ struct json_object *jo = json_object_from_file( FNAME );
+ if ( jo == NULL )
+ {
+ printf("ERR:Cannot get file\n");
+ ret = 1;
+ goto free_resources;
+ }
+
+ struct json_object *jarr = json_object_object_get( jo, "data" );
+ if ( jarr == NULL )
+ {
+ printf("ERR:Cannot get data object\n");
+ ret = 1;
+ goto free_resources;
+ }
+
+ if ( !json_object_is_type( jarr, json_type_array ) )
+ {
+ printf("ERR:Object isnot array\n");
+ ret = 1;
+ goto free_resources;
+ }
+
+ for (i=0; i<json_object_array_length(jarr); i++)
+ {
+ json_object *obj = json_object_array_get_idx(jarr, i);
+ struct json_object *jmcc = json_object_object_get( obj, "mcc" );
+ struct json_object *jmnc = json_object_object_get( obj, "mnc" );
+ struct json_object *jname = json_object_object_get( obj, "name" );
+ struct json_object *jfullname = json_object_object_get( obj, "fullname" );
+ if ( (jmcc != NULL) && (jmnc != NULL) && ( (jname != NULL) || (jfullname != NULL) ) )
+ {
+ const char *tmp_mcc = json_object_to_json_string( jmcc );
+ const char *tmp_mnc = json_object_to_json_string( jmnc );
+ if ( strncmp( tmp_mcc+1, mcc, 3 ) != 0 )
+ {
+ continue;
+ }
+ if ( strncmp( tmp_mnc+1, mnc, 2 ) != 0 )
+ {
+ continue;
+ }
+ printf("%s ", tmp_mcc );
+ printf("%s ", tmp_mnc );
+ if ( jname != NULL )
+ printf("%s ", json_object_to_json_string( jname ) );
+ if ( jfullname != NULL )
+ printf("%s ", json_object_to_json_string( jfullname ) );
+ printf("\n");
+ cnt_apn++;
+ }
+ }
+free_resources:
+ json_object_put( jo );
+
+ if (cnt_apn<=0)
+ ret = 1;
+ return ret;
+}
diff --git a/package/query3g/src/modemname b/package/query3g/src/modemname
new file mode 100755
index 000000000..e5ed78cd9
--- /dev/null
+++ b/package/query3g/src/modemname
Binary files differ
diff --git a/package/query3g/src/modemname.c b/package/query3g/src/modemname.c
new file mode 100644
index 000000000..0e31f979d
--- /dev/null
+++ b/package/query3g/src/modemname.c
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <json/json.h>
+
+#define MAX_MANUF_NAME 128
+#define MAX_MODEL_NAME 128
+
+#define FNAME "/usr/share/3gmodem/modem.json"
+
+int main( int argc, char **argv )
+{
+ int i,j,k;
+ int ret=0;
+ int cnt_apn=0;
+ if ( argc != 3 )
+ {
+ printf(" %s [Manufacturer Name] [Modem model]\n", argv[0]);
+ printf("%s huawei e180\n", argv[0]);
+ return -1;
+ }
+
+ char *str_manuf = argv[1];
+ char *str_model = argv[2];
+ char manuf[MAX_MANUF_NAME+1]; memset( manuf, 0, MAX_MANUF_NAME+1 );
+ char model[MAX_MODEL_NAME+1]; memset( model, 0, MAX_MODEL_NAME+1 );
+
+ //printf( "%d", ((i=strlen(str_manuf))<MAX_MANUF_NAME) ? i : MAX_MANUF_NAME );
+ memcpy( manuf, str_manuf, ((i=strlen(str_manuf))<MAX_MANUF_NAME) ? i : MAX_MANUF_NAME );
+ memcpy( model, str_model, ((i=strlen(str_model))<MAX_MODEL_NAME) ? i : MAX_MODEL_NAME );
+
+ struct json_object *jo = json_object_from_file( FNAME );
+ if ( jo == NULL )
+ {
+ printf("ERR:Cannot get file\n");
+ ret = 1;
+ goto free_resources;
+ }
+
+ struct json_object *jarr = json_object_object_get( jo, "data" );
+ if ( jarr == NULL )
+ {
+ printf("ERR:Cannot get data object\n");
+ ret = 1;
+ goto free_resources;
+ }
+
+ if ( !json_object_is_type( jarr, json_type_array ) )
+ {
+ printf("ERR:Object isnot array\n");
+ ret = 1;
+ goto free_resources;
+ }
+
+ for (i=0; i<json_object_array_length(jarr); i++)
+ {
+ json_object *obj = json_object_array_get_idx(jarr, i);
+ struct json_object *jusbid = json_object_object_get( obj, "usbid" );
+ struct json_object *jmanuf = json_object_object_get( obj, "manufacture" );
+ struct json_object *jmodel = json_object_object_get( obj, "model" );
+ struct json_object *jspn = json_object_object_get( obj, "serialportnum" );
+ struct json_object *jsp = json_object_object_get( obj, "serialport" );
+ struct json_object *jcmds = json_object_object_get( obj, "cmds" );
+ struct json_object *jreset = json_object_object_get( obj, "reset" );
+ struct json_object *jarr[]={ jusbid, jmanuf, jmodel, jspn, jsp, jcmds, jreset };
+ const char *smo = json_object_to_json_string( jmodel );
+ const char *sma = json_object_to_json_string( jmanuf );
+ if ( ( strncmp( sma+1, manuf, strlen( sma )-2 ) == 0) &&
+ ((strlen(sma+1)-1) == strlen(manuf) ) &&
+ ( strncmp( smo+1, model, strlen( smo )-2 ) == 0) &&
+ ((strlen(smo+1)-1) == strlen(model) ))
+ {
+ for (j=0; j<7; j++,(j<7)?printf(","):0)
+ {
+ if ( jarr[j] != NULL )
+ {
+ const char *str = json_object_to_json_string( jarr[j] );
+ k=1;
+ while (str[k+1]!=0x0)
+ {
+ putc(str[k],stdout);
+ k++;
+ }
+ }
+ }
+ printf("\n");
+ cnt_apn++;
+ }
+ }
+free_resources:
+ json_object_put( jo );
+
+ if (cnt_apn<=0)
+ ret = 1;
+ return ret;
+}