Fix V2 for APN
Change-Id: I936f6f3cb99cdfb2c28765e1229ddac29eab6e87
diff --git a/mbtk/include/mbtk/mbtk_ril_api.h b/mbtk/include/mbtk/mbtk_ril_api.h
index 862309e..4cb916a 100755
--- a/mbtk/include/mbtk/mbtk_ril_api.h
+++ b/mbtk/include/mbtk/mbtk_ril_api.h
@@ -19,7 +19,13 @@
#define MBTK_APN_CID_MIN 1
#define MBTK_APN_CID_MAX 7
#define CELL_NUM_MAX 15
+#if 1
+#define APN_STR_MAX 128
+#define APN_NAME_STR_MAX (150+1)
+#else
#define APN_STR_MAX 64
+#define APN_NAME_STR_MAX (64+1)
+#endif
#define RIL_PIN_STR_MAX 16
typedef void (*mbtk_ril_callback_func)(const void* data, int data_len);
@@ -50,6 +56,7 @@
MBTK_RIL_ERR_IND_FULL, // Register IND fail(FULL).
MBTK_RIL_ERR_IND_UNKNOWN, // Register IND fail(Unknown IND).
MBTK_RIL_ERR_CID, // CID error.
+ MBTK_RIL_ERR_NET_CONF,
MBTK_RIL_ERR_TIMEOUT, // Timeout.
MBTK_RIL_ERR_TIME_FORMAT, // Time format error.
@@ -385,11 +392,14 @@
uint8 auto_save;
uint8 auto_boot_call;
uint8 def_route;
- uint8 apn[APN_STR_MAX];
+ uint8 as_dns;
+ uint8 apn[APN_NAME_STR_MAX];
uint8 user[APN_STR_MAX];
uint8 pass[APN_STR_MAX];
+ uint8 type[APN_NAME_STR_MAX];
} mbtk_apn_info_t;
+#if 0
typedef struct {
mbtk_ril_cid_enum cid : 8; // 1 - 7
mbtk_ip_type_enum ip_type : 8; // mbtk_ip_type_enum
@@ -398,12 +408,14 @@
uint8 auto_boot_call;
uint8 apn[APN_STR_MAX];
} mbtk_apn_get_info_t;
+#endif
typedef struct {
mbtk_ril_cid_enum cid_for_def_route;
+ mbtk_ril_cid_enum cid_for_def_dns;
int num;
- mbtk_apn_get_info_t apns[MBTK_APN_CID_MAX];
+ mbtk_apn_info_t apns[MBTK_APN_CID_MAX];
} mbtk_apn_info_array_t;
typedef enum {
@@ -482,6 +494,7 @@
mbtk_ril_cid_enum cid : 8; // 1 - 7
uint8 auto_boot_call; // Will reset proc if necessary.
uint8 def_route; // Will reset proc if necessary.
+ uint8 as_dns; // Will reset proc if necessary.
uint16 retry_interval; // second
uint16 timeout; // second
} mbtk_data_call_info_t;
@@ -679,7 +692,7 @@
* Start data call.
*/
mbtk_ril_err_enum mbtk_data_call_start(mbtk_ril_cid_enum cid, bool auto_boot_call,
- bool def_route, int retry_interval, int timeout, mbtk_ip_info_t *rsp_info);
+ bool def_route, bool as_dns, int retry_interval, int timeout, mbtk_ip_info_t *rsp_info);
/*
* Stop data call.
@@ -689,7 +702,7 @@
/*
* Get data call state.
*/
-mbtk_ril_err_enum mbtk_data_call_state_get(int cid, mbtk_ip_info_t *ip);
+mbtk_ril_err_enum mbtk_data_call_state_get(mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip);
/*
* Get current network signal.
diff --git a/mbtk/libmbtk_ril_v2/inc/mbtk_ril.h b/mbtk/libmbtk_ril_v2/inc/mbtk_ril.h
index e32b1dd..04b5623 100755
--- a/mbtk/libmbtk_ril_v2/inc/mbtk_ril.h
+++ b/mbtk/libmbtk_ril_v2/inc/mbtk_ril.h
@@ -11,7 +11,7 @@
#define RIL_SOCK_PACKET_TAG 0x5F6F7F8F
#define RIL_SOCK_NAME "/tmp/mbtk_ril_sock"
-#define RIL_SOCK_MSG_LEN_MAX 2048
+#define RIL_SOCK_MSG_LEN_MAX (1024 * 6)
// Tag(4) + Packet_Length(2)
#define RIL_SOCK_PACK_EXTRA_LEN 6
diff --git a/mbtk/libmbtk_ril_v2/src/mbtk_ril_api.c b/mbtk/libmbtk_ril_v2/src/mbtk_ril_api.c
index 4668bd2..93efd84 100755
--- a/mbtk/libmbtk_ril_v2/src/mbtk_ril_api.c
+++ b/mbtk/libmbtk_ril_v2/src/mbtk_ril_api.c
@@ -15,6 +15,7 @@
#include "mbtk_list.h"
#include "mbtk_utils.h"
#include "mbtk_log.h"
+#include "mbtk_str.h"
typedef struct {
int cli_fd;
diff --git a/mbtk/mbtk_rild_v2/inc/ril_info.h b/mbtk/mbtk_rild_v2/inc/ril_info.h
index 595d603..e9cb822 100755
--- a/mbtk/mbtk_rild_v2/inc/ril_info.h
+++ b/mbtk/mbtk_rild_v2/inc/ril_info.h
@@ -24,7 +24,12 @@
#define IND_REGISTER_MAX 10
#define PACK_PROCESS_QUEUE_MAX 20
+#if 0
#define MBTK_APN_PROP "persist.mbtk.apn"
+#else
+#define MBTK_APN_PROP "/etc/mbtk/apn"
+#endif
+
#define MBTK_DEF_ROUTE_CID "persist.mbtk.def_route_cid"
#define MBTK_DEF_DNS_CID "persist.mbtk.def_dns_cid"
@@ -103,14 +108,6 @@
int data_len;
} ril_urc_msg_info_t;
-typedef struct {
- mbtk_ril_cid_enum cid_for_def_route;
- mbtk_ril_cid_enum cid_for_dns;
-
- int num;
- mbtk_apn_info_t apns[MBTK_APN_CID_MAX];
-} ril_apn_info_array_t;
-
typedef struct
{
int cid;
diff --git a/mbtk/mbtk_rild_v2/src/main.c b/mbtk/mbtk_rild_v2/src/main.c
index 7f68de3..5565621 100755
--- a/mbtk/mbtk_rild_v2/src/main.c
+++ b/mbtk/mbtk_rild_v2/src/main.c
@@ -240,7 +240,7 @@
}
void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len)
-{
+{
ril_msg_pack_info_t* pack = ril_msg_pack_creat(RIL_MSG_TYPE_RSP, ril_id, msg_index, data, data_len);
if(pack)
{
diff --git a/mbtk/mbtk_rild_v2/src/ril_data_call.c b/mbtk/mbtk_rild_v2/src/ril_data_call.c
index 4fbeca5..97ff338 100755
--- a/mbtk/mbtk_rild_v2/src/ril_data_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_data_call.c
@@ -44,7 +44,7 @@
char buf[100] = {0};
// Delete all default route in the first.
-
+ // route del default
// Add default route.
memset(buf, 0, sizeof(buf));
diff --git a/mbtk/mbtk_rild_v2/src/ril_net.c b/mbtk/mbtk_rild_v2/src/ril_net.c
index 3592850..6ca5d65 100755
--- a/mbtk/mbtk_rild_v2/src/ril_net.c
+++ b/mbtk/mbtk_rild_v2/src/ril_net.c
@@ -27,13 +27,68 @@
void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len);
static int req_apn_get(bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err);
static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err);
-static void apn_prop_get(ril_apn_info_array_t *apns);
+static void apn_prop_get(mbtk_apn_info_array_t *apns);
+
+static int apn_file_save(const char *file, char *data, int data_len)
+{
+ if(!file) {
+ return -1;
+ }
+
+ if(str_empty(data) || data_len <= 0) { // Delete file
+ return unlink(file);
+ } else {
+ int fd = open(file, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+ if(fd < 0) {
+ LOGE("open(%s) fail:%d", file, errno);
+ return -1;
+ }
+
+ if(write(fd, data, data_len) != data_len) {
+ LOGE("write fail:%d", errno);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+ }
+}
+
+static int apn_file_read(const char *file, char *data, int data_len)
+{
+ if(!file) {
+ LOGE("file is null");
+ return -1;
+ }
+
+ if(data == NULL || data_len <= 100) {
+ LOGE("apn_file_read() arg error.");
+ return -1;
+ } else {
+ int len = -1;
+ int fd = open(file, O_RDONLY, 0644);
+ if(fd < 0) {
+ LOGE("open(%s) fail:%d", file, errno);
+ return -1;
+ }
+
+ memset(data, 0, data_len);
+ if((len = read(fd, data, data_len)) < 0) {
+ LOGE("read fail:%d", errno);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return len;
+ }
+}
+
void apn_auto_conf_from_prop()
{
- ril_apn_info_array_t apns;
+ mbtk_apn_info_array_t apns;
int i = 0;
- memset(&apns, 0, sizeof(ril_apn_info_array_t));
+ memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
apn_prop_get(&apns);
while(i < apns.num) {
int cme_err = MBTK_RIL_ERR_CME_NON;
@@ -169,36 +224,44 @@
return 0;
}
-static void apn_prop_get(ril_apn_info_array_t *apns)
+static void apn_prop_get(mbtk_apn_info_array_t *apns)
{
- char prop_name[20] = {0};
- char prop_data[300] = {0};
+ char prop_name[128] = {0};
+ char prop_data[1024] = {0};
int cid;
- memset(apns, 0, sizeof(ril_apn_info_array_t));
+ memset(apns, 0, sizeof(mbtk_apn_info_array_t));
bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF);
// If auto data call is open,the default route is CID 1.
if(asr_auto_call_open) {
- apns->cid_for_def_route = MBTK_RIL_CID_DEF;
- apns->cid_for_dns = MBTK_RIL_CID_DEF;
+ //apns->cid_for_def_route = MBTK_RIL_CID_DEF;
+ //apns->cid_for_def_dns = MBTK_RIL_CID_DEF;
cid = MBTK_RIL_CID_2;
} else {
- if(property_get(MBTK_DEF_ROUTE_CID, prop_data, "") > 0 && !str_empty(prop_data)) {
- apns->cid_for_def_route = (mbtk_ril_cid_enum)atoi(prop_data);
- }
- memset(prop_data, 0, sizeof(prop_data));
- if(property_get(MBTK_DEF_DNS_CID, prop_data, "") > 0 && !str_empty(prop_data)) {
- apns->cid_for_dns = (mbtk_ril_cid_enum)atoi(prop_data);
- }
cid = MBTK_APN_CID_MIN;
}
+
+ char def_cid[10] = {0};
+ sprintf(def_cid, "%d", MBTK_RIL_CID_DEF);
+ if(property_get(MBTK_DEF_ROUTE_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
+ apns->cid_for_def_route = (mbtk_ril_cid_enum)atoi(prop_data);
+ }
+ memset(prop_data, 0, sizeof(prop_data));
+ if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
+ apns->cid_for_def_dns = (mbtk_ril_cid_enum)atoi(prop_data);
+ }
+
for(; cid <= MBTK_APN_CID_MAX; cid++) {
- memset(prop_name, 0, 20);
- memset(prop_data, 0, 300);
+ memset(prop_name, 0, sizeof(prop_name));
+ memset(prop_data, 0, sizeof(prop_data));
sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
// ip_type,auth,auto_data_call,apn,user,pass
+#if 0
if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
+#else
+ if(apn_file_read(prop_name, prop_data, sizeof(prop_data)) > 0 && !str_empty(prop_data)) {
+#endif
apns->apns[apns->num].cid = (mbtk_ril_cid_enum)cid;
char *ptr_1 = prop_data;
apns->apns[apns->num].ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
@@ -240,8 +303,17 @@
}
ptr_1++; // Jump ',' to pass
+ ptr_2 = strstr(ptr_1, ",");
+ if(!ptr_2) {
+ continue;
+ }
if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
- memcpy(apns->apns[apns->num].pass, ptr_1, strlen(ptr_1)); // pass
+ memcpy(apns->apns[apns->num].pass, ptr_1, ptr_2 - ptr_1); // pass
+ }
+
+ ptr_2++; // Jump ',' to type
+ if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
+ memcpy(apns->apns[apns->num].type, ptr_2, strlen(ptr_2)); // type
}
apns->num++;
@@ -251,13 +323,17 @@
static int apn_prop_get_by_cid(mbtk_ril_cid_enum cid, mbtk_apn_info_t *apn)
{
- char prop_name[20] = {0};
- char prop_data[300] = {0};
+ char prop_name[128] = {0};
+ char prop_data[1024] = {0};
memset(apn, 0, sizeof(mbtk_apn_info_t));
sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
// ip_type,auth,auto_data_call,apn,user,pass
+#if 0
if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
+#else
+ if(apn_file_read(prop_name, prop_data, sizeof(prop_data)) > 0 && !str_empty(prop_data)) {
+#endif
apn->cid = cid;
apn->auto_save = (uint8)1;
char *ptr_1 = prop_data;
@@ -300,38 +376,131 @@
}
ptr_1++; // Jump ',' to pass
+ ptr_2 = strstr(ptr_1, ",");
+ if(!ptr_2) {
+ return -1;
+ }
if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
- memcpy(apn->pass, ptr_1, strlen(ptr_1)); // pass
+ memcpy(apn->user, ptr_1, ptr_2 - ptr_1); // pass
+ }
+
+ ptr_2++; // Jump ',' to type
+ if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
+ memcpy(apn->type, ptr_2, strlen(ptr_2)); // pass
}
return 0;
}
return -1;
}
+static int apn_prop_get_by_cid_without_cgdcont(mbtk_ril_cid_enum cid, mbtk_apn_info_t *apn)
+{
+ char prop_name[128] = {0};
+ char prop_data[1024] = {0};
+
+ sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
+ // ip_type,auth,auto_data_call,apn,user,pass
+#if 0
+ if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
+#else
+ if(apn_file_read(prop_name, prop_data, sizeof(prop_data)) > 0 && !str_empty(prop_data)) {
+#endif
+ LOGD("APN : %s", prop_data);
+ char *ptr_1 = prop_data;
+ apn->auto_save = (uint8)1;
+ //apn->ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
+ ptr_1 = strstr(ptr_1, ",");
+ if(!ptr_1) {
+ return -1;
+ }
+ ptr_1++; // Jump ',' to auth
+
+ apn->auth = (mbtk_apn_auth_type_enum)atoi(ptr_1);
+ ptr_1 = strstr(ptr_1, ",");
+ if(!ptr_1) {
+ return -1;
+ }
+ ptr_1++; // Jump ',' to auto_data_call
+
+ apn->auto_boot_call = (uint8)atoi(ptr_1);
+ ptr_1 = strstr(ptr_1, ",");
+ if(!ptr_1) {
+ return -1;
+ }
+ ptr_1++; // Jump ',' to apn
+
+ char *ptr_2 = strstr(ptr_1, ",");
+ if(!ptr_2) {
+ return -1;
+ }
+#if 0
+ if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
+ memcpy(apn->apn, ptr_1, ptr_2 - ptr_1); // apn
+ }
+#endif
+
+ ptr_2++; // Jump ',' to user
+ ptr_1 = strstr(ptr_2, ",");
+ if(!ptr_1) {
+ return -1;
+ }
+ if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
+ memcpy(apn->user, ptr_2, ptr_1 - ptr_2); // user
+ }
+
+ ptr_1++; // Jump ',' to pass
+ ptr_2 = strstr(ptr_1, ",");
+ if(!ptr_2) {
+ return -1;
+ }
+ if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
+ memcpy(apn->user, ptr_1, ptr_2 - ptr_1); // pass
+ }
+
+ ptr_2++; // Jump ',' to type
+ if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
+ memcpy(apn->type, ptr_2, strlen(ptr_2)); // pass
+ }
+ return 0;
+ } else {
+ apn->auto_save = (uint8)0;
+ }
+ return -1;
+}
+
static int apn_prop_set(mbtk_apn_info_t *apn)
{
char prop_name[20] = {0};
- char prop_data[300] = {0};
+ char prop_data[1024] = {0};
int ret = -1;
if(apn->auto_save) {
sprintf(prop_name, "%s_%d", MBTK_APN_PROP, apn->cid);
// Delete apn
if(!str_empty(apn->apn)) {
- snprintf(prop_data, 300, "%d,%d,%d,%s,%s,%s", apn->ip_type, apn->auth, apn->auto_boot_call,
+ snprintf(prop_data, 1024, "%d,%d,%d,%s,%s,%s,%s", apn->ip_type, apn->auth, apn->auto_boot_call,
apn->apn,
str_empty(apn->user) ? "NULL" : apn->user,
- str_empty(apn->pass) ? "NULL" : apn->pass);
+ str_empty(apn->pass) ? "NULL" : apn->pass,
+ str_empty(apn->pass) ? "NULL" : apn->type);
}
+#if 0
ret = property_set(prop_name, prop_data);
+#else
+ if(str_empty(apn->apn)) { // Delete APN
+ ret = apn_file_save(prop_name, NULL, 0);
+ } else {
+ ret = apn_file_save(prop_name, prop_data, strlen(prop_data));
+ }
+#endif
}
- if(apn->def_route) {
+ if(!ret && apn->def_route) {
memset(prop_data, 0, sizeof(prop_data));
prop_data[0] = '0' + apn->cid;
ret = property_set(MBTK_DEF_ROUTE_CID, prop_data);
}
- if(apn->as_dns) {
+ if(!ret && apn->as_dns) {
memset(prop_data, 0, sizeof(prop_data));
prop_data[0] = '0' + apn->cid;
ret = property_set(MBTK_DEF_DNS_CID, prop_data);
@@ -1615,12 +1784,28 @@
memcpy(apns->apns[apns->num].apn, tmp_str, strlen(tmp_str));
}
+ // Get other arg from proc or file.
+ apn_prop_get_by_cid_without_cgdcont(apns->apns[apns->num].cid, &(apns->apns[apns->num]));
+
apns->num++;
}
lines_ptr = lines_ptr->p_next;
}
+ char prop_name[128] = {0};
+ char prop_data[1024] = {0};
+ char def_cid[10] = {0};
+ sprintf(def_cid, "%d", MBTK_RIL_CID_DEF);
+
+ if(property_get(MBTK_DEF_ROUTE_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
+ apns->cid_for_def_route = (mbtk_ril_cid_enum)atoi(prop_data);
+ }
+ memset(prop_data, 0, sizeof(prop_data));
+ if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
+ apns->cid_for_def_dns = (mbtk_ril_cid_enum)atoi(prop_data);
+ }
+
goto exit;
exit:
at_response_free(response);
diff --git a/mbtk/mbtk_utils/Makefile b/mbtk/mbtk_utils/Makefile
index ad5e6bb..9e1a0f4 100755
--- a/mbtk/mbtk_utils/Makefile
+++ b/mbtk/mbtk_utils/Makefile
@@ -5,8 +5,12 @@
LIB_DIR +=
-LIBS += -lmbtk_lib -lmbtk_ril -lmbtk_net -lmbtk_audio -lmbtk_fota -lmbtk_gnss -lmbtk_factory -llynq_lib \
- -lql_lib -lmbtk_coap -lmbtk_ftp -lmbtk_http -lmbtk_mqtt -lmbtk_tcpip
+LIBS += -lmbtk_lib -lmbtk_ril -lmbtk_net -lmbtk_audio -lmbtk_fota -lmbtk_gnss -lmbtk_factory \
+ -lmbtk_coap -lmbtk_ftp -lmbtk_http -lmbtk_mqtt -lmbtk_tcpip
+
+ifeq ($(MBTK_SOURCE_VERSION), 1)
+LIBS += -llynq_lib -lql_lib
+endif
CFLAGS +=
diff --git a/mbtk/mbtk_utils/mbtk_version.c b/mbtk/mbtk_utils/mbtk_version.c
index 477fb96..8c77cdb 100755
--- a/mbtk/mbtk_utils/mbtk_version.c
+++ b/mbtk/mbtk_utils/mbtk_version.c
@@ -15,8 +15,10 @@
mbtk_lib_info_print();
mbtk_ril_lib_info_print();
+#ifndef MBTK_SOURCE_VERSION_2
lynq_lib_info_print();
ql_lib_info_print();
+#endif
mbtk_audio_lib_info_print();
mbtk_coap_lib_info_print();
mbtk_factory_lib_info_print();
diff --git a/mbtk/test/libmbtk_ril/mbtk_ril_test.c b/mbtk/test/libmbtk_ril/mbtk_ril_test.c
index 30ad2a1..acc9266 100755
--- a/mbtk/test/libmbtk_ril/mbtk_ril_test.c
+++ b/mbtk/test/libmbtk_ril/mbtk_ril_test.c
@@ -646,9 +646,16 @@
printf("APN Num:%d\n", apns.num);
int i = 0;
while(i < apns.num) {
- printf("APN : %d, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type), apns.apns[i].apn);
+ // printf("APN : %d, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type), apns.apns[i].apn);
+ printf("APN : %d, %s, auth-%d, auto_save-%d, auto_boot_call-%d, %s, %s, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type),
+ apns.apns[i].auth, apns.apns[i].auto_save, apns.apns[i].auto_boot_call,
+ str_empty(apns.apns[i].apn) ? "NULL" : apns.apns[i].apn,
+ str_empty(apns.apns[i].user) ? "NULL" : apns.apns[i].user,
+ str_empty(apns.apns[i].pass) ? "NULL" : apns.apns[i].pass,
+ str_empty(apns.apns[i].type) ? "NULL" : apns.apns[i].type);
i++;
}
+ printf("Def route : %d, def dns : %d\n", apns.cid_for_def_route, apns.cid_for_def_dns);
}
} else { // apn <cid> <0/1/2/3> <0/1> <0/1> <apn>
mbtk_apn_info_t apn;