blob: 7b75631c96a9eeb1510350990be149179ce1f35a [file] [log] [blame]
b.liu4e243dc2023-11-27 11:20:00 +08001#include "lynq-qser-data.h"
2#include "mbtk_type.h"
wangyouqiang84179c82024-01-05 15:42:55 +08003#include "mbtk_info_api.h"
b.liu5fa9e772023-11-23 18:00:55 +08004
wangyouqiange2498f12024-01-06 17:55:36 +08005#include <pthread.h>
6#include <cutils/properties.h>
7#include <string.h>
wangyouqiang805b0f92024-04-07 17:06:13 +08008#include <unistd.h>
9#include <sys/types.h>
10#include <sys/stat.h>
b.liuf37bd332024-03-18 13:51:24 +080011#include <fcntl.h>
wangyouqiang84179c82024-01-05 15:42:55 +080012/****************************DEFINE***************************************/
13#define QSER_RESULT_SUCCESS 0
14#define QSER_RESULT_FAIL -1
b.liu5fa9e772023-11-23 18:00:55 +080015
b.liuf37bd332024-03-18 13:51:24 +080016#define MBTK_INFO_ERR_CID_EXIST 311
17#define MBTK_INFO_ERR_CID_NO_EXIST 312
wangyouqiangc1d72d22024-04-25 10:15:58 +080018#define MBTK_INFO_ERR_NO_APN 500
b.liuf37bd332024-03-18 13:51:24 +080019
wangyouqiange2498f12024-01-06 17:55:36 +080020#define QSER_APN_NUM 8
wangyouqiang84179c82024-01-05 15:42:55 +080021//default range: 0 - 7
22//AT+CGACT range: 1 - 8
23//1 default IDX, 8 IMS IDX
b.liuf37bd332024-03-18 13:51:24 +080024#if defined(MBTK_ALL_CID_SUPPORT)
wangyouqiang3dcb3832024-04-24 15:22:50 +080025#if defined(MBTK_SG_SUPPORT)
b.liuf37bd332024-03-18 13:51:24 +080026#define QSER_PROFILE_IDX_MIN 0
27#else
wangyouqiang84179c82024-01-05 15:42:55 +080028#define QSER_PROFILE_IDX_MIN 1
b.liuf37bd332024-03-18 13:51:24 +080029#endif
wangyouqiang805b0f92024-04-07 17:06:13 +080030#else
31#define QSER_PROFILE_IDX_MIN 1
32#endif
wangyouqiang84179c82024-01-05 15:42:55 +080033#define QSER_PROFILE_IDX_MAX 6
wangyouqiange2498f12024-01-06 17:55:36 +080034
wangyouqiang84179c82024-01-05 15:42:55 +080035/****************************DEFINE***************************************/
36
37/****************************VARIABLE***************************************/
38mbtk_info_handle_t* qser_info_handle = NULL;
39int qser_info_handle_num = 0;
40static bool inited = FALSE;
41static qser_data_call_evt_cb_t qser_net_status_cb = NULL;
wangyouqiang84179c82024-01-05 15:42:55 +080042/****************************VARIABLE***************************************/
43
44/******************************FUNC*****************************************/
wangyouqiang80487e42024-05-24 15:06:20 +080045static int qser_apn_info_param_convert(int profile_idx, qser_apn_info_s *new_apn, mbtk_qser_apn_info_s *old_apn)
wangyouqiang84179c82024-01-05 15:42:55 +080046{
47 if(new_apn == NULL || old_apn == NULL)
48 {
wangyouqiangc42b85d2024-04-24 17:05:06 +080049 LOGE("[qser_data] qser_apn_info_param_convert apn param is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +080050 return QSER_RESULT_FAIL;
51 }
wangyouqiang80487e42024-05-24 15:06:20 +080052
53 memset(new_apn, 0x0, sizeof(qser_apn_info_s));
54 new_apn->profile_idx = old_apn->cid - 1;
wangyouqiang84179c82024-01-05 15:42:55 +080055 //get ip type
56 if(old_apn->ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6
57 {
58 new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4V6;
59 }
60 else if(old_apn->ip_type == MBTK_IP_TYPE_IP) // IPV4
61 {
62 new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4;
63 }
64 else if(old_apn->ip_type == MBTK_IP_TYPE_IPV6) // IPV6
65 {
66 new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV6;
67 }
68 else
69 {
70 new_apn->pdp_type = QSER_APN_PDP_TYPE_PPP;
71 }
72
73 //get apn name
wangyouqiang80487e42024-05-24 15:06:20 +080074 if(strlen((char *)old_apn->apn_name) > QSER_APN_NAME_SIZE)
wangyouqiang84179c82024-01-05 15:42:55 +080075 {
wangyouqiangc42b85d2024-04-24 17:05:06 +080076 LOGE("[qser_data] apn_nmea length verylong.");
wangyouqiang84179c82024-01-05 15:42:55 +080077 return QSER_RESULT_FAIL;
78 }
79 else
80 {
wangyouqiang80487e42024-05-24 15:06:20 +080081 if(strlen((char *)old_apn->apn_name) > 0)
wangyouqiang84179c82024-01-05 15:42:55 +080082 {
wangyouqiang80487e42024-05-24 15:06:20 +080083 memcpy(new_apn->apn_name, old_apn->apn_name,strlen((char *)old_apn->apn_name));
wangyouqiang84179c82024-01-05 15:42:55 +080084 }
85 }
86
87 //get apn user
wangyouqiang80487e42024-05-24 15:06:20 +080088 if(strlen((char *)old_apn->user_name) > QSER_APN_USERNAME_SIZE)
wangyouqiang84179c82024-01-05 15:42:55 +080089 {
wangyouqiangc42b85d2024-04-24 17:05:06 +080090 LOGE("[qser_data] apn_user length verylong.");
wangyouqiang84179c82024-01-05 15:42:55 +080091 return QSER_RESULT_FAIL;
92 }
93 else
94 {
wangyouqiang80487e42024-05-24 15:06:20 +080095 if(strlen((char *)old_apn->user_name) > 0)
wangyouqiang84179c82024-01-05 15:42:55 +080096 {
wangyouqiang80487e42024-05-24 15:06:20 +080097 memcpy(new_apn->username, old_apn->user_name, strlen((char *)old_apn->user_name));
wangyouqiang84179c82024-01-05 15:42:55 +080098 }
99 }
100
101 //get apn password
wangyouqiang80487e42024-05-24 15:06:20 +0800102 if(strlen((char *)old_apn->user_pass) > QSER_APN_PASSWORD_SIZE)
wangyouqiang84179c82024-01-05 15:42:55 +0800103 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800104 LOGE("[qser_data] apn_password length verylong.");
wangyouqiang84179c82024-01-05 15:42:55 +0800105 return QSER_RESULT_FAIL;
106 }
107 else
108 {
wangyouqiang80487e42024-05-24 15:06:20 +0800109 if(strlen((char *)old_apn->user_pass) > 0)
wangyouqiang84179c82024-01-05 15:42:55 +0800110 {
wangyouqiang80487e42024-05-24 15:06:20 +0800111 memcpy(new_apn->password, old_apn->user_pass, strlen((char *)old_apn->user_pass));
wangyouqiang84179c82024-01-05 15:42:55 +0800112 }
113 }
114
115 //get apn proto
wangyouqiang80487e42024-05-24 15:06:20 +0800116 new_apn->auth_proto = (qser_apn_auth_proto_e)old_apn->auth_proto;
wangyouqiang84179c82024-01-05 15:42:55 +0800117
118 //get apn type
wangyouqiang80487e42024-05-24 15:06:20 +0800119 if(strlen((char *)old_apn->apn_type) > QSER_APN_PASSWORD_SIZE)
wangyouqiang84179c82024-01-05 15:42:55 +0800120 {
wangyouqiang80487e42024-05-24 15:06:20 +0800121 LOGE("[qser_data] apn_type length verylong.");
wangyouqiang8ebeafe2024-04-15 10:07:44 +0800122 return QSER_RESULT_FAIL;
123 }
wangyouqiang8ebeafe2024-04-15 10:07:44 +0800124 else
125 {
wangyouqiang80487e42024-05-24 15:06:20 +0800126 if(strlen((char *)old_apn->apn_type) > 0)
wangyouqiang8ebeafe2024-04-15 10:07:44 +0800127 {
wangyouqiang80487e42024-05-24 15:06:20 +0800128 memcpy(new_apn->apn_type, old_apn->apn_type, strlen((char *)old_apn->apn_type));
r.xiaof6ec4822024-04-03 02:46:00 -0700129 }
130 }
131
132 return QSER_RESULT_SUCCESS;
133}
134
wangyouqiang12a87812024-04-22 14:54:52 +0800135static void qser_state_init(qser_data_call_state_s *state)
wangyouqiang805b0f92024-04-07 17:06:13 +0800136{
wangyouqianga24887d2024-04-08 18:31:23 +0800137 if(state != NULL)
wangyouqiang805b0f92024-04-07 17:06:13 +0800138 {
wangyouqianga24887d2024-04-08 18:31:23 +0800139 state->profile_idx = 0;
140 memset(state->name, 0x0, 16);
141 state->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
142 state->state = QSER_DATA_CALL_DISCONNECTED;
143 state->err = QSER_DATA_CALL_ERROR_NONE;
144 inet_aton("0.0.0.0", &(state->v4.ip));
145 inet_aton("0.0.0.0", &(state->v4.gateway));
146 inet_aton("0.0.0.0", &(state->v4.pri_dns));
147 inet_aton("0.0.0.0", &(state->v4.sec_dns));
148 inet_pton(AF_INET6, "::", &(state->v6.ip));
149 inet_pton(AF_INET6, "::", &(state->v6.gateway));
150 inet_pton(AF_INET6, "::", &(state->v6.pri_dns));
151 inet_pton(AF_INET6, "::", &(state->v6.sec_dns));
wangyouqiang805b0f92024-04-07 17:06:13 +0800152 }
wangyouqiang805b0f92024-04-07 17:06:13 +0800153}
r.xiaof6ec4822024-04-03 02:46:00 -0700154
wangyouqiang84179c82024-01-05 15:42:55 +0800155void qser_wan_net_state_change_cb(const void* data, int data_len)
156{
157 if(data == NULL || data_len == 0)
158 {
159 return;
160 }
161
162 uint8 *net_data = NULL;
163 net_data = (uint8 *)data;
164
wangyouqianga24887d2024-04-08 18:31:23 +0800165 if(*net_data > 100 && *net_data < 200)
wangyouqiang84179c82024-01-05 15:42:55 +0800166 {
wangyouqianga24887d2024-04-08 18:31:23 +0800167 int idx = *net_data - 101;
168 if(idx <= QSER_PROFILE_IDX_MAX)
wangyouqiange2498f12024-01-06 17:55:36 +0800169 {
wangyouqianga24887d2024-04-08 18:31:23 +0800170 qser_data_call_state_s state = {0};
171 qser_state_init(&state);
172 state.profile_idx = idx;
wangyouqiange2498f12024-01-06 17:55:36 +0800173 state.state = QSER_DATA_CALL_DISCONNECTED;
wangyouqianga24887d2024-04-08 18:31:23 +0800174 if(qser_net_status_cb != NULL)
175 {
176 qser_net_status_cb(&state);
177 }
wangyouqiange2498f12024-01-06 17:55:36 +0800178 }
179 else
180 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800181 LOGE("[qser_data] cb fail,idx is %d.", idx);
wangyouqiange2498f12024-01-06 17:55:36 +0800182 }
wangyouqianga24887d2024-04-08 18:31:23 +0800183
184 }
wangyouqiang3947b302024-07-04 17:26:08 +0800185 else if(*net_data > 200 && *net_data < 220)
wangyouqianga24887d2024-04-08 18:31:23 +0800186 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800187 LOGE("[qser_data] cid[%d] is open.", *net_data - 201);
wangyouqianga24887d2024-04-08 18:31:23 +0800188 }
wangyouqiang3947b302024-07-04 17:26:08 +0800189 else if(*net_data > 220)
190 {
191 LOGE("[qser_data] cid[%d] is reopen.", *net_data - 221);
192 int idx = *net_data - 221;
193 if(idx <= QSER_PROFILE_IDX_MAX)
194 {
195 qser_data_call_state_s state = {0};
196 qser_state_init(&state);
197 state.profile_idx = idx;
198 state.state = QSER_DATA_CALL_CONNECTED;
199 snprintf(state.name, 16, "ccinet%d", idx);
200 if(qser_net_status_cb != NULL)
201 {
202 qser_net_status_cb(&state);
203 }
204 }
205 }
wangyouqianga24887d2024-04-08 18:31:23 +0800206 else if(*net_data == 1)
207 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800208 LOGE("[qser_data] pdp is open.");
wangyouqianga24887d2024-04-08 18:31:23 +0800209 }
210 else
211 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800212 LOGE("[qser_data] unkonwn param [%d].", *net_data);
wangyouqiang84179c82024-01-05 15:42:55 +0800213 }
214}
wangyouqiange2498f12024-01-06 17:55:36 +0800215
216static void* data_call_async_thread(void* arg)
217{
liuyang2c21d622024-07-29 14:05:55 +0800218 LOGE("[qser_data] entry data_call_async_thread.");
219 qser_data_call_error_e err = QSER_DATA_CALL_ERROR_NONE;
wangyouqianga24887d2024-04-08 18:31:23 +0800220
221 qser_data_call_s qser_data_backup = {0};
liuyang2c21d622024-07-29 14:05:55 +0800222 qser_data_call_info_s info = {0};
wangyouqianga24887d2024-04-08 18:31:23 +0800223 if(arg != NULL)
224 {
225 memcpy(&qser_data_backup, (qser_data_call_s *)arg, sizeof(qser_data_call_s));
226 }
227 else
228 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800229 LOGE("[qser_data] arg is NULL.");
wangyouqianga24887d2024-04-08 18:31:23 +0800230 }
231
232 qser_data_call_state_s state = {0};
233 qser_state_init(&state);
234 state.profile_idx = qser_data_backup.profile_idx;
liuyang2c21d622024-07-29 14:05:55 +0800235 snprintf(state.name, 16, "ccinet%d", qser_data_backup.profile_idx);
wangyouqianga24887d2024-04-08 18:31:23 +0800236 state.ip_family = qser_data_backup.ip_family;
237
wangyouqiange2498f12024-01-06 17:55:36 +0800238 int ret = qser_data_call_start(&qser_data_backup, &err);
239 if(ret != QSER_RESULT_SUCCESS)
240 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800241 LOGE("[qser_data] qser_data_call_start() fail.");
wangyouqianga24887d2024-04-08 18:31:23 +0800242 state.err = err;
wangyouqiange2498f12024-01-06 17:55:36 +0800243 }
liuyang2c21d622024-07-29 14:05:55 +0800244 else
wangyouqianga24887d2024-04-08 18:31:23 +0800245 {
liuyang2c21d622024-07-29 14:05:55 +0800246 state.state = QSER_DATA_CALL_CONNECTED;
247 ret = qser_data_call_info_get(qser_data_backup.profile_idx, qser_data_backup.ip_family, &info, &err);
248 if(ret != QSER_RESULT_SUCCESS)
wangyouqianga24887d2024-04-08 18:31:23 +0800249 {
liuyang2c21d622024-07-29 14:05:55 +0800250 LOGE("[qser_data] qser_data_call_info_get() fail.");
251 state.err = err;
252 }
253 else
254 {
255 memcpy(&(state.v4), &(info.v4.addr), sizeof(struct v4_address_status));
256 memcpy(&(state.v6), &(info.v6.addr), sizeof(struct v6_address_status));
wangyouqianga24887d2024-04-08 18:31:23 +0800257 }
258 }
liuyang2c21d622024-07-29 14:05:55 +0800259
wangyouqianga24887d2024-04-08 18:31:23 +0800260 if(qser_net_status_cb != NULL)
261 {
262 qser_net_status_cb(&state);
263 }
wangyouqiange2498f12024-01-06 17:55:36 +0800264 return NULL;
265}
266
wangyouqiang84179c82024-01-05 15:42:55 +0800267/******************************FUNC*****************************************/
268
269/****************************API***************************************/
b.liu5fa9e772023-11-23 18:00:55 +0800270int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
271{
wangyouqiang84179c82024-01-05 15:42:55 +0800272 //UNUSED(evt_cb);
273 if(!inited && qser_info_handle == NULL)
274 {
275 qser_info_handle = mbtk_info_handle_get();
276 if(qser_info_handle)
277 {
278 qser_info_handle_num++;
279 inited = TRUE;
280 mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb);
281 }
282 else
283 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800284 LOGE("[qser_data] mbtk_info_handle_get() fail.");
wangyouqiang84179c82024-01-05 15:42:55 +0800285 return QSER_RESULT_FAIL;
286 }
287 }
288 else
289 {
290 if(!inited)
291 {
292 qser_info_handle_num++;
293 inited = TRUE;
294 mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb);
295 }
296 }
297 qser_net_status_cb = evt_cb;
b.liu5fa9e772023-11-23 18:00:55 +0800298
wangyouqiangc42b85d2024-04-24 17:05:06 +0800299 LOGE("[qser_data] mbtk_info_handle_get() success.");
wangyouqiang84179c82024-01-05 15:42:55 +0800300 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800301}
302
303void qser_data_call_destroy(void)
304{
wangyouqiang84179c82024-01-05 15:42:55 +0800305 if(qser_info_handle)
306 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800307 LOGE("[qser_data] qser_info_handle_num = %d", qser_info_handle_num);
wangyouqiang84179c82024-01-05 15:42:55 +0800308 if(qser_info_handle_num == 1)
309 { // 最后一个引用,可释放。
310 int ret = mbtk_info_handle_free(&qser_info_handle);
311 if(ret)
312 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800313 LOGE("[qser_data] mbtk_info_handle_free() fail.");
wangyouqiang84179c82024-01-05 15:42:55 +0800314 }
315 else
316 {
317 qser_info_handle_num = 0;
318 qser_info_handle = NULL;
wangyouqiang45cfff82024-04-15 19:35:15 +0800319 qser_net_status_cb = NULL;
wangyouqiang84179c82024-01-05 15:42:55 +0800320 inited = FALSE;
321 }
322 }
323 else
324 {
325 qser_info_handle_num--;
wangyouqiang45cfff82024-04-15 19:35:15 +0800326 qser_net_status_cb = NULL;
wangyouqiang84179c82024-01-05 15:42:55 +0800327 }
328 }
329 else
330 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800331 LOGE("[qser_data] handle not inited.");
wangyouqiang84179c82024-01-05 15:42:55 +0800332 }
b.liu5fa9e772023-11-23 18:00:55 +0800333}
334
335int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
336{
wangyouqiang84179c82024-01-05 15:42:55 +0800337 //UNUSED(data_call);
338 //UNUSED(err);
339 if(data_call == NULL || err == NULL)
340 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800341 LOGE("[qser_data] data_call or err is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800342 if(err != NULL)
343 {
344 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
345 }
346 return QSER_RESULT_FAIL;
347 }
348
349 if(qser_info_handle == NULL)
350 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800351 LOGE("[qser_data] handle is NULL.");
b.liuf37bd332024-03-18 13:51:24 +0800352 *err = QSER_DATA_CALL_ERROR_NO_INIT;
wangyouqiang84179c82024-01-05 15:42:55 +0800353 return QSER_RESULT_FAIL;
354 }
b.liu5fa9e772023-11-23 18:00:55 +0800355
wangyouqiang84179c82024-01-05 15:42:55 +0800356 int ret = -1;
357 ret = mbtk_data_call_start(qser_info_handle, data_call->profile_idx + 1, 0, FALSE, 0);
358 if(ret != 0)
359 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800360 LOGE("[qser_data] mbtk_data_call_start fail.[ret = %d]", ret);
b.liuf37bd332024-03-18 13:51:24 +0800361 if(ret == MBTK_INFO_ERR_CID_EXIST)
362 {
363 *err = QSER_DATA_CALL_ERROR_PDP_ACTIVATE;
364 }
365 else
366 {
367 *err = QSER_DATA_CALL_ERROR_UNKNOWN;
368 }
wangyouqiang84179c82024-01-05 15:42:55 +0800369 return QSER_RESULT_FAIL;
370 }
371 else
372 {
373 *err = QSER_DATA_CALL_ERROR_NONE;
374 }
wangyouqiange2498f12024-01-06 17:55:36 +0800375
wangyouqiange2498f12024-01-06 17:55:36 +0800376 return QSER_RESULT_SUCCESS;
377}
378
379int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
380{
381 //UNUSED(data_call);
382 UNUSED(err);
383 if(data_call == NULL || err == NULL)
384 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800385 LOGE("[qser_data] data_call or err is NULL.");
wangyouqiange2498f12024-01-06 17:55:36 +0800386 if(err != NULL)
387 {
388 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
389 }
390 return QSER_RESULT_FAIL;
391 }
392
393 if(qser_info_handle == NULL)
394 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800395 LOGE("[qser_data] handle is NULL.");
b.liuf37bd332024-03-18 13:51:24 +0800396 *err = QSER_DATA_CALL_ERROR_NO_INIT;
wangyouqiange2498f12024-01-06 17:55:36 +0800397 return QSER_RESULT_FAIL;
398 }
399
wangyouqiange2498f12024-01-06 17:55:36 +0800400 pthread_attr_t thread_attr;
401 pthread_t data_call_thread_id;
402 pthread_attr_init(&thread_attr);
403 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
404 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800405 LOGE("[qser_data] pthread_attr_setdetachstate() fail.");
b.liuf37bd332024-03-18 13:51:24 +0800406 *err = QSER_DATA_CALL_ERROR_UNKNOWN;
wangyouqiange2498f12024-01-06 17:55:36 +0800407 return QSER_RESULT_FAIL;
408 }
409
wangyouqianga24887d2024-04-08 18:31:23 +0800410 //memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s));
411 if(pthread_create(&data_call_thread_id, &thread_attr, data_call_async_thread, (void *) data_call))
wangyouqiange2498f12024-01-06 17:55:36 +0800412 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800413 LOGE("[qser_data] pthread_create() fail.");
b.liuf37bd332024-03-18 13:51:24 +0800414 *err = QSER_DATA_CALL_ERROR_UNKNOWN;
wangyouqiange2498f12024-01-06 17:55:36 +0800415 return QSER_RESULT_FAIL;
416 }
417 pthread_attr_destroy(&thread_attr);
wangyouqiange2498f12024-01-06 17:55:36 +0800418
wangyouqiang84179c82024-01-05 15:42:55 +0800419 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800420}
421
422int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
423{
wangyouqiang84179c82024-01-05 15:42:55 +0800424 //UNUSED(profile_idx);
b.liu5fa9e772023-11-23 18:00:55 +0800425 UNUSED(ip_family);
wangyouqiang84179c82024-01-05 15:42:55 +0800426 //UNUSED(err);
427 if(err == NULL)
428 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800429 LOGE("[qser_data] err is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800430 return QSER_RESULT_FAIL;
431 }
b.liu5fa9e772023-11-23 18:00:55 +0800432
wangyouqiang84179c82024-01-05 15:42:55 +0800433 if(qser_info_handle == NULL)
434 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800435 LOGE("[qser_data] handle is NULL.");
b.liuf37bd332024-03-18 13:51:24 +0800436 *err = QSER_DATA_CALL_ERROR_NO_INIT;
wangyouqiang84179c82024-01-05 15:42:55 +0800437 return QSER_RESULT_FAIL;
438 }
439
wangyouqiang84179c82024-01-05 15:42:55 +0800440 int ret = -1;
441 ret = mbtk_data_call_stop(qser_info_handle, profile_idx + 1, 15);
442 if(ret != 0)
443 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800444 LOGE("[qser_data] mbtk_data_call_stop fail.[ret = %d]", ret);
b.liuf37bd332024-03-18 13:51:24 +0800445 if(ret == MBTK_INFO_ERR_CID_NO_EXIST)
446 {
447 *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE;
448 }
449 else
450 {
451 *err = QSER_DATA_CALL_ERROR_UNKNOWN;
452 }
wangyouqiang84179c82024-01-05 15:42:55 +0800453 return QSER_RESULT_FAIL;
454 }
455 else
456 {
457 *err = QSER_DATA_CALL_ERROR_NONE;
458 }
wangyouqiange2498f12024-01-06 17:55:36 +0800459
wangyouqiang84179c82024-01-05 15:42:55 +0800460 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800461}
462
463int qser_data_call_info_get(char profile_idx,qser_data_call_ip_family_e ip_family,
464 qser_data_call_info_s *info, qser_data_call_error_e *err)
465{
wangyouqiang84179c82024-01-05 15:42:55 +0800466 //UNUSED(profile_idx);
b.liu5fa9e772023-11-23 18:00:55 +0800467 UNUSED(ip_family);
wangyouqiang84179c82024-01-05 15:42:55 +0800468 //UNUSED(info);
469 //UNUSED(err);
b.liu5fa9e772023-11-23 18:00:55 +0800470
wangyouqiang84179c82024-01-05 15:42:55 +0800471 if(info == NULL || err == NULL)
472 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800473 LOGE("[qser_data] info or err is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800474 if(err != NULL)
475 {
476 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
477 }
478 return QSER_RESULT_FAIL;
479 }
480
481 if(qser_info_handle == NULL)
482 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800483 LOGE("[qser_data] handle is NULL.");
b.liuf37bd332024-03-18 13:51:24 +0800484 *err = QSER_DATA_CALL_ERROR_NO_INIT;
wangyouqiang84179c82024-01-05 15:42:55 +0800485 return QSER_RESULT_FAIL;
486 }
487
wangyouqiang84179c82024-01-05 15:42:55 +0800488 int ret = -1;
489 mbtk_ipv4_info_t ipv4;
490 mbtk_ipv6_info_t ipv6;
491#ifdef QSER_TEST
492 char v4_buff[32] = {0};
493 char v6_buff[128] = {0};
494#endif
495 memset(info, 0, sizeof(qser_data_call_info_s));
496 ret = mbtk_data_call_state_get(qser_info_handle, profile_idx + 1, &ipv4, &ipv6);
497 if(ret != 0)
498 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800499 LOGE("[qser_data] mbtk_data_call_state_get fail.[ret = %d]", ret);
b.liuf37bd332024-03-18 13:51:24 +0800500 if(ret == MBTK_INFO_ERR_CID_NO_EXIST)
501 {
502 *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE;
503 }
504 else
505 {
506 *err = QSER_DATA_CALL_ERROR_UNKNOWN;
507 }
wangyouqiang84179c82024-01-05 15:42:55 +0800508 return QSER_RESULT_FAIL;
509 }
510 else
511 {
512 info->profile_idx = profile_idx;
513 if(ipv4.valid)
514 {
515 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
516 info->v4.state = QSER_DATA_CALL_CONNECTED;
517 sprintf(info->v4.name, "ccinet%d", profile_idx);
b.liuf37bd332024-03-18 13:51:24 +0800518 info->v4.addr.ip.s_addr = ipv4.IPAddr;
519 info->v4.addr.pri_dns.s_addr = ipv4.PrimaryDNS;
520 info->v4.addr.sec_dns.s_addr = ipv4.SecondaryDNS;
liuyang8ced5422024-08-05 19:26:01 +0800521 info->v4.reconnect = 1;
b.liuf37bd332024-03-18 13:51:24 +0800522
wangyouqiang84179c82024-01-05 15:42:55 +0800523#ifdef QSER_TEST
wangyouqiangc42b85d2024-04-24 17:05:06 +0800524 //LOGE("[qser_data] IP: %x pri_DNS: %x sec_DNS: %x.", ipv4.IPAddr, ipv4.PrimaryDNS, ipv4.SecondaryDNS);
wangyouqiang84179c82024-01-05 15:42:55 +0800525 if(inet_ntop(AF_INET, &(info->v4.addr.ip), v4_buff, 32) == NULL) {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800526 LOGE("[qser_data] IP error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800527 } else {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800528 LOGE("[qser_data] IP : %s", v4_buff);
wangyouqiang84179c82024-01-05 15:42:55 +0800529 }
530 if(inet_ntop(AF_INET, &(info->v4.addr.pri_dns), v4_buff, 32) == NULL) {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800531 LOGE("[qser_data] PrimaryDNS error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800532 } else {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800533 LOGE("[qser_data] PrimaryDNS : %s", v4_buff);
wangyouqiang84179c82024-01-05 15:42:55 +0800534 }
535 if(inet_ntop(AF_INET, &(info->v4.addr.sec_dns), v4_buff, 32) == NULL) {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800536 LOGE("[qser_data] SecondaryDNS error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800537 } else {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800538 LOGE("[qser_data] SecondaryDNS : %s", v4_buff);
wangyouqiang84179c82024-01-05 15:42:55 +0800539 }
540#endif
541 }
542
543 if(ipv6.valid)
544 {
545 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
546 info->v6.state = QSER_DATA_CALL_CONNECTED;
547 sprintf(info->v6.name, "ccinet%d", profile_idx);
b.liuf37bd332024-03-18 13:51:24 +0800548 memcpy(&(info->v6.addr.ip), &(ipv6.IPV6Addr), sizeof(ipv6.IPV6Addr));
549 memcpy(&(info->v6.addr.pri_dns), &(ipv6.PrimaryDNS), sizeof(ipv6.PrimaryDNS));
550 memcpy(&(info->v6.addr.sec_dns), &(ipv6.SecondaryDNS), sizeof(ipv6.SecondaryDNS));
liuyang7fc538e2024-08-14 10:29:26 +0800551 info->v6.reconnect = 1;
552
wangyouqiang84179c82024-01-05 15:42:55 +0800553#ifdef QSER_TEST
554 if(ipv6_2_str(&(info->v6.addr.ip), v6_buff))
555 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800556 LOGE("[qser_data] IP error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800557 } else {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800558 LOGE("[qser_data] IP : %s", v6_buff);
wangyouqiang84179c82024-01-05 15:42:55 +0800559 }
560 if(ipv6_2_str(&(info->v6.addr.pri_dns), v6_buff))
561 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800562 LOGE("[qser_data] PrimaryDNS error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800563 } else {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800564 LOGE("[qser_data] PrimaryDNS : %s", v6_buff);
wangyouqiang84179c82024-01-05 15:42:55 +0800565 }
566 if(ipv6_2_str(&(info->v6.addr.sec_dns), v6_buff))
567 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800568 LOGE("[qser_data] SecondaryDNS error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800569 } else {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800570 LOGE("[qser_data] SecondaryDNS : %s", v6_buff);
wangyouqiang84179c82024-01-05 15:42:55 +0800571 }
572#endif
573 }
574
575 if(ipv4.valid && ipv6.valid)
576 {
577 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
578 }
579
580 if(!ipv4.valid && !ipv6.valid)
581 {
582 info->v4.state = QSER_DATA_CALL_DISCONNECTED;
583 info->v6.state = QSER_DATA_CALL_DISCONNECTED;
584 }
585 }
586
587 *err = QSER_DATA_CALL_ERROR_NONE;
588 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800589}
590
591int qser_apn_set(qser_apn_info_s *apn)
592{
wangyouqiang84179c82024-01-05 15:42:55 +0800593 //UNUSED(apn);
594 if(qser_info_handle == NULL)
595 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800596 LOGE("[qser_data] handle is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800597 return QSER_RESULT_FAIL;
598 }
599
600 if(apn == NULL)
601 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800602 LOGE("[qser_data] apn param is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800603 return QSER_RESULT_FAIL;
604 }
b.liu5fa9e772023-11-23 18:00:55 +0800605
wangyouqiang80487e42024-05-24 15:06:20 +0800606 int ret = 0;
607 mbtk_qser_apn_info_s apninfo;
608 memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s));
609 apninfo.cid = apn->profile_idx + 1;
610
wangyouqiang84179c82024-01-05 15:42:55 +0800611 if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4)
612 {
wangyouqiang80487e42024-05-24 15:06:20 +0800613 apninfo.ip_type = MBTK_IP_TYPE_IP;
wangyouqiang84179c82024-01-05 15:42:55 +0800614 }
615 else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6)
616 {
wangyouqiang80487e42024-05-24 15:06:20 +0800617 apninfo.ip_type = MBTK_IP_TYPE_IPV6;
wangyouqiang84179c82024-01-05 15:42:55 +0800618 }
619 else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6)
620 {
wangyouqiang80487e42024-05-24 15:06:20 +0800621 apninfo.ip_type = MBTK_IP_TYPE_IPV4V6;
wangyouqiang84179c82024-01-05 15:42:55 +0800622 }
623 else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP)
624 {
wangyouqiang80487e42024-05-24 15:06:20 +0800625 apninfo.ip_type = MBTK_IP_TYPE_PPP;
wangyouqiang84179c82024-01-05 15:42:55 +0800626 }
627 else
628 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800629 LOGE("[qser_data] pdp_type error.");
wangyouqiang84179c82024-01-05 15:42:55 +0800630 return QSER_RESULT_FAIL;
631 }
632
wangyouqiange2498f12024-01-06 17:55:36 +0800633
wangyouqiang80487e42024-05-24 15:06:20 +0800634 apninfo.req_type = MBTK_APN_REQ_TYPE_SET;
635 apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto;
636 if(strlen(apn->apn_name))
wangyouqiang84179c82024-01-05 15:42:55 +0800637 {
wangyouqiang80487e42024-05-24 15:06:20 +0800638 memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name));
639 }
640 else
641 {
642 LOGE("[qser_data] apn_name is NULL.");
643 return QSER_RESULT_FAIL;
644 }
645 if(strlen(apn->username))
646 {
647 memcpy(apninfo.user_name, apn->username, strlen(apn->username));
648 }
649 if(strlen(apn->password))
650 {
651 memcpy(apninfo.user_pass, apn->password, strlen(apn->password));
652 }
653 if(strlen(apn->apn_type))
654 {
655 memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type));
656 }
657 ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, NULL);
658 if(ret != 0)
659 {
660 LOGE("[qser_data] mbtk_qser_apn_set fail.");
wangyouqiang84179c82024-01-05 15:42:55 +0800661 return QSER_RESULT_FAIL;
662 }
663
wangyouqiang84179c82024-01-05 15:42:55 +0800664 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800665}
666
667int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
668{
wangyouqiang84179c82024-01-05 15:42:55 +0800669 //UNUSED(profile_idx);
670 //UNUSED(apn);
671 if(qser_info_handle == NULL)
672 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800673 LOGE("[qser_data] handle is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800674 return QSER_RESULT_FAIL;
675 }
676
677 if(apn == NULL)
678 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800679 LOGE("[qser_data] apn param is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800680 return QSER_RESULT_FAIL;
681 }
b.liu5fa9e772023-11-23 18:00:55 +0800682
wangyouqiang84179c82024-01-05 15:42:55 +0800683 //get apn info
wangyouqiang80487e42024-05-24 15:06:20 +0800684 mbtk_qser_apn_info_s apns[10] = {0};
wangyouqiang84179c82024-01-05 15:42:55 +0800685 int apn_num = 10;
wangyouqiang80487e42024-05-24 15:06:20 +0800686 int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns);
wangyouqiang84179c82024-01-05 15:42:55 +0800687 if(ret != 0)
688 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800689 LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret);
wangyouqiang84179c82024-01-05 15:42:55 +0800690 return QSER_RESULT_FAIL;
691 }
692 else
693 {
694 int i = 0;
695 for(i = 0; i < apn_num; i++)
696 {
697 if(apns[i].cid == profile_idx + 1)
698 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800699 LOGE("[qser_data] find IDX.");
wangyouqiang84179c82024-01-05 15:42:55 +0800700 break;
701 }
702 }
703
704 if(i == apn_num)
705 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800706 LOGE("[qser_data] not find IDX.[apn_num = %d]", apn_num);
wangyouqiang84179c82024-01-05 15:42:55 +0800707 return QSER_RESULT_FAIL;
708 }
709
710 if(qser_apn_info_param_convert(profile_idx, apn, &apns[i]) != 0)
711 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800712 LOGE("[qser_data] qser_apn_info_param_convert fail");
wangyouqiang84179c82024-01-05 15:42:55 +0800713 return QSER_RESULT_FAIL;
714 }
715 }
716 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800717}
718
719int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
720{
wangyouqiange2498f12024-01-06 17:55:36 +0800721 //UNUSED(apn);
722 //UNUSED(profile_idx);
723 if(qser_info_handle == NULL)
724 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800725 LOGE("[qser_data] handle is NULL.");
wangyouqiange2498f12024-01-06 17:55:36 +0800726 return QSER_RESULT_FAIL;
727 }
728
wangyouqiang80487e42024-05-24 15:06:20 +0800729 if(apn == NULL || profile_idx == NULL)
wangyouqiange2498f12024-01-06 17:55:36 +0800730 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800731 LOGE("[qser_data] apn param is NULL.");
wangyouqiange2498f12024-01-06 17:55:36 +0800732 return QSER_RESULT_FAIL;
733 }
b.liu5fa9e772023-11-23 18:00:55 +0800734
wangyouqiange2498f12024-01-06 17:55:36 +0800735 int ret = 0;
wangyouqiang80487e42024-05-24 15:06:20 +0800736 unsigned char idx[2] = {0};
737 mbtk_qser_apn_info_s apninfo;
738 memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s));
739 apninfo.cid = 0;
740
741 if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4)
wangyouqiange2498f12024-01-06 17:55:36 +0800742 {
wangyouqiang80487e42024-05-24 15:06:20 +0800743 apninfo.ip_type = MBTK_IP_TYPE_IP;
744 }
745 else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6)
746 {
747 apninfo.ip_type = MBTK_IP_TYPE_IPV6;
748 }
749 else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6)
750 {
751 apninfo.ip_type = MBTK_IP_TYPE_IPV4V6;
752 }
753 else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP)
754 {
755 apninfo.ip_type = MBTK_IP_TYPE_PPP;
wangyouqiange2498f12024-01-06 17:55:36 +0800756 }
757 else
758 {
wangyouqiang80487e42024-05-24 15:06:20 +0800759 LOGE("[qser_data] pdp_type error.");
760 return QSER_RESULT_FAIL;
wangyouqiange2498f12024-01-06 17:55:36 +0800761 }
wangyouqiang80487e42024-05-24 15:06:20 +0800762
wangyouqiang80487e42024-05-24 15:06:20 +0800763 apninfo.req_type = MBTK_APN_REQ_TYPE_ADD;
764 apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto;
765 if(strlen(apn->apn_name))
766 {
767 memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name));
768 }
liuyangc3283982024-06-04 17:00:15 +0800769
wangyouqiang80487e42024-05-24 15:06:20 +0800770 if(strlen(apn->username))
771 {
772 memcpy(apninfo.user_name, apn->username, strlen(apn->username));
773 }
774 if(strlen(apn->password))
775 {
776 memcpy(apninfo.user_pass, apn->password, strlen(apn->password));
777 }
778 if(strlen(apn->apn_type))
779 {
780 memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type));
781 }
782 ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, idx);
783 if(ret != 0)
784 {
785 LOGE("[qser_data] mbtk_qser_apn_set fail.");
786 return QSER_RESULT_FAIL;
787 }
788 *profile_idx = idx[0] - 1;
wangyouqiange2498f12024-01-06 17:55:36 +0800789 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800790}
791
792int qser_apn_del(unsigned char profile_idx)
793{
liuyang0e49d9a2024-04-23 21:04:54 +0800794 int ret = 0;
795
wangyouqiange2498f12024-01-06 17:55:36 +0800796 //UNUSED(profile_idx);
797 if(qser_info_handle == NULL)
798 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800799 LOGE("[qser_data] handle is NULL.");
wangyouqiange2498f12024-01-06 17:55:36 +0800800 return QSER_RESULT_FAIL;
801 }
wangyouqiange2498f12024-01-06 17:55:36 +0800802
liuyang0e49d9a2024-04-23 21:04:54 +0800803 ret = mbtk_apn_del(qser_info_handle, profile_idx);
liuyang0e49d9a2024-04-23 21:04:54 +0800804 if(ret < 0)
805 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800806 LOGE("[qser_data] mbtk_apn_del fail!");
liuyang0e49d9a2024-04-23 21:04:54 +0800807 return QSER_RESULT_FAIL;
808 }
wangyouqiange2498f12024-01-06 17:55:36 +0800809 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800810}
811
812int qser_apn_get_list(qser_apn_info_list_s *apn_list)
813{
wangyouqiang84179c82024-01-05 15:42:55 +0800814 //UNUSED(apn_list);
b.liu5fa9e772023-11-23 18:00:55 +0800815
wangyouqiang84179c82024-01-05 15:42:55 +0800816 if(qser_info_handle == NULL)
817 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800818 LOGE("[qser_data] handle is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800819 return QSER_RESULT_FAIL;
820 }
821
822 if(apn_list == NULL)
823 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800824 LOGE("[qser_data] apn_list param is NULL.");
wangyouqiang84179c82024-01-05 15:42:55 +0800825 return QSER_RESULT_FAIL;
826 }
827
wangyouqiang80487e42024-05-24 15:06:20 +0800828 mbtk_qser_apn_info_s apns[10] = {0};
wangyouqiang84179c82024-01-05 15:42:55 +0800829 int apn_num = 10;
wangyouqiang80487e42024-05-24 15:06:20 +0800830 int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns);
wangyouqiang84179c82024-01-05 15:42:55 +0800831 if(ret != 0)
832 {
wangyouqiangc1d72d22024-04-25 10:15:58 +0800833 if(ret == MBTK_INFO_ERR_NO_APN)
834 {
835 apn_list->cnt = 0;
836 return QSER_RESULT_SUCCESS;
837 }
wangyouqiangc42b85d2024-04-24 17:05:06 +0800838 LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret);
wangyouqiang84179c82024-01-05 15:42:55 +0800839 return QSER_RESULT_FAIL;
840 }
841 else
842 {
843 if(apn_num > 0 && apn_num <= QSER_APN_MAX_LIST)
844 {
845 int i = 0;
wangyouqiange2498f12024-01-06 17:55:36 +0800846 apn_list->cnt = 0;
wangyouqiang84179c82024-01-05 15:42:55 +0800847 for(i = 0; i < apn_num; i++)
848 {
wangyouqiang8ebeafe2024-04-15 10:07:44 +0800849 if(qser_apn_info_param_convert(apns[i].cid - 1, &apn_list->apn[apn_list->cnt], &apns[i]) != 0)
wangyouqiang84179c82024-01-05 15:42:55 +0800850 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800851 LOGE("[qser_data] qser_apn_info_param_convert fail");
wangyouqiang84179c82024-01-05 15:42:55 +0800852 return QSER_RESULT_FAIL;
853 }
wangyouqiange2498f12024-01-06 17:55:36 +0800854 apn_list->cnt++;
wangyouqiang84179c82024-01-05 15:42:55 +0800855 }
wangyouqiang84179c82024-01-05 15:42:55 +0800856 }
857 else if(apn_num > QSER_APN_MAX_LIST)
858 {
wangyouqiangc42b85d2024-04-24 17:05:06 +0800859 LOGE("[qser_data] apn_num overlong");
wangyouqiang84179c82024-01-05 15:42:55 +0800860 return QSER_RESULT_FAIL;
861 }
862 else
863 {
864 apn_list->cnt = 0;
865 }
866 }
867 return QSER_RESULT_SUCCESS;
b.liu5fa9e772023-11-23 18:00:55 +0800868}
wangyouqiang84179c82024-01-05 15:42:55 +0800869/****************************API***************************************/
b.liu5fa9e772023-11-23 18:00:55 +0800870