b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 1 | #include "lynq-qser-data.h" |
| 2 | #include "mbtk_type.h" |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 3 | #include "mbtk_info_api.h" |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 4 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 5 | #include <pthread.h> |
| 6 | #include <cutils/properties.h> |
| 7 | #include <string.h> |
wangyouqiang | 805b0f9 | 2024-04-07 17:06:13 +0800 | [diff] [blame] | 8 | #include <unistd.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 11 | #include <fcntl.h> |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 12 | /****************************DEFINE***************************************/ |
| 13 | #define QSER_RESULT_SUCCESS 0 |
| 14 | #define QSER_RESULT_FAIL -1 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 15 | |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 16 | #define MBTK_INFO_ERR_CID_EXIST 311 |
| 17 | #define MBTK_INFO_ERR_CID_NO_EXIST 312 |
wangyouqiang | c1d72d2 | 2024-04-25 10:15:58 +0800 | [diff] [blame] | 18 | #define MBTK_INFO_ERR_NO_APN 500 |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 19 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 20 | #define QSER_APN_NUM 8 |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 21 | //default range: 0 - 7 |
| 22 | //AT+CGACT range: 1 - 8 |
| 23 | //1 default IDX, 8 IMS IDX |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 24 | #if defined(MBTK_ALL_CID_SUPPORT) |
wangyouqiang | 3dcb383 | 2024-04-24 15:22:50 +0800 | [diff] [blame] | 25 | #if defined(MBTK_SG_SUPPORT) |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 26 | #define QSER_PROFILE_IDX_MIN 0 |
| 27 | #else |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 28 | #define QSER_PROFILE_IDX_MIN 1 |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 29 | #endif |
wangyouqiang | 805b0f9 | 2024-04-07 17:06:13 +0800 | [diff] [blame] | 30 | #else |
| 31 | #define QSER_PROFILE_IDX_MIN 1 |
| 32 | #endif |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 33 | #define QSER_PROFILE_IDX_MAX 6 |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 34 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 35 | /****************************DEFINE***************************************/ |
| 36 | |
| 37 | /****************************VARIABLE***************************************/ |
| 38 | mbtk_info_handle_t* qser_info_handle = NULL; |
| 39 | int qser_info_handle_num = 0; |
| 40 | static bool inited = FALSE; |
| 41 | static qser_data_call_evt_cb_t qser_net_status_cb = NULL; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 42 | /****************************VARIABLE***************************************/ |
| 43 | |
| 44 | /******************************FUNC*****************************************/ |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 45 | static int qser_apn_info_param_convert(int profile_idx, qser_apn_info_s *new_apn, mbtk_qser_apn_info_s *old_apn) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 46 | { |
| 47 | if(new_apn == NULL || old_apn == NULL) |
| 48 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 49 | LOGE("[qser_data] qser_apn_info_param_convert apn param is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 50 | return QSER_RESULT_FAIL; |
| 51 | } |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 52 | |
| 53 | memset(new_apn, 0x0, sizeof(qser_apn_info_s)); |
| 54 | new_apn->profile_idx = old_apn->cid - 1; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 55 | //get ip type |
| 56 | if(old_apn->ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6 |
| 57 | { |
| 58 | new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4V6; |
| 59 | } |
| 60 | else if(old_apn->ip_type == MBTK_IP_TYPE_IP) // IPV4 |
| 61 | { |
| 62 | new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4; |
| 63 | } |
| 64 | else if(old_apn->ip_type == MBTK_IP_TYPE_IPV6) // IPV6 |
| 65 | { |
| 66 | new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV6; |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | new_apn->pdp_type = QSER_APN_PDP_TYPE_PPP; |
| 71 | } |
| 72 | |
| 73 | //get apn name |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 74 | if(strlen((char *)old_apn->apn_name) > QSER_APN_NAME_SIZE) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 75 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 76 | LOGE("[qser_data] apn_nmea length verylong."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 77 | return QSER_RESULT_FAIL; |
| 78 | } |
| 79 | else |
| 80 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 81 | if(strlen((char *)old_apn->apn_name) > 0) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 82 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 83 | memcpy(new_apn->apn_name, old_apn->apn_name,strlen((char *)old_apn->apn_name)); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | //get apn user |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 88 | if(strlen((char *)old_apn->user_name) > QSER_APN_USERNAME_SIZE) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 89 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 90 | LOGE("[qser_data] apn_user length verylong."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 91 | return QSER_RESULT_FAIL; |
| 92 | } |
| 93 | else |
| 94 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 95 | if(strlen((char *)old_apn->user_name) > 0) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 96 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 97 | memcpy(new_apn->username, old_apn->user_name, strlen((char *)old_apn->user_name)); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | //get apn password |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 102 | if(strlen((char *)old_apn->user_pass) > QSER_APN_PASSWORD_SIZE) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 103 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 104 | LOGE("[qser_data] apn_password length verylong."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 105 | return QSER_RESULT_FAIL; |
| 106 | } |
| 107 | else |
| 108 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 109 | if(strlen((char *)old_apn->user_pass) > 0) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 110 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 111 | memcpy(new_apn->password, old_apn->user_pass, strlen((char *)old_apn->user_pass)); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | //get apn proto |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 116 | new_apn->auth_proto = (qser_apn_auth_proto_e)old_apn->auth_proto; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 117 | |
| 118 | //get apn type |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 119 | if(strlen((char *)old_apn->apn_type) > QSER_APN_PASSWORD_SIZE) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 120 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 121 | LOGE("[qser_data] apn_type length verylong."); |
wangyouqiang | 8ebeafe | 2024-04-15 10:07:44 +0800 | [diff] [blame] | 122 | return QSER_RESULT_FAIL; |
| 123 | } |
wangyouqiang | 8ebeafe | 2024-04-15 10:07:44 +0800 | [diff] [blame] | 124 | else |
| 125 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 126 | if(strlen((char *)old_apn->apn_type) > 0) |
wangyouqiang | 8ebeafe | 2024-04-15 10:07:44 +0800 | [diff] [blame] | 127 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 128 | memcpy(new_apn->apn_type, old_apn->apn_type, strlen((char *)old_apn->apn_type)); |
r.xiao | f6ec482 | 2024-04-03 02:46:00 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | return QSER_RESULT_SUCCESS; |
| 133 | } |
| 134 | |
wangyouqiang | 12a8781 | 2024-04-22 14:54:52 +0800 | [diff] [blame] | 135 | static void qser_state_init(qser_data_call_state_s *state) |
wangyouqiang | 805b0f9 | 2024-04-07 17:06:13 +0800 | [diff] [blame] | 136 | { |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 137 | if(state != NULL) |
wangyouqiang | 805b0f9 | 2024-04-07 17:06:13 +0800 | [diff] [blame] | 138 | { |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 139 | state->profile_idx = 0; |
| 140 | memset(state->name, 0x0, 16); |
| 141 | state->ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 142 | state->state = QSER_DATA_CALL_DISCONNECTED; |
| 143 | state->err = QSER_DATA_CALL_ERROR_NONE; |
| 144 | inet_aton("0.0.0.0", &(state->v4.ip)); |
| 145 | inet_aton("0.0.0.0", &(state->v4.gateway)); |
| 146 | inet_aton("0.0.0.0", &(state->v4.pri_dns)); |
| 147 | inet_aton("0.0.0.0", &(state->v4.sec_dns)); |
| 148 | inet_pton(AF_INET6, "::", &(state->v6.ip)); |
| 149 | inet_pton(AF_INET6, "::", &(state->v6.gateway)); |
| 150 | inet_pton(AF_INET6, "::", &(state->v6.pri_dns)); |
| 151 | inet_pton(AF_INET6, "::", &(state->v6.sec_dns)); |
wangyouqiang | 805b0f9 | 2024-04-07 17:06:13 +0800 | [diff] [blame] | 152 | } |
wangyouqiang | 805b0f9 | 2024-04-07 17:06:13 +0800 | [diff] [blame] | 153 | } |
r.xiao | f6ec482 | 2024-04-03 02:46:00 -0700 | [diff] [blame] | 154 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 155 | void qser_wan_net_state_change_cb(const void* data, int data_len) |
| 156 | { |
| 157 | if(data == NULL || data_len == 0) |
| 158 | { |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | uint8 *net_data = NULL; |
| 163 | net_data = (uint8 *)data; |
| 164 | |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 165 | if(*net_data > 100 && *net_data < 200) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 166 | { |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 167 | int idx = *net_data - 101; |
| 168 | if(idx <= QSER_PROFILE_IDX_MAX) |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 169 | { |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 170 | qser_data_call_state_s state = {0}; |
| 171 | qser_state_init(&state); |
| 172 | state.profile_idx = idx; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 173 | state.state = QSER_DATA_CALL_DISCONNECTED; |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 174 | if(qser_net_status_cb != NULL) |
| 175 | { |
| 176 | qser_net_status_cb(&state); |
| 177 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 178 | } |
| 179 | else |
| 180 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 181 | LOGE("[qser_data] cb fail,idx is %d.", idx); |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 182 | } |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 183 | |
| 184 | } |
wangyouqiang | 3947b30 | 2024-07-04 17:26:08 +0800 | [diff] [blame] | 185 | else if(*net_data > 200 && *net_data < 220) |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 186 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 187 | LOGE("[qser_data] cid[%d] is open.", *net_data - 201); |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 188 | } |
wangyouqiang | 3947b30 | 2024-07-04 17:26:08 +0800 | [diff] [blame] | 189 | else if(*net_data > 220) |
| 190 | { |
| 191 | LOGE("[qser_data] cid[%d] is reopen.", *net_data - 221); |
| 192 | int idx = *net_data - 221; |
| 193 | if(idx <= QSER_PROFILE_IDX_MAX) |
| 194 | { |
| 195 | qser_data_call_state_s state = {0}; |
| 196 | qser_state_init(&state); |
| 197 | state.profile_idx = idx; |
| 198 | state.state = QSER_DATA_CALL_CONNECTED; |
| 199 | snprintf(state.name, 16, "ccinet%d", idx); |
| 200 | if(qser_net_status_cb != NULL) |
| 201 | { |
| 202 | qser_net_status_cb(&state); |
| 203 | } |
| 204 | } |
| 205 | } |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 206 | else if(*net_data == 1) |
| 207 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 208 | LOGE("[qser_data] pdp is open."); |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 209 | } |
| 210 | else |
| 211 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 212 | LOGE("[qser_data] unkonwn param [%d].", *net_data); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 213 | } |
| 214 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 215 | |
| 216 | static void* data_call_async_thread(void* arg) |
| 217 | { |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 218 | LOGE("[qser_data] entry data_call_async_thread."); |
| 219 | qser_data_call_error_e err = QSER_DATA_CALL_ERROR_NONE; |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 220 | |
| 221 | qser_data_call_s qser_data_backup = {0}; |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 222 | qser_data_call_info_s info = {0}; |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 223 | if(arg != NULL) |
| 224 | { |
| 225 | memcpy(&qser_data_backup, (qser_data_call_s *)arg, sizeof(qser_data_call_s)); |
| 226 | } |
| 227 | else |
| 228 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 229 | LOGE("[qser_data] arg is NULL."); |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | qser_data_call_state_s state = {0}; |
| 233 | qser_state_init(&state); |
| 234 | state.profile_idx = qser_data_backup.profile_idx; |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 235 | snprintf(state.name, 16, "ccinet%d", qser_data_backup.profile_idx); |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 236 | state.ip_family = qser_data_backup.ip_family; |
| 237 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 238 | int ret = qser_data_call_start(&qser_data_backup, &err); |
| 239 | if(ret != QSER_RESULT_SUCCESS) |
| 240 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 241 | LOGE("[qser_data] qser_data_call_start() fail."); |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 242 | state.err = err; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 243 | } |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 244 | else |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 245 | { |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 246 | state.state = QSER_DATA_CALL_CONNECTED; |
| 247 | ret = qser_data_call_info_get(qser_data_backup.profile_idx, qser_data_backup.ip_family, &info, &err); |
| 248 | if(ret != QSER_RESULT_SUCCESS) |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 249 | { |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 250 | LOGE("[qser_data] qser_data_call_info_get() fail."); |
| 251 | state.err = err; |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | memcpy(&(state.v4), &(info.v4.addr), sizeof(struct v4_address_status)); |
| 256 | memcpy(&(state.v6), &(info.v6.addr), sizeof(struct v6_address_status)); |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 257 | } |
| 258 | } |
liuyang | 2c21d62 | 2024-07-29 14:05:55 +0800 | [diff] [blame] | 259 | |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 260 | if(qser_net_status_cb != NULL) |
| 261 | { |
| 262 | qser_net_status_cb(&state); |
| 263 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 264 | return NULL; |
| 265 | } |
| 266 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 267 | /******************************FUNC*****************************************/ |
| 268 | |
| 269 | /****************************API***************************************/ |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 270 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 271 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 272 | //UNUSED(evt_cb); |
| 273 | if(!inited && qser_info_handle == NULL) |
| 274 | { |
| 275 | qser_info_handle = mbtk_info_handle_get(); |
| 276 | if(qser_info_handle) |
| 277 | { |
| 278 | qser_info_handle_num++; |
| 279 | inited = TRUE; |
| 280 | mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb); |
| 281 | } |
| 282 | else |
| 283 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 284 | LOGE("[qser_data] mbtk_info_handle_get() fail."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 285 | return QSER_RESULT_FAIL; |
| 286 | } |
| 287 | } |
| 288 | else |
| 289 | { |
| 290 | if(!inited) |
| 291 | { |
| 292 | qser_info_handle_num++; |
| 293 | inited = TRUE; |
| 294 | mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb); |
| 295 | } |
| 296 | } |
| 297 | qser_net_status_cb = evt_cb; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 298 | |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 299 | LOGE("[qser_data] mbtk_info_handle_get() success."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 300 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void qser_data_call_destroy(void) |
| 304 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 305 | if(qser_info_handle) |
| 306 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 307 | LOGE("[qser_data] qser_info_handle_num = %d", qser_info_handle_num); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 308 | if(qser_info_handle_num == 1) |
| 309 | { // 最后一个引用,可释放。 |
| 310 | int ret = mbtk_info_handle_free(&qser_info_handle); |
| 311 | if(ret) |
| 312 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 313 | LOGE("[qser_data] mbtk_info_handle_free() fail."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 314 | } |
| 315 | else |
| 316 | { |
| 317 | qser_info_handle_num = 0; |
| 318 | qser_info_handle = NULL; |
wangyouqiang | 45cfff8 | 2024-04-15 19:35:15 +0800 | [diff] [blame] | 319 | qser_net_status_cb = NULL; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 320 | inited = FALSE; |
| 321 | } |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | qser_info_handle_num--; |
wangyouqiang | 45cfff8 | 2024-04-15 19:35:15 +0800 | [diff] [blame] | 326 | qser_net_status_cb = NULL; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | else |
| 330 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 331 | LOGE("[qser_data] handle not inited."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 332 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 336 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 337 | //UNUSED(data_call); |
| 338 | //UNUSED(err); |
| 339 | if(data_call == NULL || err == NULL) |
| 340 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 341 | LOGE("[qser_data] data_call or err is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 342 | if(err != NULL) |
| 343 | { |
| 344 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 345 | } |
| 346 | return QSER_RESULT_FAIL; |
| 347 | } |
| 348 | |
| 349 | if(qser_info_handle == NULL) |
| 350 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 351 | LOGE("[qser_data] handle is NULL."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 352 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 353 | return QSER_RESULT_FAIL; |
| 354 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 355 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 356 | int ret = -1; |
| 357 | ret = mbtk_data_call_start(qser_info_handle, data_call->profile_idx + 1, 0, FALSE, 0); |
| 358 | if(ret != 0) |
| 359 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 360 | LOGE("[qser_data] mbtk_data_call_start fail.[ret = %d]", ret); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 361 | if(ret == MBTK_INFO_ERR_CID_EXIST) |
| 362 | { |
| 363 | *err = QSER_DATA_CALL_ERROR_PDP_ACTIVATE; |
| 364 | } |
| 365 | else |
| 366 | { |
| 367 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 368 | } |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 369 | return QSER_RESULT_FAIL; |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | *err = QSER_DATA_CALL_ERROR_NONE; |
| 374 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 375 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 376 | return QSER_RESULT_SUCCESS; |
| 377 | } |
| 378 | |
| 379 | int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 380 | { |
| 381 | //UNUSED(data_call); |
| 382 | UNUSED(err); |
| 383 | if(data_call == NULL || err == NULL) |
| 384 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 385 | LOGE("[qser_data] data_call or err is NULL."); |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 386 | if(err != NULL) |
| 387 | { |
| 388 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 389 | } |
| 390 | return QSER_RESULT_FAIL; |
| 391 | } |
| 392 | |
| 393 | if(qser_info_handle == NULL) |
| 394 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 395 | LOGE("[qser_data] handle is NULL."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 396 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 397 | return QSER_RESULT_FAIL; |
| 398 | } |
| 399 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 400 | pthread_attr_t thread_attr; |
| 401 | pthread_t data_call_thread_id; |
| 402 | pthread_attr_init(&thread_attr); |
| 403 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 404 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 405 | LOGE("[qser_data] pthread_attr_setdetachstate() fail."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 406 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 407 | return QSER_RESULT_FAIL; |
| 408 | } |
| 409 | |
wangyouqiang | a24887d | 2024-04-08 18:31:23 +0800 | [diff] [blame] | 410 | //memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s)); |
| 411 | if(pthread_create(&data_call_thread_id, &thread_attr, data_call_async_thread, (void *) data_call)) |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 412 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 413 | LOGE("[qser_data] pthread_create() fail."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 414 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 415 | return QSER_RESULT_FAIL; |
| 416 | } |
| 417 | pthread_attr_destroy(&thread_attr); |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 418 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 419 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 423 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 424 | //UNUSED(profile_idx); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 425 | UNUSED(ip_family); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 426 | //UNUSED(err); |
| 427 | if(err == NULL) |
| 428 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 429 | LOGE("[qser_data] err is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 430 | return QSER_RESULT_FAIL; |
| 431 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 432 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 433 | if(qser_info_handle == NULL) |
| 434 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 435 | LOGE("[qser_data] handle is NULL."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 436 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 437 | return QSER_RESULT_FAIL; |
| 438 | } |
| 439 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 440 | int ret = -1; |
| 441 | ret = mbtk_data_call_stop(qser_info_handle, profile_idx + 1, 15); |
| 442 | if(ret != 0) |
| 443 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 444 | LOGE("[qser_data] mbtk_data_call_stop fail.[ret = %d]", ret); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 445 | if(ret == MBTK_INFO_ERR_CID_NO_EXIST) |
| 446 | { |
| 447 | *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE; |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 452 | } |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 453 | return QSER_RESULT_FAIL; |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | *err = QSER_DATA_CALL_ERROR_NONE; |
| 458 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 459 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 460 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | int qser_data_call_info_get(char profile_idx,qser_data_call_ip_family_e ip_family, |
| 464 | qser_data_call_info_s *info, qser_data_call_error_e *err) |
| 465 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 466 | //UNUSED(profile_idx); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 467 | UNUSED(ip_family); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 468 | //UNUSED(info); |
| 469 | //UNUSED(err); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 470 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 471 | if(info == NULL || err == NULL) |
| 472 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 473 | LOGE("[qser_data] info or err is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 474 | if(err != NULL) |
| 475 | { |
| 476 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 477 | } |
| 478 | return QSER_RESULT_FAIL; |
| 479 | } |
| 480 | |
| 481 | if(qser_info_handle == NULL) |
| 482 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 483 | LOGE("[qser_data] handle is NULL."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 484 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 485 | return QSER_RESULT_FAIL; |
| 486 | } |
| 487 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 488 | int ret = -1; |
| 489 | mbtk_ipv4_info_t ipv4; |
| 490 | mbtk_ipv6_info_t ipv6; |
| 491 | #ifdef QSER_TEST |
| 492 | char v4_buff[32] = {0}; |
| 493 | char v6_buff[128] = {0}; |
| 494 | #endif |
| 495 | memset(info, 0, sizeof(qser_data_call_info_s)); |
| 496 | ret = mbtk_data_call_state_get(qser_info_handle, profile_idx + 1, &ipv4, &ipv6); |
| 497 | if(ret != 0) |
| 498 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 499 | LOGE("[qser_data] mbtk_data_call_state_get fail.[ret = %d]", ret); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 500 | if(ret == MBTK_INFO_ERR_CID_NO_EXIST) |
| 501 | { |
| 502 | *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE; |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 507 | } |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 508 | return QSER_RESULT_FAIL; |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | info->profile_idx = profile_idx; |
| 513 | if(ipv4.valid) |
| 514 | { |
| 515 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 516 | info->v4.state = QSER_DATA_CALL_CONNECTED; |
| 517 | sprintf(info->v4.name, "ccinet%d", profile_idx); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 518 | info->v4.addr.ip.s_addr = ipv4.IPAddr; |
| 519 | info->v4.addr.pri_dns.s_addr = ipv4.PrimaryDNS; |
| 520 | info->v4.addr.sec_dns.s_addr = ipv4.SecondaryDNS; |
liuyang | 8ced542 | 2024-08-05 19:26:01 +0800 | [diff] [blame] | 521 | info->v4.reconnect = 1; |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 522 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 523 | #ifdef QSER_TEST |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 524 | //LOGE("[qser_data] IP: %x pri_DNS: %x sec_DNS: %x.", ipv4.IPAddr, ipv4.PrimaryDNS, ipv4.SecondaryDNS); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 525 | if(inet_ntop(AF_INET, &(info->v4.addr.ip), v4_buff, 32) == NULL) { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 526 | LOGE("[qser_data] IP error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 527 | } else { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 528 | LOGE("[qser_data] IP : %s", v4_buff); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 529 | } |
| 530 | if(inet_ntop(AF_INET, &(info->v4.addr.pri_dns), v4_buff, 32) == NULL) { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 531 | LOGE("[qser_data] PrimaryDNS error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 532 | } else { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 533 | LOGE("[qser_data] PrimaryDNS : %s", v4_buff); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 534 | } |
| 535 | if(inet_ntop(AF_INET, &(info->v4.addr.sec_dns), v4_buff, 32) == NULL) { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 536 | LOGE("[qser_data] SecondaryDNS error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 537 | } else { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 538 | LOGE("[qser_data] SecondaryDNS : %s", v4_buff); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 539 | } |
| 540 | #endif |
| 541 | } |
| 542 | |
| 543 | if(ipv6.valid) |
| 544 | { |
| 545 | info->ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 546 | info->v6.state = QSER_DATA_CALL_CONNECTED; |
| 547 | sprintf(info->v6.name, "ccinet%d", profile_idx); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 548 | memcpy(&(info->v6.addr.ip), &(ipv6.IPV6Addr), sizeof(ipv6.IPV6Addr)); |
| 549 | memcpy(&(info->v6.addr.pri_dns), &(ipv6.PrimaryDNS), sizeof(ipv6.PrimaryDNS)); |
| 550 | memcpy(&(info->v6.addr.sec_dns), &(ipv6.SecondaryDNS), sizeof(ipv6.SecondaryDNS)); |
liuyang | 7fc538e | 2024-08-14 10:29:26 +0800 | [diff] [blame] | 551 | info->v6.reconnect = 1; |
| 552 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 553 | #ifdef QSER_TEST |
| 554 | if(ipv6_2_str(&(info->v6.addr.ip), v6_buff)) |
| 555 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 556 | LOGE("[qser_data] IP error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 557 | } else { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 558 | LOGE("[qser_data] IP : %s", v6_buff); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 559 | } |
| 560 | if(ipv6_2_str(&(info->v6.addr.pri_dns), v6_buff)) |
| 561 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 562 | LOGE("[qser_data] PrimaryDNS error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 563 | } else { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 564 | LOGE("[qser_data] PrimaryDNS : %s", v6_buff); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 565 | } |
| 566 | if(ipv6_2_str(&(info->v6.addr.sec_dns), v6_buff)) |
| 567 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 568 | LOGE("[qser_data] SecondaryDNS error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 569 | } else { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 570 | LOGE("[qser_data] SecondaryDNS : %s", v6_buff); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 571 | } |
| 572 | #endif |
| 573 | } |
| 574 | |
| 575 | if(ipv4.valid && ipv6.valid) |
| 576 | { |
| 577 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 578 | } |
| 579 | |
| 580 | if(!ipv4.valid && !ipv6.valid) |
| 581 | { |
| 582 | info->v4.state = QSER_DATA_CALL_DISCONNECTED; |
| 583 | info->v6.state = QSER_DATA_CALL_DISCONNECTED; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | *err = QSER_DATA_CALL_ERROR_NONE; |
| 588 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | int qser_apn_set(qser_apn_info_s *apn) |
| 592 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 593 | //UNUSED(apn); |
| 594 | if(qser_info_handle == NULL) |
| 595 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 596 | LOGE("[qser_data] handle is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 597 | return QSER_RESULT_FAIL; |
| 598 | } |
| 599 | |
| 600 | if(apn == NULL) |
| 601 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 602 | LOGE("[qser_data] apn param is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 603 | return QSER_RESULT_FAIL; |
| 604 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 605 | |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 606 | int ret = 0; |
| 607 | mbtk_qser_apn_info_s apninfo; |
| 608 | memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s)); |
| 609 | apninfo.cid = apn->profile_idx + 1; |
| 610 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 611 | if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4) |
| 612 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 613 | apninfo.ip_type = MBTK_IP_TYPE_IP; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 614 | } |
| 615 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6) |
| 616 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 617 | apninfo.ip_type = MBTK_IP_TYPE_IPV6; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 618 | } |
| 619 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6) |
| 620 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 621 | apninfo.ip_type = MBTK_IP_TYPE_IPV4V6; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 622 | } |
| 623 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP) |
| 624 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 625 | apninfo.ip_type = MBTK_IP_TYPE_PPP; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 626 | } |
| 627 | else |
| 628 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 629 | LOGE("[qser_data] pdp_type error."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 630 | return QSER_RESULT_FAIL; |
| 631 | } |
| 632 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 633 | |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 634 | apninfo.req_type = MBTK_APN_REQ_TYPE_SET; |
| 635 | apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto; |
| 636 | if(strlen(apn->apn_name)) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 637 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 638 | memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name)); |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | LOGE("[qser_data] apn_name is NULL."); |
| 643 | return QSER_RESULT_FAIL; |
| 644 | } |
| 645 | if(strlen(apn->username)) |
| 646 | { |
| 647 | memcpy(apninfo.user_name, apn->username, strlen(apn->username)); |
| 648 | } |
| 649 | if(strlen(apn->password)) |
| 650 | { |
| 651 | memcpy(apninfo.user_pass, apn->password, strlen(apn->password)); |
| 652 | } |
| 653 | if(strlen(apn->apn_type)) |
| 654 | { |
| 655 | memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type)); |
| 656 | } |
| 657 | ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, NULL); |
| 658 | if(ret != 0) |
| 659 | { |
| 660 | LOGE("[qser_data] mbtk_qser_apn_set fail."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 661 | return QSER_RESULT_FAIL; |
| 662 | } |
| 663 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 664 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 668 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 669 | //UNUSED(profile_idx); |
| 670 | //UNUSED(apn); |
| 671 | if(qser_info_handle == NULL) |
| 672 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 673 | LOGE("[qser_data] handle is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 674 | return QSER_RESULT_FAIL; |
| 675 | } |
| 676 | |
| 677 | if(apn == NULL) |
| 678 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 679 | LOGE("[qser_data] apn param is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 680 | return QSER_RESULT_FAIL; |
| 681 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 682 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 683 | //get apn info |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 684 | mbtk_qser_apn_info_s apns[10] = {0}; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 685 | int apn_num = 10; |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 686 | int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 687 | if(ret != 0) |
| 688 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 689 | LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 690 | return QSER_RESULT_FAIL; |
| 691 | } |
| 692 | else |
| 693 | { |
| 694 | int i = 0; |
| 695 | for(i = 0; i < apn_num; i++) |
| 696 | { |
| 697 | if(apns[i].cid == profile_idx + 1) |
| 698 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 699 | LOGE("[qser_data] find IDX."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if(i == apn_num) |
| 705 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 706 | LOGE("[qser_data] not find IDX.[apn_num = %d]", apn_num); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 707 | return QSER_RESULT_FAIL; |
| 708 | } |
| 709 | |
| 710 | if(qser_apn_info_param_convert(profile_idx, apn, &apns[i]) != 0) |
| 711 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 712 | LOGE("[qser_data] qser_apn_info_param_convert fail"); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 713 | return QSER_RESULT_FAIL; |
| 714 | } |
| 715 | } |
| 716 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 720 | { |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 721 | //UNUSED(apn); |
| 722 | //UNUSED(profile_idx); |
| 723 | if(qser_info_handle == NULL) |
| 724 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 725 | LOGE("[qser_data] handle is NULL."); |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 726 | return QSER_RESULT_FAIL; |
| 727 | } |
| 728 | |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 729 | if(apn == NULL || profile_idx == NULL) |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 730 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 731 | LOGE("[qser_data] apn param is NULL."); |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 732 | return QSER_RESULT_FAIL; |
| 733 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 734 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 735 | int ret = 0; |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 736 | unsigned char idx[2] = {0}; |
| 737 | mbtk_qser_apn_info_s apninfo; |
| 738 | memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s)); |
| 739 | apninfo.cid = 0; |
| 740 | |
| 741 | if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4) |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 742 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 743 | apninfo.ip_type = MBTK_IP_TYPE_IP; |
| 744 | } |
| 745 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6) |
| 746 | { |
| 747 | apninfo.ip_type = MBTK_IP_TYPE_IPV6; |
| 748 | } |
| 749 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6) |
| 750 | { |
| 751 | apninfo.ip_type = MBTK_IP_TYPE_IPV4V6; |
| 752 | } |
| 753 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP) |
| 754 | { |
| 755 | apninfo.ip_type = MBTK_IP_TYPE_PPP; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 759 | LOGE("[qser_data] pdp_type error."); |
| 760 | return QSER_RESULT_FAIL; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 761 | } |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 762 | |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 763 | apninfo.req_type = MBTK_APN_REQ_TYPE_ADD; |
| 764 | apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto; |
| 765 | if(strlen(apn->apn_name)) |
| 766 | { |
| 767 | memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name)); |
| 768 | } |
liuyang | c328398 | 2024-06-04 17:00:15 +0800 | [diff] [blame] | 769 | |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 770 | if(strlen(apn->username)) |
| 771 | { |
| 772 | memcpy(apninfo.user_name, apn->username, strlen(apn->username)); |
| 773 | } |
| 774 | if(strlen(apn->password)) |
| 775 | { |
| 776 | memcpy(apninfo.user_pass, apn->password, strlen(apn->password)); |
| 777 | } |
| 778 | if(strlen(apn->apn_type)) |
| 779 | { |
| 780 | memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type)); |
| 781 | } |
| 782 | ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, idx); |
| 783 | if(ret != 0) |
| 784 | { |
| 785 | LOGE("[qser_data] mbtk_qser_apn_set fail."); |
| 786 | return QSER_RESULT_FAIL; |
| 787 | } |
| 788 | *profile_idx = idx[0] - 1; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 789 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | int qser_apn_del(unsigned char profile_idx) |
| 793 | { |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 794 | int ret = 0; |
| 795 | |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 796 | //UNUSED(profile_idx); |
| 797 | if(qser_info_handle == NULL) |
| 798 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 799 | LOGE("[qser_data] handle is NULL."); |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 800 | return QSER_RESULT_FAIL; |
| 801 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 802 | |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 803 | ret = mbtk_apn_del(qser_info_handle, profile_idx); |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 804 | if(ret < 0) |
| 805 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 806 | LOGE("[qser_data] mbtk_apn_del fail!"); |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 807 | return QSER_RESULT_FAIL; |
| 808 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 809 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 813 | { |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 814 | //UNUSED(apn_list); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 815 | |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 816 | if(qser_info_handle == NULL) |
| 817 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 818 | LOGE("[qser_data] handle is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 819 | return QSER_RESULT_FAIL; |
| 820 | } |
| 821 | |
| 822 | if(apn_list == NULL) |
| 823 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 824 | LOGE("[qser_data] apn_list param is NULL."); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 825 | return QSER_RESULT_FAIL; |
| 826 | } |
| 827 | |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 828 | mbtk_qser_apn_info_s apns[10] = {0}; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 829 | int apn_num = 10; |
wangyouqiang | 80487e4 | 2024-05-24 15:06:20 +0800 | [diff] [blame] | 830 | int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 831 | if(ret != 0) |
| 832 | { |
wangyouqiang | c1d72d2 | 2024-04-25 10:15:58 +0800 | [diff] [blame] | 833 | if(ret == MBTK_INFO_ERR_NO_APN) |
| 834 | { |
| 835 | apn_list->cnt = 0; |
| 836 | return QSER_RESULT_SUCCESS; |
| 837 | } |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 838 | LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 839 | return QSER_RESULT_FAIL; |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | if(apn_num > 0 && apn_num <= QSER_APN_MAX_LIST) |
| 844 | { |
| 845 | int i = 0; |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 846 | apn_list->cnt = 0; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 847 | for(i = 0; i < apn_num; i++) |
| 848 | { |
wangyouqiang | 8ebeafe | 2024-04-15 10:07:44 +0800 | [diff] [blame] | 849 | if(qser_apn_info_param_convert(apns[i].cid - 1, &apn_list->apn[apn_list->cnt], &apns[i]) != 0) |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 850 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 851 | LOGE("[qser_data] qser_apn_info_param_convert fail"); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 852 | return QSER_RESULT_FAIL; |
| 853 | } |
wangyouqiang | e2498f1 | 2024-01-06 17:55:36 +0800 | [diff] [blame] | 854 | apn_list->cnt++; |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 855 | } |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 856 | } |
| 857 | else if(apn_num > QSER_APN_MAX_LIST) |
| 858 | { |
wangyouqiang | c42b85d | 2024-04-24 17:05:06 +0800 | [diff] [blame] | 859 | LOGE("[qser_data] apn_num overlong"); |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 860 | return QSER_RESULT_FAIL; |
| 861 | } |
| 862 | else |
| 863 | { |
| 864 | apn_list->cnt = 0; |
| 865 | } |
| 866 | } |
| 867 | return QSER_RESULT_SUCCESS; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 868 | } |
wangyouqiang | 84179c8 | 2024-01-05 15:42:55 +0800 | [diff] [blame] | 869 | /****************************API***************************************/ |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 870 | |