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 |
|
| 131 | static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
|
| 132 | static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle);
|
| 133 | int (*mbtk_pdp_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
|
| 134 | int (*mbtk_qser_apn_set)(mbtk_info_handle_t* handle, mbtk_qser_apn_info_s *apninfo, unsigned char *cid);
|
| 135 | int (*mbtk_data_call_start)(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout);
|
| 136 | int (*mbtk_data_call_stop)(mbtk_info_handle_t* handle, int cid, int timeout);
|
| 137 | int (*mbtk_data_call_state_get)(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6);
|
| 138 | 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);
|
| 139 | int (*ipv6_2_str)(const void *ipv6, void *ipv6_str);
|
| 140 | static void (*mbtk_log)(int level, const char *format, ...);
|
| 141 | static void (*mbtk_log_init)(char *path, char *tag);
|
| 142 |
|
| 143 | #ifndef LOG_ERR_LEVEL
|
| 144 | #define LOG_ERR_LEVEL 3 /* error conditions */
|
| 145 | #endif
|
| 146 | #ifndef LOG_WARN_LEVEL
|
| 147 | #define LOG_WARN_LEVEL 4 /* warning conditions */
|
| 148 | #endif
|
| 149 | #ifndef LOG_INFO_LEVEL
|
| 150 | #define LOG_INFO_LEVEL 6 /* informational */
|
| 151 | #endif
|
| 152 | #ifndef LOG_DEBUG_LEVEL
|
| 153 | #define LOG_DEBUG_LEVEL 7 /* debug-level messages */
|
| 154 | #endif
|
| 155 | #ifndef LOG_VERBOSE_LEVEL
|
| 156 | #define LOG_VERBOSE_LEVEL 8
|
| 157 | #endif
|
| 158 |
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 159 | #define GSW_DATA "[HAL][GSW_DATA]"
|
| 160 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 161 | #define LOGV(fmt, args ...) \
|
| 162 | do{ \
|
| 163 | char *file_ptr_1001 = __FILE__; \
|
| 164 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 165 | char line_1001[10] = {0}; \
|
| 166 | sprintf(line_1001, "%d", __LINE__); \
|
| 167 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 168 | if(*ptr_1001 == '/') \
|
| 169 | break; \
|
| 170 | ptr_1001--; \
|
| 171 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 172 | 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] | 173 | } while(0)
|
| 174 |
|
| 175 | #define LOGI(fmt, args...) \
|
| 176 | do{ \
|
| 177 | char *file_ptr_1001 = __FILE__; \
|
| 178 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 179 | char line_1001[10] = {0}; \
|
| 180 | sprintf(line_1001, "%d", __LINE__); \
|
| 181 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 182 | if(*ptr_1001 == '/') \
|
| 183 | break; \
|
| 184 | ptr_1001--; \
|
| 185 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 186 | 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] | 187 | } while(0)
|
| 188 |
|
| 189 | #define LOGD(fmt, args...) \
|
| 190 | do{ \
|
| 191 | char *file_ptr_1001 = __FILE__; \
|
| 192 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 193 | char line_1001[10] = {0}; \
|
| 194 | sprintf(line_1001, "%d", __LINE__); \
|
| 195 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 196 | if(*ptr_1001 == '/') \
|
| 197 | break; \
|
| 198 | ptr_1001--; \
|
| 199 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 200 | 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] | 201 | } while(0)
|
| 202 |
|
| 203 | #define LOGW(fmt, args...) \
|
| 204 | do{ \
|
| 205 | char *file_ptr_1001 = __FILE__; \
|
| 206 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 207 | char line_1001[10] = {0}; \
|
| 208 | sprintf(line_1001, "%d", __LINE__); \
|
| 209 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 210 | if(*ptr_1001 == '/') \
|
| 211 | break; \
|
| 212 | ptr_1001--; \
|
| 213 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 214 | 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] | 215 | } while(0)
|
| 216 |
|
| 217 | #define LOGE(fmt, args...) \
|
| 218 | do{ \
|
| 219 | char *file_ptr_1001 = __FILE__; \
|
| 220 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 221 | char line_1001[10] = {0}; \
|
| 222 | sprintf(line_1001, "%d", __LINE__); \
|
| 223 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 224 | if(*ptr_1001 == '/') \
|
| 225 | break; \
|
| 226 | ptr_1001--; \
|
| 227 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 228 | 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] | 229 | } while(0)
|
| 230 |
|
| 231 |
|
| 232 | //define
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 233 | #define lib_mbtk_path "/lib/libmbtk_lib.so"
|
| 234 | pthread_mutex_t data_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 235 | static int data_call_lock = 0;
|
| 236 | static int data_init_flag = 0;
|
| 237 | static void *dlHandle_mbtk;
|
| 238 | static mbtk_info_handle_t* data_info_handle = NULL;
|
| 239 | static gsw_data_call_evt_cb_t gsw_data_call_evt_cb;
|
| 240 |
|
| 241 | Wan_State_ind_s *linkState_arr;
|
| 242 |
|
| 243 | static int Wan_State_ind_malloc(Wan_State_ind_s **linkState)
|
| 244 | {
|
| 245 | (*linkState) = (Wan_State_ind_s *)malloc(sizeof(Wan_State_ind_s));
|
| 246 | if((*linkState) == NULL)
|
| 247 | {
|
| 248 | LOGE("malloc Wan_State_ind_s fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 249 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 250 | }
|
| 251 |
|
| 252 | memset((*linkState), 0x00, sizeof(Wan_State_ind_s));
|
| 253 |
|
| 254 | (*linkState)->handle = -1;
|
| 255 | (*linkState)->cid = -1;
|
| 256 | (*linkState)->state = 0;
|
| 257 | (*linkState)->fail_cause = 0;
|
| 258 |
|
| 259 | (*linkState)->type = (char *)malloc(GSW_PDP_TYPE_MAX_LEN);
|
| 260 | memset((*linkState)->type, 0x00, GSW_PDP_TYPE_MAX_LEN);
|
| 261 |
|
| 262 | (*linkState)->ifname = (char *)malloc(GSW_IFACE_NAME_MAX_LEN);
|
| 263 | memset((*linkState)->ifname, 0x00, GSW_IFACE_NAME_MAX_LEN);
|
| 264 |
|
| 265 | (*linkState)->v4_ip = (char *)malloc(GSW_PDP_ADDR_MAX_LEN);
|
| 266 | memset((*linkState)->v4_ip, 0x00, GSW_PDP_ADDR_MAX_LEN);
|
| 267 |
|
| 268 | (*linkState)->v4_pdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 269 | memset((*linkState)->v4_pdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 270 |
|
| 271 | (*linkState)->v4_sdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 272 | memset((*linkState)->v4_sdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 273 |
|
| 274 | (*linkState)->v4_gw = (char *)malloc(GSW_GETWAYS_ADDR_MAX_LEN);
|
| 275 | memset((*linkState)->v4_gw, 0x00, GSW_GETWAYS_ADDR_MAX_LEN);
|
| 276 |
|
| 277 | (*linkState)->v6_ip = (char *)malloc(GSW_PDP_ADDR_MAX_LEN);
|
| 278 | memset((*linkState)->v6_ip, 0x00, GSW_PDP_ADDR_MAX_LEN);
|
| 279 |
|
| 280 | (*linkState)->v6_pdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 281 | memset((*linkState)->v6_pdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 282 |
|
| 283 | (*linkState)->v6_sdns = (char *)malloc(GSW_DNS_ADDR_MAX_LEN);
|
| 284 | memset((*linkState)->v6_sdns, 0x00, GSW_DNS_ADDR_MAX_LEN);
|
| 285 |
|
| 286 | return GSW_HAL_SUCCESS;
|
| 287 | }
|
| 288 |
|
| 289 | static int Wan_State_ind_free(Wan_State_ind_s **linkState)
|
| 290 | {
|
| 291 | if ((*linkState) == NULL)
|
| 292 | {
|
| 293 | LOGE("(*linkState) is null\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 294 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 295 | }
|
| 296 |
|
| 297 | free((*linkState)->type);
|
| 298 | (*linkState)->type = NULL;
|
| 299 |
|
| 300 | free((*linkState)->ifname);
|
| 301 | (*linkState)->ifname = NULL;
|
| 302 |
|
| 303 | free((*linkState)->v4_ip);
|
| 304 | (*linkState)->v4_ip = NULL;
|
| 305 |
|
| 306 | free((*linkState)->v4_pdns);
|
| 307 | (*linkState)->v4_pdns = NULL;
|
| 308 |
|
| 309 | free((*linkState)->v4_sdns);
|
| 310 | (*linkState)->v4_sdns = NULL;
|
| 311 |
|
| 312 | free((*linkState)->v4_gw);
|
| 313 | (*linkState)->v4_gw = NULL;
|
| 314 |
|
| 315 | free((*linkState)->v6_ip);
|
| 316 | (*linkState)->v6_ip = NULL;
|
| 317 |
|
| 318 | free((*linkState)->v6_pdns);
|
| 319 | (*linkState)->v6_pdns = NULL;
|
| 320 |
|
| 321 | free((*linkState)->v6_sdns);
|
| 322 | (*linkState)->v6_sdns = NULL;
|
| 323 |
|
| 324 |
|
| 325 | free((*linkState));
|
| 326 | (*linkState) = NULL;
|
| 327 |
|
| 328 | return GSW_HAL_SUCCESS;
|
| 329 | }
|
| 330 |
|
| 331 | static int mbtk_data_api_import()
|
| 332 | {
|
| 333 | dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
|
| 334 | if (dlHandle_mbtk == NULL)
|
| 335 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 336 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 337 | }
|
| 338 |
|
| 339 | mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
|
| 340 | if (mbtk_log_init == NULL)
|
| 341 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 342 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 343 | }
|
| 344 |
|
| 345 | mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
|
| 346 | if (mbtk_log == NULL)
|
| 347 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 348 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 349 | }
|
| 350 |
|
| 351 | mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
|
| 352 | if (mbtk_info_handle_get == NULL)
|
| 353 | {
|
| 354 | LOGE("mbtk_info_handle_get dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 355 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 356 | }
|
| 357 |
|
| 358 | mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
|
| 359 | if (mbtk_info_handle_free == NULL)
|
| 360 | {
|
| 361 | LOGE("mbtk_info_handle_free dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 362 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 363 | }
|
| 364 |
|
| 365 | 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");
|
| 366 | if (mbtk_pdp_state_change_cb_reg == NULL)
|
| 367 | {
|
| 368 | LOGE("mbtk_pdp_state_change_cb_reg dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 369 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 370 | }
|
| 371 |
|
| 372 | 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");
|
| 373 | if (mbtk_qser_apn_set == NULL)
|
| 374 | {
|
| 375 | LOGE("mbtk_qser_apn_set dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 376 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 377 | }
|
| 378 |
|
| 379 | 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");
|
| 380 | if (mbtk_data_call_start == NULL)
|
| 381 | {
|
| 382 | LOGE("mbtk_data_call_start dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 383 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 384 | }
|
| 385 |
|
| 386 | mbtk_data_call_stop = (int (*)(mbtk_info_handle_t* handle, int cid, int timeout))dlsym(dlHandle_mbtk, "mbtk_data_call_stop");
|
| 387 | if (mbtk_data_call_stop == NULL)
|
| 388 | {
|
| 389 | LOGE("mbtk_data_call_stop dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 390 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 391 | }
|
| 392 |
|
| 393 | 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");
|
| 394 | if (mbtk_data_call_state_get == NULL)
|
| 395 | {
|
| 396 | LOGE("mbtk_data_call_state_get dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 397 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 398 | }
|
| 399 |
|
| 400 | 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");
|
| 401 | if (mbtk_apn_set == NULL)
|
| 402 | {
|
| 403 | LOGE("mbtk_apn_set dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 404 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 405 | }
|
| 406 |
|
| 407 | ipv6_2_str = (int (*)(const void *ipv6, void *ipv6_str))dlsym(dlHandle_mbtk, "ipv6_2_str");
|
| 408 | if (ipv6_2_str == NULL)
|
| 409 | {
|
| 410 | LOGE("ipv6_2_str dlsym fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 411 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 412 | }
|
| 413 |
|
| 414 | return GSW_HAL_SUCCESS;
|
| 415 | }
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 | static int data_call_state_query(int call_id,Wan_State_ind_s *linkState)
|
| 420 | {
|
| 421 | int ret = -1;
|
| 422 | mbtk_ipv4_info_t ipv4;
|
| 423 | mbtk_ipv6_info_t ipv6;
|
| 424 |
|
| 425 | LOGE("mbtk_data_call_state_get start\n");
|
| 426 | ret = mbtk_data_call_state_get(data_info_handle, call_id, &ipv4, &ipv6);
|
| 427 | LOGE("mbtk_data_call_state_get end\n");
|
| 428 | if (ret != 0)
|
| 429 | {
|
| 430 | LOGE("mbtk_data_call_state_get fail\n");
|
| 431 | return ret;
|
| 432 | }
|
| 433 |
|
| 434 | //ifname
|
| 435 | sprintf(linkState->ifname, "ccinet%d", call_id-1);
|
| 436 |
|
| 437 | //type
|
| 438 | if(ipv4.valid)
|
| 439 | {
|
| 440 | if(ipv6.valid)
|
| 441 | {
|
| 442 | strcpy(linkState->type, "IPV4V6");
|
| 443 | }
|
| 444 | else {
|
| 445 | strcpy(linkState->type, "IP");
|
| 446 | }
|
| 447 | }
|
| 448 | else if(ipv6.valid)
|
| 449 | {
|
| 450 | strcpy(linkState->type, "IPV6");
|
| 451 | }
|
| 452 |
|
| 453 | //ip
|
| 454 | LOGE("ipv4.valid = %d\n", ipv4.valid);
|
| 455 | if(ipv4.valid)
|
| 456 | {
|
| 457 | if(linkState==NULL)
|
| 458 | {
|
| 459 | LOGE("linkState is NULL\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 460 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 461 | }
|
| 462 |
|
| 463 | //parse ipv4_addr,gw,dns,sdns
|
| 464 | if(inet_ntop(AF_INET, &(ipv4.IPAddr), linkState->v4_ip , GSW_PDP_ADDR_MAX_LEN) == NULL) {
|
| 465 | LOGE("IPv4 error.\n");
|
| 466 | } else {
|
| 467 | LOGE("IPv4 : %s\n", linkState->v4_ip);
|
| 468 |
|
| 469 | }
|
| 470 |
|
| 471 |
|
| 472 | if(inet_ntop(AF_INET, &(ipv4.GateWay), linkState->v4_gw , GSW_PDP_ADDR_MAX_LEN) == NULL) {
|
| 473 | LOGE("GateWay error.\n");
|
| 474 | } else {
|
| 475 | LOGE("GateWay : %s\n", linkState->v4_gw);
|
| 476 | }
|
| 477 |
|
| 478 | if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), linkState->v4_pdns , GSW_DNS_ADDR_MAX_LEN) == NULL) {
|
| 479 | LOGE("PrimaryDNS error.\n");
|
| 480 | } else {
|
| 481 | LOGE("PrimaryDNS : %s\n", linkState->v4_pdns);
|
| 482 | }
|
| 483 |
|
| 484 | if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), linkState->v4_sdns , GSW_DNS_ADDR_MAX_LEN) == NULL) {
|
| 485 | LOGE("SecondaryDNS error.\n");
|
| 486 | } else {
|
| 487 | LOGE("SecondaryDNS : %s\n", linkState->v4_sdns);
|
| 488 | }
|
| 489 | }
|
| 490 |
|
| 491 | LOGE("ipv6.valid = %d\n", ipv6.valid);
|
| 492 | if(ipv6.valid)
|
| 493 | {
|
| 494 | //parse ipv6_addr,gw,dns,sdns
|
| 495 | if(ipv6_2_str(&(ipv6.IPV6Addr), linkState->v6_ip)) {
|
| 496 | LOGE("IPv6 error.\n");
|
| 497 | } else {
|
| 498 | LOGE("IPv6 : %s\n", linkState->v6_ip);
|
| 499 | }
|
| 500 |
|
| 501 | if(ipv6_2_str(&(ipv6.PrimaryDNS), linkState->v6_pdns)) {
|
| 502 | LOGE("PrimaryDNS error.\n");
|
| 503 | } else {
|
| 504 | LOGE("PrimaryDNS : %s\n", linkState->v6_pdns);
|
| 505 | }
|
| 506 |
|
| 507 | if(ipv6_2_str(&(ipv6.SecondaryDNS), linkState->v6_sdns)) {
|
| 508 | LOGE("SecondaryDNS error.\n");
|
| 509 | } else {
|
| 510 | LOGE("SecondaryDNS : %s\n", linkState->v6_sdns);
|
| 511 | }
|
| 512 | }
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 | return GSW_HAL_SUCCESS;
|
| 517 | }
|
| 518 |
|
| 519 |
|
| 520 | static void data_call_state_change_cb(const void* data, int data_len)
|
| 521 | {
|
| 522 | LOGE("data_call_state_change_cb() start\n");
|
| 523 |
|
| 524 | if(data == NULL || data_len == 0)
|
| 525 | {
|
| 526 | return;
|
| 527 | }
|
| 528 |
|
| 529 | int ret = -1;
|
| 530 |
|
| 531 | LOGD("Wan_State_ind_malloc start\n");
|
| 532 | ret = Wan_State_ind_malloc(&linkState_arr);
|
| 533 | if (ret != 0)
|
| 534 | {
|
| 535 | LOGE("Wan_State_ind_malloc[0] fail\n");
|
| 536 | return ;
|
| 537 | }
|
| 538 |
|
| 539 | if(linkState_arr == NULL)
|
| 540 | {
|
| 541 | LOGE("linkState_arr is NULL");
|
| 542 | return ;
|
| 543 | }
|
| 544 | else
|
| 545 | {
|
| 546 | LOGE("linkState_arr is not NULL");
|
| 547 | }
|
| 548 |
|
| 549 | uint8 *net_data = NULL;
|
| 550 | net_data = (uint8 *)data;
|
| 551 | //disconnected
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 552 | LOGE("net_data = %d", *net_data);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 553 | if(*net_data > 100 && *net_data < 200)
|
| 554 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 555 | int cid = *net_data - 100;
|
| 556 | LOGE("[%s] apn_id = %d", __func__, cid);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 557 | linkState_arr->state = 0;//disconnected
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 558 | linkState_arr->cid = cid;
|
| 559 | linkState_arr->handle = cid;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 560 |
|
| 561 | //get data_call_state
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 562 | #if 0
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 563 | if(!data_call_lock)
|
| 564 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 565 | data_call_state_query(cid, linkState_arr);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 566 | }
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 567 | #endif
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 568 |
|
| 569 | if(gsw_data_call_evt_cb)
|
| 570 | {
|
| 571 | gsw_data_call_evt_cb(linkState_arr);
|
| 572 | }
|
| 573 | }
|
| 574 |
|
| 575 | else if(*net_data > 200 && *net_data < 220)
|
| 576 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 577 | LOGE("[%s] cid[%d] is open", __func__, *net_data - 200);
|
| 578 | int cid = *net_data-200;
|
| 579 | //int handle_temp = apn_id-2;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 580 |
|
| 581 | linkState_arr->state = 2;//connected
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 582 | linkState_arr->cid = cid;
|
| 583 | linkState_arr->handle = cid;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 584 | //get data_call_state
|
| 585 | if(!data_call_lock)
|
| 586 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 587 | data_call_state_query(cid, linkState_arr);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 588 | }
|
| 589 |
|
| 590 | if(gsw_data_call_evt_cb)
|
| 591 | {
|
| 592 | gsw_data_call_evt_cb(linkState_arr);
|
| 593 | }
|
| 594 | }
|
| 595 |
|
| 596 | else if(*net_data > 220)
|
| 597 | {
|
| 598 | LOGE("cid [%d] is reopen.\n", *net_data - 220);
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 599 | int cid = *net_data-220;
|
| 600 | //int handle_temp = apn_id-2;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 601 |
|
| 602 | linkState_arr->state = 2;//connected
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 603 | linkState_arr->cid = cid;
|
| 604 | linkState_arr->handle = cid;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 605 |
|
| 606 | //get data_call_state
|
| 607 | if(!data_call_lock)
|
| 608 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 609 | data_call_state_query(cid, linkState_arr);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 610 | }
|
| 611 |
|
| 612 | if(gsw_data_call_evt_cb)
|
| 613 | {
|
| 614 | gsw_data_call_evt_cb(linkState_arr);
|
| 615 | }
|
| 616 | }
|
| 617 |
|
| 618 | else if(*net_data == 1)
|
| 619 | {
|
| 620 | LOGE("pdp is open.\n");
|
| 621 | }
|
| 622 |
|
| 623 | else
|
| 624 | {
|
| 625 | LOGE("unknown param [%d].\n", *net_data);
|
| 626 | }
|
| 627 |
|
| 628 | ret = Wan_State_ind_free(&linkState_arr);
|
| 629 | if (ret != 0)
|
| 630 | {
|
| 631 | LOGE("Wan_State_ind_free fail\n");
|
| 632 | }
|
| 633 |
|
| 634 | }
|
| 635 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 636 | static int gsw_id_convert_to_channel_id(int gsw_id, gsw_id_convert_type_e type, int *channel_id)
|
| 637 | {
|
| 638 | if(GSW_ID_CONVERT_TYPE_LINKID == type)
|
| 639 | {
|
| 640 | switch(gsw_id)
|
| 641 | {
|
| 642 | case 0:
|
| 643 | {
|
| 644 | *channel_id = MBTK_CHANNEL_ID_2;
|
| 645 | break;
|
| 646 | }
|
| 647 | case 1:
|
| 648 | {
|
| 649 | *channel_id = MBTK_CHANNEL_ID_1;
|
| 650 | break;
|
| 651 | }
|
| 652 | default :
|
| 653 | {
|
| 654 | LOGE("[%s] gsw_id(linkid) unknown.[%d]", __func__, gsw_id);
|
| 655 | return -1;
|
| 656 | }
|
| 657 | }
|
| 658 | }
|
| 659 | else
|
| 660 | {
|
| 661 | switch(gsw_id)
|
| 662 | {
|
| 663 | case 1:
|
| 664 | case -2:
|
| 665 | {
|
| 666 | *channel_id = MBTK_CHANNEL_ID_1;
|
| 667 | break;
|
| 668 | }
|
| 669 | case -1:
|
| 670 | {
|
| 671 | *channel_id = MBTK_CHANNEL_ID_2;
|
| 672 | break;
|
| 673 | }
|
| 674 | default :
|
| 675 | {
|
| 676 | LOGE("[%s] gsw_id(apnid) unknown.[%d]", __func__, gsw_id);
|
| 677 | return -1;
|
| 678 | }
|
| 679 | }
|
| 680 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 681 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 682 | return 0;
|
| 683 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 | /**
|
| 689 | * @brief datacall sdk init
|
| 690 | * @param [in] evt_cb callback function for data connection state change event
|
| 691 | * call back;
|
| 692 | * @retval 0: success
|
| 693 | * @retval other: fail
|
| 694 | */
|
| 695 | int gsw_data_call_init(gsw_data_call_evt_cb_t evt_cb)
|
| 696 | {
|
| 697 | int ret;
|
| 698 | ret = mbtk_data_api_import();
|
| 699 | if (ret != 0)
|
| 700 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 701 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 702 | }
|
| 703 |
|
| 704 | if(data_init_flag != 0 && data_info_handle != NULL)
|
| 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 (ret != GSW_HAL_SUCCESS)
|
| 710 | {
|
| 711 | LOGE("mbtk_data_api_import fail\n");
|
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 | data_info_handle = (mbtk_info_handle_t*)mbtk_info_handle_get();
|
| 716 | if (data_info_handle == NULL)
|
| 717 | {
|
| 718 | LOGE("mbtk_info_handle_get fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 719 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 720 | }
|
| 721 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 722 | #if 0
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 723 | ret = mbtk_pdp_state_change_cb_reg((mbtk_info_handle_t*)data_info_handle, data_call_state_change_cb);
|
| 724 | if (ret != 0)
|
| 725 | {
|
| 726 | LOGE("mbtk_pdp_state_change_cb_reg fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 727 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 728 | }
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 729 | #endif
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 730 | gsw_data_call_evt_cb = evt_cb;
|
| 731 | data_init_flag = 1;
|
| 732 | return GSW_HAL_SUCCESS;
|
| 733 | }
|
| 734 |
|
| 735 |
|
| 736 | /**
|
| 737 | * @brief data_call sdk deinit
|
| 738 | * @param
|
| 739 | * @retval 0: success
|
| 740 | * @retval other: fail
|
| 741 | */
|
| 742 | int gsw_data_call_deinit(void)
|
| 743 | {
|
| 744 | int ret;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 745 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 746 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 747 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 748 | }
|
| 749 |
|
| 750 | ret = mbtk_info_handle_free((mbtk_info_handle_t**)&data_info_handle);
|
| 751 | if (ret != 0)
|
| 752 | {
|
| 753 | LOGE("mbtk_info_handle_free fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 754 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 755 | }
|
| 756 |
|
| 757 | data_init_flag = 0;
|
| 758 | return GSW_HAL_SUCCESS;
|
| 759 | }
|
| 760 |
|
| 761 | /**
|
| 762 | * @brief set apn parameters for data call
|
| 763 | * @param [in/out] LinkInf apn info for pub or private datacall
|
| 764 | * inlcude apn name mcc mnc, passwork apnid type cid etc
|
| 765 | * @retval 0: success
|
| 766 | * @retval other: fail
|
| 767 | */
|
| 768 | int gsw_data_call_set_apn(Link_Info_s *LinkInf)
|
| 769 | {
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 770 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 771 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 772 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 773 | }
|
| 774 |
|
| 775 | if(LinkInf == NULL)
|
| 776 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 777 | LOGE("apn info is null");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 778 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 779 | }
|
| 780 |
|
| 781 | int ret = 0;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 782 | int cid = -1;
|
| 783 | int apnid = -1;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 784 | mbtk_ip_type_enum ip_type;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 785 | char auth_type[GSW_AUTH_TYPE_MAX_LEN + 1] = {0};
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 786 |
|
| 787 | //pdp type
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 788 | if(strcmp(LinkInf->normalProtocol,"IP") == 0)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 789 | {
|
| 790 | ip_type = MBTK_IP_TYPE_IP;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 791 | LOGE("pdp_type(protocol) is IP");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 792 | }
|
| 793 | else if(strcmp(LinkInf->normalProtocol,"IPV6") == 0)
|
| 794 | {
|
| 795 | ip_type = MBTK_IP_TYPE_IPV6;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 796 | LOGE("pdp_type(protocol) is IPV6");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 797 | }
|
| 798 | else if(strcmp(LinkInf->normalProtocol,"IPV4V6") == 0)
|
| 799 | {
|
| 800 | ip_type = MBTK_IP_TYPE_IPV4V6;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 801 | LOGE("pdp_type(protocol) is IPV4V6");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 802 | }
|
| 803 | else
|
| 804 | {
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 805 | LOGE("pdp_type(protocol) error");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 806 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 807 | }
|
| 808 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 809 | apnid = atoi(LinkInf->apnid);
|
| 810 | ret = gsw_id_convert_to_channel_id(apnid, GSW_ID_CONVERT_TYPE_APNID, &cid);
|
| 811 | if(0 != ret)
|
| 812 | {
|
| 813 | LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);
|
| 814 | return GSW_HAL_NORMAL_FAIL;
|
| 815 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 816 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 817 | //bypass solution for authparams issue
|
| 818 | #if 0
|
| 819 | memset(LinkInf->usr, 0x00, sizeof(LinkInf->usr));
|
| 820 | memset(LinkInf->pwd, 0x00, sizeof(LinkInf->pwd));
|
| 821 | memset(LinkInf->authType, 0x00, sizeof(LinkInf->authType));
|
| 822 | #endif
|
| 823 | //auth type
|
| 824 | memset(auth_type, 0x00, GSW_AUTH_TYPE_MAX_LEN + 1);
|
| 825 | if(0 == strlen(LinkInf->authType) || 0 == strcmp(LinkInf->authType, "0"))
|
| 826 | {
|
| 827 | memcpy(auth_type, "NONE", strlen("NONE"));
|
| 828 | }
|
| 829 | else if(0 == strcmp(LinkInf->authType, "1"))
|
| 830 | {
|
| 831 | memcpy(auth_type, "PAP", strlen("PAP"));
|
| 832 | }
|
| 833 | else if(0 == strcmp(LinkInf->authType, "2"))
|
| 834 | {
|
| 835 | memcpy(auth_type, "CHAP", strlen("CHAP"));
|
| 836 | }
|
| 837 | else if(0 == strcmp(LinkInf->authType, "3"))
|
| 838 | {
|
| 839 | //nonsupport
|
| 840 | LOGE("[%s] LinkInf->authType(3) nonsupport", __func__);
|
| 841 | return GSW_HAL_NORMAL_FAIL;
|
| 842 | }
|
| 843 | else
|
| 844 | {
|
| 845 | LOGE("[%s] LinkInf->authType(%s) unknown", __func__, LinkInf->authType);
|
| 846 | return GSW_HAL_NORMAL_FAIL;
|
| 847 | }
|
| 848 |
|
| 849 | 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] | 850 | if(ret != 0)
|
| 851 | {
|
hong.liu | 006db56 | 2025-06-05 17:19:27 +0800 | [diff] [blame] | 852 | LOGE("[%s] mbtk_apn_set fail() fail.[%d]", __func__, ret);
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 853 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 854 | }
|
| 855 |
|
| 856 | return GSW_HAL_SUCCESS;
|
| 857 | }
|
| 858 |
|
| 859 |
|
| 860 | /**
|
| 861 | * @brief set apn parameters for data call
|
| 862 | * @param [in] linkid data connetion link number
|
| 863 | * @param [in/out] LinkInf link info req: apn info for pub or private datacall
|
| 864 | * inlcude apn name mcc mnc, passwork apnid etc
|
| 865 | * resp: data call link state ipaddress type etc
|
| 866 | * @retval 0: success
|
| 867 | * @retval other: fail
|
| 868 | */
|
| 869 | int gsw_data_call_connect(int linkid, Link_Info_s *LinkInf)
|
| 870 | {
|
| 871 | int ret = -1;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 872 | int cid = -1;
|
| 873 | uint8_t cid_temp = 0;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 874 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 875 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 876 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 877 | }
|
| 878 |
|
| 879 | if(LinkInf == NULL)
|
| 880 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 881 | LOGE("apn info is null");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 882 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 883 | }
|
| 884 |
|
hong.liu | 006db56 | 2025-06-05 17:19:27 +0800 | [diff] [blame] | 885 | ret = gsw_data_call_set_apn(LinkInf);
|
| 886 | if(ret != GSW_HAL_SUCCESS)
|
| 887 | {
|
| 888 | LOGE("[%s] gsw_data_call_set_apn() fail", __func__);
|
| 889 | return GSW_HAL_NORMAL_FAIL;
|
| 890 | }
|
| 891 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 892 | ret = gsw_id_convert_to_channel_id(linkid, GSW_ID_CONVERT_TYPE_LINKID, &cid);
|
| 893 | if(0 != ret)
|
| 894 | {
|
| 895 | LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);
|
| 896 | return GSW_HAL_NORMAL_FAIL;
|
| 897 | }
|
| 898 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 899 | data_call_lock = 1;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 900 | 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] | 901 | data_call_lock = 0;
|
| 902 | if(ret != 0)
|
| 903 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 904 | LOGE("[%s] mbtk_data_call_start fail.[%d]", __func__, ret);
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 905 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 906 | }
|
| 907 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 908 | cid_temp = (uint8_t)(cid + 200);
|
| 909 | //LOGE("[%s] cid = %d, cid_temp = %d", __func__, cid, cid_temp);
|
| 910 | data_call_state_change_cb(&cid_temp, sizeof(uint8_t));
|
| 911 |
|
| 912 | LinkInf->handle = cid;
|
| 913 | memset(LinkInf->apnid, 0x00, sizeof(LinkInf->apnid));
|
| 914 | sprintf(LinkInf->apnid, "%d", cid);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 915 |
|
| 916 | return GSW_HAL_SUCCESS;
|
| 917 | }
|
| 918 |
|
| 919 |
|
| 920 | /**
|
| 921 | * @brief set apn parameters for data call
|
| 922 | * @param [in] linkid
|
| 923 | * @param [in/out] LinkInf link info req: apn info for pub or private datacall
|
| 924 | * inlcude apn name mcc mnc, passwork apnid etc
|
| 925 | * resp: data call link state ipaddress type etc
|
| 926 | * @retval 0: success
|
| 927 | * @retval other: fail
|
| 928 | */
|
| 929 | int gsw_data_call_disconnect(int linkid, Link_Info_s *LinkInf)
|
| 930 | {
|
| 931 | int ret = -1;
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 932 | int cid = -1;
|
| 933 | uint8_t cid_temp = 0;
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 934 | if(data_init_flag == 0 || data_info_handle == NULL)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 935 | {
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 936 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 937 | }
|
| 938 |
|
| 939 | if(LinkInf == NULL)
|
| 940 | {
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 941 | LOGE("apn info is null");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 942 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 943 | }
|
| 944 |
|
yq.wang | 22b1bae | 2025-06-10 13:09:59 +0800 | [diff] [blame] | 945 | ret = gsw_id_convert_to_channel_id(linkid, GSW_ID_CONVERT_TYPE_LINKID, &cid);
|
| 946 | if(0 != ret)
|
| 947 | {
|
| 948 | LOGE("[%s] gsw_id_convert_to_channel_id() fail", __func__);
|
| 949 | return GSW_HAL_NORMAL_FAIL;
|
| 950 | }
|
| 951 |
|
| 952 | data_call_lock = 1;
|
| 953 | ret = mbtk_data_call_stop((mbtk_info_handle_t*)data_info_handle, cid, 15);
|
| 954 | data_call_lock = 0;
|
| 955 | if(ret != 0)
|
| 956 | {
|
| 957 | LOGE("[%s] mbtk_data_call_stop() fail.[%d]",__func__, ret);
|
| 958 | return GSW_HAL_NORMAL_FAIL;
|
| 959 | }
|
| 960 |
|
| 961 | cid_temp = (uint8_t)(cid + 100);
|
| 962 | data_call_state_change_cb(&cid_temp, sizeof(uint8_t));
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 963 |
|
| 964 | return GSW_HAL_SUCCESS;
|
| 965 | }
|
| 966 |
|
| 967 |
|
| 968 | /*
|
| 969 | * @brief get mobile operator name
|
| 970 | @param [in] linkid apn id
|
| 971 | @param [out] data_pkt obtian actual data call network card data traffic
|
| 972 | @retval 0: success
|
| 973 | @retval 0: other: fail
|
| 974 | */
|
| 975 | int gsw_get_data_call_pkt_stats(int linkid, gsw_data_pkt_stats *data_pkt)
|
| 976 | {
|
q.huang | 09ae5bc | 2025-06-10 15:25:36 +0800 | [diff] [blame^] | 977 |
|
| 978 | if(data_init_flag == 0 || data_info_handle == NULL)
|
| 979 | {
|
| 980 | return GSW_HAL_NORMAL_FAIL;
|
| 981 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 982 | char temp_linkid[12] = {0};
|
| 983 | char interface_name[32] = {0};
|
| 984 | sprintf(temp_linkid,"%d",linkid+1);
|
| 985 | snprintf(interface_name, sizeof(interface_name),"ccinet%s", temp_linkid);
|
| 986 |
|
| 987 | uint64_t tx_bytes = 0;
|
| 988 | uint64_t tx_packets = 0;
|
| 989 | uint64_t tx_dropped = 0;
|
| 990 | uint64_t rx_bytes = 0;
|
| 991 | uint64_t rx_packets = 0;
|
| 992 | uint64_t rx_dropped = 0;
|
| 993 | char command[128] = {0};
|
| 994 | char* temp;
|
| 995 | char buffer[512] = {0};
|
| 996 |
|
| 997 | snprintf(command, sizeof(command), "ifconfig %s", interface_name);
|
| 998 |
|
| 999 | FILE *fp = popen(command, "r");
|
| 1000 | if(fp == NULL)
|
| 1001 | {
|
| 1002 | LOGE("popen fail\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 1003 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1004 | }
|
| 1005 |
|
| 1006 | //read line by line
|
| 1007 | while (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
| 1008 | // TX bytes
|
| 1009 | if (strstr(buffer, "TX bytes")) {
|
| 1010 | temp = strstr(buffer, "TX bytes");
|
| 1011 | sscanf(temp, " TX bytes:%llu ", &tx_bytes);
|
| 1012 | }
|
| 1013 | // TX packets
|
| 1014 | if (strstr(buffer, "TX packets")) {
|
| 1015 | sscanf(buffer, " TX packets:%llu ", &tx_packets);
|
| 1016 | sscanf(buffer, " TX packets:%*u errors:%*u dropped:%llu", &tx_dropped);
|
| 1017 | }
|
| 1018 | // RX bytes
|
| 1019 | if (strstr(buffer, "RX bytes")) {
|
| 1020 | LOGE("RX bytes %s\n",strstr(buffer, "RX bytes"));
|
| 1021 | sscanf(buffer, " RX bytes:%llu ", &rx_bytes);
|
| 1022 | }
|
| 1023 | // RX packets
|
| 1024 | if (strstr(buffer, "RX packets")) {
|
| 1025 | sscanf(buffer, " RX packets:%llu ", &rx_packets);
|
| 1026 | sscanf(buffer, " RX packets:%*u errors:%*u dropped:%llu", &rx_dropped);
|
| 1027 | }
|
| 1028 | }
|
| 1029 |
|
| 1030 | // 关闭管道
|
| 1031 | pclose(fp);
|
| 1032 |
|
| 1033 | // 输出结果
|
| 1034 | LOGE("TX Bytes: %llu\n", tx_bytes);
|
| 1035 | LOGE("TX Packets: %llu\n", tx_packets);
|
| 1036 | LOGE("TX Dropped: %llu\n", tx_dropped);
|
| 1037 | LOGE("RX Bytes: %llu\n", rx_bytes);
|
| 1038 | LOGE("RX Packets: %llu\n", rx_packets);
|
| 1039 | LOGE("RX Dropped: %llu\n", rx_dropped);
|
| 1040 |
|
| 1041 | if(data_pkt == NULL)
|
| 1042 | {
|
| 1043 | LOGE("data_pkt is null\n");
|
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 1044 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1045 | }
|
| 1046 |
|
| 1047 | else
|
| 1048 | {
|
| 1049 | data_pkt->tx_bytes = tx_bytes;
|
| 1050 | data_pkt->tx_pkts = tx_packets;
|
| 1051 | data_pkt->tx_dropped_pkts = tx_dropped;
|
| 1052 | data_pkt->rx_bytes = rx_bytes;
|
| 1053 | data_pkt->rx_pkts = rx_packets;
|
| 1054 | data_pkt->rx_dropped_pkts = rx_dropped;
|
| 1055 | }
|
| 1056 |
|
| 1057 | return GSW_HAL_SUCCESS;
|
| 1058 |
|
| 1059 | }
|