b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include "gsw_nw_interface.h"
|
| 2 | #include <stdint.h>
|
| 3 | #include <string.h>
|
| 4 | #include <stdbool.h>
|
| 5 | #include <stdio.h>
|
| 6 | #include <dlfcn.h>
|
| 7 | #include <stdlib.h>
|
| 8 | #include <sys/socket.h>
|
| 9 | #include <netinet/in.h>
|
| 10 | #include <arpa/inet.h>
|
| 11 | #include <pthread.h>
|
| 12 |
|
| 13 |
|
| 14 | //mbtk include
|
| 15 | #define MBTK_APN_NAME_SIZE 150+1
|
| 16 | #define MBTK_APN_USERNAME_SIZE 127+1
|
| 17 | #define MBTK_APN_PASSWORD_SIZE 127+1
|
| 18 | #define MBTK_APN_TYPE_SIZE 127+1
|
| 19 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 20 | #define MBTK_CHANNEL_ID_1 1
|
| 21 | #define MBTK_CHANNEL_ID_2 2
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 22 |
|
| 23 | #ifndef FALSE
|
| 24 | #define FALSE (0)
|
| 25 | #endif
|
| 26 |
|
| 27 |
|
| 28 | #ifndef TRUE
|
| 29 | #define TRUE (!FALSE)
|
| 30 | #endif
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 | typedef unsigned int uint32;
|
| 36 | typedef unsigned char uint8;
|
| 37 | typedef unsigned short uint16;
|
| 38 | typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
|
| 39 | typedef unsigned long long uint64_t;
|
| 40 |
|
| 41 | typedef struct
|
| 42 | {
|
| 43 | int client_fd;
|
| 44 | pthread_t read_thread_id;
|
| 45 | int exit_fd[2];
|
| 46 | bool is_waitting;
|
| 47 | pthread_cond_t cond;
|
| 48 | pthread_mutex_t mutex;
|
| 49 |
|
| 50 | pthread_mutex_t send_mutex;
|
| 51 |
|
| 52 | // Temp response data.
|
| 53 | uint16 info_err;
|
| 54 | uint16 data_len;
|
| 55 | void *data;
|
| 56 |
|
| 57 | //mbtk wyq for server_ready_status add start
|
| 58 | char server_ready_status;
|
| 59 | //mbtk wyq for server_ready_status add end
|
| 60 |
|
| 61 | mbtk_info_callback_func net_state_cb;
|
| 62 | mbtk_info_callback_func call_state_cb;
|
| 63 | mbtk_info_callback_func sms_state_cb;
|
| 64 | mbtk_info_callback_func radio_state_cb;
|
| 65 | mbtk_info_callback_func sim_state_cb;
|
| 66 | mbtk_info_callback_func pdp_state_cb;
|
| 67 | //add signal by xr
|
| 68 | mbtk_info_callback_func signal_state_cb;
|
| 69 | } mbtk_info_handle_t;
|
| 70 |
|
| 71 | typedef enum {
|
| 72 | MBTK_IP_TYPE_IP,
|
| 73 | MBTK_IP_TYPE_IPV6,
|
| 74 | MBTK_IP_TYPE_IPV4V6,
|
| 75 | MBTK_IP_TYPE_PPP
|
| 76 | } mbtk_ip_type_enum;
|
| 77 |
|
| 78 | typedef enum {
|
| 79 | MBTK_APN_REQ_TYPE_SET = 0, // set apn req
|
| 80 | MBTK_APN_REQ_TYPE_ADD // add apn req
|
| 81 | }mbtk_apn_req_type_enum;
|
| 82 |
|
| 83 | typedef enum {
|
| 84 | MBTK_APN_AUTH_PROTO_DEFAULT = 0,
|
| 85 | MBTK_APN_AUTH_PROTO_NONE,
|
| 86 | MBTK_APN_AUTH_PROTO_PAP,
|
| 87 | MBTK_APN_AUTH_PROTO_CHAP,
|
| 88 | #if 0
|
| 89 | MBTK_APN_AUTH_PROTO_PAP_CHAP,
|
| 90 | //NOT SUPPORT
|
| 91 | #endif
|
| 92 | } mbtk_apn_auth_proto_enum;
|
| 93 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 94 | typedef enum {
|
| 95 | GSW_ID_CONVERT_TYPE_LINKID = 0,
|
| 96 | GSW_ID_CONVERT_TYPE_APNID
|
| 97 | }gsw_id_convert_type_e;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 98 |
|
| 99 | typedef struct {
|
| 100 | bool valid;
|
| 101 | uint32 IPAddr;
|
| 102 | uint32 PrimaryDNS;
|
| 103 | uint32 SecondaryDNS;
|
| 104 | uint32 GateWay;
|
| 105 | uint32 NetMask;
|
| 106 | } __attribute__((packed)) mbtk_ipv4_info_t;
|
| 107 |
|
| 108 | typedef struct {
|
| 109 | bool valid;
|
| 110 | uint32 IPV6Addr[4];
|
| 111 | uint32 PrimaryDNS[4];
|
| 112 | uint32 SecondaryDNS[4];
|
| 113 | uint32 GateWay[4];
|
| 114 | uint32 NetMask[4];
|
| 115 | } __attribute__((packed)) mbtk_ipv6_info_t;
|
| 116 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 117 | typedef struct {
|
| 118 | int cid; /*!< UMTS/CDMA profile ID. range: 0 - 7*/
|
| 119 | mbtk_ip_type_enum ip_type; /*!< Packet Data Protocol (PDP) type specifies the type of data payload
|
| 120 | exchanged over the airlink when the packet data session is
|
| 121 | established with this profile. */
|
| 122 | mbtk_apn_req_type_enum req_type; /*!< apn req type*/
|
| 123 | mbtk_apn_auth_proto_enum auth_proto; /*!< Authentication Protocol. */
|
| 124 | uint8 apn_name[MBTK_APN_NAME_SIZE]; /*!< A string parameter that is a logical name used to select the GGSN
|
| 125 | and external packet data network. */
|
| 126 | uint8 user_name[MBTK_APN_USERNAME_SIZE]; /*!< Username used during data network authentication. */
|
| 127 | uint8 user_pass[MBTK_APN_PASSWORD_SIZE]; /*!< Password to be used during data network authentication. */
|
| 128 | uint8 apn_type[MBTK_APN_TYPE_SIZE];
|
| 129 | } mbtk_qser_apn_info_s;
|
| 130 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 131 | typedef struct{
|
| 132 | uint8 cid; //cid number
|
| 133 | bool connect_state; //true: connect, false: disconnect;
|
| 134 | bool auto_urc; //urc generated by manual/auto dialing
|
| 135 | uint8 pdp_result; //The cause of the dialing result
|
| 136 | mbtk_ipv4_info_t ipv4; //ipv4 info
|
| 137 | mbtk_ipv6_info_t ipv6; //ipv6 info
|
| 138 | }mbtk_pdp_cb_info_s;
|
| 139 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 140 | static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
|
| 141 | static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);
|
| 142 | int (*mbtk_pdp_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
|
| 143 | int (*mbtk_qser_apn_set)(mbtk_info_handle_t* handle, mbtk_qser_apn_info_s *apninfo, unsigned char *cid);
|
| 144 | int (*mbtk_data_call_start)(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout);
|
| 145 | int (*mbtk_data_call_stop)(mbtk_info_handle_t* handle, int cid, int timeout);
|
| 146 | int (*mbtk_data_call_state_get)(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6);
|
| 147 | int (*mbtk_apn_set)(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name, const void *user_name, const void *user_pass, const void *auth);
|
| 148 | int (*ipv6_2_str)(const void *ipv6, void *ipv6_str);
|
| 149 | static void (*mbtk_log)(int level, const char *format, ...);
|
| 150 | static void (*mbtk_log_init)(char *path, char *tag);
|
| 151 |
|
| 152 | #ifndef LOG_ERR_LEVEL
|
| 153 | #define LOG_ERR_LEVEL 3 /* error conditions */
|
| 154 | #endif
|
| 155 | #ifndef LOG_WARN_LEVEL
|
| 156 | #define LOG_WARN_LEVEL 4 /* warning conditions */
|
| 157 | #endif
|
| 158 | #ifndef LOG_INFO_LEVEL
|
| 159 | #define LOG_INFO_LEVEL 6 /* informational */
|
| 160 | #endif
|
| 161 | #ifndef LOG_DEBUG_LEVEL
|
| 162 | #define LOG_DEBUG_LEVEL 7 /* debug-level messages */
|
| 163 | #endif
|
| 164 | #ifndef LOG_VERBOSE_LEVEL
|
| 165 | #define LOG_VERBOSE_LEVEL 8
|
| 166 | #endif
|
| 167 |
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 168 | #define GSW_DATA "[HAL][GSW_DATA]"
|
| 169 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 170 | #define LOGV(fmt, args ...) \
|
| 171 | do{ \
|
| 172 | char *file_ptr_1001 = __FILE__; \
|
| 173 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 174 | char line_1001[10] = {0}; \
|
| 175 | sprintf(line_1001, "%d", __LINE__); \
|
| 176 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 177 | if(*ptr_1001 == '/') \
|
| 178 | break; \
|
| 179 | ptr_1001--; \
|
| 180 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 181 | mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_DATA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 182 | } while(0)
|
| 183 |
|
| 184 | #define LOGI(fmt, args...) \
|
| 185 | do{ \
|
| 186 | char *file_ptr_1001 = __FILE__; \
|
| 187 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 188 | char line_1001[10] = {0}; \
|
| 189 | sprintf(line_1001, "%d", __LINE__); \
|
| 190 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 191 | if(*ptr_1001 == '/') \
|
| 192 | break; \
|
| 193 | ptr_1001--; \
|
| 194 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 195 | mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_DATA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 196 | } while(0)
|
| 197 |
|
| 198 | #define LOGD(fmt, args...) \
|
| 199 | do{ \
|
| 200 | char *file_ptr_1001 = __FILE__; \
|
| 201 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 202 | char line_1001[10] = {0}; \
|
| 203 | sprintf(line_1001, "%d", __LINE__); \
|
| 204 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 205 | if(*ptr_1001 == '/') \
|
| 206 | break; \
|
| 207 | ptr_1001--; \
|
| 208 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 209 | mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_DATA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 210 | } while(0)
|
| 211 |
|
| 212 | #define LOGW(fmt, args...) \
|
| 213 | do{ \
|
| 214 | char *file_ptr_1001 = __FILE__; \
|
| 215 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 216 | char line_1001[10] = {0}; \
|
| 217 | sprintf(line_1001, "%d", __LINE__); \
|
| 218 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 219 | if(*ptr_1001 == '/') \
|
| 220 | break; \
|
| 221 | ptr_1001--; \
|
| 222 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 223 | mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_DATA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 224 | } while(0)
|
| 225 |
|
| 226 | #define LOGE(fmt, args...) \
|
| 227 | do{ \
|
| 228 | char *file_ptr_1001 = __FILE__; \
|
| 229 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 230 | char line_1001[10] = {0}; \
|
| 231 | sprintf(line_1001, "%d", __LINE__); \
|
| 232 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 233 | if(*ptr_1001 == '/') \
|
| 234 | break; \
|
| 235 | ptr_1001--; \
|
| 236 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 237 | mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_DATA"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 238 | } while(0)
|
| 239 |
|
| 240 |
|
| 241 | //define
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 242 | #define lib_mbtk_path "/lib/libmbtk_lib.so"
|
| 243 | pthread_mutex_t data_mutex = PTHREAD_MUTEX_INITIALIZER;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 244 | static int data_init_flag = 0;
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 245 | static void *dlHandle_mbtk = NULL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 246 | static mbtk_info_handle_t* data_info_handle = NULL;
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 247 | static gsw_data_call_evt_cb_t gsw_data_call_evt_cb = NULL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 248 |
|
| 249 | Wan_State_ind_s *linkState_arr;
|
| 250 |
|
| 251 | static int Wan_State_ind_malloc(Wan_State_ind_s **linkState)
|
| 252 | {
|
| 253 | (*linkState) = (Wan_State_ind_s *)malloc(sizeof(Wan_State_ind_s));
|
| 254 | if((*linkState) == NULL)
|
| 255 | {
|
| 256 | LOGE("malloc Wan_State_ind_s fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 257 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 258 | }
|
| 259 |
|
| 260 | memset((*linkState), 0x00, sizeof(Wan_State_ind_s));
|
| 261 |
|
| 262 | (*linkState)->handle = -1;
|
| 263 | (*linkState)->cid = -1;
|
| 264 | (*linkState)->state = 0;
|
| 265 | (*linkState)->fail_cause = 0;
|
| 266 |
|
| 267 | (*linkState)->type = (char *)malloc(GSW_PDP_TYPE_MAX_LEN);
|
| 268 | memset((*linkState)->type, 0x00, GSW_PDP_TYPE_MAX_LEN);
|
| 269 |
|
| 270 | (*linkState)->ifname = (char *)malloc(GSW_IFACE_NAME_MAX_LEN);
|
| 271 | memset((*linkState)->ifname, 0x00, GSW_IFACE_NAME_MAX_LEN);
|
| 272 |
|
| 273 | (*linkState)->v4_ip = (char *)malloc(GSW_PDP_ADDR_MAX_LEN);
|
| 274 | memset((*linkState)->v4_ip, 0x00, GSW_PDP_ADDR_MAX_LEN);
|
| 275 |
|
| 276 | (*linkState)->v4_pdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 277 | memset((*linkState)->v4_pdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 278 |
|
| 279 | (*linkState)->v4_sdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 280 | memset((*linkState)->v4_sdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 281 |
|
| 282 | (*linkState)->v4_gw = (char *)malloc(GSW_GETWAYS_ADDR_MAX_LEN);
|
| 283 | memset((*linkState)->v4_gw, 0x00, GSW_GETWAYS_ADDR_MAX_LEN);
|
| 284 |
|
| 285 | (*linkState)->v6_ip = (char *)malloc(GSW_PDP_ADDR_MAX_LEN);
|
| 286 | memset((*linkState)->v6_ip, 0x00, GSW_PDP_ADDR_MAX_LEN);
|
| 287 |
|
| 288 | (*linkState)->v6_pdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 289 | memset((*linkState)->v6_pdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 290 |
|
| 291 | (*linkState)->v6_sdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 292 | memset((*linkState)->v6_sdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 293 |
|
| 294 | return GSW_HAL_SUCCESS;
|
| 295 | }
|
| 296 |
|
| 297 | static int Wan_State_ind_free(Wan_State_ind_s **linkState)
|
| 298 | {
|
| 299 | if ((*linkState) == NULL)
|
| 300 | {
|
| 301 | LOGE("(*linkState) is null\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 302 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 303 | }
|
| 304 |
|
| 305 | free((*linkState)->type);
|
| 306 | (*linkState)->type = NULL;
|
| 307 |
|
| 308 | free((*linkState)->ifname);
|
| 309 | (*linkState)->ifname = NULL;
|
| 310 |
|
| 311 | free((*linkState)->v4_ip);
|
| 312 | (*linkState)->v4_ip = NULL;
|
| 313 |
|
| 314 | free((*linkState)->v4_pdns);
|
| 315 | (*linkState)->v4_pdns = NULL;
|
| 316 |
|
| 317 | free((*linkState)->v4_sdns);
|
| 318 | (*linkState)->v4_sdns = NULL;
|
| 319 |
|
| 320 | free((*linkState)->v4_gw);
|
| 321 | (*linkState)->v4_gw = NULL;
|
| 322 |
|
| 323 | free((*linkState)->v6_ip);
|
| 324 | (*linkState)->v6_ip = NULL;
|
| 325 |
|
| 326 | free((*linkState)->v6_pdns);
|
| 327 | (*linkState)->v6_pdns = NULL;
|
| 328 |
|
| 329 | free((*linkState)->v6_sdns);
|
| 330 | (*linkState)->v6_sdns = NULL;
|
| 331 |
|
| 332 |
|
| 333 | free((*linkState));
|
| 334 | (*linkState) = NULL;
|
| 335 |
|
| 336 | return GSW_HAL_SUCCESS;
|
| 337 | }
|
| 338 |
|
| 339 | static int mbtk_data_api_import()
|
| 340 | {
|
| 341 | dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
|
| 342 | if (dlHandle_mbtk == NULL)
|
| 343 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 344 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 345 | }
|
| 346 |
|
| 347 | mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
|
| 348 | if (mbtk_log_init == NULL)
|
| 349 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 350 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 351 | }
|
| 352 |
|
| 353 | mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
|
| 354 | if (mbtk_log == NULL)
|
| 355 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 356 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 357 | }
|
| 358 |
|
| 359 | mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
|
| 360 | if (mbtk_info_handle_get == NULL)
|
| 361 | {
|
| 362 | LOGE("mbtk_info_handle_get dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 363 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 364 | }
|
| 365 |
|
| 366 | mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
|
| 367 | if (mbtk_info_handle_free == NULL)
|
| 368 | {
|
| 369 | LOGE("mbtk_info_handle_free dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 370 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 371 | }
|
| 372 |
|
| 373 | mbtk_pdp_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_pdp_state_change_cb_reg");
|
| 374 | if (mbtk_pdp_state_change_cb_reg == NULL)
|
| 375 | {
|
| 376 | LOGE("mbtk_pdp_state_change_cb_reg dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 377 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 378 | }
|
| 379 |
|
| 380 | mbtk_qser_apn_set = (int (*)(mbtk_info_handle_t* handle, mbtk_qser_apn_info_s *apninfo, unsigned char *cid))dlsym(dlHandle_mbtk, "mbtk_qser_apn_set");
|
| 381 | if (mbtk_qser_apn_set == NULL)
|
| 382 | {
|
| 383 | LOGE("mbtk_qser_apn_set dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 384 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 385 | }
|
| 386 |
|
| 387 | mbtk_data_call_start = (int (*)(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout))dlsym(dlHandle_mbtk, "mbtk_data_call_start");
|
| 388 | if (mbtk_data_call_start == NULL)
|
| 389 | {
|
| 390 | LOGE("mbtk_data_call_start dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 391 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 392 | }
|
| 393 |
|
| 394 | mbtk_data_call_stop = (int (*)(mbtk_info_handle_t* handle, int cid, int timeout))dlsym(dlHandle_mbtk, "mbtk_data_call_stop");
|
| 395 | if (mbtk_data_call_stop == NULL)
|
| 396 | {
|
| 397 | LOGE("mbtk_data_call_stop dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 398 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 399 | }
|
| 400 |
|
| 401 | mbtk_data_call_state_get = (int (*)(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6))dlsym(dlHandle_mbtk, "mbtk_data_call_state_get");
|
| 402 | if (mbtk_data_call_state_get == NULL)
|
| 403 | {
|
| 404 | LOGE("mbtk_data_call_state_get dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 405 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 406 | }
|
| 407 |
|
| 408 | mbtk_apn_set = (int (*)(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name, const void *user_name, const void *user_pass, const void *auth))dlsym(dlHandle_mbtk, "mbtk_apn_set");
|
| 409 | if (mbtk_apn_set == NULL)
|
| 410 | {
|
| 411 | LOGE("mbtk_apn_set dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 412 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 413 | }
|
| 414 |
|
| 415 | ipv6_2_str = (int (*)(const void *ipv6, void *ipv6_str))dlsym(dlHandle_mbtk, "ipv6_2_str");
|
| 416 | if (ipv6_2_str == NULL)
|
| 417 | {
|
| 418 | LOGE("ipv6_2_str dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 419 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 420 | }
|
| 421 |
|
| 422 | return GSW_HAL_SUCCESS;
|
| 423 | }
|
| 424 |
|
| 425 |
|
| 426 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 427 | static int data_call_state_query(int call_id,Wan_State_ind_s *linkState, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 428 | {
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 429 | //ifname
|
| 430 | sprintf(linkState->ifname, "ccinet%d", call_id-1);
|
| 431 |
|
| 432 | //type
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 433 | if(ipv4->valid)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 434 | {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 435 | if(ipv6->valid)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 436 | {
|
| 437 | strcpy(linkState->type, "IPV4V6");
|
| 438 | }
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 439 | else
|
| 440 | {
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 441 | strcpy(linkState->type, "IP");
|
| 442 | }
|
| 443 | }
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 444 | else if(ipv6->valid)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 445 | {
|
| 446 | strcpy(linkState->type, "IPV6");
|
| 447 | }
|
| 448 |
|
| 449 | //ip
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 450 | LOGD("ipv4.valid = %d", ipv4->valid);
|
| 451 | if(ipv4->valid)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 452 | {
|
| 453 | if(linkState==NULL)
|
| 454 | {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 455 | LOGE("linkState is NULL");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 456 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 457 | }
|
| 458 |
|
| 459 | //parse ipv4_addr,gw,dns,sdns
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 460 | if(inet_ntop(AF_INET, &(ipv4->IPAddr), linkState->v4_ip , GSW_PDP_ADDR_MAX_LEN) == NULL) {
|
| 461 | LOGE("IPv4 error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 462 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 463 | LOGD("IPv4 : %s", linkState->v4_ip);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 464 |
|
| 465 | }
|
| 466 |
|
| 467 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 468 | if(inet_ntop(AF_INET, &(ipv4->GateWay), linkState->v4_gw , GSW_PDP_ADDR_MAX_LEN) == NULL) {
|
| 469 | LOGE("GateWay error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 470 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 471 | LOGE("GateWay : %s", linkState->v4_gw);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 472 | }
|
| 473 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 474 | if(inet_ntop(AF_INET, &(ipv4->PrimaryDNS), linkState->v4_pdns , GSW_DNS_ADDR_MAX_LEN) == NULL) {
|
| 475 | LOGE("PrimaryDNS error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 476 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 477 | LOGD("PrimaryDNS : %s", linkState->v4_pdns);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 478 | }
|
| 479 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 480 | if(inet_ntop(AF_INET, &(ipv4->SecondaryDNS), linkState->v4_sdns , GSW_DNS_ADDR_MAX_LEN) == NULL) {
|
| 481 | LOGE("SecondaryDNS error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 482 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 483 | LOGD("SecondaryDNS : %s", linkState->v4_sdns);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 484 | }
|
| 485 | }
|
| 486 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 487 | LOGD("ipv6.valid = %d", ipv6->valid);
|
| 488 | if(ipv6->valid)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 489 | {
|
| 490 | //parse ipv6_addr,gw,dns,sdns
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 491 | if(ipv6_2_str(&(ipv6->IPV6Addr), linkState->v6_ip)) {
|
| 492 | LOGE("IPv6 error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 493 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 494 | LOGD("IPv6 : %s", linkState->v6_ip);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 495 | }
|
| 496 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 497 | if(ipv6_2_str(&(ipv6->PrimaryDNS), linkState->v6_pdns)) {
|
| 498 | LOGE("PrimaryDNS error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 499 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 500 | LOGD("PrimaryDNS : %s", linkState->v6_pdns);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 501 | }
|
| 502 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 503 | if(ipv6_2_str(&(ipv6->SecondaryDNS), linkState->v6_sdns)) {
|
| 504 | LOGE("SecondaryDNS error");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 505 | } else {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 506 | LOGD("SecondaryDNS : %s", linkState->v6_sdns);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 507 | }
|
| 508 | }
|
| 509 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 510 | return GSW_HAL_SUCCESS;
|
| 511 | }
|
| 512 |
|
| 513 |
|
| 514 | static void data_call_state_change_cb(const void* data, int data_len)
|
| 515 | {
|
| 516 | LOGE("data_call_state_change_cb() start\n");
|
| 517 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 518 | if(data == NULL || data_len != sizeof(mbtk_pdp_cb_info_s))
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 519 | {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 520 | LOGE("data = [NULL], data_len(%d) != sizeof(mbtk_pdp_cb_info_s)(%d)", data_len, sizeof(mbtk_pdp_cb_info_s));
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 521 | return;
|
| 522 | }
|
| 523 |
|
| 524 | int ret = -1;
|
| 525 |
|
| 526 | LOGD("Wan_State_ind_malloc start\n");
|
| 527 | ret = Wan_State_ind_malloc(&linkState_arr);
|
| 528 | if (ret != 0)
|
| 529 | {
|
| 530 | LOGE("Wan_State_ind_malloc[0] fail\n");
|
| 531 | return ;
|
| 532 | }
|
| 533 |
|
| 534 | if(linkState_arr == NULL)
|
| 535 | {
|
| 536 | LOGE("linkState_arr is NULL");
|
| 537 | return ;
|
| 538 | }
|
| 539 | else
|
| 540 | {
|
| 541 | LOGE("linkState_arr is not NULL");
|
| 542 | }
|
| 543 |
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 544 | mbtk_pdp_cb_info_s *pdp_cb_info = (mbtk_pdp_cb_info_s *)data;
|
| 545 | linkState_arr->cid = pdp_cb_info->cid;
|
| 546 | linkState_arr->handle = pdp_cb_info->cid;
|
| 547 | if(pdp_cb_info->connect_state)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 548 | {
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 549 | linkState_arr->state = 2;//connected
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 550 | data_call_state_query(pdp_cb_info->cid, linkState_arr, &(pdp_cb_info->ipv4), &(pdp_cb_info->ipv6));
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 551 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 552 | else
|
| 553 | {
|
yq.wang | f0f589c | 2025-06-11 14:59:49 +0800 | [diff] [blame] | 554 | linkState_arr->state = 0;//disconnected
|
| 555 | }
|
| 556 |
|
| 557 | if(gsw_data_call_evt_cb)
|
| 558 | {
|
| 559 | gsw_data_call_evt_cb(linkState_arr);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 560 | }
|
| 561 |
|
| 562 | ret = Wan_State_ind_free(&linkState_arr);
|
| 563 | if (ret != 0)
|
| 564 | {
|
| 565 | LOGE("Wan_State_ind_free fail\n");
|
| 566 | }
|
| 567 |
|
| 568 | }
|
| 569 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 570 | static int gsw_id_convert_to_channel_id(int gsw_id, gsw_id_convert_type_e type, int *channel_id)
|
| 571 | {
|
| 572 | if(GSW_ID_CONVERT_TYPE_LINKID == type)
|
| 573 | {
|
| 574 | switch(gsw_id)
|
| 575 | {
|
| 576 | case 0:
|
| 577 | {
|
| 578 | *channel_id = MBTK_CHANNEL_ID_2;
|
| 579 | break;
|
| 580 | }
|
| 581 | case 1:
|
| 582 | {
|
| 583 | *channel_id = MBTK_CHANNEL_ID_1;
|
| 584 | break;
|
| 585 | }
|
| 586 | default :
|
| 587 | {
|
| 588 | LOGE("[%s] gsw_id(linkid) unknown.[%d]", __func__, gsw_id);
|
| 589 | return -1;
|
| 590 | }
|
| 591 | }
|
| 592 | }
|
| 593 | else
|
| 594 | {
|
| 595 | switch(gsw_id)
|
| 596 | {
|
| 597 | case 1:
|
| 598 | case -2:
|
| 599 | {
|
| 600 | *channel_id = MBTK_CHANNEL_ID_1;
|
| 601 | break;
|
| 602 | }
|
| 603 | case -1:
|
hong.liu | 7adeb60 | 2025-06-18 17:19:01 +0800 | [diff] [blame] | 604 | case 2:
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 605 | {
|
| 606 | *channel_id = MBTK_CHANNEL_ID_2;
|
| 607 | break;
|
| 608 | }
|
| 609 | default :
|
| 610 | {
|
| 611 | LOGE("[%s] gsw_id(apnid) unknown.[%d]", __func__, gsw_id);
|
| 612 | return -1;
|
| 613 | }
|
| 614 | }
|
| 615 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 616 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 617 | return 0;
|
| 618 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 | /**
|
| 624 | * @brief datacall sdk init
|
| 625 | * @param [in] evt_cb callback function for data connection state change event
|
| 626 | * call back;
|
| 627 | * @retval 0: success
|
| 628 | * @retval other: fail
|
| 629 | */
|
| 630 | int gsw_data_call_init(gsw_data_call_evt_cb_t evt_cb)
|
| 631 | {
|
| 632 | int ret;
|
| 633 | ret = mbtk_data_api_import();
|
| 634 | if (ret != 0)
|
| 635 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 636 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 637 | }
|
| 638 |
|
| 639 | if(data_init_flag != 0 && data_info_handle != NULL)
|
| 640 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 641 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 642 | }
|
| 643 |
|
| 644 | if (ret != GSW_HAL_SUCCESS)
|
| 645 | {
|
| 646 | LOGE("mbtk_data_api_import fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 647 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 648 | }
|
| 649 |
|
| 650 | data_info_handle = (mbtk_info_handle_t*)mbtk_info_handle_get();
|
| 651 | if (data_info_handle == NULL)
|
| 652 | {
|
| 653 | LOGE("mbtk_info_handle_get fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 654 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 655 | }
|
| 656 |
|
| 657 | ret = mbtk_pdp_state_change_cb_reg((mbtk_info_handle_t*)data_info_handle, data_call_state_change_cb);
|
| 658 | if (ret != 0)
|
| 659 | {
|
| 660 | LOGE("mbtk_pdp_state_change_cb_reg fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 661 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 662 | }
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 663 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 664 | gsw_data_call_evt_cb = evt_cb;
|
| 665 | data_init_flag = 1;
|
| 666 | return GSW_HAL_SUCCESS;
|
| 667 | }
|
| 668 |
|
| 669 |
|
| 670 | /**
|
| 671 | * @brief data_call sdk deinit
|
| 672 | * @param
|
| 673 | * @retval 0: success
|
| 674 | * @retval other: fail
|
| 675 | */
|
| 676 | int gsw_data_call_deinit(void)
|
| 677 | {
|
| 678 | int ret;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 679 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 680 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 681 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 682 | }
|
| 683 |
|
| 684 | ret = mbtk_info_handle_free((mbtk_info_handle_t**)&data_info_handle);
|
| 685 | if (ret != 0)
|
| 686 | {
|
| 687 | LOGE("mbtk_info_handle_free fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 688 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 689 | }
|
| 690 |
|
| 691 | data_init_flag = 0;
|
| 692 | return GSW_HAL_SUCCESS;
|
| 693 | }
|
| 694 |
|
| 695 | /**
|
| 696 | * @brief set apn parameters for data call
|
| 697 | * @param [in/out] LinkInf apn info for pub or private datacall
|
| 698 | * inlcude apn name mcc mnc, passwork apnid type cid etc
|
| 699 | * @retval 0: success
|
| 700 | * @retval other: fail
|
| 701 | */
|
| 702 | int gsw_data_call_set_apn(Link_Info_s *LinkInf)
|
| 703 | {
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 704 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 705 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 706 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 707 | }
|
| 708 |
|
| 709 | if(LinkInf == NULL)
|
| 710 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 711 | LOGE("apn info is null");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 712 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 713 | }
|
| 714 |
|
| 715 | int ret = 0;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 716 | int cid = -1;
|
| 717 | int apnid = -1;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 718 | mbtk_ip_type_enum ip_type;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 719 | char auth_type[GSW_AUTH_TYPE_MAX_LEN + 1] = {0};
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 720 |
|
| 721 | //pdp type
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 722 | if(strcmp(LinkInf->normalProtocol,"IP") == 0)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 723 | {
|
| 724 | ip_type = MBTK_IP_TYPE_IP;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 725 | LOGE("pdp_type(protocol) is IP");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 726 | }
|
| 727 | else if(strcmp(LinkInf->normalProtocol,"IPV6") == 0)
|
| 728 | {
|
| 729 | ip_type = MBTK_IP_TYPE_IPV6;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 730 | LOGE("pdp_type(protocol) is IPV6");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 731 | }
|
| 732 | else if(strcmp(LinkInf->normalProtocol,"IPV4V6") == 0)
|
| 733 | {
|
| 734 | ip_type = MBTK_IP_TYPE_IPV4V6;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 735 | LOGE("pdp_type(protocol) is IPV4V6");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 736 | }
|
| 737 | else
|
| 738 | {
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 739 | LOGE("pdp_type(protocol) error");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 740 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 741 | }
|
| 742 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 743 | apnid = atoi(LinkInf->apnid);
|
| 744 | ret = gsw_id_convert_to_channel_id(apnid, GSW_ID_CONVERT_TYPE_APNID, &cid);
|
| 745 | if(0 != ret)
|
| 746 | {
|
| 747 | LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);
|
| 748 | return GSW_HAL_NORMAL_FAIL;
|
| 749 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 750 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 751 | //bypass solution for authparams issue
|
| 752 | #if 0
|
| 753 | memset(LinkInf->usr, 0x00, sizeof(LinkInf->usr));
|
| 754 | memset(LinkInf->pwd, 0x00, sizeof(LinkInf->pwd));
|
| 755 | memset(LinkInf->authType, 0x00, sizeof(LinkInf->authType));
|
| 756 | #endif
|
| 757 | //auth type
|
| 758 | memset(auth_type, 0x00, GSW_AUTH_TYPE_MAX_LEN + 1);
|
| 759 | if(0 == strlen(LinkInf->authType) || 0 == strcmp(LinkInf->authType, "0"))
|
| 760 | {
|
| 761 | memcpy(auth_type, "NONE", strlen("NONE"));
|
| 762 | }
|
| 763 | else if(0 == strcmp(LinkInf->authType, "1"))
|
| 764 | {
|
| 765 | memcpy(auth_type, "PAP", strlen("PAP"));
|
| 766 | }
|
| 767 | else if(0 == strcmp(LinkInf->authType, "2"))
|
| 768 | {
|
| 769 | memcpy(auth_type, "CHAP", strlen("CHAP"));
|
| 770 | }
|
| 771 | else if(0 == strcmp(LinkInf->authType, "3"))
|
| 772 | {
|
| 773 | //nonsupport
|
| 774 | LOGE("[%s] LinkInf->authType(3) nonsupport", __func__);
|
| 775 | return GSW_HAL_NORMAL_FAIL;
|
| 776 | }
|
| 777 | else
|
| 778 | {
|
| 779 | LOGE("[%s] LinkInf->authType(%s) unknown", __func__, LinkInf->authType);
|
| 780 | return GSW_HAL_NORMAL_FAIL;
|
| 781 | }
|
| 782 |
|
| 783 | ret = mbtk_apn_set(data_info_handle, cid, ip_type, LinkInf -> apn, LinkInf -> usr, LinkInf -> pwd, (const void *)auth_type);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 784 | if(ret != 0)
|
| 785 | {
|
hong.liu | 006db56 | 2025-06-05 17:19:27 +0800 | [diff] [blame] | 786 | LOGE("[%s] mbtk_apn_set fail() fail.[%d]", __func__, ret);
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 787 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 788 | }
|
| 789 |
|
| 790 | return GSW_HAL_SUCCESS;
|
| 791 | }
|
| 792 |
|
| 793 |
|
| 794 | /**
|
| 795 | * @brief set apn parameters for data call
|
| 796 | * @param [in] linkid data connetion link number
|
| 797 | * @param [in/out] LinkInf link info req: apn info for pub or private datacall
|
| 798 | * inlcude apn name mcc mnc, passwork apnid etc
|
| 799 | * resp: data call link state ipaddress type etc
|
| 800 | * @retval 0: success
|
| 801 | * @retval other: fail
|
| 802 | */
|
| 803 | int gsw_data_call_connect(int linkid, Link_Info_s *LinkInf)
|
| 804 | {
|
| 805 | int ret = -1;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 806 | int cid = -1;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 807 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 808 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 809 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 810 | }
|
| 811 |
|
| 812 | if(LinkInf == NULL)
|
| 813 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 814 | LOGE("apn info is null");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 815 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 816 | }
|
| 817 |
|
hong.liu | 006db56 | 2025-06-05 17:19:27 +0800 | [diff] [blame] | 818 | ret = gsw_data_call_set_apn(LinkInf);
|
| 819 | if(ret != GSW_HAL_SUCCESS)
|
| 820 | {
|
| 821 | LOGE("[%s] gsw_data_call_set_apn() fail", __func__);
|
| 822 | return GSW_HAL_NORMAL_FAIL;
|
| 823 | }
|
| 824 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 825 | ret = gsw_id_convert_to_channel_id(linkid, GSW_ID_CONVERT_TYPE_LINKID, &cid);
|
| 826 | if(0 != ret)
|
| 827 | {
|
| 828 | LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);
|
| 829 | return GSW_HAL_NORMAL_FAIL;
|
| 830 | }
|
| 831 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 832 | ret = mbtk_data_call_start((mbtk_info_handle_t*)data_info_handle, cid, 0, FALSE, 0);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 833 | if(ret != 0)
|
| 834 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 835 | LOGE("[%s] mbtk_data_call_start fail.[%d]", __func__, ret);
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 836 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 837 | }
|
| 838 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 839 | LinkInf->handle = cid;
|
| 840 | memset(LinkInf->apnid, 0x00, sizeof(LinkInf->apnid));
|
| 841 | sprintf(LinkInf->apnid, "%d", cid);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 842 |
|
| 843 | return GSW_HAL_SUCCESS;
|
| 844 | }
|
| 845 |
|
| 846 |
|
| 847 | /**
|
| 848 | * @brief set apn parameters for data call
|
| 849 | * @param [in] linkid
|
| 850 | * @param [in/out] LinkInf link info req: apn info for pub or private datacall
|
| 851 | * inlcude apn name mcc mnc, passwork apnid etc
|
| 852 | * resp: data call link state ipaddress type etc
|
| 853 | * @retval 0: success
|
| 854 | * @retval other: fail
|
| 855 | */
|
| 856 | int gsw_data_call_disconnect(int linkid, Link_Info_s *LinkInf)
|
| 857 | {
|
| 858 | int ret = -1;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 859 | int cid = -1;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 860 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 861 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 862 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 863 | }
|
| 864 |
|
| 865 | if(LinkInf == NULL)
|
| 866 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 867 | LOGE("apn info is null");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 868 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 869 | }
|
| 870 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 871 | ret = gsw_id_convert_to_channel_id(linkid, GSW_ID_CONVERT_TYPE_LINKID, &cid);
|
| 872 | if(0 != ret)
|
| 873 | {
|
| 874 | LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);
|
| 875 | return GSW_HAL_NORMAL_FAIL;
|
| 876 | }
|
| 877 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 878 | ret = mbtk_data_call_stop((mbtk_info_handle_t*)data_info_handle, cid, 15);
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 879 | if(ret != 0)
|
| 880 | {
|
| 881 | LOGE("[%s] mbtk_data_call_stop() fail.[%d]",__func__, ret);
|
| 882 | return GSW_HAL_NORMAL_FAIL;
|
| 883 | }
|
| 884 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 885 | return GSW_HAL_SUCCESS;
|
| 886 | }
|
| 887 |
|
| 888 |
|
| 889 | /*
|
| 890 | * @brief get mobile operator name
|
| 891 | @param [in] linkid apn id
|
| 892 | @param [out] data_pkt obtian actual data call network card data traffic
|
| 893 | @retval 0: success
|
| 894 | @retval 0: other: fail
|
| 895 | */
|
| 896 | int gsw_get_data_call_pkt_stats(int linkid, gsw_data_pkt_stats *data_pkt)
|
| 897 | {
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame] | 898 |
|
| 899 | if(data_init_flag == 0 || data_info_handle == NULL)
|
| 900 | {
|
| 901 | return GSW_HAL_NORMAL_FAIL;
|
| 902 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 903 | char temp_linkid[12] = {0};
|
| 904 | char interface_name[32] = {0};
|
| 905 | sprintf(temp_linkid,"%d",linkid+1);
|
| 906 | snprintf(interface_name, sizeof(interface_name),"ccinet%s", temp_linkid);
|
| 907 |
|
| 908 | uint64_t tx_bytes = 0;
|
| 909 | uint64_t tx_packets = 0;
|
| 910 | uint64_t tx_dropped = 0;
|
| 911 | uint64_t rx_bytes = 0;
|
| 912 | uint64_t rx_packets = 0;
|
| 913 | uint64_t rx_dropped = 0;
|
| 914 | char command[128] = {0};
|
| 915 | char* temp;
|
| 916 | char buffer[512] = {0};
|
| 917 |
|
| 918 | snprintf(command, sizeof(command), "ifconfig %s", interface_name);
|
| 919 |
|
| 920 | FILE *fp = popen(command, "r");
|
| 921 | if(fp == NULL)
|
| 922 | {
|
| 923 | LOGE("popen fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 924 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 925 | }
|
| 926 |
|
| 927 | //read line by line
|
| 928 | while (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
| 929 | // TX bytes
|
| 930 | if (strstr(buffer, "TX bytes")) {
|
| 931 | temp = strstr(buffer, "TX bytes");
|
| 932 | sscanf(temp, " TX bytes:%llu ", &tx_bytes);
|
| 933 | }
|
| 934 | // TX packets
|
| 935 | if (strstr(buffer, "TX packets")) {
|
| 936 | sscanf(buffer, " TX packets:%llu ", &tx_packets);
|
| 937 | sscanf(buffer, " TX packets:%*u errors:%*u dropped:%llu", &tx_dropped);
|
| 938 | }
|
| 939 | // RX bytes
|
| 940 | if (strstr(buffer, "RX bytes")) {
|
| 941 | LOGE("RX bytes %s\n",strstr(buffer, "RX bytes"));
|
| 942 | sscanf(buffer, " RX bytes:%llu ", &rx_bytes);
|
| 943 | }
|
| 944 | // RX packets
|
| 945 | if (strstr(buffer, "RX packets")) {
|
| 946 | sscanf(buffer, " RX packets:%llu ", &rx_packets);
|
| 947 | sscanf(buffer, " RX packets:%*u errors:%*u dropped:%llu", &rx_dropped);
|
| 948 | }
|
| 949 | }
|
| 950 |
|
| 951 | // 关闭管道
|
| 952 | pclose(fp);
|
| 953 |
|
| 954 | // 输出结果
|
| 955 | LOGE("TX Bytes: %llu\n", tx_bytes);
|
| 956 | LOGE("TX Packets: %llu\n", tx_packets);
|
| 957 | LOGE("TX Dropped: %llu\n", tx_dropped);
|
| 958 | LOGE("RX Bytes: %llu\n", rx_bytes);
|
| 959 | LOGE("RX Packets: %llu\n", rx_packets);
|
| 960 | LOGE("RX Dropped: %llu\n", rx_dropped);
|
| 961 |
|
| 962 | if(data_pkt == NULL)
|
| 963 | {
|
| 964 | LOGE("data_pkt is null\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 965 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 966 | }
|
| 967 |
|
| 968 | else
|
| 969 | {
|
| 970 | data_pkt->tx_bytes = tx_bytes;
|
| 971 | data_pkt->tx_pkts = tx_packets;
|
| 972 | data_pkt->tx_dropped_pkts = tx_dropped;
|
| 973 | data_pkt->rx_bytes = rx_bytes;
|
| 974 | data_pkt->rx_pkts = rx_packets;
|
| 975 | data_pkt->rx_dropped_pkts = rx_dropped;
|
| 976 | }
|
| 977 |
|
| 978 | return GSW_HAL_SUCCESS;
|
| 979 |
|
| 980 | }
|