diff options
author | Artur Artamonov <freeartman@wechall.net> | 2013-07-18 16:51:06 +0300 |
---|---|---|
committer | Artur Artamonov <freeartman@wechall.net> | 2013-07-18 16:51:06 +0300 |
commit | 5bfe1cdae38c39a4fe7ca891aac31233165e3531 (patch) | |
tree | c5cf5ec00e46af86258397fbe502f599ce77b58d /package/query3g/src | |
parent | cdb691fe07b833808f90c9b214725b22f1644bf6 (diff) |
query3g pre-release changes. added modem info search, added apnfinder by id, apn provider database, supported modem database
Diffstat (limited to 'package/query3g/src')
-rw-r--r-- | package/query3g/src/Makefile | 6 | ||||
-rwxr-xr-x | package/query3g/src/apnprovider | bin | 0 -> 48352 bytes | |||
-rw-r--r-- | package/query3g/src/apnprovider.c | 91 | ||||
-rwxr-xr-x | package/query3g/src/modemname | bin | 0 -> 50332 bytes | |||
-rw-r--r-- | package/query3g/src/modemname.c | 97 |
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 Binary files differnew file mode 100755 index 000000000..7fee85c8a --- /dev/null +++ b/package/query3g/src/apnprovider 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 Binary files differnew file mode 100755 index 000000000..e5ed78cd9 --- /dev/null +++ b/package/query3g/src/modemname 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; +} |