T108: fix data_call
Change-Id: I48ac56b38bd7bbfaad8c310398bc3a1e7e2613d1
diff --git a/mbtk/libmbtk_ril/mbtk_info_api.c b/mbtk/libmbtk_ril/mbtk_info_api.c
index a78fbfa..ce9cc9c 100644
--- a/mbtk/libmbtk_ril/mbtk_info_api.c
+++ b/mbtk/libmbtk_ril/mbtk_info_api.c
@@ -394,6 +394,14 @@
return -1;
}
+#ifdef MBTK_SG_SUPPORT
+ if(handle->handle_state)
+ {
+ LOG("hangdle BUSY.");
+ return -2;
+ }
+#endif
+
mbtk_info_pack_t* pack = mbtk_info_pack_creat(id);
if(pack == NULL) {
return -1;
@@ -405,8 +413,13 @@
pack->data = (const uint8*)send_buff;
}
+#ifndef MBTK_SG_SUPPORT
pthread_mutex_lock(&handle->send_mutex);
+#endif
pthread_mutex_lock(&handle->mutex);
+#ifdef MBTK_SG_SUPPORT
+ handle->handle_state = 1;
+#endif
handle->is_waitting = true;
mbtk_info_pack_send(handle->client_fd, pack);
@@ -414,12 +427,10 @@
if(recv_buff != NULL)
handle->data = recv_buff;
-
// Wait for server response.
pthread_cond_wait(&handle->cond, &handle->mutex);
handle->is_waitting = false;
pthread_mutex_unlock(&handle->mutex);
-
if(handle->info_err == MBTK_INFO_ERR_SUCCESS)
{
LOG("REQ %s success.", id2str(id));
@@ -429,11 +440,21 @@
handle->data_len = 0;
handle->data = NULL;
}
+#ifdef MBTK_SG_SUPPORT
+ handle->handle_state = 0;
+#else
pthread_mutex_unlock(&handle->send_mutex);
+#endif
+
return recv_len;
} else {
LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err));
- pthread_mutex_unlock(&handle->send_mutex);
+#ifdef MBTK_SG_SUPPORT
+ handle->handle_state = 0;
+#else
+ pthread_mutex_unlock(&handle->send_mutex);
+#endif
+
return -1;
}
}
@@ -508,7 +529,9 @@
#endif
pthread_mutex_init(&handle->mutex, NULL);
+#ifndef MBTK_SG_SUPPORT
pthread_mutex_init(&handle->send_mutex, NULL);
+#endif
pthread_cond_init(&handle->cond, NULL);
handle->is_waitting = false;
@@ -1158,6 +1181,161 @@
}
/*
+* Get all APN informations.
+*/
+int mbtk_qser_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_qser_apn_info_s apns[])
+{
+ int len;
+ if(handle == NULL || apn_num == NULL || apns == NULL)
+ {
+ LOGE("ARG error.");
+ return -1;
+ }
+ uint8 data[SOCK_MSG_LEN_MAX];
+ if((len = info_item_process(handle, MBTK_INFO_ID_NET_QSER_APN_REQ, NULL, 0, data)) > 0) {
+ /*
+ <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth[1]><apn_type_len[2]><apn_type_len>...
+ <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth[1]><apn_type_len[2]><apn_type_len>
+ */
+ uint8* ptr = data;
+ if(apn_num == NULL || apns == NULL || *apn_num < *ptr) {
+ *apn_num = 0;
+ LOGE("APN array size to not enough.");
+ return -1;
+ }
+ *apn_num = *ptr++;
+ LOGD("APN Number : %d", *apn_num);
+ int i = 0;
+ while(i < *apn_num) {
+ memset(&(apns[i]), 0x0 ,sizeof(mbtk_qser_apn_info_s));
+ apns[i].cid = *ptr++;
+ apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++);
+
+ // apn
+ len = byte_2_uint16(ptr, false);
+ ptr += sizeof(uint16);
+ if(len > 0) { // Has APN
+ memcpy(apns[i].apn_name, ptr, len);
+ ptr += len;
+ }
+ // user
+ len = byte_2_uint16(ptr, false);
+ ptr += sizeof(uint16);
+ if(len > 0) { // Has APN
+ memcpy(apns[i].user_name, ptr, len);
+ ptr += len;
+ }
+
+ // pass
+ len = byte_2_uint16(ptr, false);
+ ptr += sizeof(uint16);
+ if(len > 0) { // Has APN
+ memcpy(apns[i].user_pass, ptr, len);
+ ptr += len;
+ }
+ // auth
+ apns[i].auth_proto = (mbtk_apn_auth_proto_enum)(*ptr++);
+
+ //apn_type
+ len = byte_2_uint16(ptr, false);
+ ptr += sizeof(uint16);
+ if(len > 0) { // Has APN
+ memcpy(apns[i].apn_type, ptr, len);
+ ptr += len;
+ }
+
+ i++;
+ }
+ }
+ else if(len == 0)
+ {
+ LOGD("get data len : 0.");
+ *apn_num = 0;
+ return 0;
+ }
+ else
+ {
+ return handle->info_err;
+ }
+
+ return 0;
+}
+
+/*
+* qser Set current APN informations.
+*/
+int mbtk_qser_apn_set(mbtk_info_handle_t* handle, mbtk_qser_apn_info_s *apninfo, unsigned char *cid)
+{
+ if(handle == NULL)
+ {
+ LOGE("ARG error.");
+ return -1;
+ }
+
+ uint8 data[SOCK_MSG_LEN_MAX];
+ memset(data, 0, SOCK_MSG_LEN_MAX);
+ // cid : 2 - 7
+ if(apninfo->req_type != MBTK_APN_REQ_TYPE_ADD && (apninfo->cid < MBTK_APN_CID_MIN || apninfo->cid > MBTK_APN_CID_MAX)) {
+ LOGE("CID error.");
+ return -1;
+ }
+
+ uint8* ptr = data;
+ // <cid[1]><ip_type[1]><req_type[1]><auth[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><apn_type[2]>
+ *ptr++ = (uint8)apninfo->cid;
+ *ptr++ = (uint8)apninfo->ip_type;
+ *ptr++ = (uint8)apninfo->req_type;
+ *ptr++ = (uint8)apninfo->auth_proto;
+ if(str_empty(apninfo->apn_name)) {
+ uint16_2_byte((uint16)0, ptr, false);
+ ptr += sizeof(uint16);
+ } else {
+ uint16_2_byte((uint16)strlen((char *)apninfo->apn_name), ptr, false);
+ ptr += sizeof(uint16);
+ memcpy(ptr, apninfo->apn_name, strlen((char *)apninfo->apn_name));
+ ptr += strlen((char *)apninfo->apn_name);
+ }
+ if(str_empty(apninfo->user_name)) {
+ uint16_2_byte((uint16)0, ptr, false);
+ ptr += sizeof(uint16);
+ } else {
+ uint16_2_byte((uint16)strlen((char *)apninfo->user_name), ptr, false);
+ ptr += sizeof(uint16);
+ memcpy(ptr, apninfo->user_name, strlen((char *)apninfo->user_name));
+ ptr += strlen((char *)apninfo->user_name);
+ }
+
+ if(str_empty(apninfo->user_pass)) {
+ uint16_2_byte((uint16)0, ptr, false);
+ ptr += sizeof(uint16);
+ } else {
+ uint16_2_byte((uint16)strlen((char *)apninfo->user_pass), ptr, false);
+ ptr += sizeof(uint16);
+ memcpy(ptr, apninfo->user_pass, strlen((char *)apninfo->user_pass));
+ ptr += strlen((char *)apninfo->user_pass);
+ }
+
+ if(str_empty(apninfo->apn_type)) {
+ uint16_2_byte((uint16)0, ptr, false);
+ ptr += sizeof(uint16);
+ }
+ else
+ {
+ uint16_2_byte((uint16)strlen((char *)apninfo->apn_type), ptr, false);
+ ptr += sizeof(uint16);
+ memcpy(ptr, apninfo->apn_type, strlen((char *)apninfo->apn_type));
+ ptr += strlen((char *)apninfo->apn_type);
+ }
+
+ if(info_item_process(handle, MBTK_INFO_ID_NET_QSER_APN_REQ, data, ptr - data, (void *)cid) < 0)
+ {
+ return handle->info_err;
+ }
+
+ return 0;
+}
+
+/*
* Set current APN informations.
*/
int mbtk_apn_set(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name,