data_call: 更新代码,兼容T106
Change-Id: Id693c13f44bb16052a258eb7697e559109bb093a
diff --git a/mbtk/liblynq_lib/src/lynq_data_call.c b/mbtk/liblynq_lib/src/lynq_data_call.c
index 040b96f..9e42d85 100755
--- a/mbtk/liblynq_lib/src/lynq_data_call.c
+++ b/mbtk/liblynq_lib/src/lynq_data_call.c
@@ -41,8 +41,7 @@
static qser_apn_info_s qser_apn_info[QSER_APN_NUM] = {0};
static bool qser_apn_info_state[QSER_APN_NUM] = {0};
static char qser_apn_add_save_state[QSER_APN_NUM + 1] = {0};
-static qser_data_call_s qser_data_backup;
-static bool qser_start_async = false;
+static char qser_apn_auth_state[QSER_APN_NUM + 1] = {0};
#if defined(MBTK_ALL_CID_SUPPORT)
static int qser_apn_default_idx = -1;
static int qser_default_pdp_idx = -1;
@@ -50,7 +49,6 @@
static int qser_apn_default_idx = 0xFF;
static int qser_default_pdp_idx = 0;
#endif
-int now_idx = 0;
/****************************VARIABLE***************************************/
/******************************FUNC*****************************************/
@@ -249,7 +247,14 @@
{
if(strcmp(old_apn->auth, "NONE") == 0)
{
- new_apn->auth_proto = QSER_APN_AUTH_PROTO_NONE;
+ if(qser_apn_auth_state[profile_idx] == '1')
+ {
+ new_apn->auth_proto = QSER_APN_AUTH_PROTO_NONE;
+ }
+ else
+ {
+ new_apn->auth_proto = QSER_APN_AUTH_PROTO_DEFAULT;
+ }
}
else if(strcmp(old_apn->auth, "PAP") == 0)
{
@@ -283,7 +288,11 @@
int pdp_type_tmp = 0;
for (;pdp_type_tmp < QSER_APN_NUM; pdp_type_tmp++)
{
- if(qser_apn_add_save_state[pdp_type_tmp] == '1')
+ if(pdp_type_tmp == apn->profile_idx)
+ {
+ continue;
+ }
+ if( (qser_apn_add_save_state[pdp_type_tmp] == '1') || (qser_apn_add_save_state[pdp_type_tmp] == '2') )
{
if (strcmp(qser_apn_info[pdp_type_tmp].apn_name, apn->apn_name) == 0 || strcmp(qser_apn_info[pdp_type_tmp].apn_type, apn->apn_type) == 0)
{
@@ -296,153 +305,24 @@
return QSER_RESULT_SUCCESS;
}
-int qser_get_ip(char *buf, char *check_buf, char *ip_buf)
+void qser_state_init(qser_data_call_state_s *state)
{
- int i = 0, num = 0;
- char *p1 = strstr(buf, check_buf);
- if(p1 != NULL)
+ if(state != NULL)
{
- p1 += strlen(check_buf);
- for(; i < 32; i++)
- {
- if(*(p1 + i) >= '0' && *(p1 + i) <= '9' || *(p1 + i) == '.' || *(p1 + i) == ':')
- {
- num++;
- }
- else
- {
- break;
- }
- }
-
- memcpy(ip_buf, p1, num);
-
+ state->profile_idx = 0;
+ memset(state->name, 0x0, 16);
+ state->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
+ state->state = QSER_DATA_CALL_DISCONNECTED;
+ state->err = QSER_DATA_CALL_ERROR_NONE;
+ inet_aton("0.0.0.0", &(state->v4.ip));
+ inet_aton("0.0.0.0", &(state->v4.gateway));
+ inet_aton("0.0.0.0", &(state->v4.pri_dns));
+ inet_aton("0.0.0.0", &(state->v4.sec_dns));
+ inet_pton(AF_INET6, "::", &(state->v6.ip));
+ inet_pton(AF_INET6, "::", &(state->v6.gateway));
+ inet_pton(AF_INET6, "::", &(state->v6.pri_dns));
+ inet_pton(AF_INET6, "::", &(state->v6.sec_dns));
}
- else
- {
- return QSER_RESULT_FAIL;
- }
-
- return QSER_RESULT_SUCCESS;
-}
-
-int qser_get_ip_info(qser_data_call_state_s *state)
-{
- if(state == NULL)
- {
- LOGE("[qser_data_call] state is NULL");
- return QSER_RESULT_FAIL;
- }
-
- //get ip
- FILE *fp = NULL;
- int ret = QSER_RESULT_FAIL;
- char buffer[1024] = {0};
- char path[32] = {0};
- char ipv4[32] = {0};
- char ipv6[64] = {0};
-
- sprintf(path, "ifconfig ccinet%d", state->profile_idx);
- fp = popen(path, "r");
- if (fp == NULL)
- {
- LOGE("[qser_data_call] popen fail");
- return QSER_RESULT_FAIL;
- }
-
- fread(buffer,1, sizeof(buffer) -1, fp);
- pclose(fp);
-
- ret = qser_get_ip(buffer, "inet addr:", ipv4);
- if(ret == QSER_RESULT_SUCCESS)
- {
- LOGE("[qser_data_call] ipv4: %s len: %d", ipv4, strlen(ipv4));
- //ip and gateway is same
- }
- else
- {
- LOGE("[qser_data_call] ipv4 is invain");
- }
-
- ret = qser_get_ip(buffer, "inet6 addr: ", ipv6);
- if(ret == QSER_RESULT_SUCCESS)
- {
- LOGE("[qser_data_call] ipv4: %s len: %d", ipv6, strlen(ipv6));
- }
- else
- {
- LOGE("[qser_data_call] ipv4 is invain");
- }
-
- //get DNS
- int fd = -1;
- int i = 0;
- char *p = NULL;
- char DNS_v4[32] = {0};
- char DNS_v6[64] = {0};
-
- fd = open("/etc/resolv.conf", O_RDWR);
- if(fd < 0)
- {
- LOGE("[qser_data_call] open fail");
- return QSER_RESULT_FAIL;
- }
-
- memset(buffer, 0x0, 1024);
- ret = read(fd, buffer, 1023);
- close(fd);
- if(ret < 0)
- {
- LOGE("[qser_data_call] open fail");
- return QSER_RESULT_FAIL;
- }
-
- p = buffer;
- for(; i < 4; i++)
- {
- switch(i)
- {
- case 0:
- case 1:
- {
- memset(DNS_v4, 0x0, 32);
- ret = qser_get_ip(buffer, "nameserver ", DNS_v4);
- if(ret == QSER_RESULT_SUCCESS)
- {
- LOGE("[qser_data_call] DNS_v4: %s len: %d", DNS_v4, strlen(DNS_v4));
- }
- else
- {
- LOGE("[qser_data_call] DNS_v4 is invain");
- }
- break;
- }
- case 2:
- case 3:
- {
- memset(DNS_v6, 0x0, 64);
- ret = qser_get_ip(buffer, "nameserver ", DNS_v6);
- if(ret == QSER_RESULT_SUCCESS)
- {
- LOGE("[qser_data_call] DNS_v6: %s len: %d", DNS_v6, strlen(DNS_v6));
- }
- else
- {
- LOGE("[qser_data_call] DNS_v6 is invain");
- }
- break;
- }
- default:
- {
- break;
- }
- }
-
- p = strstr(p, "nameserver ");
- p += strlen("nameserver ");
- }
-
- return QSER_RESULT_SUCCESS;
}
void qser_wan_net_state_change_cb(const void* data, int data_len)
@@ -455,48 +335,96 @@
uint8 *net_data = NULL;
net_data = (uint8 *)data;
- if(qser_net_status_cb != NULL)
+ if(*net_data > 100 && *net_data < 200)
{
- qser_data_call_state_s state = {0};
- state.profile_idx = now_idx;
- state.ip_family = qser_apn_info[now_idx].pdp_type;
- if((*net_data > 100 && *net_data < 200) || *net_data == 1)
+ int idx = *net_data - 101;
+ if(idx <= QSER_PROFILE_IDX_MAX)
{
- state.state = QSER_DATA_CALL_CONNECTED;
- state.err = QSER_DATA_CALL_ERROR_NONE;
- }
- else if(*net_data > 200)
- {
+ qser_data_call_state_s state = {0};
+ qser_state_init(&state);
+ state.profile_idx = idx;
state.state = QSER_DATA_CALL_DISCONNECTED;
- state.err = QSER_DATA_CALL_ERROR_NONE;
- if( (*net_data -200) == qser_default_pdp_idx )
+ if( idx == qser_default_pdp_idx )
{
qser_default_pdp_idx = -1;
}
+
+ if(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
}
else
{
- return;
+ LOGE("[qser_data_call] cb fail,idx is %d.", idx);
}
-
- qser_get_ip_info(&state);
- if(qser_start_async == true)
- {
- qser_net_status_cb(&state);
- }
+
+ }
+ else if(*net_data > 200)
+ {
+ LOGE("[qser_data_call] cid[%d] is open.", *net_data - 201);
+ }
+ else if(*net_data == 1)
+ {
+ LOGE("[qser_data_call] pdp is open.");
+ }
+ else
+ {
+ LOGE("[qser_data_call] unkonwn param [%d].", *net_data);
}
}
static void* data_call_async_thread(void* arg)
{
qser_data_call_error_e err;
- qser_start_async = true;
+
+ qser_data_call_s qser_data_backup = {0};
+ if(arg != NULL)
+ {
+ memcpy(&qser_data_backup, (qser_data_call_s *)arg, sizeof(qser_data_call_s));
+ }
+ else
+ {
+ LOGE("[qser_data_call] arg is NULL.");
+ }
+
+ qser_data_call_state_s state = {0};
+ qser_state_init(&state);
+ state.profile_idx = qser_data_backup.profile_idx;
+ state.ip_family = qser_data_backup.ip_family;
+
int ret = qser_data_call_start(&qser_data_backup, &err);
if(ret != QSER_RESULT_SUCCESS)
{
LOGE("[qser_data_call] qser_data_call_start() fail.");
+ state.err = err;
+ if(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
}
- qser_start_async = false;
+
+ qser_data_call_info_s info = {0};
+ ret = qser_data_call_info_get(qser_data_backup.profile_idx, qser_data_backup.ip_family, &info, &err);
+ if(ret != QSER_RESULT_SUCCESS)
+ {
+ LOGE("[qser_data_call] qser_data_call_info_get() fail.");
+ state.err = err;
+ if(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
+ }
+
+ snprintf(state.name, 16, "ccinet%d", qser_data_backup.profile_idx);
+ state.state = QSER_DATA_CALL_CONNECTED;
+ state.err = err;
+ memcpy(&(state.v4), &(info.v4.addr), sizeof(struct v4_address_status));
+ memcpy(&(state.v6), &(info.v6.addr), sizeof(struct v6_address_status));
+ if(qser_net_status_cb != NULL)
+ {
+ qser_net_status_cb(&state);
+ }
return NULL;
}
@@ -534,6 +462,7 @@
property_get("persist.qser.datacall.apn", qser_apn_add_save_state, "00000000");
LOGE("[qser_data_call] qser_apn_add_save_state = %s", qser_apn_add_save_state);
+ property_get("persist.qser.apn.auth", qser_apn_auth_state, "00000000");
mbtk_apn_info_t apns[10] = {0};
int apn_num = 10;
char qser_apn_type[32] = {0};
@@ -677,8 +606,6 @@
*err = QSER_DATA_CALL_ERROR_NONE;
}
- now_idx = data_call->profile_idx;
-
#if defined(MBTK_ALL_CID_SUPPORT)
if(qser_apn_default_idx == data_call->profile_idx)
{
@@ -757,15 +684,14 @@
return QSER_RESULT_FAIL;
}
- memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s));
- if(pthread_create(&data_call_thread_id, &thread_attr, data_call_async_thread, NULL))
+ //memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s));
+ if(pthread_create(&data_call_thread_id, &thread_attr, data_call_async_thread, (void *) data_call))
{
LOGE("[qser_data_call] pthread_create() fail.");
*err = QSER_DATA_CALL_ERROR_UNKNOWN;
return QSER_RESULT_FAIL;
}
pthread_attr_destroy(&thread_attr);
- now_idx = data_call->profile_idx;
return QSER_RESULT_SUCCESS;
}
@@ -824,7 +750,6 @@
*err = QSER_DATA_CALL_ERROR_NONE;
}
- now_idx = 0;
#if defined(MBTK_ALL_CID_SUPPORT)
if(qser_default_pdp_idx == profile_idx)
{
@@ -1090,10 +1015,19 @@
sprintf(qser_apn_type, "persist.qser.apn.type%d", apn->profile_idx);
property_set(qser_apn_type, apn->apn_type);
+ if(apn->auth_proto == QSER_APN_AUTH_PROTO_NONE)
+ {
+ qser_apn_auth_state[apn->profile_idx] = '1';
+ }
+ else
+ {
+ qser_apn_auth_state[apn->profile_idx] = '0';
+ }
+ property_set("persist.qser.apn.auth", qser_apn_auth_state);
memcpy(&qser_apn_info[apn->profile_idx], apn, sizeof(qser_apn_info_s));
#if defined(MBTK_ALL_CID_SUPPORT)
- if(memcmp(apn->apn_type, "iot_default", strlen(apn->apn_type)) == 0)
+ if(strcmp(apn->apn_type, "iot_default") == 0)
{
qser_apn_add_save_state[apn->profile_idx] = '2';
qser_apn_default_idx = apn->profile_idx;
@@ -1104,6 +1038,7 @@
qser_apn_add_save_state[apn->profile_idx] = '1';
}
+ property_set("persist.qser.datacall.apn", qser_apn_add_save_state);
return QSER_RESULT_SUCCESS;
}
@@ -1229,8 +1164,6 @@
return QSER_RESULT_FAIL;
}
*profile_idx = idx;
-
- property_set("persist.qser.datacall.apn", qser_apn_add_save_state);
}
return QSER_RESULT_SUCCESS;
}
diff --git a/mbtk/test/liblynq_lib_t106/lynq-qser-data-demo.cpp b/mbtk/test/liblynq_lib_t106/lynq-qser-data-demo.cpp
index 221e25b..c3cb0a6 100755
--- a/mbtk/test/liblynq_lib_t106/lynq-qser-data-demo.cpp
+++ b/mbtk/test/liblynq_lib_t106/lynq-qser-data-demo.cpp
@@ -177,11 +177,12 @@
char buf_sec_dns[64] = {0};
printf("DATA_DEMO_CALL_BACK: profile_idx=%d, name=%s, ip_family=%d, state=%d, error=%d\n"
, state->profile_idx, state->name, state->ip_family, state->state, state->err);
+ #if 1
printf("DATA_DEMO_CALL_BACK: v4.ip=%s\n"
, inet_ntoa(state->v4.ip));
printf("DATA_DEMO_CALL_BACK: v4.gateway=%s\n"
, inet_ntoa(state->v4.gateway));
- printf("DATA_DEMO_CALL_BACK: v4.pri_dns=%s, v4.sec_dns=%s\n"
+ printf("DATA_DEMO_CALL_BACK: v4.pri_dns=%s\n"
, inet_ntoa(state->v4.pri_dns));
printf("DATA_DEMO_CALL_BACK: v4.sec_dns=%s\n"
, inet_ntoa(state->v4.sec_dns));
@@ -189,7 +190,10 @@
inet_ntop(AF_INET6, &(state->v6.gateway), buf_gateway, sizeof(buf_gateway));
inet_ntop(AF_INET6, &(state->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
inet_ntop(AF_INET6, &(state->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
- printf("DATA_DEMO_CALL_BACK: v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
- , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
+ printf("DATA_DEMO_CALL_BACK: v6.ip=%s\n", buf_ip);
+ printf("DATA_DEMO_CALL_BACK: v6.gateway=%s\n", buf_gateway);
+ printf("DATA_DEMO_CALL_BACK: v6.pri_dns=%s\n", buf_pri_dns);
+ printf("DATA_DEMO_CALL_BACK: v6.sec_dns=%s\n", buf_sec_dns);
+ #endif
//后续对回调函数中返回值的处理建议放在其它线程中进行,避免阻塞在回调函数中影响后续消息上报
}