blob: f86bd7d80a53319f80cefb44a3c2eb7be36ac368 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001
2/******************************************************************************
3*(C) Copyright 2015 Marvell International Ltd.
4* All Rights Reserved
5******************************************************************************/
6
7#ifndef __CHL_DB__
8#define __CHL_DB__
9
10#include <libubox/list.h>
11#include <stdbool.h>
12#include <cm.h>
13#include "chl.h"
14#include "chl_util.h"
15
16#define CHL_PDP_DNS4P 0x000000001
17#define CHL_PDP_DNS4S 0x000000002
18#define CHL_PDP_DNS6P 0x000000004
19#define CHL_PDP_DNS6S 0x000000008
20
21#define IPV4_STR "IP"
22#define IPV6_STR "IPv6"
23#define IPV4V6_STR "IPv4v6"
24
25#define MAX_IPV4_STR 16
26#define MAX_IPV6_STR 64
27#define MAX_APN_STR 32
28#define MAX_CLIENT_STR 16
29#define MAX_IFNAME_STR 16
30#define MAX_EXT_PARAM_LEN 32
31
32#define CHL_DFLT_MASK "255.255.255.255"
33#define CHL_IPV6_DFLT_PREF 64
34
35#define EXTP_RADIO 0x00000001
36#define EXTP_PROF 0x00000002
37#define EXTP_UNAME 0x00000004
38#define EXTP_PWD 0x00000008
39#define EXTP_AUTH 0x00000010
40
41enum chl_ipv6_state {
42 CHL_IPV6_IDLE,
43 CHL_IPV6_SEARCHING,
44 CHL_IPV6_FOUND,
45};
46
47struct extra_param {
48 char data_profile[MAX_EXT_PARAM_LEN];
49 char username[MAX_EXT_PARAM_LEN];
50 char password[MAX_EXT_PARAM_LEN];
51 unsigned int auth_type;
52 unsigned int radio_tech;
53 unsigned int flags;
54};
55
56struct reg_param {
57 char *name;
58 char *apn;
59 int ip_type;
60 bool internet;
61 struct extra_param *ext;
62};
63
64struct chl_pdp {
65 int id;
66 int rt_idx;
67 struct list_head clients;
68 struct list_head list;
69
70 char apn[MAX_APN_STR];
71 struct extra_param extra;
72
73 char ipv4[MAX_IPV4_STR];
74 char dns4p[MAX_IPV4_STR];
75 char dns4s[MAX_IPV4_STR];
76
77 char netmask[MAX_IPV4_STR];
78
79 char ipv6[MAX_IPV6_STR];
80 char dns6p[MAX_IPV6_STR];
81 char dns6s[MAX_IPV6_STR];
82 unsigned int prefix_len;
83
84 char gw[MAX_IPV6_STR];
85
86 char gb6addr[MAX_IPV6_STR];
87
88 unsigned int cid;
89 unsigned int type;
90 unsigned int dns;
91 unsigned int open_count;
92 unsigned int client_count;
93
94 bool untracked;
95 bool autoconf_pdp;
96 bool req_gw;
97
98 enum chl_nw_status nw_status;
99 enum chl_ipv6_state ipv6_state;
100 RIL_DataCallFailCause last_ril_status;
101};
102
103struct chl_client {
104 char name[MAX_CLIENT_STR];
105 int id;
106 unsigned int type;
107 bool req_open;
108 bool req_gw;
109 struct list_head list;
110 struct chl_pdp *pdp;
111 int rt_idx;
112};
113
114unsigned int pdp_match_ext_param(struct reg_param *rp, struct chl_pdp *pdp);
115struct chl_pdp *chl_db_add_pdp(struct reg_param *rp);
116struct chl_pdp *chl_db_get_pdp_by_id(int id);
117struct chl_pdp *chl_db_get_pdp_by_cid(int cid);
118struct chl_client *chl_db_add_client(struct reg_param *rp, struct chl_pdp *pdp);
119struct chl_client *chl_db_get_client_by_id(int id);
120struct chl_pdp *chl_db_get_autoconf_pdp(struct chl_pdp *except);
121struct chl_pdp *chl_db_get_pdp_by_apn(char *apn);
122bool chl_db_pdp_has_clients(struct chl_pdp *pdp);
123void chl_db_del_client(struct chl_client *cl);
124void chl_db_clear_pdp(struct chl_pdp *pdp, int nw_status);
125void chl_db_del_pdp(struct chl_pdp *pdp);
126void chl_db_status(void);
127void chl_db_take_over_pdp(struct chl_pdp *pdp);
128void chl_db_update_pdp(Ubus_Data_Call_Response *rsp, struct chl_pdp *pdp,
129 enum chl_nw_status nw_status);
130struct list_head *chl_db_get_list(void);
131char *cl_type_to_str(int type);
132char *ipv6_state_to_str(int state);
133
134#endif