blob: 978516baa93af9d1dd50b5141d59435d987ed847 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file ql_data_call.h
4 @brief Data service API
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 Copyright (c) 2018 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
10 Quectel Wireless Solution Proprietary and Confidential.
11-------------------------------------------------------------------------------------------------*/
12
13/*-------------------------------------------------------------------------------------------------
14 EDIT HISTORY
15 This section contains comments describing changes made to the file.
16 Notice that changes are listed in reverse chronological order.
17 $Header: $
18 when who what, where, why
19 -------- --- ----------------------------------------------------------
20 20181024 tyler.kuang Created .
21-------------------------------------------------------------------------------------------------*/
22
23#ifndef __QL_DATA_CALL_H__
24#define __QL_DATA_CALL_H__
25#include <sys/socket.h>
26#include <netinet/in.h>
27#include <arpa/inet.h>
28#include "ql_net_common.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34typedef void ql_data_call_param_t;
35
36typedef struct
37{
38 int call_id;
39 char call_name[QL_NET_MAX_NAME_LEN + 1];
40 QL_NET_IP_VER_E ip_ver;
41 QL_NET_DATA_CALL_STATUS_E call_status;
42 char device[QL_NET_MAX_NAME_LEN + 1];
43 uint8_t has_addr; /**< Valid when data call state is connected*/
44 ql_net_addr_t addr;
45 uint8_t has_addr6; /**< Valid when data call state is connected*/
46 ql_net_addr6_t addr6;
47 int call_end_reason_type; /**< Last data call disconnect reason type */
48 int call_end_reason_code; /**< Last data call disconnect reason code */
49} ql_data_call_status_t;
50
51typedef struct
52{
53 int call_id;
54 char call_name[QL_NET_MAX_NAME_LEN + 1];
55} ql_data_call_item_t;
56
57typedef struct
58{
59 QL_NET_IP_VER_E ip_ver;
60 QL_NET_AUTH_PREF_E auth_pref;
61 char apn_name[QL_NET_MAX_APN_NAME_LEN + 1];
62 char username[QL_NET_MAX_APN_USERNAME_LEN + 1];
63 char password[QL_NET_MAX_APN_PASSWORD_LEN + 1];
64} ql_data_call_apn_config_t;
65
66typedef struct
67{
68 uint64_t tx_pkts;
69 uint64_t tx_bytes;
70 uint64_t tx_dropped_pkts;
71 uint64_t rx_pkts;
72 uint64_t rx_bytes;
73 uint64_t rx_dropped_pkts;
74}ql_data_call_pkt_stats_t;
75
76typedef void (*ql_data_call_status_ind_cb_f)(int call_id,
77 QL_NET_DATA_CALL_STATUS_E pre_call_status,
78 ql_data_call_status_t *p_msg);
79
80typedef void (*ql_data_call_service_error_cb_f)(int error);
81
82
83/*-----------------------------------------------------------------------------------------------*/
84/**
85 @brief Initialize the data call service
86 @return
87 QL_ERR_OK - successful
88 QL_ERR_INVALID_ARG - as defined
89 QL_ERR_UNKNOWN - unknown error, failed to connect to service
90 QL_ERR_SERVICE_NOT_READY - service is not ready, need to retry
91 Other - error code defined by ql_type.h
92 */
93/*-----------------------------------------------------------------------------------------------*/
94int ql_data_call_init(void);
95
96/*-----------------------------------------------------------------------------------------------*/
97/**
98 @brief Create a data call instance
99 @param[in] call_id The unique identifier of the data call instance, specified by the user
100 @param[in] call_name Friendly data call name, specified by the user
101 @param[in] is_background Whether the data call status is maintained by the data call service daemon.
102 If it is 0, the data call instance will be deleted after the data call process exits.
103 @return
104 QL_ERR_OK - successful
105 QL_ERR_INVALID_ARG - as defined
106 QL_ERR_UNKNOWN - unknown error, failed to connect to service
107 QL_ERR_SERVICE_NOT_READY - service is not ready, need to retry
108 Other - error code defined by ql_type.h
109 */
110/*-----------------------------------------------------------------------------------------------*/
111int ql_data_call_create(int call_id, const char *call_name, int is_background);
112
113/*-----------------------------------------------------------------------------------------------*/
114/**
115 @brief Alloc for a data call configuration instance
116 @return
117 NULL - Not enough memory
118 Other - successful
119 */
120/*-----------------------------------------------------------------------------------------------*/
121ql_data_call_param_t *ql_data_call_param_alloc(void);
122
123/*-----------------------------------------------------------------------------------------------*/
124/**
125 @brief Initialize the data call configuration instance
126 @param[in] param Point to the data call configuration instance
127 @return
128 QL_ERR_OK - Successful
129 QL_ERR_INVALID_ARG - Invalid arguments
130 */
131/*-----------------------------------------------------------------------------------------------*/
132int ql_data_call_param_init(ql_data_call_param_t *param);
133
134/*-----------------------------------------------------------------------------------------------*/
135/**
136 @brief Release the data call configuration instance
137 @param[in] param Point to the data call configuration instance
138 @return
139 QL_ERR_OK - Successful
140 QL_ERR_INVALID_ARG - Invalid arguments
141 */
142/*-----------------------------------------------------------------------------------------------*/
143int ql_data_call_param_free(ql_data_call_param_t *param);
144
145
146/*-----------------------------------------------------------------------------------------------*/
147/**
148 @brief Bind APN ID, range:1-16
149 @param[in] param Point to the data call configuration instance
150 @param[in] apn_id APN ID, range:1-16
151 @return
152 QL_ERR_OK - Successful
153 QL_ERR_INVALID_ARG - Invalid arguments
154 */
155/*-----------------------------------------------------------------------------------------------*/
156int ql_data_call_param_set_apn_id(ql_data_call_param_t *param, int apn_id);
157
158/*-----------------------------------------------------------------------------------------------*/
159/**
160 @brief Get APN name from configuration instance
161 @param[in] param Point to the data call configuration instance
162 @param[out] buf APN ID
163 @return
164 QL_ERR_OK - Successful
165 QL_ERR_INVALID_ARG - Invalid arguments
166 */
167/*-----------------------------------------------------------------------------------------------*/
168int ql_data_call_param_get_apn_id(ql_data_call_param_t *param, int *apn_id);
169
170
171/*-----------------------------------------------------------------------------------------------*/
172/**
173 @brief Configure APN name
174 @param[in] param Point to the data call configuration instance
175 @param[in] apn_name APN name
176 @return
177 QL_ERR_OK - Successful
178 QL_ERR_INVALID_ARG - Invalid arguments
179 */
180/*-----------------------------------------------------------------------------------------------*/
181int ql_data_call_param_set_apn_name(ql_data_call_param_t *param, const char *apn_name);
182
183/*-----------------------------------------------------------------------------------------------*/
184/**
185 @brief Get APN name from configuration instance
186 @param[in] param Point to the data call configuration instance
187 @param[out] buf APN name buffer
188 @param[in] buf_len APN name buffer size
189 @return
190 QL_ERR_OK - Successful
191 QL_ERR_INVALID_ARG - Invalid arguments
192 */
193/*-----------------------------------------------------------------------------------------------*/
194int ql_data_call_param_get_apn_name(ql_data_call_param_t *param, char *buf, int buf_len);
195
196/*-----------------------------------------------------------------------------------------------*/
197/**
198 @brief Configure APN user name
199 @param[in] param Point to the data call configuration instance
200 @param[in] user_name APN user name
201 @return
202 QL_ERR_OK - Successful
203 QL_ERR_INVALID_ARG - Invalid arguments
204 */
205/*-----------------------------------------------------------------------------------------------*/
206int ql_data_call_param_set_user_name(ql_data_call_param_t *param, const char *user_name);
207
208/*-----------------------------------------------------------------------------------------------*/
209/**
210 @brief Get APN user name from configuration instance
211 @param[in] param Point to the data call configuration instance
212 @param[out] buf APN user name buffer
213 @param[in] buf_len APN user name buffer size
214 @return
215 QL_ERR_OK - Successful
216 QL_ERR_INVALID_ARG - Invalid arguments
217 */
218/*-----------------------------------------------------------------------------------------------*/
219int ql_data_call_param_get_user_name(ql_data_call_param_t *param, char *buf, int buf_len);
220
221/*-----------------------------------------------------------------------------------------------*/
222/**
223 @brief Configure APN user password
224 @param[in] param Point to the data call configuration instance
225 @param[in] user_password APN user password
226 @return
227 QL_ERR_OK - Not enough memory
228 QL_ERR_INVALID_ARG - Invalid arguments
229 */
230/*-----------------------------------------------------------------------------------------------*/
231int ql_data_call_param_set_user_password(ql_data_call_param_t *param, const char *user_password);
232
233/*-----------------------------------------------------------------------------------------------*/
234/**
235 @brief Get APN user password from configuration instance
236 @param[in] param Point to the data call configuration instance
237 @param[out] buf APN user password buffer
238 @param[in] buf_len APN user password buffer size
239 @return
240 QL_ERR_OK - Not enough memory
241 QL_ERR_INVALID_ARG - Invalid arguments
242 */
243/*-----------------------------------------------------------------------------------------------*/
244int ql_data_call_param_get_user_password(ql_data_call_param_t *param, char *buf, int buf_len);
245
246
247/*-----------------------------------------------------------------------------------------------*/
248/**
249 @brief Configure the data call authentication method
250 @param[in] param Point to the data call configuration instance
251 @param[in] auth_pref Defined by QL_DATA_CALL_AUTH_PREF_E
252 @return
253 QL_ERR_OK - Successful
254 QL_ERR_INVALID_ARG - Invalid arguments
255 */
256/*-----------------------------------------------------------------------------------------------*/
257int ql_data_call_param_set_auth_pref(ql_data_call_param_t *param, int auth_pref);
258
259/*-----------------------------------------------------------------------------------------------*/
260/**
261 @brief Configure the data call authentication method
262 @param[in] param Point to the data call configuration instance
263 @param[out] p_data Store return value
264 @return
265 QL_ERR_OK - Successful
266 QL_ERR_INVALID_ARG - Invalid arguments
267 */
268/*-----------------------------------------------------------------------------------------------*/
269int ql_data_call_param_get_auth_pref(ql_data_call_param_t *param, int *p_data);
270
271
272/*-----------------------------------------------------------------------------------------------*/
273/**
274 @brief Configure the data call IP version
275 @param[in] param Point to the data call configuration instance
276 @param[in] ip_ver Defined by QL_NET_IP_VER_E
277 @return
278 QL_ERR_OK - Successful
279 QL_ERR_INVALID_ARG - Invalid arguments
280 */
281/*-----------------------------------------------------------------------------------------------*/
282int ql_data_call_param_set_ip_version(ql_data_call_param_t *param, int ip_ver);
283
284/*-----------------------------------------------------------------------------------------------*/
285/**
286 @brief Get IP version from configuration instance
287 @param[in] param Point to the data call configuration instance
288 @param[out] p_ver Store return value
289 @return
290 QL_ERR_OK - Successful
291 QL_ERR_INVALID_ARG - Invalid arguments
292 */
293/*-----------------------------------------------------------------------------------------------*/
294int ql_data_call_param_get_ip_version(ql_data_call_param_t *param, int *p_ver);
295
296/*-----------------------------------------------------------------------------------------------*/
297/**
298 @brief Configure the data call auto reconnection mode
299 @param[in] param Point to the data call configuration instance
300 @param[in] mode Defined by QL_NET_DATA_CALL_RECONNECT_MODE_E
301 @return
302 QL_ERR_OK - Successful
303 QL_ERR_INVALID_ARG - Invalid arguments
304 */
305/*-----------------------------------------------------------------------------------------------*/
306int ql_data_call_param_set_reconnect_mode(ql_data_call_param_t *param, int reconnect_mode);
307
308/*-----------------------------------------------------------------------------------------------*/
309/**
310 @brief Get auto reconnection mode from configuration instance
311 @param[in] param Point to the data call configuration instance
312 @param[out] p_mode Store return value
313 @return
314 QL_ERR_OK - Successful
315 QL_ERR_INVALID_ARG - Invalid arguments
316 */
317/*-----------------------------------------------------------------------------------------------*/
318int ql_data_call_param_get_reconnect_mode(ql_data_call_param_t *param, int *p_mode);
319
320/*-----------------------------------------------------------------------------------------------*/
321/**
322 @brief Configure the data call auto reconnection interval
323 @param[in] param Point to the data call configuration instance
324 @param[in] time_list Interval time list in ms
325 @param[in] num Number of time list
326 @return
327 QL_ERR_OK - Successful
328 QL_ERR_INVALID_ARG - Invalid arguments
329 */
330/*-----------------------------------------------------------------------------------------------*/
331int ql_data_call_param_set_reconnect_interval(ql_data_call_param_t *param, int *time_list, int num);
332
333/*-----------------------------------------------------------------------------------------------*/
334/**
335 @brief Get auto reconnection interval from configuration instance
336 @param[in] param Point to the data call configuration instance
337 @param[out] time_list Store return value
338 @param[in,out] p_num
339 @return
340 QL_ERR_OK - Successful
341 QL_ERR_INVALID_ARG - Invalid arguments
342 */
343/*-----------------------------------------------------------------------------------------------*/
344int ql_data_call_param_get_reconnect_interval(ql_data_call_param_t *param, int *time_list, int *p_num);
345
346/*-----------------------------------------------------------------------------------------------*/
347/**
348 @brief Configure the specified data call instance
349 @param[in] call_id Specify a data call instance
350 @param[in] param Point to the data call configuration instance
351 @return
352 QL_ERR_OK - Successful
353 QL_ERR_INVALID_ARG - Invalid arguments
354 */
355/*-----------------------------------------------------------------------------------------------*/
356int ql_data_call_config(int call_id, ql_data_call_param_t *param);
357
358/*-----------------------------------------------------------------------------------------------*/
359/**
360 @brief Get the specified data call configuration instance
361 @param[in] call_id Specify a data call instance
362 @param[in] param Point to the data call configuration instance
363 @return
364 QL_ERR_OK - Successful
365 QL_ERR_INVALID_ARG - Invalid arguments
366 */
367/*-----------------------------------------------------------------------------------------------*/
368int ql_data_call_get_config(int call_id, ql_data_call_param_t *param);
369
370/*-----------------------------------------------------------------------------------------------*/
371/**
372 @brief Start data call
373 @param[in] call_id Specify a data call instance
374 @return
375 QL_ERR_OK - successful
376 QL_ERR_NOT_INIT - uninitialized
377 QL_ERR_SERVICE_NOT_READY - service is not ready
378 QL_ERR_INVALID_ARG - Invalid arguments
379 Other - error code defined by ql_type.h
380 */
381/*-----------------------------------------------------------------------------------------------*/
382int ql_data_call_start(int call_id);
383
384/*-----------------------------------------------------------------------------------------------*/
385/**
386 @brief Stop data call
387 @param[in] call_id Specify a data call instance
388 @return
389 QL_ERR_OK - successful
390 QL_ERR_NOT_INIT - uninitialized
391 QL_ERR_SERVICE_NOT_READY - service is not ready
392 QL_ERR_INVALID_ARG - Invalid arguments
393 Other - error code defined by ql_type.h
394 */
395/*-----------------------------------------------------------------------------------------------*/
396int ql_data_call_stop(int call_id);
397
398/*-----------------------------------------------------------------------------------------------*/
399/**
400 @brief Delete a data call instance
401 @param[in] call_id Specify a data call instance
402 @return
403 QL_ERR_OK - successful
404 QL_ERR_NOT_INIT - uninitialized
405 QL_ERR_SERVICE_NOT_READY - service is not ready
406 QL_ERR_INVALID_ARG - Invalid arguments
407 Other - error code defined by ql_type.h
408 */
409/*-----------------------------------------------------------------------------------------------*/
410int ql_data_call_delete(int call_id);
411
412/*-----------------------------------------------------------------------------------------------*/
413/**
414 @brief Get the current data call instance list
415 @param[out] list Data call instance array
416 @param[in,out] list_len, in-> Data call instance array size, out->current data call instance number
417 @return
418 QL_ERR_OK - successful
419 QL_ERR_NOT_INIT - uninitialized
420 QL_ERR_SERVICE_NOT_READY - service is not ready
421 QL_ERR_INVALID_ARG - Invalid arguments
422 Other - error code defined by ql_type.h
423 */
424/*-----------------------------------------------------------------------------------------------*/
425int ql_data_call_get_list(ql_data_call_item_t *list, int *list_len);
426
427/*-----------------------------------------------------------------------------------------------*/
428/**
429 @brief Get the data call status
430 @param[in] call_id Specify a data call instance
431 @param[out] p_sta Point to status instance
432 @return
433 QL_ERR_OK - successful
434 QL_ERR_NOT_INIT - uninitialized
435 QL_ERR_SERVICE_NOT_READY - service is not ready
436 QL_ERR_INVALID_ARG - Invalid arguments
437 Other - error code defined by ql_type.h
438 */
439/*-----------------------------------------------------------------------------------------------*/
440int ql_data_call_get_status(int call_id, ql_data_call_status_t *p_sta);
441
442/*-----------------------------------------------------------------------------------------------*/
443/**
444 @brief Register data call status change event
445 @param[in] cb
446 @return
447 QL_ERR_OK - successful
448 QL_ERR_NOT_INIT - uninitialized
449 QL_ERR_SERVICE_NOT_READY - service is not ready
450 QL_ERR_INVALID_ARG - Invalid arguments
451 Other - error code defined by ql_type.h
452 */
453/*-----------------------------------------------------------------------------------------------*/
454int ql_data_call_set_status_ind_cb(ql_data_call_status_ind_cb_f cb);
455
456/*-----------------------------------------------------------------------------------------------*/
457/**
458 @brief Set APN related configuration.If the apn does not exist, it is automatically created.
459 @param[in] apn_id APN ID, range:1-16
460 @param[in] p_info APN configuration
461 @return
462 QL_ERR_OK - successful
463 QL_ERR_NOT_INIT - uninitialized
464 QL_ERR_SERVICE_NOT_READY - service is not ready
465 QL_ERR_INVALID_ARG - Invalid arguments
466 Other - error code defined by ql_type.h
467 */
468/*-----------------------------------------------------------------------------------------------*/
469int ql_data_call_set_apn_config(int apn_id, ql_data_call_apn_config_t *p_info);
470
471/*-----------------------------------------------------------------------------------------------*/
472/**
473 @brief Set APN related configuration. If the apn does not exist, it is automatically created and
474 the default parameters are set.
475 @param[in] apn_id APN ID, range:1-16
476 @param[out] p_info APN configuration
477 @return
478 QL_ERR_OK - successful
479 QL_ERR_NOT_INIT - uninitialized
480 QL_ERR_SERVICE_NOT_READY - service is not ready
481 QL_ERR_INVALID_ARG - Invalid arguments
482 Other - error code defined by ql_type.h
483 */
484/*-----------------------------------------------------------------------------------------------*/
485int ql_data_call_get_apn_config(int apn_id, ql_data_call_apn_config_t *p_info);
486
487/*-----------------------------------------------------------------------------------------------*/
488/**
489 @brief Set APN related configuration,APN ID:1
490 @param[in] p_info APN configuration
491 @return
492 QL_ERR_OK - successful
493 QL_ERR_NOT_INIT - uninitialized
494 QL_ERR_SERVICE_NOT_READY - service is not ready
495 QL_ERR_INVALID_ARG - Invalid arguments
496 Other - error code defined by ql_type.h
497 */
498/*-----------------------------------------------------------------------------------------------*/
499int ql_data_call_set_attach_apn_config(ql_data_call_apn_config_t *p_info);
500
501/*-----------------------------------------------------------------------------------------------*/
502/**
503 @brief Registration server error callback. Currently, only if the server exits abnormally,
504 the callback function will be executed, and the error code is QL_ERR_ABORTED;
505 @param[in] cb Callback function
506 @return
507 QL_ERR_OK - successful
508 Other - error code defined by ql_type.h
509 */
510/*-----------------------------------------------------------------------------------------------*/
511int ql_data_call_set_service_error_cb(ql_data_call_service_error_cb_f cb);
512
513/*-----------------------------------------------------------------------------------------------*/
514/**
515 @brief Deinitialize the data call service
516 @return
517 QL_ERR_OK - successful
518 Other - error code defined by ql_type.h
519 */
520/*-----------------------------------------------------------------------------------------------*/
521int ql_data_call_deinit(void);
522
523#ifdef __cplusplus
524}
525#endif
526
527#endif
528