liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <errno.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <sys/un.h> |
| 7 | #include <netinet/in.h> |
| 8 | #include <pthread.h> |
| 9 | #include <sys/epoll.h> |
| 10 | #include <fcntl.h> |
| 11 | #include <signal.h> |
| 12 | #include <cutils/properties.h> |
| 13 | |
| 14 | #include "mbtk_type.h" |
| 15 | #include "mbtk_info.h" |
| 16 | #include "mbtk_queue.h" |
| 17 | #include "atchannel.h" |
| 18 | #include "at_tok.h" |
| 19 | #include "mbtk_utils.h" |
| 20 | #include "mbtk_ifc.h" |
| 21 | #include "info_data.h" |
wangyouqiang | 38e5336 | 2024-01-23 10:53:48 +0800 | [diff] [blame] | 22 | #include "mbtk_led.h" |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 23 | #include "cust_info.h" |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 24 | #include "mbtk_device.h" |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 25 | |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 26 | typedef struct { |
| 27 | bool band_set_success; |
| 28 | |
| 29 | mbtk_modem_band_area_enum band_area; |
| 30 | uint32 band_gsm; |
| 31 | uint32 band_wcdma; |
| 32 | uint32 band_tdlte; |
| 33 | uint32 band_fddlte; |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame^] | 34 | uint32 band_lte_ext; |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 35 | } band_set_info_t; |
| 36 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 37 | static int sock_listen_fd = -1; |
| 38 | static int epoll_fd = -1; |
| 39 | static list_node_t *sock_client_list = NULL; |
| 40 | static mbtk_queue_node_t info_queue; |
| 41 | static pthread_cond_t info_cond; |
| 42 | static pthread_mutex_t info_mutex; |
| 43 | static mbtk_queue_node_t urc_queue; |
| 44 | static pthread_cond_t urc_cond; |
| 45 | static pthread_mutex_t urc_mutex; |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 46 | static band_set_info_t band_set_info; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 47 | |
| 48 | static mbtk_band_info_t band_support; |
| 49 | net_info_t net_info; |
| 50 | mbtK_cell_pack_info_t cell_info; |
| 51 | info_cgact_wait_t cgact_wait; |
| 52 | static int cid_active[MBTK_APN_CID_MAX + 1] = {0}; |
| 53 | bool at_process = false; |
| 54 | //mbtk wyq for data_call_ex add start |
| 55 | // |2----7| |
| 56 | //"00000000"+'\0' |
| 57 | static char cid_bootconn[MBTK_APN_CID_MAX + 2] = {0}; |
| 58 | #define DATA_CALL_BOOTCONN_FD 0x5f6f7f8f |
| 59 | //mbtk wyq for data_call_ex add end |
| 60 | |
| 61 | //mbtk wyq for server_ready_status add start |
| 62 | static char server_ready_status = 0; |
| 63 | //mbtk wyq for server_ready_status add end |
| 64 | |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 65 | static mbtk_signal_info_t signal_globe; |
| 66 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | AT*POWERIND=0" |
| 70 | or |
| 71 | AT*POWERIND=1~31" |
| 72 | |
| 73 | OK |
| 74 | |
| 75 | AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报, |
| 76 | 其中PS DATA目前暂时不支持,只是保留了这个标志位,0 means resume all. |
| 77 | |
| 78 | AP power state: 1~31 means suspend, |
| 79 | bitmap: |
| 80 | bit0 - NETWORK; |
| 81 | bit1 - SIM; |
| 82 | bit2 - SMS; |
| 83 | bit3 - CS CALL |
| 84 | bit4 - PS DATA |
| 85 | |
| 86 | */ |
| 87 | static int req_powerind_set(uint32 state, int *cme_err) |
| 88 | { |
| 89 | ATResponse *response = NULL; |
| 90 | char cmd[100] = {0}; |
| 91 | |
| 92 | if (state >= 0 && state < 32) |
| 93 | { |
| 94 | sprintf(cmd, "AT*POWERIND=%d", state); |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 95 | LOG("Set the powerind command is = [%s]\n", cmd); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 96 | } |
| 97 | int err = at_send_command(cmd, &response); |
| 98 | if (err < 0 || response->success == 0){ |
| 99 | *cme_err = at_get_cme_error(response); |
| 100 | goto exit; |
| 101 | } |
| 102 | |
| 103 | exit: |
| 104 | at_response_free(response); |
| 105 | return err; |
| 106 | } |
| 107 | |
| 108 | /* |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 109 | AT+OOSPP=1 |
| 110 | or |
| 111 | AT+OOSPP=0 |
| 112 | or |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 113 | AT+OOSPP=1,20,30,40 //AtOospp() |
| 114 | param1:mode |
| 115 | param2:oosPhasePeriod[0] //5 times, 5s by default; |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 116 | param3:oosPhasePeriod[1] //5 times, 10s by default; |
| 117 | param4:oosPhasePeriod[2] //unlimited, 20s by default; |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 118 | |
| 119 | |
| 120 | BTW |
| 121 | 1, 如果只输入mode=1,其余参数不设置,相当于这个功能打开,时间间隔是这个功能的默认值。 |
| 122 | 2, 如果当mode=1加上其余设置参数后,功能打开,时间间隔是本次设置的值; |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 123 | 3,如果再设置mode=0,相当于这个功能关闭,是走平台自己另一套的搜网设置。 |
| 124 | 平台本身是有一套间隔搜网,也有历史频点优先处理的逻辑(不需要我们进行处理), |
| 125 | 提供给我们的AT+OOSPP指令是让我们可以自定义搜网间隔 |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 126 | */ |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 127 | static int req_oos_set(mbtk_oos_info* state, int *cme_err) |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 128 | { |
| 129 | ATResponse *response = NULL; |
| 130 | char cmd[100] = {0}; |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 131 | |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 132 | if ((state->mode == 1 && state->oosPhase[0] == 0 && state->oosPhase[1] == 0 && state->oosPhase[2] == 0) \ |
| 133 | || state->mode == 0) |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 134 | { |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 135 | sprintf(cmd, "AT+OOSPP=%d", state->mode);//只有一个值0/1 |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 136 | } |
| 137 | else |
| 138 | { |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 139 | if ((state->oosPhase[0] != 0) && (state->oosPhase[1] != 0) && (state->oosPhase[2] != 0)) |
| 140 | { |
| 141 | sprintf(cmd, "AT+OOSPP=%d,%d,%d,%d", state->mode, state->oosPhase[0], state->oosPhase[1], state->oosPhase[2]); |
| 142 | } |
| 143 | else if ((state->oosPhase[0] != 0) && (state->oosPhase[1] != 0) && (state->oosPhase[2] == 0)) |
| 144 | { |
| 145 | sprintf(cmd, "AT+OOSPP=%d,%d,%d", state->mode, state->oosPhase[0], state->oosPhase[1]); |
| 146 | } |
| 147 | else if ((state->oosPhase[0] != 0) && (state->oosPhase[1] == 0) && (state->oosPhase[2] == 0)) |
| 148 | { |
| 149 | sprintf(cmd, "AT+OOSPP=%d,%d", state->mode, state->oosPhase[0]); |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | LOG("AT+OOSPP SET ERR"); |
| 154 | goto exit; |
| 155 | } |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 156 | } |
| 157 | |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 158 | LOG("Set the oos command is = [%s]\n", cmd); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 159 | int err = at_send_command(cmd, &response); |
| 160 | if (err < 0 || response->success == 0){ |
| 161 | *cme_err = at_get_cme_error(response); |
| 162 | goto exit; |
| 163 | } |
| 164 | |
| 165 | exit: |
| 166 | at_response_free(response); |
| 167 | return err; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | /* |
| 172 | AT+OOSPP? |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 173 | 开(默认值): |
| 174 | +OOSPP:5,10,20 |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 175 | 关: |
| 176 | +OOSPP:0 |
| 177 | */ |
| 178 | static int req_oos_get(mbtk_oos_info *req, int *cme_err) |
| 179 | { |
| 180 | ATResponse *response = NULL; |
| 181 | |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 182 | int err = at_send_command_singleline("AT+OOSPP?", "+OOSPP:", &response); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 183 | |
| 184 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 185 | *cme_err = at_get_cme_error(response); |
| 186 | goto exit; |
| 187 | } |
| 188 | |
| 189 | char *line = response->p_intermediates->line; |
| 190 | |
| 191 | char *tmp_str = NULL; |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 192 | err = at_tok_start(&line);//+OOSPP:10,15,20,过滤+OOSPP: |
| 193 | if (err < 0) |
| 194 | { |
| 195 | goto exit; |
| 196 | } |
| 197 | |
| 198 | //LOG("req_oos_get =[%s]",line); |
| 199 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 200 | err = at_tok_nextstr(&line, &tmp_str); |
| 201 | if (err < 0) |
| 202 | { |
| 203 | goto exit; |
| 204 | } |
| 205 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 206 | int mode = atoi(tmp_str); |
| 207 | if (mode == 0)//关闭状态 |
| 208 | { |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 209 | req->mode = mode; |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 210 | } |
| 211 | else//开状态 |
| 212 | { |
| 213 | req->mode = 1; |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 214 | //LOG("tmp_str =[%s]",tmp_str); |
| 215 | req->oosPhase[0] = atoi(tmp_str); |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 216 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 217 | err = at_tok_nextstr(&line, &tmp_str); |
| 218 | if (err < 0) |
| 219 | { |
| 220 | goto exit; |
| 221 | } |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 222 | //LOG("tmp_str =[%s]",tmp_str); |
| 223 | req->oosPhase[1] = atoi(tmp_str); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 224 | |
| 225 | err = at_tok_nextstr(&line, &tmp_str); |
| 226 | if (err < 0) |
| 227 | { |
| 228 | goto exit; |
| 229 | } |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 230 | //LOG("tmp_str =[%s]",tmp_str); |
| 231 | req->oosPhase[2] = atoi(tmp_str); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 232 | } |
| 233 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 234 | exit: |
| 235 | at_response_free(response); |
| 236 | return err; |
| 237 | } |
| 238 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 239 | static void sock_cli_free_func(void *data) |
| 240 | { |
| 241 | if (data) |
| 242 | { |
| 243 | sock_client_info_t *info = (sock_client_info_t*) data; |
| 244 | LOG("Free Socket client[fd = %d].", info->fd); |
| 245 | free(info); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | static void cli_close(sock_client_info_t* client) |
| 250 | { |
| 251 | struct epoll_event ev; |
| 252 | memset(&ev,0,sizeof(struct epoll_event)); |
| 253 | ev.data.fd = client->fd; |
| 254 | ev.events = EPOLLIN | EPOLLERR | EPOLLET; |
| 255 | epoll_ctl(epoll_fd, EPOLL_CTL_DEL, client->fd, &ev); |
| 256 | |
| 257 | close(client->fd); |
| 258 | |
| 259 | if(list_remove(sock_client_list, client)) |
| 260 | { |
| 261 | sock_cli_free_func(client); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | static void pack_error_send(int fd, int info_id, int err) |
| 266 | { |
| 267 | mbtk_info_pack_t* pack = mbtk_info_pack_creat(info_id); |
| 268 | if(pack) |
| 269 | { |
| 270 | pack->info_err = (uint16)err; |
| 271 | mbtk_info_pack_send(fd, pack); |
| 272 | mbtk_info_pack_free(&pack); |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | LOG("mbtk_info_pack_creat() fail."); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void pack_rsp_send(int fd, int info_id, const void* data, int data_len) |
| 281 | { |
| 282 | mbtk_info_pack_t* pack = mbtk_info_pack_creat(info_id); |
| 283 | if(pack) |
| 284 | { |
| 285 | pack->info_err = (uint16)MBTK_INFO_ERR_SUCCESS; |
| 286 | if(data != NULL && data_len > 0) |
| 287 | { |
| 288 | //mbtk_info_pack_data_set(pack, data, data_len); |
| 289 | pack->data_len = (uint16)data_len; |
| 290 | pack->data = (const uint8*)data; |
| 291 | } |
| 292 | mbtk_info_pack_send(fd, pack); |
| 293 | mbtk_info_pack_free(&pack); |
| 294 | } |
| 295 | else |
| 296 | { |
| 297 | LOG("mbtk_info_pack_creat() fail."); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | static int apn_prop_set(mbtk_apn_info_t *apn) |
| 302 | { |
| 303 | char prop_name[20] = {0}; |
| 304 | char prop_data[300] = {0}; |
| 305 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,apn->cid); |
| 306 | snprintf(prop_data, 300, "%d,%s,%s,%s,%s", apn->ip_type, apn->apn, |
| 307 | str_empty(apn->user) ? "NULL" : apn->user, |
| 308 | str_empty(apn->pass) ? "NULL" : apn->pass, |
| 309 | str_empty(apn->auth) ? "NULL" : apn->auth); |
| 310 | |
| 311 | return property_set(prop_name, prop_data); |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | AT*BAND=? |
| 316 | *BAND:(0-18),79,147,482,524503 |
| 317 | |
| 318 | |
| 319 | OK |
| 320 | |
| 321 | AT*BAND=15,78,147,482,134742231 |
| 322 | |
| 323 | |
| 324 | */ |
| 325 | static void band_support_get() |
| 326 | { |
| 327 | // Support band has get. |
| 328 | if(band_support.net_pref != 0xFF) { |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | #if 1 |
| 333 | // 79,147,482,524503 |
| 334 | band_support.gsm_band = (uint16)79; |
| 335 | band_support.umts_band = (uint16)147; |
| 336 | band_support.tdlte_band = (uint32)482; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 337 | band_support.fddlte_band = (uint32)134742231; |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 338 | //band_support.fddlte_band = (uint32)524503; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 339 | band_support.net_pref = (uint8)0; |
| 340 | #else |
| 341 | ATResponse *response = NULL; |
| 342 | int tmp_int; |
| 343 | char *tmp_str; |
| 344 | int err = at_send_command_singleline("AT*BAND=?", "*BAND:", &response); |
| 345 | |
| 346 | if (err < 0 || response->success == 0 || !response->p_intermediates) |
| 347 | goto exit; |
| 348 | |
| 349 | char *line = response->p_intermediates->line; |
| 350 | err = at_tok_start(&line); |
| 351 | if (err < 0) |
| 352 | { |
| 353 | goto exit; |
| 354 | } |
| 355 | |
| 356 | err = at_tok_nextstr(&line, &tmp_str); |
| 357 | if (err < 0) |
| 358 | { |
| 359 | goto exit; |
| 360 | } |
| 361 | |
| 362 | err = at_tok_nextint(&line, &tmp_int); |
| 363 | if (err < 0) |
| 364 | { |
| 365 | goto exit; |
| 366 | } |
| 367 | band_support.gsm_band = (uint16)tmp_int; |
| 368 | |
| 369 | err = at_tok_nextint(&line, &tmp_int); |
| 370 | if (err < 0) |
| 371 | { |
| 372 | goto exit; |
| 373 | } |
| 374 | band_support.umts_band = (uint16)tmp_int; |
| 375 | |
| 376 | err = at_tok_nextint(&line, &tmp_int); |
| 377 | if (err < 0) |
| 378 | { |
| 379 | goto exit; |
| 380 | } |
| 381 | band_support.tdlte_band = (uint32)tmp_int; |
| 382 | |
| 383 | err = at_tok_nextint(&line, &tmp_int); |
| 384 | if (err < 0) |
| 385 | { |
| 386 | goto exit; |
| 387 | } |
| 388 | band_support.fddlte_band = (uint32)tmp_int; |
| 389 | band_support.net_pref = (uint8)0; |
| 390 | exit: |
| 391 | at_response_free(response); |
| 392 | #endif |
| 393 | } |
| 394 | |
| 395 | static int parseRegistrationState(char *str, int *items, int **response) |
| 396 | { |
| 397 | int err; |
| 398 | char *line = str, *p; |
| 399 | int *resp = NULL; |
| 400 | int skip; |
| 401 | int commas; |
| 402 | |
| 403 | LOGD("parseRegistrationState. Parsing: %s",str); |
| 404 | err = at_tok_start(&line); |
| 405 | if (err < 0) goto error; |
| 406 | |
| 407 | /* Ok you have to be careful here |
| 408 | * The solicited version of the CREG response is |
| 409 | * +CREG: n, stat, [lac, cid] |
| 410 | * and the unsolicited version is |
| 411 | * +CREG: stat, [lac, cid] |
| 412 | * The <n> parameter is basically "is unsolicited creg on?" |
| 413 | * which it should always be |
| 414 | * |
| 415 | * Now we should normally get the solicited version here, |
| 416 | * but the unsolicited version could have snuck in |
| 417 | * so we have to handle both |
| 418 | * |
| 419 | * Also since the LAC and CID are only reported when registered, |
| 420 | * we can have 1, 2, 3, or 4 arguments here |
| 421 | * |
| 422 | * finally, a +CGREG: answer may have a fifth value that corresponds |
| 423 | * to the network type, as in; |
| 424 | * |
| 425 | * +CGREG: n, stat [,lac, cid [,networkType]] |
| 426 | */ |
| 427 | |
| 428 | /* count number of commas */ |
| 429 | commas = 0; |
| 430 | for (p = line ; *p != '\0' ; p++) |
| 431 | { |
| 432 | if (*p == ',') commas++; |
| 433 | } |
| 434 | |
| 435 | resp = (int *)calloc(commas + 1, sizeof(int)); |
| 436 | if (!resp) goto error; |
| 437 | switch (commas) |
| 438 | { |
| 439 | case 0: /* +CREG: <stat> */ |
| 440 | err = at_tok_nextint(&line, &resp[0]); |
| 441 | if (err < 0) goto error; |
| 442 | //resp[1] = -1; |
| 443 | //resp[2] = -1; |
| 444 | break; |
| 445 | |
| 446 | case 1: /* +CREG: <n>, <stat> */ |
| 447 | err = at_tok_nextint(&line, &skip); |
| 448 | if (err < 0) goto error; |
| 449 | err = at_tok_nextint(&line, &resp[0]); |
| 450 | if (err < 0) goto error; |
| 451 | resp[1] = -1; |
| 452 | //resp[2] = -1; |
| 453 | if (err < 0) goto error; |
| 454 | break; |
| 455 | |
| 456 | case 2: /* +CREG: <stat>, <lac>, <cid> */ |
| 457 | err = at_tok_nextint(&line, &resp[0]); |
| 458 | if (err < 0) goto error; |
| 459 | err = at_tok_nexthexint(&line, &resp[1]); |
| 460 | if (err < 0) goto error; |
| 461 | err = at_tok_nexthexint(&line, &resp[2]); |
| 462 | if (err < 0) goto error; |
| 463 | break; |
| 464 | case 3: /* +CREG: <n>, <stat>, <lac>, <cid> */ |
| 465 | /* +CEREG: 1,"8330","06447340",7 */ |
| 466 | #if 0 |
| 467 | err = at_tok_nextint(&line, &skip); |
| 468 | if (err < 0) goto error; |
| 469 | err = at_tok_nextint(&line, &resp[0]); |
| 470 | if (err < 0) goto error; |
| 471 | err = at_tok_nexthexint(&line, &resp[1]); |
| 472 | if (err < 0) goto error; |
| 473 | err = at_tok_nexthexint(&line, &resp[2]); |
| 474 | if (err < 0) goto error; |
| 475 | #else |
| 476 | err = at_tok_nextint(&line, &resp[0]); |
| 477 | if (err < 0) goto error; |
| 478 | err = at_tok_nextint(&line, &resp[1]); |
| 479 | if (err < 0) goto error; |
| 480 | err = at_tok_nexthexint(&line, &resp[2]); |
| 481 | if (err < 0) goto error; |
| 482 | err = at_tok_nextint(&line, &resp[3]); |
| 483 | if (err < 0) goto error; |
| 484 | #endif |
| 485 | break; |
| 486 | /* special case for CGREG, there is a fourth parameter |
| 487 | * that is the network type (unknown/gprs/edge/umts) |
| 488 | */ |
| 489 | case 4: /* +CGREG: <n>, <stat>, <lac>, <cid>, <networkType> */ |
| 490 | /* +CEREG: 2,1,"8330","06447340",7 */ |
| 491 | err = at_tok_nextint(&line, &skip); |
| 492 | if (err < 0) goto error; |
| 493 | err = at_tok_nextint(&line, &resp[0]); |
| 494 | if (err < 0) goto error; |
| 495 | err = at_tok_nexthexint(&line, &resp[1]); |
| 496 | if (err < 0) goto error; |
| 497 | err = at_tok_nexthexint(&line, &resp[2]); |
| 498 | if (err < 0) goto error; |
| 499 | err = at_tok_nexthexint(&line, &resp[3]); |
| 500 | if (err < 0) goto error; |
| 501 | break; |
| 502 | default: |
| 503 | goto error; |
| 504 | } |
| 505 | /* |
| 506 | if(commas > 1) { |
| 507 | s_lac = resp[1]; |
| 508 | s_cid = resp[2]; |
| 509 | }*/ |
| 510 | if (response) |
| 511 | *response = resp; |
| 512 | if (items) |
| 513 | *items = commas + 1; |
| 514 | return 0; |
| 515 | error: |
| 516 | free(resp); |
| 517 | return -1; |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | 0: minimum functionality |
| 522 | 1: full functionality |
| 523 | 3: disable phone receive RF circuits. |
| 524 | 4: disable phone both transmit and receive RF circuits |
| 525 | 5: disable SIM |
| 526 | 6: turn off full secondary receive. |
| 527 | -1: fail |
| 528 | */ |
| 529 | static int isRadioOn() |
| 530 | { |
| 531 | ATResponse *p_response = NULL; |
| 532 | int err; |
| 533 | char *line; |
| 534 | int ret; |
| 535 | |
| 536 | err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &p_response); |
| 537 | |
| 538 | if (err < 0 || p_response->success == 0 || !p_response->p_intermediates) |
| 539 | { |
| 540 | // assume radio is off |
| 541 | goto error; |
| 542 | } |
| 543 | |
| 544 | line = p_response->p_intermediates->line; |
| 545 | |
| 546 | err = at_tok_start(&line); |
| 547 | if (err < 0) goto error; |
| 548 | |
| 549 | err = at_tok_nextint(&line, &ret); |
| 550 | if (err < 0) goto error; |
| 551 | |
| 552 | at_response_free(p_response); |
| 553 | |
| 554 | if(ret == 1) { |
| 555 | net_info.radio_state = MBTK_RADIO_STATE_ON; |
| 556 | } else { |
| 557 | net_info.radio_state = MBTK_RADIO_STATE_OFF; |
| 558 | } |
| 559 | |
| 560 | return ret; |
| 561 | |
| 562 | error: |
| 563 | |
| 564 | at_response_free(p_response); |
| 565 | return -1; |
| 566 | } |
| 567 | |
| 568 | /** Returns SIM_NOT_READY on error */ |
| 569 | static mbtk_sim_state_enum getSIMStatus() |
| 570 | { |
| 571 | ATResponse *p_response = NULL; |
| 572 | int err; |
| 573 | mbtk_sim_state_enum ret; |
| 574 | char *cpinLine; |
| 575 | char *cpinResult; |
| 576 | |
| 577 | err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &p_response); |
| 578 | |
| 579 | if (err < 0 || p_response->success == 0 || !p_response->p_intermediates) |
| 580 | { |
| 581 | ret = MBTK_SIM_NOT_READY; |
| 582 | goto done; |
| 583 | } |
| 584 | |
| 585 | switch (at_get_cme_error(p_response)) |
| 586 | { |
| 587 | case CME_SUCCESS: |
| 588 | break; |
| 589 | |
| 590 | case CME_SIM_NOT_INSERTED: |
| 591 | ret = MBTK_SIM_ABSENT; |
| 592 | goto done; |
| 593 | |
| 594 | default: |
| 595 | ret = MBTK_SIM_NOT_READY; |
| 596 | goto done; |
| 597 | } |
| 598 | |
| 599 | /* CPIN? has succeeded, now look at the result */ |
| 600 | |
| 601 | cpinLine = p_response->p_intermediates->line; |
| 602 | err = at_tok_start (&cpinLine); |
| 603 | |
| 604 | if (err < 0) |
| 605 | { |
| 606 | ret = MBTK_SIM_NOT_READY; |
| 607 | goto done; |
| 608 | } |
| 609 | |
| 610 | err = at_tok_nextstr(&cpinLine, &cpinResult); |
| 611 | |
| 612 | if (err < 0) |
| 613 | { |
| 614 | ret = MBTK_SIM_NOT_READY; |
| 615 | goto done; |
| 616 | } |
| 617 | |
| 618 | if (0 == strcmp (cpinResult, "SIM PIN")) |
| 619 | { |
| 620 | ret = MBTK_SIM_PIN; |
| 621 | goto done; |
| 622 | } |
| 623 | else if (0 == strcmp (cpinResult, "SIM PUK")) |
| 624 | { |
| 625 | ret = MBTK_SIM_PUK; |
| 626 | goto done; |
| 627 | } |
| 628 | else if (0 == strcmp (cpinResult, "PH-NET PIN")) |
| 629 | { |
| 630 | return MBTK_SIM_NETWORK_PERSONALIZATION; |
| 631 | } |
| 632 | else if (0 != strcmp (cpinResult, "READY")) |
| 633 | { |
| 634 | /* we're treating unsupported lock types as "sim absent" */ |
| 635 | ret = MBTK_SIM_ABSENT; |
| 636 | goto done; |
| 637 | } |
| 638 | |
| 639 | at_response_free(p_response); |
| 640 | p_response = NULL; |
| 641 | cpinResult = NULL; |
| 642 | |
| 643 | // ret = net_info.radio_state == MBTK_RADIO_STATE_ON ? MBTK_SIM_READY : MBTK_SIM_NOT_READY; |
| 644 | net_info.sim_state = MBTK_SIM_READY; |
| 645 | return MBTK_SIM_READY; |
| 646 | done: |
| 647 | at_response_free(p_response); |
| 648 | net_info.sim_state = ret; |
| 649 | return ret; |
| 650 | } |
| 651 | |
| 652 | void setRadioPower(int isOn) |
| 653 | { |
| 654 | int err; |
| 655 | ATResponse *p_response = NULL; |
| 656 | |
| 657 | LOGI("RadioPower - %s", isOn == 0 ? "OFF" : "ON"); |
| 658 | |
| 659 | if(isOn == 0 && net_info.radio_state == MBTK_RADIO_STATE_ON) |
| 660 | { |
| 661 | err = at_send_command("AT+CFUN=0", &p_response); |
| 662 | if (err || !p_response->success) |
| 663 | goto error; |
| 664 | |
| 665 | net_info.radio_state = MBTK_RADIO_STATE_OFF; |
| 666 | } |
| 667 | else if(isOn && net_info.radio_state != MBTK_RADIO_STATE_ON) |
| 668 | { |
| 669 | err = at_send_command("AT+CFUN=1", &p_response); |
| 670 | if (err || !p_response->success) |
| 671 | { |
| 672 | if(isRadioOn() == 1) |
| 673 | { |
| 674 | net_info.radio_state = MBTK_RADIO_STATE_ON; |
| 675 | } |
| 676 | goto error; |
| 677 | } |
| 678 | |
| 679 | net_info.radio_state = MBTK_RADIO_STATE_ON; |
| 680 | } |
| 681 | |
| 682 | at_response_free(p_response); |
| 683 | return; |
| 684 | error: |
| 685 | at_response_free(p_response); |
| 686 | } |
| 687 | |
| 688 | static int apn_user_pass_set_by_cid(int cid, mbtk_apn_info_t *apn) |
| 689 | { |
| 690 | char prop_name[20] = {0}; |
| 691 | char prop_data[300] = {0}; |
| 692 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid); |
| 693 | if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 694 | char apn_name[128] = {0}; |
| 695 | char *ptr_1 = prop_data; |
| 696 | mbtk_ip_type_enum ip_type = (mbtk_ip_type_enum)atoi(ptr_1); |
| 697 | ptr_1 = strstr(ptr_1, ","); |
| 698 | if(!ptr_1) { |
| 699 | return -1; |
| 700 | } |
| 701 | ptr_1++; // Jump ',' to apn |
| 702 | |
| 703 | char *ptr_2 = strstr(ptr_1, ","); |
| 704 | if(!ptr_2) { |
| 705 | return -1; |
| 706 | } |
| 707 | memcpy(apn_name, ptr_1, ptr_2 - ptr_1); // apn |
| 708 | |
| 709 | // Check ip_type and apn_name |
| 710 | if(ip_type != apn->ip_type || strcmp(apn_name, apn->apn)) { |
| 711 | LOGD("APN Changed, not get user/pass/auth."); |
| 712 | return -1; |
| 713 | } |
| 714 | |
| 715 | ptr_2++; // Jump ',' to user |
| 716 | ptr_1 = strstr(ptr_2, ","); |
| 717 | if(!ptr_1) { |
| 718 | return -1; |
| 719 | } |
| 720 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 721 | memcpy(apn->user, ptr_2, ptr_1 - ptr_2); // user |
| 722 | } |
| 723 | |
| 724 | ptr_1++; // Jump ',' to pass |
| 725 | ptr_2 = strstr(ptr_1, ","); |
| 726 | if(!ptr_2) { |
| 727 | return -1; |
| 728 | } |
| 729 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 730 | memcpy(apn->pass, ptr_1, ptr_2 - ptr_1); // pass |
| 731 | } |
| 732 | |
| 733 | ptr_2++; // Jump ',' to auth (Is last item) |
| 734 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 735 | memcpy(apn->auth, ptr_2, strlen(ptr_2)); // auth |
| 736 | } |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | return -1; |
| 741 | } |
| 742 | |
| 743 | |
| 744 | /* |
| 745 | AT+CPOL? |
| 746 | *EUICC: 1 |
| 747 | |
| 748 | OK |
| 749 | */ |
| 750 | static int req_plmn_get(mbtk_plmn_info *type, int *cme_err) |
| 751 | { |
| 752 | ATResponse *response = NULL; |
| 753 | char *tmp_ptr = NULL; |
| 754 | int err = at_send_command_multiline("AT+CPOL?", "+CPOL:", &response); |
| 755 | |
| 756 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 757 | *cme_err = at_get_cme_error(response); |
| 758 | goto exit; |
| 759 | } |
| 760 | |
| 761 | int mccmnc_type = -1; |
| 762 | int count = -1; |
| 763 | char *mccmnc_name = NULL; |
| 764 | ATLine* lines_ptr = response->p_intermediates; |
| 765 | char *line = NULL; |
| 766 | while(lines_ptr) |
| 767 | { |
| 768 | line = lines_ptr->line; |
| 769 | //if(strStartsWith(line, "+CPOL:")) |
| 770 | { |
| 771 | err = at_tok_start(&line); |
| 772 | if (err < 0) |
| 773 | { |
| 774 | goto exit; |
| 775 | } |
| 776 | err = at_tok_nextint(&line, &count); |
| 777 | if (err < 0) |
| 778 | { |
| 779 | goto exit; |
| 780 | } |
| 781 | type->count = count; |
| 782 | |
| 783 | err = at_tok_nextint(&line, &mccmnc_type); |
| 784 | if (err < 0) |
| 785 | { |
| 786 | goto exit; |
| 787 | } |
| 788 | type->mbtk_plmn_name[count-1].format = mccmnc_type; |
| 789 | |
| 790 | err = at_tok_nextstr(&line, &mccmnc_name); |
| 791 | if (err < 0) |
| 792 | { |
| 793 | goto exit; |
| 794 | } |
| 795 | memcpy(type->mbtk_plmn_name[count-1].plmn_name, mccmnc_name, strlen(mccmnc_name)); |
| 796 | mccmnc_name = NULL; |
| 797 | } |
| 798 | lines_ptr = lines_ptr->p_next; |
| 799 | } |
| 800 | |
| 801 | exit: |
| 802 | at_response_free(response); |
| 803 | return err; |
| 804 | } |
| 805 | |
| 806 | |
| 807 | /* |
| 808 | AT*EUICC? |
| 809 | *EUICC: 1 |
| 810 | |
| 811 | OK |
| 812 | */ |
| 813 | static int req_sim_card_type_get(uint8 *type, int *cme_err) |
| 814 | { |
| 815 | ATResponse *response = NULL; |
| 816 | char *tmp_ptr = NULL; |
| 817 | int err = at_send_command_singleline("AT*EUICC?", "*EUICC:", &response); |
| 818 | |
| 819 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 820 | *cme_err = at_get_cme_error(response); |
| 821 | goto exit; |
| 822 | } |
| 823 | |
| 824 | char *line = response->p_intermediates->line; |
| 825 | err = at_tok_start(&line); |
| 826 | if (err < 0) |
| 827 | { |
| 828 | goto exit; |
| 829 | } |
| 830 | int sim_card_type = -1; |
| 831 | err = at_tok_nextint(&line, &sim_card_type); |
| 832 | if (err < 0) |
| 833 | { |
| 834 | goto exit; |
| 835 | } |
| 836 | if(sim_card_type != -1) |
| 837 | *type = sim_card_type; |
| 838 | goto exit; |
| 839 | exit: |
| 840 | at_response_free(response); |
| 841 | return err; |
| 842 | } |
| 843 | |
| 844 | /* |
| 845 | AT+EPIN? |
| 846 | +EPIN: 3,0,10,0 |
| 847 | |
| 848 | OK |
| 849 | */ |
| 850 | static int req_pin_puk_last_times_get(mbtk_pin_puk_last_times *times, int *cme_err) |
| 851 | { |
| 852 | ATResponse *response = NULL; |
| 853 | char *tmp_ptr = NULL; |
| 854 | int err = at_send_command_singleline("AT+EPIN?", "+EPIN:", &response); |
| 855 | |
| 856 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 857 | *cme_err = at_get_cme_error(response); |
| 858 | goto exit; |
| 859 | } |
| 860 | |
| 861 | char *line = response->p_intermediates->line; |
| 862 | err = at_tok_start(&line); |
| 863 | if (err < 0) |
| 864 | { |
| 865 | goto exit; |
| 866 | } |
| 867 | mbtk_pin_puk_last_times last_times={0}; |
| 868 | err = at_tok_nextint(&line, &(last_times.p1_retry)); |
| 869 | if (err < 0) |
| 870 | { |
| 871 | goto exit; |
| 872 | } |
| 873 | times->p1_retry = last_times.p1_retry; |
| 874 | err = at_tok_nextint(&line, &(last_times.p2_retry)); |
| 875 | if (err < 0) |
| 876 | { |
| 877 | goto exit; |
| 878 | } |
| 879 | times->p2_retry = last_times.p2_retry; |
| 880 | err = at_tok_nextint(&line, &(last_times.puk1_retry)); |
| 881 | if (err < 0) |
| 882 | { |
| 883 | goto exit; |
| 884 | } |
| 885 | times->puk1_retry = last_times.puk1_retry; |
| 886 | err = at_tok_nextint(&line, &(last_times.puk2_retry)); |
| 887 | if (err < 0) |
| 888 | { |
| 889 | goto exit; |
| 890 | } |
| 891 | times->puk2_retry = last_times.puk2_retry; |
| 892 | |
| 893 | exit: |
| 894 | at_response_free(response); |
| 895 | return err; |
| 896 | } |
| 897 | |
| 898 | |
| 899 | /* |
| 900 | AT+CGSN |
| 901 | 864788050901201 |
| 902 | |
| 903 | OK |
| 904 | */ |
| 905 | static int req_imei_get(void *data, int *cme_err) |
| 906 | { |
| 907 | ATResponse *response = NULL; |
| 908 | int err = at_send_command_numeric("AT+CGSN", &response); |
| 909 | |
| 910 | if (err < 0 || response->success == 0 || !response->p_intermediates) { |
| 911 | *cme_err = at_get_cme_error(response); |
| 912 | goto exit; |
| 913 | } |
| 914 | |
| 915 | memcpy(data, response->p_intermediates->line, strlen(response->p_intermediates->line)); |
| 916 | exit: |
| 917 | at_response_free(response); |
| 918 | return err; |
| 919 | } |
| 920 | |
| 921 | /* |
| 922 | AT+MRD_SN=R |
| 923 | +MRD_SN:0101,Thu Nov 12 00:00:00 2020,G4M32301020006 |
| 924 | |
| 925 | OK |
| 926 | |
| 927 | */ |
| 928 | static int req_sn_get(void *data, int *cme_err) |
| 929 | { |
| 930 | ATResponse *response = NULL; |
| 931 | char *tmp_ptr = NULL; |
| 932 | int err = at_send_command_singleline("AT+MRD_SN=R", "+MRD_SN:", &response); |
| 933 | |
| 934 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 935 | *cme_err = at_get_cme_error(response); |
| 936 | goto exit; |
| 937 | } |
| 938 | |
| 939 | char *line = response->p_intermediates->line; |
| 940 | err = at_tok_start(&line); |
| 941 | if (err < 0) |
| 942 | { |
| 943 | goto exit; |
| 944 | } |
| 945 | |
| 946 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 947 | if (err < 0) |
| 948 | { |
| 949 | goto exit; |
| 950 | } |
| 951 | |
| 952 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 953 | if (err < 0) |
| 954 | { |
| 955 | goto exit; |
| 956 | } |
| 957 | |
| 958 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 959 | if (err < 0) |
| 960 | { |
| 961 | goto exit; |
| 962 | } |
| 963 | |
| 964 | memcpy(data, tmp_ptr, strlen(tmp_ptr)); |
| 965 | |
| 966 | goto exit; |
| 967 | exit: |
| 968 | at_response_free(response); |
| 969 | return err; |
| 970 | } |
| 971 | |
| 972 | /* |
| 973 | AT+SYSTIME? |
| 974 | +SYSTIME: 1 |
| 975 | |
| 976 | OK |
| 977 | |
| 978 | */ |
| 979 | static int req_time_get(int *data, int *cme_err) |
| 980 | { |
| 981 | ATResponse *response = NULL; |
| 982 | int tmp_int; |
| 983 | int err = at_send_command_singleline("AT+SYSTIME?", "+SYSTIME:", &response); |
| 984 | |
| 985 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 986 | *cme_err = at_get_cme_error(response); |
| 987 | goto exit; |
| 988 | } |
| 989 | |
| 990 | char *line = response->p_intermediates->line; |
| 991 | err = at_tok_start(&line); |
| 992 | if (err < 0) |
| 993 | { |
| 994 | goto exit; |
| 995 | } |
| 996 | err = at_tok_nextint(&line, &tmp_int); |
| 997 | if (err < 0) |
| 998 | { |
| 999 | goto exit; |
| 1000 | } |
| 1001 | *data = tmp_int; |
| 1002 | |
| 1003 | exit: |
| 1004 | at_response_free(response); |
| 1005 | return err; |
| 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | AT+CCLK? |
| 1010 | +CCLK: "23/03/20,01:58:00+32" |
| 1011 | |
| 1012 | OK |
| 1013 | |
| 1014 | */ |
| 1015 | static int req_net_time_get(char *data, int *cme_err) |
| 1016 | { |
| 1017 | ATResponse *response = NULL; |
| 1018 | char *tmp_ptr = NULL; |
| 1019 | int err = at_send_command_singleline("AT+CCLK?", "+CCLK:", &response); |
| 1020 | |
| 1021 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1022 | *cme_err = at_get_cme_error(response); |
| 1023 | goto exit; |
| 1024 | } |
| 1025 | |
| 1026 | char *line = response->p_intermediates->line; |
| 1027 | err = at_tok_start(&line); |
| 1028 | if (err < 0) |
| 1029 | { |
| 1030 | goto exit; |
| 1031 | } |
| 1032 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 1033 | if (err < 0) |
| 1034 | { |
| 1035 | goto exit; |
| 1036 | } |
| 1037 | memcpy(data, tmp_ptr, strlen(tmp_ptr)); |
| 1038 | |
| 1039 | exit: |
| 1040 | at_response_free(response); |
| 1041 | return err; |
| 1042 | } |
| 1043 | |
| 1044 | /* |
| 1045 | AT+CFUN? |
| 1046 | +CFUN: 1 |
| 1047 | OK |
| 1048 | */ |
| 1049 | static int req_modem_get(int *data, int *cme_err) |
| 1050 | { |
| 1051 | ATResponse *response = NULL; |
| 1052 | int modem; |
| 1053 | int err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &response); |
| 1054 | |
| 1055 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1056 | *cme_err = at_get_cme_error(response); |
| 1057 | goto exit; |
| 1058 | } |
| 1059 | |
| 1060 | char *line = response->p_intermediates->line; |
| 1061 | err = at_tok_start(&line); |
| 1062 | if (err < 0) |
| 1063 | { |
| 1064 | goto exit; |
| 1065 | } |
| 1066 | err = at_tok_nextint(&line, &modem); |
| 1067 | if (err < 0) |
| 1068 | { |
| 1069 | goto exit; |
| 1070 | } |
| 1071 | *data = modem; |
| 1072 | |
| 1073 | exit: |
| 1074 | at_response_free(response); |
| 1075 | return err; |
| 1076 | } |
| 1077 | |
| 1078 | /* |
| 1079 | AT+CFUN=<fun>[,<rst>] |
| 1080 | OK |
| 1081 | */ |
| 1082 | static int req_modem_set(mbtk_modem_info_t* modem, int *cme_err) |
| 1083 | { |
| 1084 | ATResponse *response = NULL; |
| 1085 | char cmd[30] = {0}; |
| 1086 | int err = -1; |
| 1087 | |
| 1088 | sprintf(cmd, "AT+CFUN=%d,%d", modem->fun, modem->rst); |
| 1089 | err = at_send_command(cmd, &response); |
| 1090 | |
| 1091 | if (err < 0 || response->success == 0){ |
| 1092 | *cme_err = at_get_cme_error(response); |
| 1093 | goto exit; |
| 1094 | } |
| 1095 | /* |
| 1096 | ATResponse *response = NULL; |
| 1097 | int err = at_send_command_multiline(cmd, "", &response); |
| 1098 | |
| 1099 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1100 | *cme_err = at_get_cme_error(response); |
| 1101 | goto exit; |
| 1102 | } |
| 1103 | |
| 1104 | ATLine* lines_ptr = response->p_intermediates; |
| 1105 | char *line = NULL; |
| 1106 | while(lines_ptr) |
| 1107 | { |
| 1108 | line = lines_ptr->line; |
| 1109 | if(strStartsWith(line, "Revision")) |
| 1110 | { |
| 1111 | err = at_tok_start(&line); |
| 1112 | if (err < 0) |
| 1113 | { |
| 1114 | goto exit; |
| 1115 | } |
| 1116 | memcpy(data, line, strlen(line)); |
| 1117 | break; |
| 1118 | } |
| 1119 | lines_ptr = lines_ptr->p_next; |
| 1120 | } |
| 1121 | |
| 1122 | goto exit; |
| 1123 | */ |
| 1124 | exit: |
| 1125 | at_response_free(response); |
| 1126 | return err; |
| 1127 | } |
| 1128 | |
| 1129 | |
| 1130 | /* |
| 1131 | AT+SYSTIME=0,"2022-01-25-11:15:30" |
| 1132 | OK |
| 1133 | |
| 1134 | AT+SYSTIME=1 |
| 1135 | OK |
| 1136 | */ |
| 1137 | static int req_time_set(int type, char *time, int *cme_err) |
| 1138 | { |
| 1139 | ATResponse *response = NULL; |
| 1140 | int tmp_int; |
| 1141 | char cmd[200] = {0}; |
| 1142 | if(str_empty(time)){ |
| 1143 | sprintf(cmd, "AT+SYSTIME=%d", type); |
| 1144 | } else { |
| 1145 | sprintf(cmd, "AT+SYSTIME=%d,\"%s\"", type, time); |
| 1146 | } |
| 1147 | int err = at_send_command(cmd, &response); |
| 1148 | |
| 1149 | if (err < 0 || response->success == 0){ |
| 1150 | *cme_err = at_get_cme_error(response); |
| 1151 | goto exit; |
| 1152 | } |
| 1153 | |
| 1154 | exit: |
| 1155 | at_response_free(response); |
| 1156 | return err; |
| 1157 | } |
| 1158 | |
| 1159 | |
| 1160 | /* |
| 1161 | ATI |
| 1162 | Manufacturer:"LYNQ" |
| 1163 | Model:"LYNQ_L508TLC" |
| 1164 | Revision:L508TLCv02.01b01.00 |
| 1165 | IMEI:864788050901201 |
| 1166 | |
| 1167 | OK |
| 1168 | |
| 1169 | */ |
| 1170 | static int req_version_get(void *data, int *cme_err) |
| 1171 | { |
| 1172 | ATResponse *response = NULL; |
| 1173 | int err = at_send_command_multiline("ATI", "", &response); |
| 1174 | |
| 1175 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1176 | *cme_err = at_get_cme_error(response); |
| 1177 | goto exit; |
| 1178 | } |
| 1179 | |
| 1180 | ATLine* lines_ptr = response->p_intermediates; |
| 1181 | char *line = NULL; |
| 1182 | while(lines_ptr) |
| 1183 | { |
| 1184 | line = lines_ptr->line; |
| 1185 | if(strStartsWith(line, "Revision")) |
| 1186 | { |
| 1187 | err = at_tok_start(&line); |
| 1188 | if (err < 0) |
| 1189 | { |
| 1190 | goto exit; |
| 1191 | } |
| 1192 | memcpy(data, line, strlen(line)); |
| 1193 | break; |
| 1194 | } |
| 1195 | lines_ptr = lines_ptr->p_next; |
| 1196 | } |
| 1197 | |
| 1198 | goto exit; |
| 1199 | exit: |
| 1200 | at_response_free(response); |
| 1201 | return err; |
| 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | ATI |
| 1206 | Manufacturer:"LYNQ" |
| 1207 | Model:"LYNQ_L508TLC" |
| 1208 | Revision:L508TLCv02.01b01.00 |
| 1209 | IMEI:864788050901201 |
| 1210 | |
| 1211 | OK |
| 1212 | |
| 1213 | */ |
| 1214 | static int req_model_get(void *data, int *cme_err) |
| 1215 | { |
| 1216 | ATResponse *response = NULL; |
| 1217 | int err = at_send_command_multiline("ATI", "", &response); |
| 1218 | |
| 1219 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1220 | *cme_err = at_get_cme_error(response); |
| 1221 | goto exit; |
| 1222 | } |
| 1223 | |
| 1224 | ATLine* lines_ptr = response->p_intermediates; |
| 1225 | char *line = NULL; |
| 1226 | while(lines_ptr) |
| 1227 | { |
| 1228 | line = lines_ptr->line; |
| 1229 | if(strStartsWith(line, "Model")) |
| 1230 | { |
| 1231 | err = at_tok_start(&line); |
| 1232 | if (err < 0) |
| 1233 | { |
| 1234 | goto exit; |
| 1235 | } |
| 1236 | memcpy(data, line, strlen(line)); |
| 1237 | break; |
| 1238 | } |
| 1239 | lines_ptr = lines_ptr->p_next; |
| 1240 | } |
| 1241 | |
| 1242 | goto exit; |
| 1243 | exit: |
| 1244 | at_response_free(response); |
| 1245 | return err; |
| 1246 | } |
| 1247 | |
| 1248 | /* |
| 1249 | AT+ACONFIG="IMSD=1" |
| 1250 | or |
| 1251 | AT+ACONFIG="IMSD=0" |
| 1252 | |
| 1253 | OK |
| 1254 | */ |
| 1255 | static int req_volte_set(int state, int *cme_err) |
| 1256 | { |
| 1257 | ATResponse *response = NULL; |
| 1258 | char cmd[30] = {0}; |
| 1259 | if(state) |
| 1260 | { |
| 1261 | strcpy(cmd, "AT+ACONFIG=\"IMSD=1\""); |
| 1262 | } |
| 1263 | else |
| 1264 | { |
| 1265 | strcpy(cmd, "AT+ACONFIG=\"IMSD=0\""); |
| 1266 | } |
| 1267 | int err = at_send_command(cmd, &response); |
| 1268 | |
| 1269 | if (err < 0 || response->success == 0) { |
| 1270 | *cme_err = at_get_cme_error(response); |
| 1271 | goto exit; |
| 1272 | } |
| 1273 | |
| 1274 | err = 0; |
| 1275 | exit: |
| 1276 | at_response_free(response); |
| 1277 | return err; |
| 1278 | } |
| 1279 | |
| 1280 | /* |
| 1281 | AT+ACONFIG? |
| 1282 | PID=0,VID=0,IMSD=1,PIPE=0,FAST=0,RDUP=1,NOCP=0,GEFL=-1237040617 |
| 1283 | |
| 1284 | OK |
| 1285 | */ |
| 1286 | static int req_volte_get(int *state, int *cme_err) |
| 1287 | { |
| 1288 | ATResponse *response = NULL; |
| 1289 | char *tmp_ptr = NULL; |
| 1290 | int err = at_send_command_singleline("AT+ACONFIG?", "", &response); |
| 1291 | |
| 1292 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1293 | *cme_err = at_get_cme_error(response); |
| 1294 | goto exit; |
| 1295 | } |
| 1296 | |
| 1297 | char *line = response->p_intermediates->line; |
| 1298 | char* ptr = strstr(line, "IMSD="); |
| 1299 | if(ptr) |
| 1300 | { |
| 1301 | *state = atoi(ptr + strlen("IMSD=")); |
| 1302 | } |
| 1303 | else |
| 1304 | { |
| 1305 | err = -1; |
| 1306 | } |
| 1307 | exit: |
| 1308 | at_response_free(response); |
| 1309 | return err; |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | /* |
| 1314 | * Get system temperature. |
| 1315 | * |
| 1316 | * type[IN]: |
| 1317 | * 0: Soc temperature. |
| 1318 | * 1: RF temperature. |
| 1319 | * temp[OUT]: |
| 1320 | * temperature in celsius. |
| 1321 | * |
| 1322 | |
| 1323 | AT*RFTEMP |
| 1324 | *RFTEMP:0,28 |
| 1325 | OK |
| 1326 | |
| 1327 | AT*SOCTEMP |
| 1328 | *SOCTEMP:24000 |
| 1329 | OK |
| 1330 | |
| 1331 | */ |
| 1332 | static int req_temp_get(int type, int *temp, int *cme_err) |
| 1333 | { |
| 1334 | ATResponse *response = NULL; |
| 1335 | int err = -1; |
| 1336 | int tmp_int; |
| 1337 | if(type == 0) { // Soc |
| 1338 | err = at_send_command_singleline("AT*SOCTEMP", "*SOCTEMP:", &response); |
| 1339 | } else { // RF |
| 1340 | err = at_send_command_singleline("AT*RFTEMP", "*RFTEMP:", &response); |
| 1341 | } |
| 1342 | |
| 1343 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1344 | *cme_err = at_get_cme_error(response); |
| 1345 | goto exit; |
| 1346 | } |
| 1347 | |
| 1348 | char *line = response->p_intermediates->line; |
| 1349 | err = at_tok_start(&line); |
| 1350 | if (err < 0) |
| 1351 | { |
| 1352 | goto exit; |
| 1353 | } |
| 1354 | err = at_tok_nextint(&line, &tmp_int); |
| 1355 | if (err < 0) |
| 1356 | { |
| 1357 | goto exit; |
| 1358 | } |
| 1359 | |
| 1360 | if(type == 1) { // RF |
| 1361 | err = at_tok_nextint(&line, &tmp_int); |
| 1362 | if (err < 0) |
| 1363 | { |
| 1364 | goto exit; |
| 1365 | } |
| 1366 | *temp = tmp_int; |
| 1367 | } else { |
| 1368 | *temp = tmp_int / 1000; |
| 1369 | } |
| 1370 | |
| 1371 | exit: |
| 1372 | at_response_free(response); |
| 1373 | return err; |
| 1374 | } |
| 1375 | |
| 1376 | /* |
| 1377 | AT*BAND=15 |
| 1378 | OK |
| 1379 | |
| 1380 | */ |
| 1381 | static int req_band_set(mbtk_band_info_t* band, int *cme_err) |
| 1382 | { |
| 1383 | ATResponse *response = NULL; |
| 1384 | char cmd[30] = {0}; |
| 1385 | int err = -1; |
| 1386 | |
| 1387 | if(band->gsm_band == 0 && band->umts_band == 0 |
| 1388 | && band->tdlte_band == 0 && band->fddlte_band == 0) { |
| 1389 | sprintf(cmd, "AT*BAND=%d", band->net_pref); |
| 1390 | } else { |
| 1391 | band_support_get(); |
| 1392 | |
| 1393 | log_hex("BAND_SUPPORT", &band_support, sizeof(mbtk_band_info_t)); |
| 1394 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 1395 | |
| 1396 | if(band->gsm_band == 0) { |
| 1397 | band->gsm_band = band_support.gsm_band; |
| 1398 | } |
| 1399 | if(band->umts_band == 0) { |
| 1400 | band->umts_band = band_support.umts_band; |
| 1401 | } |
| 1402 | if(band->tdlte_band == 0) { |
| 1403 | band->tdlte_band = band_support.tdlte_band; |
| 1404 | } |
| 1405 | if(band->fddlte_band == 0) { |
| 1406 | band->fddlte_band = band_support.fddlte_band; |
| 1407 | } |
| 1408 | |
| 1409 | if((band->gsm_band & band_support.gsm_band) != band->gsm_band) { |
| 1410 | LOG("GSM band error."); |
| 1411 | goto exit; |
| 1412 | } |
| 1413 | |
| 1414 | if((band->umts_band & band_support.umts_band) != band->umts_band) { |
| 1415 | LOG("UMTS band error."); |
| 1416 | goto exit; |
| 1417 | } |
| 1418 | |
| 1419 | if((band->tdlte_band & band_support.tdlte_band) != band->tdlte_band) { |
| 1420 | LOG("TDLTE band error."); |
| 1421 | goto exit; |
| 1422 | } |
| 1423 | |
| 1424 | if((band->fddlte_band & band_support.fddlte_band) != band->fddlte_band) { |
| 1425 | LOG("FDDLTE band error."); |
| 1426 | goto exit; |
| 1427 | } |
| 1428 | |
| 1429 | if(band->net_pref == 0xFF) { // No change net_pref. |
| 1430 | int tmp_int; |
| 1431 | err = at_send_command_singleline("AT*BAND?", "*BAND:", &response); |
| 1432 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1433 | *cme_err = at_get_cme_error(response); |
| 1434 | goto exit; |
| 1435 | } |
| 1436 | |
| 1437 | char *line = response->p_intermediates->line; |
| 1438 | err = at_tok_start(&line); |
| 1439 | if (err < 0) |
| 1440 | { |
| 1441 | goto exit; |
| 1442 | } |
| 1443 | |
| 1444 | err = at_tok_nextint(&line, &tmp_int); |
| 1445 | if (err < 0) |
| 1446 | { |
| 1447 | goto exit; |
| 1448 | } |
| 1449 | band->net_pref = (uint8)tmp_int; // Set to current net_pref. |
| 1450 | |
| 1451 | at_response_free(response); |
| 1452 | } |
| 1453 | |
| 1454 | sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band); |
| 1455 | } |
| 1456 | err = at_send_command(cmd, &response); |
| 1457 | |
| 1458 | if (err < 0 || response->success == 0){ |
| 1459 | *cme_err = at_get_cme_error(response); |
| 1460 | goto exit; |
| 1461 | } |
| 1462 | |
| 1463 | err = 0; |
| 1464 | exit: |
| 1465 | at_response_free(response); |
| 1466 | return err; |
| 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | // ??????? |
| 1471 | AT*BAND=? |
| 1472 | *BAND:(0-18),79,147,482,524503 |
| 1473 | |
| 1474 | OK |
| 1475 | |
| 1476 | // ??????????? |
| 1477 | AT*BAND? |
| 1478 | *BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0 |
| 1479 | |
| 1480 | OK |
| 1481 | |
| 1482 | // ????????? |
| 1483 | AT*BAND=5,79,147,128,1 |
| 1484 | OK |
| 1485 | |
| 1486 | net_prefferred?? |
| 1487 | 0 : GSM only |
| 1488 | 1 : UMTS only |
| 1489 | 2 : GSM/UMTS(auto) |
| 1490 | 3 : GSM/UMTS(GSM preferred) |
| 1491 | 4 : GSM/UMTS(UMTS preferred) |
| 1492 | 5 : LTE only |
| 1493 | 6 : GSM/LTE(auto) |
| 1494 | 7 : GSM/LTE(GSM preferred) |
| 1495 | 8 : GSM/LTE(LTE preferred) |
| 1496 | 9 : UMTS/LTE(auto) |
| 1497 | 10 : UMTS/LTE(UMTS preferred) |
| 1498 | 11 : UMTS/LTE(LTE preferred) |
| 1499 | 12 : GSM/UMTS/LTE(auto) |
| 1500 | 13 : GSM/UMTS/LTE(GSM preferred) |
| 1501 | 14 : GSM/UMTS/LTE(UMTS preferred) |
| 1502 | 15 : GSM/UMTS/LTE(LTE preferred) |
| 1503 | GSM band?? |
| 1504 | 1 ?C PGSM 900 (standard or primary) |
| 1505 | 2 ?C DCS GSM 1800 |
| 1506 | 4 ?C PCS GSM 1900 |
| 1507 | 8 ?C EGSM 900 (extended) |
| 1508 | 16 ?C GSM 450 |
| 1509 | 32 ?C GSM 480 |
| 1510 | 64 ?C GSM 850 |
| 1511 | 512 - BAND_LOCK_BIT // used for GSM band setting |
| 1512 | UMTS band?? |
| 1513 | 1 ?C UMTS_BAND_1 |
| 1514 | 2 ?C UMTS_BAND_2 |
| 1515 | 4 ?C UMTS_BAND_3 |
| 1516 | 8 ?C UMTS_BAND_4 |
| 1517 | 16 ?C UMTS_BAND_5 |
| 1518 | 32 ?C UMTS_BAND_6 |
| 1519 | 64 ?C UMTS_BAND_7 |
| 1520 | 128 ?C UMTS_BAND_8 |
| 1521 | 256 ?C UMTS_BAND_9 |
| 1522 | LTEbandH(TDD-LTE band) |
| 1523 | 32 ?C TDLTE_BAND_38 |
| 1524 | 64 ?C TDLTE_BAND_39 |
| 1525 | 128 ?C TDLTE_BAND_40 |
| 1526 | 256 ?C TDLTE_BAND_41 |
| 1527 | LTEbandL(FDD-LTE band) |
| 1528 | 1 ?C FDDLTE_BAND_1 |
| 1529 | 4 ?C FDDLTE _BAND_3 |
| 1530 | 8 ?C FDDLTE _BAND_4 |
| 1531 | 64 ?C FDDLTE _BAND_7 |
| 1532 | 65536 ?C FDDLTE _BAND_17 |
| 1533 | 524288 ?C FDDLTE _BAND_20 |
| 1534 | */ |
| 1535 | static int req_band_get(mbtk_band_info_t *band, int *cme_err) |
| 1536 | { |
| 1537 | ATResponse *response = NULL; |
| 1538 | int tmp_int; |
| 1539 | |
| 1540 | band_support_get(); |
| 1541 | |
| 1542 | log_hex("BAND_SUPPORT", &band_support, sizeof(mbtk_band_info_t)); |
| 1543 | int err = at_send_command_singleline("AT*BAND?", "*BAND:", &response); |
| 1544 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1545 | *cme_err = at_get_cme_error(response); |
| 1546 | goto exit; |
| 1547 | } |
| 1548 | |
| 1549 | char *line = response->p_intermediates->line; |
| 1550 | err = at_tok_start(&line); |
| 1551 | if (err < 0) |
| 1552 | { |
| 1553 | goto exit; |
| 1554 | } |
| 1555 | |
| 1556 | err = at_tok_nextint(&line, &tmp_int); |
| 1557 | if (err < 0) |
| 1558 | { |
| 1559 | goto exit; |
| 1560 | } |
| 1561 | band->net_pref = (uint8)tmp_int; |
| 1562 | |
| 1563 | err = at_tok_nextint(&line, &tmp_int); |
| 1564 | if (err < 0) |
| 1565 | { |
| 1566 | goto exit; |
| 1567 | } |
| 1568 | band->gsm_band = (uint16)tmp_int; |
| 1569 | |
| 1570 | err = at_tok_nextint(&line, &tmp_int); |
| 1571 | if (err < 0) |
| 1572 | { |
| 1573 | goto exit; |
| 1574 | } |
| 1575 | band->umts_band = (uint16)tmp_int; |
| 1576 | |
| 1577 | err = at_tok_nextint(&line, &tmp_int); |
| 1578 | if (err < 0) |
| 1579 | { |
| 1580 | goto exit; |
| 1581 | } |
| 1582 | band->tdlte_band = (uint32)tmp_int; |
| 1583 | |
| 1584 | err = at_tok_nextint(&line, &tmp_int); |
| 1585 | if (err < 0) |
| 1586 | { |
| 1587 | goto exit; |
| 1588 | } |
| 1589 | band->fddlte_band = (uint32)tmp_int; |
| 1590 | |
| 1591 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 1592 | |
| 1593 | exit: |
| 1594 | at_response_free(response); |
| 1595 | return err; |
| 1596 | } |
| 1597 | |
| 1598 | /* |
| 1599 | AT+ICCID |
| 1600 | +ICCID: 89860621330065648041 |
| 1601 | |
| 1602 | OK |
| 1603 | */ |
| 1604 | static int req_iccid_get(void *data, int *cme_err) |
| 1605 | { |
| 1606 | ATResponse *response = NULL; |
| 1607 | char *tmp_ptr = NULL; |
| 1608 | int err = at_send_command_singleline("AT+ICCID", "+ICCID:", &response); |
| 1609 | |
| 1610 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1611 | *cme_err = at_get_cme_error(response); |
| 1612 | goto exit; |
| 1613 | } |
| 1614 | |
| 1615 | char *line = response->p_intermediates->line; |
| 1616 | err = at_tok_start(&line); |
| 1617 | if (err < 0) |
| 1618 | { |
| 1619 | goto exit; |
| 1620 | } |
| 1621 | |
| 1622 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 1623 | if (err < 0) |
| 1624 | { |
| 1625 | goto exit; |
| 1626 | } |
| 1627 | |
| 1628 | memcpy(data, tmp_ptr, strlen(tmp_ptr)); |
| 1629 | exit: |
| 1630 | at_response_free(response); |
| 1631 | return err; |
| 1632 | } |
| 1633 | |
| 1634 | /* |
| 1635 | AT+CNUM? |
| 1636 | +CNUM: "","13980414101",129 |
| 1637 | |
| 1638 | OK |
| 1639 | |
| 1640 | */ |
| 1641 | static int req_phone_number_get(void *data, int *cme_err) |
| 1642 | { |
| 1643 | ATResponse *response = NULL; |
| 1644 | char *tmp_ptr = NULL; |
| 1645 | int err = at_send_command_singleline("AT+CNUM?", "+CNUM:", &response); |
| 1646 | if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){ |
| 1647 | if(response) { |
| 1648 | *cme_err = at_get_cme_error(response); |
| 1649 | } |
| 1650 | LOGD("AT+CNUM? fail."); |
| 1651 | goto exit; |
| 1652 | } |
| 1653 | |
| 1654 | char *line = response->p_intermediates->line; |
| 1655 | if(line == NULL) { |
| 1656 | LOGD("line is NULL"); |
| 1657 | goto exit; |
| 1658 | } |
| 1659 | err = at_tok_start(&line); |
| 1660 | if (err < 0) |
| 1661 | { |
| 1662 | goto exit; |
| 1663 | } |
| 1664 | |
| 1665 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 1666 | if (err < 0) |
| 1667 | { |
| 1668 | goto exit; |
| 1669 | } |
| 1670 | |
| 1671 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 1672 | if (err < 0) |
| 1673 | { |
| 1674 | goto exit; |
| 1675 | } |
| 1676 | |
| 1677 | memcpy(data, tmp_ptr, strlen(tmp_ptr)); |
| 1678 | exit: |
| 1679 | at_response_free(response); |
| 1680 | return err; |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | /* |
| 1685 | AT+CIMI |
| 1686 | 460068103383304 |
| 1687 | |
| 1688 | OK |
| 1689 | |
| 1690 | */ |
| 1691 | static int req_imsi_get(void *data, int *cme_err) |
| 1692 | { |
| 1693 | ATResponse *response = NULL; |
| 1694 | int err = at_send_command_numeric("AT+CIMI", &response); |
| 1695 | |
| 1696 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1697 | *cme_err = at_get_cme_error(response); |
| 1698 | goto exit; |
| 1699 | } |
| 1700 | |
| 1701 | memcpy(data, response->p_intermediates->line, strlen(response->p_intermediates->line)); |
| 1702 | exit: |
| 1703 | at_response_free(response); |
| 1704 | return err; |
| 1705 | } |
| 1706 | |
| 1707 | |
| 1708 | /* |
| 1709 | AT+CLCK=SC,1/0,1234 |
| 1710 | +CLCK:1/0 |
| 1711 | |
| 1712 | OK |
| 1713 | |
| 1714 | */ |
| 1715 | static int req_pin_enable(mbtk_enable_pin_info *data, int *cme_err) |
| 1716 | { |
| 1717 | ATResponse *response = NULL; |
| 1718 | char cmd[64]={0}; |
| 1719 | sprintf(cmd, "AT+CLCK=SC,%d,%s", data->enable, data->pin_value); |
| 1720 | |
| 1721 | int err = at_send_command_singleline(cmd, "+CLCK:", &response); |
| 1722 | if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){ |
| 1723 | if(response) { |
| 1724 | *cme_err = at_get_cme_error(response); |
| 1725 | } |
| 1726 | LOGD("AT+CLCK? fail."); |
| 1727 | goto exit; |
| 1728 | } |
| 1729 | |
| 1730 | char *line = response->p_intermediates->line; |
| 1731 | if(line == NULL) { |
| 1732 | LOGD("line is NULL"); |
| 1733 | goto exit; |
| 1734 | } |
| 1735 | err = at_tok_start(&line); |
| 1736 | if (err < 0) |
| 1737 | { |
| 1738 | goto exit; |
| 1739 | } |
| 1740 | int clck; |
| 1741 | err = at_tok_nextint(&line, &clck); |
| 1742 | if (err < 0) |
| 1743 | { |
| 1744 | goto exit; |
| 1745 | } |
| 1746 | |
| 1747 | exit: |
| 1748 | at_response_free(response); |
| 1749 | return err; |
| 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | AT+CPIN=1234 |
| 1754 | |
| 1755 | OK |
| 1756 | |
| 1757 | */ |
| 1758 | static int req_pin_verify(char *data, int *cme_err) |
| 1759 | { |
| 1760 | ATResponse *response = NULL; |
| 1761 | char cmd[64]={0}; |
| 1762 | sprintf(cmd, "AT+CPIN=%s", data); |
| 1763 | int err = at_send_command(cmd, &response); |
| 1764 | if (err < 0 || response->success == 0){ |
| 1765 | if(cme_err) { |
| 1766 | *cme_err = at_get_cme_error(response); |
| 1767 | } |
| 1768 | goto exit; |
| 1769 | } |
| 1770 | |
| 1771 | exit: |
| 1772 | at_response_free(response); |
| 1773 | return err; |
| 1774 | } |
| 1775 | |
| 1776 | /* |
| 1777 | AT+CLCK=SC,2 |
| 1778 | +CLCK: 1 |
| 1779 | |
| 1780 | OK |
| 1781 | |
| 1782 | AT+CLCK="SC",1,"1234" |
| 1783 | +CLCK:1 |
| 1784 | |
| 1785 | OK |
| 1786 | |
| 1787 | AT+CPWD="SC","1234","4321" |
| 1788 | |
| 1789 | OK |
| 1790 | |
| 1791 | */ |
| 1792 | static int req_pin_change(mbtk_change_pin_info *data, int *cme_err) |
| 1793 | { |
| 1794 | ATResponse *response = NULL; |
| 1795 | char cmd[64]={0}; |
| 1796 | |
| 1797 | int err = at_send_command_singleline("AT+CLCK=SC,2", "+CLCK:", &response); |
| 1798 | if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){ |
| 1799 | if(response) { |
| 1800 | *cme_err = at_get_cme_error(response); |
| 1801 | } |
| 1802 | LOGD("AT+CLCK fail."); |
| 1803 | goto exit; |
| 1804 | } |
| 1805 | |
| 1806 | char *line = response->p_intermediates->line; |
| 1807 | if(line == NULL) { |
| 1808 | LOGD("line is NULL"); |
| 1809 | goto exit; |
| 1810 | } |
| 1811 | err = at_tok_start(&line); |
| 1812 | if (err < 0) |
| 1813 | { |
| 1814 | goto exit; |
| 1815 | } |
| 1816 | int clck; |
| 1817 | err = at_tok_nextint(&line, &clck); |
| 1818 | if (err < 0) |
| 1819 | { |
| 1820 | goto exit; |
| 1821 | } |
| 1822 | at_response_free(response); |
| 1823 | |
| 1824 | if(clck==0) |
| 1825 | { |
| 1826 | sprintf(cmd, "AT+CLCK=SC,1,%s", data->old_pin_value); |
| 1827 | err = at_send_command_singleline(cmd, "+CLCK:", &response); |
| 1828 | if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){ |
| 1829 | if(response) { |
| 1830 | *cme_err = at_get_cme_error(response); |
| 1831 | } |
| 1832 | LOGD("AT+CLCK fail."); |
| 1833 | goto exit; |
| 1834 | } |
| 1835 | line = response->p_intermediates->line; |
| 1836 | if(line == NULL) { |
| 1837 | LOGD("line is NULL"); |
| 1838 | goto exit; |
| 1839 | } |
| 1840 | err = at_tok_start(&line); |
| 1841 | if (err < 0) |
| 1842 | { |
| 1843 | goto exit; |
| 1844 | } |
| 1845 | clck = -1; |
| 1846 | err = at_tok_nextint(&line, &clck); |
| 1847 | if (err < 0) |
| 1848 | { |
| 1849 | goto exit; |
| 1850 | } |
| 1851 | at_response_free(response); |
| 1852 | if(clck != 1) |
| 1853 | return err; |
| 1854 | } |
| 1855 | memset(cmd, 0, 64); |
| 1856 | sprintf(cmd, "AT+CPWD=SC,%s,%s", data->old_pin_value,data->new_pin_value); |
| 1857 | err = at_send_command(cmd, &response); |
| 1858 | if (err < 0 || response->success == 0){ |
| 1859 | if(cme_err) { |
| 1860 | *cme_err = at_get_cme_error(response); |
| 1861 | } |
| 1862 | goto exit; |
| 1863 | } |
| 1864 | |
| 1865 | exit: |
| 1866 | at_response_free(response); |
| 1867 | return err; |
| 1868 | } |
| 1869 | |
| 1870 | /* |
| 1871 | AT+CPIN? |
| 1872 | +CPIN:SIM PUK |
| 1873 | |
| 1874 | OK |
| 1875 | |
| 1876 | AT+CPIN="PUK","PIN" |
| 1877 | +CPIN: READY |
| 1878 | |
| 1879 | OK |
| 1880 | */ |
| 1881 | static int req_puk_unlock_pin(mbtk_unlock_pin_info *data, int *cme_err) |
| 1882 | { |
| 1883 | ATResponse *response = NULL; |
| 1884 | char cmd[64]={0}; |
| 1885 | #if 0 |
| 1886 | int err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &response); |
| 1887 | if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){ |
| 1888 | if(response) { |
| 1889 | *cme_err = at_get_cme_error(response); |
| 1890 | } |
| 1891 | LOGD("AT+CNUM? fail."); |
| 1892 | goto exit; |
| 1893 | } |
| 1894 | |
| 1895 | char *line = response->p_intermediates->line; |
| 1896 | if(line == NULL) { |
| 1897 | LOGD("line is NULL"); |
| 1898 | goto exit; |
| 1899 | } |
| 1900 | err = at_tok_start(&line); |
| 1901 | if (err < 0) |
| 1902 | { |
| 1903 | goto exit; |
| 1904 | } |
| 1905 | char *tmp_ptr = NULL; |
| 1906 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 1907 | if (err < 0) |
| 1908 | { |
| 1909 | goto exit; |
| 1910 | } |
| 1911 | at_response_free(response); |
| 1912 | |
| 1913 | if(!strstr(tmp_ptr,"SIM PUK")) |
| 1914 | { |
| 1915 | sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value); |
| 1916 | err = at_send_command_singleline(cmd, "+CPIN:", &response); |
| 1917 | if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){ |
| 1918 | if(response) { |
| 1919 | *cme_err = at_get_cme_error(response); |
| 1920 | } |
| 1921 | LOGD("AT+CNUM? fail."); |
| 1922 | goto exit; |
| 1923 | } |
| 1924 | line = response->p_intermediates->line; |
| 1925 | if(line == NULL) { |
| 1926 | LOGD("line is NULL"); |
| 1927 | goto exit; |
| 1928 | } |
| 1929 | err = at_tok_start(&line); |
| 1930 | if (err < 0) |
| 1931 | { |
| 1932 | goto exit; |
| 1933 | } |
| 1934 | memset(tmp_ptr, 0, strlen(tmp_ptr)); |
| 1935 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 1936 | if (err < 0) |
| 1937 | { |
| 1938 | goto exit; |
| 1939 | } |
| 1940 | at_response_free(response); |
| 1941 | if(strstr(tmp_ptr, "READY")) |
| 1942 | return err; |
| 1943 | } |
| 1944 | else |
| 1945 | return err; |
| 1946 | #else |
| 1947 | sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value); |
r.xiao | 2ad43d1 | 2024-03-23 00:03:29 -0700 | [diff] [blame] | 1948 | int err = at_send_command(cmd, &response); |
| 1949 | if (err < 0 || response->success == 0){ |
| 1950 | if(cme_err) { |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1951 | *cme_err = at_get_cme_error(response); |
| 1952 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1953 | goto exit; |
| 1954 | } |
r.xiao | 2ad43d1 | 2024-03-23 00:03:29 -0700 | [diff] [blame] | 1955 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1956 | #endif |
| 1957 | exit: |
| 1958 | at_response_free(response); |
| 1959 | return err; |
| 1960 | } |
| 1961 | |
| 1962 | /* |
| 1963 | AT+COPS=? |
| 1964 | |
| 1965 | +COPS: (2, "CHINA MOBILE", "CMCC", "46000", 7),(3, "CHN-CT", "CT", "46011", 7),(3, "CHN-UNICOM", "UNICOM", "46001", 7),(1, "460 15", "460 15", "46015", 7),,(0,1,2,3,4),(0,1,2) |
| 1966 | |
| 1967 | OK |
| 1968 | |
| 1969 | // Return [sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)] |
| 1970 | */ |
| 1971 | #if 0 |
| 1972 | static int req_available_net_get(mbtk_net_array_info_t *data_ptr) |
| 1973 | { |
| 1974 | ATResponse *response = NULL; |
| 1975 | char *tmp_ptr = NULL; |
| 1976 | int tmp_int; |
| 1977 | int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response); |
| 1978 | |
| 1979 | if (err < 0 || response->success == 0 || !response->p_intermediates) |
| 1980 | goto exit; |
| 1981 | #if 1 |
| 1982 | char *line_ptr = response->p_intermediates->line; |
| 1983 | if(line_ptr == NULL) { |
| 1984 | LOG("line is NULL"); |
| 1985 | goto exit; |
| 1986 | } |
| 1987 | //LOG("Line:%s",line_ptr); |
| 1988 | line_ptr = strstr(line_ptr, "("); |
| 1989 | while(line_ptr) { |
| 1990 | line_ptr++; |
| 1991 | // Only for available/current net. |
| 1992 | if(*line_ptr == '1' || *line_ptr == '2') { |
| 1993 | //LOG("Temp:%s",line_ptr); |
| 1994 | //sleep(1); |
| 1995 | line_ptr = strstr(line_ptr, ","); |
| 1996 | if(line_ptr == NULL) |
| 1997 | goto exit; |
| 1998 | line_ptr++; |
| 1999 | |
| 2000 | line_ptr = strstr(line_ptr, ","); |
| 2001 | if(line_ptr == NULL) |
| 2002 | goto exit; |
| 2003 | line_ptr++; |
| 2004 | |
| 2005 | line_ptr = strstr(line_ptr, ","); |
| 2006 | if(line_ptr == NULL) |
| 2007 | goto exit; |
| 2008 | |
| 2009 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"')) |
| 2010 | line_ptr++; |
| 2011 | |
| 2012 | mbtk_net_info_t *net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t)); |
| 2013 | if(net == NULL) { |
| 2014 | LOG("malloc() fail."); |
| 2015 | goto exit; |
| 2016 | } |
| 2017 | memset(net, 0, sizeof(mbtk_net_info_t)); |
| 2018 | |
| 2019 | // Point to "46000" |
| 2020 | //LOG("PLMN:%s",line_ptr); |
| 2021 | //sleep(1); |
| 2022 | net->plmn = (uint32)atoi(line_ptr); |
| 2023 | |
| 2024 | line_ptr = strstr(line_ptr, ","); |
| 2025 | if(line_ptr == NULL) |
| 2026 | goto exit; |
| 2027 | |
| 2028 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ')) |
| 2029 | line_ptr++; |
| 2030 | |
| 2031 | // Point to "7" |
| 2032 | if(*line_ptr == '\0') { |
| 2033 | free(net); |
| 2034 | goto exit; |
| 2035 | } |
| 2036 | //LOG("Type:%s",line_ptr); |
| 2037 | //sleep(1); |
| 2038 | net->net_type = (uint8)atoi(line_ptr); |
| 2039 | list_add(data_ptr->net_list, net); |
| 2040 | data_ptr->count++; |
| 2041 | } |
| 2042 | |
| 2043 | line_ptr = strstr(line_ptr, "("); |
| 2044 | } |
| 2045 | #endif |
| 2046 | exit: |
| 2047 | at_response_free(response); |
| 2048 | return err; |
| 2049 | } |
| 2050 | #else |
| 2051 | static int req_available_net_get(void* buff, int *cme_err) |
| 2052 | { |
| 2053 | ATResponse *response = NULL; |
| 2054 | char *tmp_ptr = NULL; |
| 2055 | int tmp_int; |
| 2056 | int buff_size = 0; |
| 2057 | int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response); |
| 2058 | |
| 2059 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2060 | *cme_err = at_get_cme_error(response); |
| 2061 | goto exit; |
| 2062 | } |
| 2063 | char *line_ptr = response->p_intermediates->line; |
| 2064 | if(line_ptr == NULL) { |
| 2065 | LOG("line is NULL"); |
| 2066 | goto exit; |
| 2067 | } |
| 2068 | uint8* buff_ptr = (uint8*)buff; |
| 2069 | //LOG("Line:%s",line_ptr); |
| 2070 | line_ptr = strstr(line_ptr, "("); |
| 2071 | while(line_ptr) { |
| 2072 | line_ptr++; |
| 2073 | // Only for available/current net. |
| 2074 | if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') { |
| 2075 | *(buff_ptr + 2) = (uint8)atoi(line_ptr); // net_state |
| 2076 | |
| 2077 | line_ptr = strstr(line_ptr, ","); |
| 2078 | if(line_ptr == NULL) |
| 2079 | goto exit; |
| 2080 | line_ptr++; |
| 2081 | |
| 2082 | line_ptr = strstr(line_ptr, ","); |
| 2083 | if(line_ptr == NULL) |
| 2084 | goto exit; |
| 2085 | line_ptr++; |
| 2086 | |
| 2087 | line_ptr = strstr(line_ptr, ","); |
| 2088 | if(line_ptr == NULL) |
| 2089 | goto exit; |
| 2090 | |
| 2091 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"')) |
| 2092 | line_ptr++; |
| 2093 | |
| 2094 | // set sel_mode to 0 |
| 2095 | *buff_ptr = (uint8)0; |
| 2096 | // Point to "46000" |
| 2097 | //LOG("PLMN:%s",line_ptr); |
| 2098 | //sleep(1); |
| 2099 | uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn |
| 2100 | |
| 2101 | line_ptr = strstr(line_ptr, ","); |
| 2102 | if(line_ptr == NULL) |
| 2103 | goto exit; |
| 2104 | |
| 2105 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ')) |
| 2106 | line_ptr++; |
| 2107 | |
| 2108 | // Point to "7" |
| 2109 | if(*line_ptr == '\0') { |
| 2110 | goto exit; |
| 2111 | } |
| 2112 | //LOG("Type:%s",line_ptr); |
| 2113 | //sleep(1); |
| 2114 | *(buff_ptr + 1) = (uint8)atoi(line_ptr); // net_type |
| 2115 | |
| 2116 | buff_size += sizeof(mbtk_net_info_t); |
| 2117 | buff_ptr += sizeof(mbtk_net_info_t); |
| 2118 | } |
| 2119 | |
| 2120 | line_ptr = strstr(line_ptr, "("); |
| 2121 | } |
| 2122 | exit: |
| 2123 | at_response_free(response); |
| 2124 | return buff_size; |
| 2125 | } |
| 2126 | #endif |
| 2127 | |
| 2128 | /* |
| 2129 | AT+COPS? |
| 2130 | +COPS: 1 |
| 2131 | |
| 2132 | OK |
| 2133 | |
| 2134 | or |
| 2135 | |
| 2136 | AT+COPS? |
| 2137 | +COPS: 0,2,"46001",7 |
| 2138 | |
| 2139 | OK |
| 2140 | |
| 2141 | */ |
| 2142 | static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err) |
| 2143 | { |
| 2144 | //LOG("req_net_sel_mode_get() 0"); |
| 2145 | //sleep(1); |
| 2146 | ATResponse *response = NULL; |
| 2147 | int tmp_int; |
| 2148 | char *tmp_ptr = NULL; |
| 2149 | int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 2150 | //LOG("req_net_sel_mode_get() 00"); |
| 2151 | //sleep(1); |
| 2152 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2153 | if(cme_err != NULL) |
| 2154 | *cme_err = at_get_cme_error(response); |
| 2155 | err = -1; |
| 2156 | goto exit; |
| 2157 | } |
| 2158 | //LOG("req_net_sel_mode_get() 1"); |
| 2159 | //sleep(1); |
| 2160 | char *line = response->p_intermediates->line; |
| 2161 | if(line == NULL) { |
| 2162 | LOG("line is NULL"); |
| 2163 | goto exit; |
| 2164 | } |
| 2165 | //LOG("req_net_sel_mode_get() 2"); |
| 2166 | //sleep(1); |
| 2167 | err = at_tok_start(&line); |
| 2168 | if (err < 0) |
| 2169 | { |
| 2170 | goto exit; |
| 2171 | } |
| 2172 | //LOG("req_net_sel_mode_get() 3"); |
| 2173 | //sleep(1); |
| 2174 | err = at_tok_nextint(&line, &tmp_int); |
| 2175 | if (err < 0) |
| 2176 | { |
| 2177 | goto exit; |
| 2178 | } |
| 2179 | net->net_sel_mode = (uint8)tmp_int; |
| 2180 | //LOG("req_net_sel_mode_get() 4"); |
| 2181 | //sleep(1); |
| 2182 | // +COPS: 1 |
| 2183 | if(!at_tok_hasmore(&line)) { |
| 2184 | goto exit; |
| 2185 | } |
| 2186 | //LOG("req_net_sel_mode_get() 5"); |
| 2187 | //sleep(1); |
| 2188 | err = at_tok_nextint(&line, &tmp_int); |
| 2189 | if (err < 0) |
| 2190 | { |
| 2191 | goto exit; |
| 2192 | } |
| 2193 | //LOG("req_net_sel_mode_get() 6"); |
| 2194 | //sleep(1); |
| 2195 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 2196 | if (err < 0) |
| 2197 | { |
| 2198 | goto exit; |
| 2199 | } |
| 2200 | // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr)); |
| 2201 | net->plmn = (uint32)atoi(tmp_ptr); |
| 2202 | //LOG("req_net_sel_mode_get() 7"); |
| 2203 | //sleep(1); |
| 2204 | err = at_tok_nextint(&line, &tmp_int); |
| 2205 | if (err < 0) |
| 2206 | { |
| 2207 | goto exit; |
| 2208 | } |
| 2209 | net->net_type = (uint8)tmp_int; |
| 2210 | |
| 2211 | net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT; |
| 2212 | |
| 2213 | exit: |
| 2214 | //LOG("req_net_sel_mode_get() 8"); |
| 2215 | //sleep(1); |
| 2216 | at_response_free(response); |
| 2217 | return err; |
| 2218 | } |
| 2219 | |
| 2220 | /* |
| 2221 | AT+COPS=0 |
| 2222 | or |
| 2223 | AT+COPS=1,2,"46000",7 |
| 2224 | |
| 2225 | OK |
| 2226 | |
| 2227 | */ |
| 2228 | static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err) |
| 2229 | { |
| 2230 | ATResponse *response = NULL; |
| 2231 | char cmd[50] = {0}; |
| 2232 | char* cmp_ptr = cmd; |
| 2233 | if(net == NULL) { |
| 2234 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0"); |
| 2235 | } else { |
| 2236 | if(net->net_sel_mode == 0) { |
| 2237 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0"); |
| 2238 | } else if(net->net_type == 0xFF) { |
| 2239 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn); |
| 2240 | } else { |
| 2241 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | int err = at_send_command(cmd, &response); |
| 2246 | |
| 2247 | if (err < 0 || response->success == 0) { |
| 2248 | *cme_err = at_get_cme_error(response); |
| 2249 | goto exit; |
| 2250 | } |
| 2251 | |
| 2252 | exit: |
| 2253 | at_response_free(response); |
| 2254 | return err; |
| 2255 | } |
| 2256 | |
| 2257 | /* |
| 2258 | AT+EEMOPT=1 |
| 2259 | OK |
| 2260 | |
| 2261 | // LTE |
| 2262 | AT+EEMGINFO? |
| 2263 | // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>, |
| 2264 | // <rsrp>,<rsrq>, <sinr>, |
| 2265 | // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi, |
| 2266 | // cellId,subFrameAssignType,specialSubframePatterns,transMode |
| 2267 | // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt, |
| 2268 | // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB, |
| 2269 | // dlBer, ulBer, |
| 2270 | // diversitySinr, diversityRssi |
| 2271 | +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20, |
| 2272 | 0, 0, 0, |
| 2273 | 1, 10, 0, 1, 0, 1059, 78, 3959566565, |
| 2274 | 105149248, 2, 7, 7, |
| 2275 | 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777, |
| 2276 | 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0, |
| 2277 | 0, 0, |
| 2278 | 7, 44 |
| 2279 | |
| 2280 | // index,phyCellId,euArfcn,rsrp,rsrq |
| 2281 | +EEMLTEINTER: 0, 65535, 38950, 0, 0 |
| 2282 | |
| 2283 | +EEMLTEINTER: 1, 0, 0, 0, 0 |
| 2284 | |
| 2285 | +EEMLTEINTER: 2, 0, 4294967295, 255, 255 |
| 2286 | |
| 2287 | +EEMLTEINTER: 3, 65535, 1300, 0, 0 |
| 2288 | |
| 2289 | +EEMLTEINTER: 4, 0, 0, 0, 0 |
| 2290 | |
| 2291 | +EEMLTEINTER: 5, 0, 4294967295, 247, 0 |
| 2292 | |
| 2293 | +EEMLTEINTER: 6, 197, 41332, 24, 9 |
| 2294 | |
| 2295 | +EEMLTEINTER: 7, 0, 0, 0, 0 |
| 2296 | |
| 2297 | +EEMLTEINTER: 8, 0, 0, 0, 0 |
| 2298 | |
| 2299 | +EEMLTEINTRA: 0, 429, 40936, 56, 12 |
| 2300 | |
| 2301 | +EEMLTEINTERRAT: 0,0 |
| 2302 | |
| 2303 | +EEMLTEINTERRAT: 1,0 |
| 2304 | |
| 2305 | +EEMGINFO: 3, 2 // <state>: |
| 2306 | // 0: ME in Idle mode |
| 2307 | // 1: ME in Dedicated mode |
| 2308 | // 2: ME in PS PTM mode |
| 2309 | // 3: invalid state |
| 2310 | // <nw_type>: |
| 2311 | // 0: GSM 1: UMTS 2: LTE |
| 2312 | |
| 2313 | OK |
| 2314 | |
| 2315 | // WCDMA |
| 2316 | AT+EEMGINFO? |
| 2317 | // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent, |
| 2318 | |
| 2319 | // if sCMeasPresent == 1 |
| 2320 | // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower, |
| 2321 | // endif |
| 2322 | |
| 2323 | // if sCParamPresent == 1 |
| 2324 | // rac, nom, mcc, mnc_len, mnc, lac, ci, |
| 2325 | // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed, |
| 2326 | // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport, |
| 2327 | // endif |
| 2328 | |
| 2329 | // if ueOpStatusPresent == 1 |
| 2330 | // rrcState, numLinks, srncId, sRnti, |
| 2331 | // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn, |
| 2332 | // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause, |
| 2333 | // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput, |
| 2334 | // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count |
| 2335 | // endif |
| 2336 | // |
| 2337 | +EEMUMTSSVC: 3, 1, 1, 1, |
| 2338 | -80, 27, -6, -18, -115, -32768, |
| 2339 | 1, 1, 1120, 2, 1, 61697, 168432821, |
| 2340 | 15, 24, 10763, 0, 0, 0, 0, |
| 2341 | 128, 128, 65535, 0, 0, |
| 2342 | 2, 255, 65535, 4294967295, |
| 2343 | 0, 0, 0, 0, 0, 0, |
| 2344 | 0, 0, 0, 0, 0, 0, 1, 1, |
| 2345 | 28672, 28672, 0, 0, 0, 0, 0, 0, 0, |
| 2346 | 0, 0, 0, 0, 0, 0 |
| 2347 | |
| 2348 | // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc |
| 2349 | +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32 |
| 2350 | |
| 2351 | +EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768 |
| 2352 | |
| 2353 | +EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535 |
| 2354 | |
| 2355 | +EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768 |
| 2356 | |
| 2357 | +EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518 |
| 2358 | |
| 2359 | +EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421 |
| 2360 | |
| 2361 | +EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0 |
| 2362 | |
| 2363 | +EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0 |
| 2364 | |
| 2365 | +EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534 |
| 2366 | |
| 2367 | +EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11 |
| 2368 | |
| 2369 | +EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763 |
| 2370 | |
| 2371 | +EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66 |
| 2372 | |
| 2373 | +EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768 |
| 2374 | |
| 2375 | +EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535 |
| 2376 | |
| 2377 | +EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768 |
| 2378 | |
| 2379 | +EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518 |
| 2380 | |
| 2381 | +EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421 |
| 2382 | |
| 2383 | +EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0 |
| 2384 | |
| 2385 | +EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0 |
| 2386 | |
| 2387 | +EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534 |
| 2388 | |
| 2389 | +EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23 |
| 2390 | |
| 2391 | +EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763 |
| 2392 | |
| 2393 | +EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0 |
| 2394 | |
| 2395 | +EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768 |
| 2396 | |
| 2397 | +EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535 |
| 2398 | |
| 2399 | +EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768 |
| 2400 | |
| 2401 | +EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518 |
| 2402 | |
| 2403 | +EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0 |
| 2404 | |
| 2405 | +EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 2406 | |
| 2407 | +EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239 |
| 2408 | |
| 2409 | // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic |
| 2410 | +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36 |
| 2411 | |
| 2412 | +EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0 |
| 2413 | |
| 2414 | +EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149 |
| 2415 | |
| 2416 | +EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0 |
| 2417 | |
| 2418 | +EEMGINFO: 3, 1 |
| 2419 | |
| 2420 | OK |
| 2421 | |
| 2422 | |
| 2423 | // GSM |
| 2424 | AT+EEMGINFO? |
| 2425 | +EEMGINFOBASIC: 2 |
| 2426 | |
| 2427 | // mcc, mnc_len, mnc, lac, ci, nom, nco, |
| 2428 | // bsic, C1, C2, TA, TxPwr, |
| 2429 | // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub, |
| 2430 | // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn, |
| 2431 | // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support, |
| 2432 | // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count, |
| 2433 | // gsmBand,channelMode |
| 2434 | +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0, |
| 2435 | 63, 36, 146, 1, 7, |
| 2436 | 46, 42, 42, 7, 0, |
| 2437 | 53, 0, 8, 0, 1, 6, 53, |
| 2438 | 2, 0, 146, 42, 54, 0, 1, |
| 2439 | 1, 32, 0, 0, 0, 0, |
| 2440 | 0, 0 |
| 2441 | |
| 2442 | // PS_attached, attach_type, service_type, tx_power, c_value, |
| 2443 | // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation, |
| 2444 | // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause |
| 2445 | // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status |
| 2446 | +EEMGINFOPS: 1, 255, 0, 0, 0, |
| 2447 | 0, 0, 268435501, 1, 0, 0, |
| 2448 | 4, 0, 96, 0, 0, 0, |
| 2449 | 0, 0, 0, 65535, 0, 13350 |
| 2450 | |
| 2451 | +EEMGINFO: 0, 0 |
| 2452 | |
| 2453 | OK |
| 2454 | |
| 2455 | */ |
| 2456 | static int req_cell_info_get(int *cme_err) |
| 2457 | { |
| 2458 | ATResponse *response = NULL; |
| 2459 | int tmp_int; |
| 2460 | int buff_size = 0; |
| 2461 | // AT+EEMOPT=1 in the first. |
| 2462 | int err = at_send_command("AT+EEMOPT=1", &response); |
| 2463 | if (err < 0 || response->success == 0){ |
| 2464 | *cme_err = at_get_cme_error(response); |
| 2465 | goto exit; |
| 2466 | } |
| 2467 | |
| 2468 | // Reset buffer in the first. |
| 2469 | memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t)); |
| 2470 | cell_info.running = true; |
| 2471 | cell_info.cell_num = 0; |
| 2472 | |
| 2473 | err = at_send_command_singleline("AT+EEMGINFO?", "+EEMGINFO:", &response); |
| 2474 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2475 | *cme_err = at_get_cme_error(response); |
| 2476 | goto exit; |
| 2477 | } |
| 2478 | |
| 2479 | // Now, cell infomation has get from URC message. |
| 2480 | |
| 2481 | char *line = response->p_intermediates->line; |
| 2482 | err = at_tok_start(&line); |
| 2483 | if (err < 0) |
| 2484 | { |
| 2485 | goto exit; |
| 2486 | } |
| 2487 | err = at_tok_nextint(&line, &tmp_int); |
| 2488 | if (err < 0) |
| 2489 | { |
| 2490 | goto exit; |
| 2491 | } |
| 2492 | err = at_tok_nextint(&line, &tmp_int); |
| 2493 | if (err < 0) |
| 2494 | { |
| 2495 | goto exit; |
| 2496 | } |
| 2497 | |
| 2498 | cell_info.type = (uint8)tmp_int; |
| 2499 | cell_info.running = false; |
| 2500 | |
| 2501 | #if 0 |
| 2502 | while(lines_ptr) |
| 2503 | { |
| 2504 | // LTE |
| 2505 | if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell |
| 2506 | { |
| 2507 | |
| 2508 | } |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 2509 | else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2510 | { |
| 2511 | |
| 2512 | } |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 2513 | else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2514 | { |
| 2515 | |
| 2516 | } |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 2517 | else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2518 | { |
| 2519 | |
| 2520 | } |
| 2521 | else if(strStartsWith(line, "+EEMGINFO:")) // <state>: 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode 3: invalid state |
| 2522 | // <nw_type>: 0: GSM 1: UMTS 2: LTE |
| 2523 | { |
| 2524 | |
| 2525 | } |
| 2526 | // WCDMA |
| 2527 | else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell |
| 2528 | { |
| 2529 | |
| 2530 | } |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 2531 | else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2532 | { |
| 2533 | |
| 2534 | } |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 2535 | else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2536 | { |
| 2537 | |
| 2538 | } |
| 2539 | // GSM |
| 2540 | else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM |
| 2541 | // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode |
| 2542 | { |
| 2543 | |
| 2544 | } |
| 2545 | else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell |
| 2546 | { |
| 2547 | |
| 2548 | } |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 2549 | else if(strStartsWith(line, "+EEMGINFOPS:")) // PS |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2550 | { |
| 2551 | |
| 2552 | } |
| 2553 | |
| 2554 | |
| 2555 | lines_ptr = lines_ptr->p_next; |
| 2556 | } |
| 2557 | #endif |
| 2558 | |
| 2559 | exit: |
| 2560 | at_response_free(response); |
| 2561 | return buff_size; |
| 2562 | } |
| 2563 | |
| 2564 | static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err) |
| 2565 | { |
| 2566 | printf("req_cmgl_set(2)-----------------start\n"); |
| 2567 | printf("cmgl:%s\n", cmgl); |
| 2568 | ATResponse *response = NULL; |
| 2569 | char cmd[30] = {0}; |
| 2570 | char data[218] = {0}; |
| 2571 | int err = 0; |
| 2572 | |
| 2573 | memcpy(data, cmgl, len); |
| 2574 | |
| 2575 | sprintf(cmd, "at*cell=%s", data); |
| 2576 | printf("cmd:%s\n", cmd); |
| 2577 | |
| 2578 | if(strlen(cmd) > 0) |
| 2579 | { |
| 2580 | err = at_send_command_multiline(cmd, "", &response); |
| 2581 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2582 | *cme_err = at_get_cme_error(response); |
| 2583 | // printf("at_send_command_multiline() is err-----------------\n"); |
| 2584 | goto exit; |
| 2585 | } |
| 2586 | |
| 2587 | ATLine* lines_ptr = response->p_intermediates; |
| 2588 | char *line = NULL; |
| 2589 | int reg_len = 0; |
| 2590 | bool flag = false; |
| 2591 | while(lines_ptr) |
| 2592 | { |
| 2593 | line = lines_ptr->line; |
| 2594 | if(line ==NULL) |
| 2595 | { |
| 2596 | printf("line is null----------------------\n"); |
| 2597 | } |
| 2598 | printf("-----line:%s\n", line); |
| 2599 | |
| 2600 | lines_ptr = lines_ptr->p_next; |
| 2601 | } |
| 2602 | } |
| 2603 | err = 0; |
| 2604 | memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss")); |
| 2605 | exit: |
| 2606 | at_response_free(response); |
| 2607 | printf("req_cell_info_set()-----------------end\n"); |
| 2608 | return err; |
| 2609 | } |
| 2610 | |
| 2611 | |
| 2612 | |
| 2613 | /* |
| 2614 | AT+CSQ |
| 2615 | +CSQ: 31,99 |
| 2616 | |
| 2617 | OK |
| 2618 | |
| 2619 | AT+CESQ |
| 2620 | +CESQ: 60,99,255,255,20,61 |
| 2621 | |
| 2622 | OK |
| 2623 | |
| 2624 | AT+COPS? |
| 2625 | +COPS: 0,2,"46001",7 |
| 2626 | |
| 2627 | OK |
| 2628 | |
| 2629 | */ |
| 2630 | static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err) |
| 2631 | { |
| 2632 | ATResponse *response = NULL; |
| 2633 | int tmp_int; |
| 2634 | char *tmp_ptr = NULL; |
| 2635 | // AT+EEMOPT=1 in the first. |
| 2636 | int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response); |
| 2637 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2638 | if(cme_err != NULL) |
| 2639 | *cme_err = at_get_cme_error(response); |
| 2640 | err = -1; |
| 2641 | goto exit; |
| 2642 | } |
| 2643 | |
| 2644 | char *line = response->p_intermediates->line; |
| 2645 | err = at_tok_start(&line); |
| 2646 | if (err < 0) |
| 2647 | { |
| 2648 | goto exit; |
| 2649 | } |
| 2650 | err = at_tok_nextint(&line, &tmp_int); |
| 2651 | if (err < 0) |
| 2652 | { |
| 2653 | goto exit; |
| 2654 | } |
| 2655 | signal->rssi = (uint8)tmp_int; |
| 2656 | at_response_free(response); |
| 2657 | |
| 2658 | err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response); |
| 2659 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2660 | if(cme_err != NULL) |
| 2661 | *cme_err = at_get_cme_error(response); |
| 2662 | err = -1; |
| 2663 | goto exit; |
| 2664 | } |
| 2665 | |
| 2666 | line = response->p_intermediates->line; |
| 2667 | err = at_tok_start(&line); |
| 2668 | if (err < 0) |
| 2669 | { |
| 2670 | goto exit; |
| 2671 | } |
| 2672 | err = at_tok_nextint(&line, &tmp_int); |
| 2673 | if (err < 0) |
| 2674 | { |
| 2675 | goto exit; |
| 2676 | } |
| 2677 | signal->rxlev = (uint8)tmp_int; |
| 2678 | |
| 2679 | err = at_tok_nextint(&line, &tmp_int); |
| 2680 | if (err < 0) |
| 2681 | { |
| 2682 | goto exit; |
| 2683 | } |
| 2684 | signal->ber = (uint8)tmp_int; |
| 2685 | |
| 2686 | err = at_tok_nextint(&line, &tmp_int); |
| 2687 | if (err < 0) |
| 2688 | { |
| 2689 | goto exit; |
| 2690 | } |
| 2691 | signal->rscp = (uint8)tmp_int; |
| 2692 | |
| 2693 | err = at_tok_nextint(&line, &tmp_int); |
| 2694 | if (err < 0) |
| 2695 | { |
| 2696 | goto exit; |
| 2697 | } |
| 2698 | signal->ecno = (uint8)tmp_int; |
| 2699 | |
| 2700 | err = at_tok_nextint(&line, &tmp_int); |
| 2701 | if (err < 0) |
| 2702 | { |
| 2703 | goto exit; |
| 2704 | } |
| 2705 | signal->rsrq = (uint8)tmp_int; |
| 2706 | |
| 2707 | err = at_tok_nextint(&line, &tmp_int); |
| 2708 | if (err < 0) |
| 2709 | { |
| 2710 | goto exit; |
| 2711 | } |
| 2712 | signal->rsrp = (uint8)tmp_int; |
| 2713 | |
| 2714 | at_response_free(response); |
| 2715 | err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 2716 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2717 | if(cme_err != NULL) |
| 2718 | *cme_err = at_get_cme_error(response); |
| 2719 | err = -1; |
| 2720 | goto exit; |
| 2721 | } |
| 2722 | line = response->p_intermediates->line; |
| 2723 | err = at_tok_start(&line); |
| 2724 | if (err < 0) |
| 2725 | { |
| 2726 | goto exit; |
| 2727 | } |
| 2728 | err = at_tok_nextint(&line, &tmp_int); |
| 2729 | if (err < 0) |
| 2730 | { |
| 2731 | goto exit; |
| 2732 | } |
| 2733 | if(!at_tok_hasmore(&line)) { |
| 2734 | goto exit; |
| 2735 | } |
| 2736 | err = at_tok_nextint(&line, &tmp_int); |
| 2737 | if (err < 0) |
| 2738 | { |
| 2739 | goto exit; |
| 2740 | } |
| 2741 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 2742 | if (err < 0) |
| 2743 | { |
| 2744 | goto exit; |
| 2745 | } |
| 2746 | err = at_tok_nextint(&line, &tmp_int); |
| 2747 | if (err < 0) |
| 2748 | { |
| 2749 | goto exit; |
| 2750 | } |
| 2751 | signal->type = (uint8)tmp_int; |
| 2752 | net_info.net_type = signal->type; |
| 2753 | |
| 2754 | exit: |
| 2755 | at_response_free(response); |
| 2756 | return err; |
| 2757 | } |
| 2758 | |
| 2759 | /* |
| 2760 | AT+CREG=3 |
| 2761 | OK |
| 2762 | |
| 2763 | AT+CREG? |
| 2764 | +CREG: 3,1,"8330","06447340",7 |
| 2765 | |
| 2766 | OK |
| 2767 | |
| 2768 | AT+CREG? |
| 2769 | +CREG: 3,0 |
| 2770 | |
| 2771 | OK |
| 2772 | |
| 2773 | AT+CEREG? |
| 2774 | +CEREG: 3,1,"8330","06447340",7 |
| 2775 | |
| 2776 | OK |
| 2777 | |
| 2778 | |
| 2779 | AT+CIREG? |
| 2780 | +CIREG: 2,1,15 |
| 2781 | |
| 2782 | OK |
| 2783 | |
| 2784 | AT+CIREG? |
| 2785 | +CIREG: 0 |
| 2786 | |
| 2787 | OK |
| 2788 | |
| 2789 | |
| 2790 | */ |
| 2791 | static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err) |
| 2792 | { |
| 2793 | ATResponse *response = NULL; |
| 2794 | int tmp_int; |
| 2795 | char *tmp_str = NULL; |
| 2796 | int err = at_send_command("AT+CREG=3", &response); |
| 2797 | if (err < 0 || response->success == 0){ |
| 2798 | *cme_err = at_get_cme_error(response); |
| 2799 | goto exit; |
| 2800 | } |
| 2801 | at_response_free(response); |
| 2802 | |
| 2803 | err = at_send_command_multiline("AT+CREG?", "+CREG:", &response); |
| 2804 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2805 | *cme_err = at_get_cme_error(response); |
| 2806 | goto exit; |
| 2807 | } |
| 2808 | |
| 2809 | char *line = response->p_intermediates->line; |
| 2810 | err = at_tok_start(&line); |
| 2811 | if (err < 0) |
| 2812 | { |
| 2813 | goto exit; |
| 2814 | } |
| 2815 | err = at_tok_nextint(&line, &tmp_int); // n |
| 2816 | if (err < 0) |
| 2817 | { |
| 2818 | goto exit; |
| 2819 | } |
| 2820 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 2821 | if (err < 0) |
| 2822 | { |
| 2823 | goto exit; |
| 2824 | } |
| 2825 | reg->call_state = (uint8)tmp_int; |
| 2826 | |
| 2827 | if(at_tok_hasmore(&line)) { |
| 2828 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 2829 | if (err < 0) |
| 2830 | { |
| 2831 | goto exit; |
| 2832 | } |
| 2833 | reg->lac = strtol(tmp_str, NULL, 16); |
| 2834 | |
| 2835 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 2836 | if (err < 0) |
| 2837 | { |
| 2838 | goto exit; |
| 2839 | } |
| 2840 | reg->ci = strtol(tmp_str, NULL, 16); |
| 2841 | |
| 2842 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 2843 | if (err < 0) |
| 2844 | { |
| 2845 | goto exit; |
| 2846 | } |
| 2847 | reg->type = (uint8)tmp_int; |
| 2848 | } |
| 2849 | at_response_free(response); |
| 2850 | |
| 2851 | err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response); |
| 2852 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2853 | *cme_err = at_get_cme_error(response); |
| 2854 | goto exit; |
| 2855 | } |
| 2856 | |
| 2857 | line = response->p_intermediates->line; |
| 2858 | err = at_tok_start(&line); |
| 2859 | if (err < 0) |
| 2860 | { |
| 2861 | goto exit; |
| 2862 | } |
| 2863 | err = at_tok_nextint(&line, &tmp_int); // n |
| 2864 | if (err < 0) |
| 2865 | { |
| 2866 | goto exit; |
| 2867 | } |
| 2868 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 2869 | if (err < 0) |
| 2870 | { |
| 2871 | goto exit; |
| 2872 | } |
| 2873 | reg->data_state = (uint8)tmp_int; |
| 2874 | |
| 2875 | if(reg->lac == 0 && at_tok_hasmore(&line)) { |
| 2876 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 2877 | if (err < 0) |
| 2878 | { |
| 2879 | goto exit; |
| 2880 | } |
| 2881 | reg->lac = strtol(tmp_str, NULL, 16); |
| 2882 | |
| 2883 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 2884 | if (err < 0) |
| 2885 | { |
| 2886 | goto exit; |
| 2887 | } |
| 2888 | reg->ci = strtol(tmp_str, NULL, 16); |
| 2889 | |
| 2890 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 2891 | if (err < 0) |
| 2892 | { |
| 2893 | goto exit; |
| 2894 | } |
| 2895 | reg->type = (uint8)tmp_int; |
| 2896 | } |
| 2897 | at_response_free(response); |
| 2898 | |
| 2899 | err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response); |
| 2900 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2901 | reg->ims_state = (uint8)0; |
| 2902 | err = 0; |
| 2903 | goto exit; |
| 2904 | } |
| 2905 | line = response->p_intermediates->line; |
| 2906 | err = at_tok_start(&line); |
| 2907 | if (err < 0) |
| 2908 | { |
| 2909 | goto exit; |
| 2910 | } |
| 2911 | err = at_tok_nextint(&line, &tmp_int); // n/stat |
| 2912 | if (err < 0) |
| 2913 | { |
| 2914 | goto exit; |
| 2915 | } |
| 2916 | if(at_tok_hasmore(&line)) { |
| 2917 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 2918 | if (err < 0) |
| 2919 | { |
| 2920 | goto exit; |
| 2921 | } |
| 2922 | reg->ims_state = (uint8)tmp_int; |
| 2923 | } else { |
| 2924 | reg->ims_state = (uint8)tmp_int; |
| 2925 | } |
| 2926 | |
| 2927 | exit: |
| 2928 | at_response_free(response); |
| 2929 | return err; |
| 2930 | } |
| 2931 | |
r.xiao | 06db9a1 | 2024-04-14 18:51:15 -0700 | [diff] [blame] | 2932 | |
| 2933 | static int net_ims_set(uint8 reg, int *cme_err) |
| 2934 | { |
| 2935 | ATResponse *response = NULL; |
| 2936 | char cmd[30] = {0}; |
| 2937 | int err = -1; |
| 2938 | |
| 2939 | sprintf(cmd, "AT+CIREG=%d", reg); |
| 2940 | err = at_send_command(cmd, &response); |
| 2941 | LOG("cmd : %s", cmd); |
| 2942 | |
| 2943 | if (err < 0 || response->success == 0){ |
| 2944 | *cme_err = at_get_cme_error(response); |
| 2945 | goto exit; |
| 2946 | } |
| 2947 | |
| 2948 | exit: |
| 2949 | at_response_free(response); |
| 2950 | return err; |
| 2951 | } |
| 2952 | |
| 2953 | |
| 2954 | static int net_ims_get(int *reg, int *cme_err) |
| 2955 | { |
| 2956 | ATResponse *response = NULL; |
| 2957 | int tmp_int, tmp_reg; |
| 2958 | int err; |
| 2959 | char *tmp_str = NULL; |
| 2960 | |
| 2961 | err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response); |
| 2962 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 2963 | tmp_reg = 0; |
| 2964 | err = 0; |
| 2965 | goto exit; |
| 2966 | } |
| 2967 | char *line = response->p_intermediates->line; |
| 2968 | err = at_tok_start(&line); |
| 2969 | if (err < 0) |
| 2970 | { |
| 2971 | goto exit; |
| 2972 | } |
| 2973 | err = at_tok_nextint(&line, &tmp_int); // n/stat |
| 2974 | if (err < 0) |
| 2975 | { |
| 2976 | goto exit; |
| 2977 | } |
| 2978 | if(at_tok_hasmore(&line)) { |
| 2979 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 2980 | if (err < 0) |
| 2981 | { |
| 2982 | goto exit; |
| 2983 | } |
| 2984 | tmp_reg = tmp_int; |
| 2985 | } else { |
| 2986 | tmp_reg = tmp_int; |
| 2987 | } |
| 2988 | |
| 2989 | LOG("net_ims_get reg : %u", tmp_reg); |
| 2990 | |
| 2991 | exit: |
| 2992 | at_response_free(response); |
| 2993 | *reg = tmp_reg; |
| 2994 | return err; |
| 2995 | } |
| 2996 | |
| 2997 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2998 | /* |
| 2999 | AT+CGDCONT? |
| 3000 | +CGDCONT: 1,"IPV4V6","cmnet.MNC000.MCC460.GPRS","10.131.67.146 254.128.0.0.0.0.0.0.0.1.0.2.200.2.158.0",0,0,,,, |
| 3001 | |
| 3002 | +CGDCONT: 8,"IPV4V6","IMS","254.128.0.0.0.0.0.0.0.1.0.2.200.2.160.160",0,0,0,2,1,1 |
| 3003 | |
| 3004 | OK |
| 3005 | |
| 3006 | |
| 3007 | */ |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 3008 | #ifdef MBTK_AF_SUPPORT |
| 3009 | mbtk_ip_type_enum default_iptype = MBTK_IP_TYPE_IPV4V6; |
| 3010 | #endif |
| 3011 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 3012 | static int req_apn_get(void *data, int *data_len, int *cme_err) |
| 3013 | { |
| 3014 | ATResponse *response = NULL; |
| 3015 | int err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &response); |
| 3016 | |
| 3017 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3018 | *cme_err = at_get_cme_error(response); |
| 3019 | goto exit; |
| 3020 | } |
| 3021 | |
| 3022 | ATLine* lines_ptr = response->p_intermediates; |
| 3023 | char *line = NULL; |
| 3024 | int tmp_int; |
| 3025 | char *tmp_str = NULL; |
| 3026 | /* |
| 3027 | <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>... |
| 3028 | <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth> |
| 3029 | */ |
| 3030 | uint8* apn_num = (uint8*)data; |
| 3031 | uint8* data_ptr = (uint8*)(data + sizeof(uint8)); // Jump apn_num[1] |
| 3032 | mbtk_apn_info_t apn; |
| 3033 | while(lines_ptr) |
| 3034 | { |
| 3035 | line = lines_ptr->line; |
| 3036 | err = at_tok_start(&line); |
| 3037 | if (err < 0) |
| 3038 | { |
| 3039 | goto exit; |
| 3040 | } |
| 3041 | |
| 3042 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3043 | if (err < 0) |
| 3044 | { |
| 3045 | goto exit; |
| 3046 | } |
| 3047 | // Only get CID 1-7 |
| 3048 | if(tmp_int >= MBTK_APN_CID_MIN && tmp_int <= MBTK_APN_CID_MAX) { |
| 3049 | memset(&apn, 0x0, sizeof(mbtk_apn_info_t)); |
| 3050 | apn.cid = tmp_int; |
| 3051 | *data_ptr++ = (uint8)tmp_int; // cid |
| 3052 | |
| 3053 | err = at_tok_nextstr(&line, &tmp_str);// ip type |
| 3054 | if (err < 0) |
| 3055 | { |
| 3056 | goto exit; |
| 3057 | } |
| 3058 | if(!strcasecmp(tmp_str, "IP")) { |
| 3059 | *data_ptr++ = (uint8)MBTK_IP_TYPE_IP; |
| 3060 | apn.ip_type = MBTK_IP_TYPE_IP; |
| 3061 | } else if(!strcasecmp(tmp_str, "IPV6")) { |
| 3062 | *data_ptr++ = (uint8)MBTK_IP_TYPE_IPV6; |
| 3063 | apn.ip_type = MBTK_IP_TYPE_IPV6; |
| 3064 | } else if(!strcasecmp(tmp_str, "IPV4V6")) { |
| 3065 | *data_ptr++ = (uint8)MBTK_IP_TYPE_IPV4V6; |
| 3066 | apn.ip_type = MBTK_IP_TYPE_IPV4V6; |
| 3067 | } else { |
| 3068 | *data_ptr++ = (uint8)MBTK_IP_TYPE_PPP; |
| 3069 | apn.ip_type = MBTK_IP_TYPE_PPP; |
| 3070 | } |
| 3071 | |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 3072 | #ifdef MBTK_AF_SUPPORT |
| 3073 | if(apn.cid == 1) |
| 3074 | { |
| 3075 | default_iptype = apn.ip_type; |
| 3076 | } |
| 3077 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 3078 | err = at_tok_nextstr(&line, &tmp_str); // apn |
| 3079 | if (err < 0) |
| 3080 | { |
| 3081 | goto exit; |
| 3082 | } |
| 3083 | if(str_empty(tmp_str)) { |
| 3084 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3085 | data_ptr += sizeof(uint16); |
| 3086 | } else { |
| 3087 | uint16_2_byte((uint16)strlen(tmp_str), data_ptr, false); |
| 3088 | data_ptr += sizeof(uint16); |
| 3089 | memcpy(data_ptr, tmp_str, strlen(tmp_str)); |
| 3090 | data_ptr += strlen(tmp_str); |
| 3091 | memcpy(apn.apn, tmp_str, strlen(tmp_str)); |
| 3092 | } |
| 3093 | |
| 3094 | if(apn_user_pass_set_by_cid(apn.cid, &apn)) { |
| 3095 | // user |
| 3096 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3097 | data_ptr += sizeof(uint16); |
| 3098 | |
| 3099 | // pass |
| 3100 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3101 | data_ptr += sizeof(uint16); |
| 3102 | |
| 3103 | // auth |
| 3104 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3105 | data_ptr += sizeof(uint16); |
| 3106 | } else { |
| 3107 | // user |
| 3108 | if(str_empty(apn.user)) { |
| 3109 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3110 | data_ptr += sizeof(uint16); |
| 3111 | } else { |
| 3112 | uint16_2_byte((uint16)strlen(apn.user), data_ptr, false); |
| 3113 | data_ptr += sizeof(uint16); |
| 3114 | memcpy(data_ptr, apn.user, strlen(apn.user)); |
| 3115 | data_ptr += strlen(apn.user); |
| 3116 | } |
| 3117 | |
| 3118 | // pass |
| 3119 | if(str_empty(apn.pass)) { |
| 3120 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3121 | data_ptr += sizeof(uint16); |
| 3122 | } else { |
| 3123 | uint16_2_byte((uint16)strlen(apn.pass), data_ptr, false); |
| 3124 | data_ptr += sizeof(uint16); |
| 3125 | memcpy(data_ptr, apn.pass, strlen(apn.pass)); |
| 3126 | data_ptr += strlen(apn.pass); |
| 3127 | } |
| 3128 | |
| 3129 | // auth |
| 3130 | if(str_empty(apn.auth)) { |
| 3131 | uint16_2_byte((uint16)0, data_ptr, false); |
| 3132 | data_ptr += sizeof(uint16); |
| 3133 | } else { |
| 3134 | uint16_2_byte((uint16)strlen(apn.auth), data_ptr, false); |
| 3135 | data_ptr += sizeof(uint16); |
| 3136 | memcpy(data_ptr, apn.auth, strlen(apn.auth)); |
| 3137 | data_ptr += strlen(apn.auth); |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | (*apn_num)++; |
| 3142 | } |
| 3143 | |
| 3144 | lines_ptr = lines_ptr->p_next; |
| 3145 | } |
| 3146 | |
| 3147 | *data_len = data_ptr - (uint8*)data; |
| 3148 | |
| 3149 | goto exit; |
| 3150 | exit: |
| 3151 | at_response_free(response); |
| 3152 | return err; |
| 3153 | } |
| 3154 | |
| 3155 | #if 0 |
| 3156 | /* |
| 3157 | LTE APN |
| 3158 | AT+CFUN=4 |
| 3159 | AT*CGDFLT=1,IP,"private.vpdn",1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1 |
| 3160 | AT*CGDFAUTH=1,2,"noc@njcc.vpdn.js","123456" |
| 3161 | AT+CFUN=1 |
| 3162 | AT+CEREG? |
| 3163 | AT+CGDCONT? |
| 3164 | |
| 3165 | 2/3G APN |
| 3166 | AT+CGREG? |
| 3167 | AT+CGDCONT=6,IP,"private.vpdn" |
| 3168 | AT*AUTHREQ=6,2,"noc@njcc.vpdn.js","123456" |
| 3169 | AT+CGDATA="",6 |
| 3170 | AT+CGDCONT? |
| 3171 | */ |
| 3172 | static int req_apn_set_username(mbtk_apn_info_t *apn, int *cme_err) |
| 3173 | { |
| 3174 | ATResponse *response = NULL; |
| 3175 | char cmd[400] = {0}; |
| 3176 | int index = 0; |
| 3177 | int err = 0; |
| 3178 | |
| 3179 | err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 3180 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3181 | if(cme_err != NULL) |
| 3182 | *cme_err = at_get_cme_error(response); |
| 3183 | err = -1; |
| 3184 | goto apn_set; |
| 3185 | } |
| 3186 | |
| 3187 | int tmp_int = 0; |
| 3188 | int state=0; |
| 3189 | char cmd_buf[64]; |
| 3190 | char *line = response->p_intermediates->line; |
| 3191 | err = at_tok_start(&line); |
| 3192 | if (err < 0) |
| 3193 | { |
| 3194 | goto apn_set; |
| 3195 | } |
| 3196 | err = at_tok_nextint(&line, &tmp_int); |
| 3197 | if (err < 0) |
| 3198 | { |
| 3199 | goto apn_set; |
| 3200 | } |
| 3201 | err = at_tok_nextint(&line, &tmp_int); |
| 3202 | if (err < 0) |
| 3203 | { |
| 3204 | goto apn_set; |
| 3205 | } |
| 3206 | err = at_tok_nextstr(&line, &cmd_buf); |
| 3207 | if (err < 0) |
| 3208 | { |
| 3209 | goto apn_set; |
| 3210 | } |
| 3211 | err = at_tok_nextint(&line, &tmp_int); |
| 3212 | if (err < 0) |
| 3213 | { |
| 3214 | goto apn_set; |
| 3215 | } |
| 3216 | else |
| 3217 | state = tmp_int; |
| 3218 | |
| 3219 | apn_set: |
| 3220 | at_response_free(response); |
| 3221 | *cme_err = MBTK_INFO_ERR_CME_NON; |
| 3222 | //if(state == 7 && apn->cid == 1) //LTE && cid = 1 |
| 3223 | if(0) //LTE && cid = 1 |
| 3224 | { |
| 3225 | err = at_send_command("AT+CFUN=4", &response); |
| 3226 | if (err < 0 || response->success == 0){ |
| 3227 | *cme_err = at_get_cme_error(response); |
| 3228 | goto exit; |
| 3229 | } |
| 3230 | at_response_free(response); |
| 3231 | |
| 3232 | memset(cmd, 0, 400); |
| 3233 | index = 0; |
| 3234 | index += sprintf(cmd, "AT*CGDFLT=%d,", 1); |
| 3235 | switch(apn->ip_type) { |
| 3236 | case MBTK_IP_TYPE_IP: { |
| 3237 | index += sprintf(cmd + index,"\"IP\","); |
| 3238 | break; |
| 3239 | } |
| 3240 | case MBTK_IP_TYPE_IPV6: { |
| 3241 | index += sprintf(cmd + index,"\"IPV6\","); |
| 3242 | break; |
| 3243 | } |
| 3244 | case MBTK_IP_TYPE_IPV4V6: { |
| 3245 | index += sprintf(cmd + index,"\"IPV4V6\","); |
| 3246 | break; |
| 3247 | } |
| 3248 | default: { |
| 3249 | index += sprintf(cmd + index,"\"PPP\","); |
| 3250 | break; |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | index += sprintf(cmd + index,"\"%s\",1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1",apn->apn); |
| 3255 | err = at_send_command(cmd, &response); |
| 3256 | if (err < 0 || response->success == 0){ |
| 3257 | *cme_err = at_get_cme_error(response); |
| 3258 | goto exit; |
| 3259 | } |
| 3260 | at_response_free(response); |
| 3261 | |
| 3262 | memset(cmd, 0, 400); |
| 3263 | int cmd_auth=0; |
| 3264 | if(strstr(apn->auth,"NONE")) |
| 3265 | cmd_auth = 0; |
| 3266 | else if(strstr(apn->auth,"PAP")) |
| 3267 | cmd_auth = 1; |
| 3268 | else if(strstr(apn->auth,"CHAP")) |
| 3269 | cmd_auth = 2; |
| 3270 | else if(strstr(apn->auth,"PAP AND CHAP")) |
| 3271 | cmd_auth = 3; |
| 3272 | else |
| 3273 | goto exit; |
| 3274 | |
| 3275 | sprintf(cmd,"AT*CGDFAUTH=1,%d,%s,%s",cmd_auth,apn->user,apn->pass); |
| 3276 | |
| 3277 | err = at_send_command(cmd, &response); |
| 3278 | if (err < 0 || response->success == 0){ |
| 3279 | *cme_err = at_get_cme_error(response); |
| 3280 | goto exit; |
| 3281 | } |
| 3282 | } |
| 3283 | else //2/3G |
| 3284 | { |
| 3285 | memset(cmd,0,400); |
| 3286 | index = 0; |
| 3287 | index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid); |
| 3288 | switch(apn->ip_type) { |
| 3289 | case MBTK_IP_TYPE_IP: { |
| 3290 | index += sprintf(cmd + index,"\"IP\","); |
| 3291 | break; |
| 3292 | } |
| 3293 | case MBTK_IP_TYPE_IPV6: { |
| 3294 | index += sprintf(cmd + index,"\"IPV6\","); |
| 3295 | break; |
| 3296 | } |
| 3297 | case MBTK_IP_TYPE_IPV4V6: { |
| 3298 | index += sprintf(cmd + index,"\"IPV4V6\","); |
| 3299 | break; |
| 3300 | } |
| 3301 | default: { |
| 3302 | index += sprintf(cmd + index,"\"PPP\","); |
| 3303 | break; |
| 3304 | } |
| 3305 | } |
| 3306 | index += sprintf(cmd + index, "\"%s\"", apn->apn); |
| 3307 | |
| 3308 | err = at_send_command(cmd, &response); |
| 3309 | if (err < 0 || response->success == 0){ |
| 3310 | *cme_err = at_get_cme_error(response); |
| 3311 | goto exit; |
| 3312 | } |
| 3313 | at_response_free(response); |
| 3314 | |
| 3315 | memset(cmd,0,400); |
| 3316 | int cmd_auth=0; |
| 3317 | if(strstr(apn->auth,"NONE")) |
| 3318 | cmd_auth = 0; |
| 3319 | else if(strstr(apn->auth,"PAP")) |
| 3320 | cmd_auth = 1; |
| 3321 | else if(strstr(apn->auth,"CHAP")) |
| 3322 | cmd_auth = 2; |
| 3323 | else if(strstr(apn->auth,"PAP AND CHAP")) |
| 3324 | cmd_auth = 3; |
| 3325 | else |
| 3326 | goto exit; |
| 3327 | |
| 3328 | sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass); |
| 3329 | err = at_send_command(cmd, &response); |
| 3330 | if (err < 0 || response->success == 0){ |
| 3331 | *cme_err = at_get_cme_error(response); |
| 3332 | goto exit; |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | exit: |
| 3337 | at_response_free(response); |
| 3338 | return err; |
| 3339 | } |
| 3340 | #endif |
| 3341 | |
| 3342 | /* |
| 3343 | AT+CGDCONT=1,"IPV4V6","cmnet" |
| 3344 | OK |
| 3345 | |
| 3346 | AT*CGDFLT=1,"IPv4v6","reliance.grevpdn.zj",,,,,,,,,,,,,,,,,,1 |
| 3347 | OK |
| 3348 | |
| 3349 | */ |
| 3350 | static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err) |
| 3351 | { |
| 3352 | ATResponse *response = NULL; |
| 3353 | char cmd[400] = {0}; |
| 3354 | int index = 0; |
| 3355 | int err = 0; |
| 3356 | |
| 3357 | index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid); |
| 3358 | switch(apn->ip_type) { |
| 3359 | case MBTK_IP_TYPE_IP: { |
| 3360 | index += sprintf(cmd + index,"\"IP\","); |
| 3361 | break; |
| 3362 | } |
| 3363 | case MBTK_IP_TYPE_IPV6: { |
| 3364 | index += sprintf(cmd + index,"\"IPV6\","); |
| 3365 | break; |
| 3366 | } |
| 3367 | case MBTK_IP_TYPE_IPV4V6: { |
| 3368 | index += sprintf(cmd + index,"\"IPV4V6\","); |
| 3369 | break; |
| 3370 | } |
| 3371 | default: { |
| 3372 | index += sprintf(cmd + index,"\"PPP\","); |
| 3373 | break; |
| 3374 | } |
| 3375 | } |
| 3376 | if(strlen(apn->apn) > 0) { |
| 3377 | index += sprintf(cmd + index,"\"%s\"", apn->apn); |
| 3378 | } else { |
| 3379 | LOGE("No set APN."); |
| 3380 | err = -1; |
| 3381 | goto exit; |
| 3382 | } |
| 3383 | |
| 3384 | err = at_send_command(cmd, &response); |
| 3385 | if (err < 0 || response->success == 0){ |
| 3386 | if(cme_err) { |
| 3387 | *cme_err = at_get_cme_error(response); |
| 3388 | } |
| 3389 | goto exit; |
| 3390 | } |
| 3391 | |
| 3392 | if(!str_empty(apn->user) || !str_empty(apn->pass)) { |
| 3393 | at_response_free(response); |
| 3394 | |
| 3395 | memset(cmd,0,400); |
| 3396 | int cmd_auth=0; |
| 3397 | if(strstr(apn->auth,"NONE")) |
| 3398 | cmd_auth = 0; |
| 3399 | else if(strstr(apn->auth,"PAP")) |
| 3400 | cmd_auth = 1; |
| 3401 | else if(strstr(apn->auth,"CHAP")) |
| 3402 | cmd_auth = 2; |
| 3403 | #if 0 |
| 3404 | else if(strstr(apn->auth,"PAP AND CHAP")) |
| 3405 | cmd_auth = 3; |
| 3406 | #endif |
| 3407 | else |
| 3408 | goto exit; |
| 3409 | |
| 3410 | sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass); |
| 3411 | err = at_send_command(cmd, &response); |
| 3412 | if (err < 0 || response->success == 0){ |
| 3413 | *cme_err = at_get_cme_error(response); |
| 3414 | goto exit; |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | exit: |
| 3419 | at_response_free(response); |
| 3420 | return err; |
| 3421 | } |
| 3422 | |
liuyang | 1cefd85 | 2024-04-24 18:30:53 +0800 | [diff] [blame] | 3423 | static int req_apn_del(int data, int *cme_err) |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 3424 | { |
| 3425 | ATResponse *response = NULL; |
| 3426 | char cmd[64]={0}; |
liuyang | 1cefd85 | 2024-04-24 18:30:53 +0800 | [diff] [blame] | 3427 | sprintf(cmd, "AT+CGDCONT=%d", data); |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 3428 | int err = at_send_command(cmd, &response); |
| 3429 | if (err < 0 || response->success == 0){ |
| 3430 | if(cme_err) { |
| 3431 | *cme_err = at_get_cme_error(response); |
| 3432 | } |
| 3433 | goto exit; |
| 3434 | } |
| 3435 | |
| 3436 | exit: |
| 3437 | at_response_free(response); |
| 3438 | return err; |
| 3439 | } |
| 3440 | |
| 3441 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 3442 | int wait_cgact_complete(int timeout) |
| 3443 | { |
| 3444 | int count = timeout * 10; // timeout * 1000 / 100 |
| 3445 | int i = 0; |
| 3446 | |
| 3447 | while(cgact_wait.waitting && i < count) { |
| 3448 | i++; |
| 3449 | usleep(100000); // 100ms |
| 3450 | } |
| 3451 | |
| 3452 | if(i == count) { // Timeout |
| 3453 | return -1; |
| 3454 | } else { |
| 3455 | return 0; |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | /* |
| 3460 | AT+CGDATA="",6 |
| 3461 | CONNECT |
| 3462 | |
| 3463 | OK |
| 3464 | |
| 3465 | AT+CFUN=1 |
| 3466 | |
| 3467 | OK |
| 3468 | |
| 3469 | */ |
| 3470 | static int req_data_call_user_start(int cid, int *cme_err) |
| 3471 | { |
| 3472 | ATResponse *response = NULL; |
| 3473 | char cmd[400] = {0}; |
| 3474 | int index = 0; |
| 3475 | int err = 0; |
| 3476 | |
| 3477 | err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 3478 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3479 | if(cme_err != NULL) |
| 3480 | *cme_err = at_get_cme_error(response); |
| 3481 | err = -1; |
| 3482 | goto exit; |
| 3483 | } |
| 3484 | |
| 3485 | int tmp_int; |
| 3486 | char cmd_buf[64]; |
| 3487 | char *line = response->p_intermediates->line; |
| 3488 | err = at_tok_start(&line); |
| 3489 | if (err < 0) |
| 3490 | { |
| 3491 | goto exit; |
| 3492 | } |
| 3493 | err = at_tok_nextint(&line, &tmp_int); |
| 3494 | if (err < 0) |
| 3495 | { |
| 3496 | goto exit; |
| 3497 | } |
| 3498 | err = at_tok_nextint(&line, &tmp_int); |
| 3499 | if (err < 0) |
| 3500 | { |
| 3501 | goto exit; |
| 3502 | } |
| 3503 | err = at_tok_nextstr(&line, &cmd_buf); |
| 3504 | if (err < 0) |
| 3505 | { |
| 3506 | goto exit; |
| 3507 | } |
| 3508 | err = at_tok_nextint(&line, &tmp_int); |
| 3509 | if (err < 0) |
| 3510 | { |
| 3511 | goto exit; |
| 3512 | } |
| 3513 | at_response_free(response); |
| 3514 | |
| 3515 | if(tmp_int == 7 && cid == 1) //LTE && cid = 1 |
| 3516 | { |
| 3517 | ATResponse *response = NULL; |
| 3518 | char cmd[400] = {0}; |
| 3519 | int err = 0; |
| 3520 | |
| 3521 | err = at_send_command("AT+CFUN=1", &response); |
| 3522 | if (err < 0 || response->success == 0){ |
| 3523 | if(cme_err) { |
| 3524 | *cme_err = at_get_cme_error(response); |
| 3525 | } |
| 3526 | goto exit; |
| 3527 | } |
| 3528 | } |
| 3529 | else |
| 3530 | { |
| 3531 | ATResponse *response = NULL; |
| 3532 | char cmd[400] = {0}; |
| 3533 | int err = 0; |
| 3534 | sprintf(cmd, "AT+CGDATA=\"\",%d", cid); |
| 3535 | err = at_send_command(cmd, &response); |
| 3536 | if (err < 0 || response->success == 0){ |
| 3537 | if(cme_err) { |
| 3538 | *cme_err = at_get_cme_error(response); |
| 3539 | } |
| 3540 | goto exit; |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | exit: |
| 3545 | at_response_free(response); |
| 3546 | return err; |
| 3547 | } |
| 3548 | |
| 3549 | /* |
| 3550 | AT+CGACT? |
| 3551 | +CGACT: 1,1 |
| 3552 | +CGACT: 8,1 |
| 3553 | OK |
| 3554 | |
| 3555 | AT+CGACT=1,<cid> |
| 3556 | OK |
| 3557 | |
| 3558 | */ |
| 3559 | static int req_data_call_start(int cid, int *cme_err) |
| 3560 | { |
| 3561 | ATResponse *response = NULL; |
| 3562 | char cmd[400] = {0}; |
| 3563 | int err = 0; |
| 3564 | #if 0 |
| 3565 | err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &response); |
| 3566 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3567 | *cme_err = at_get_cme_error(response); |
| 3568 | goto exit; |
| 3569 | } |
| 3570 | ATLine* lines_ptr = response->p_intermediates; |
| 3571 | char *line = NULL; |
| 3572 | int tmp_int; |
| 3573 | while(lines_ptr) |
| 3574 | { |
| 3575 | line = lines_ptr->line; |
| 3576 | err = at_tok_start(&line); |
| 3577 | if (err < 0) |
| 3578 | { |
| 3579 | goto exit; |
| 3580 | } |
| 3581 | |
| 3582 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3583 | if (err < 0) |
| 3584 | { |
| 3585 | goto exit; |
| 3586 | } |
| 3587 | if(tmp_int == cid) { // Found cid |
| 3588 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3589 | if (err < 0) |
| 3590 | { |
| 3591 | goto exit; |
| 3592 | } |
| 3593 | if(tmp_int == 1) { // This cid has active. |
| 3594 | goto net_config; |
| 3595 | } else { |
| 3596 | goto cid_active; |
| 3597 | } |
| 3598 | break; |
| 3599 | } |
| 3600 | |
| 3601 | lines_ptr = lines_ptr->p_next; |
| 3602 | } |
| 3603 | |
| 3604 | if(lines_ptr == NULL) { // No found this cid. |
| 3605 | LOGE("No found cid : %d", cid); |
| 3606 | goto exit; |
| 3607 | } |
| 3608 | at_response_free(response); |
| 3609 | |
| 3610 | // Start active cid. |
| 3611 | cid_active: |
| 3612 | #endif |
| 3613 | |
| 3614 | sprintf(cmd, "AT+CGACT=1,%d", cid); |
| 3615 | err = at_send_command(cmd, &response); |
| 3616 | if (err < 0 || response->success == 0){ |
| 3617 | if(cme_err) { |
| 3618 | *cme_err = at_get_cme_error(response); |
| 3619 | } |
| 3620 | goto exit; |
| 3621 | } |
| 3622 | |
| 3623 | exit: |
| 3624 | at_response_free(response); |
| 3625 | return err; |
| 3626 | } |
| 3627 | |
| 3628 | /* |
| 3629 | AT+CGACT=0,<cid> |
| 3630 | OK |
| 3631 | |
| 3632 | */ |
| 3633 | static int req_data_call_stop(int cid, int *cme_err) |
| 3634 | { |
| 3635 | ATResponse *response = NULL; |
| 3636 | char cmd[400] = {0}; |
| 3637 | int err = 0; |
| 3638 | #if 0 |
| 3639 | err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &response); |
| 3640 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3641 | *cme_err = at_get_cme_error(response); |
| 3642 | goto exit; |
| 3643 | } |
| 3644 | ATLine* lines_ptr = response->p_intermediates; |
| 3645 | char *line = NULL; |
| 3646 | int tmp_int; |
| 3647 | while(lines_ptr) |
| 3648 | { |
| 3649 | line = lines_ptr->line; |
| 3650 | err = at_tok_start(&line); |
| 3651 | if (err < 0) |
| 3652 | { |
| 3653 | goto exit; |
| 3654 | } |
| 3655 | |
| 3656 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3657 | if (err < 0) |
| 3658 | { |
| 3659 | goto exit; |
| 3660 | } |
| 3661 | if(tmp_int == cid) { // Found cid |
| 3662 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3663 | if (err < 0) |
| 3664 | { |
| 3665 | goto exit; |
| 3666 | } |
| 3667 | if(tmp_int == 1) { // This cid has active. |
| 3668 | goto net_config; |
| 3669 | } else { |
| 3670 | goto cid_active; |
| 3671 | } |
| 3672 | break; |
| 3673 | } |
| 3674 | |
| 3675 | lines_ptr = lines_ptr->p_next; |
| 3676 | } |
| 3677 | |
| 3678 | if(lines_ptr == NULL) { // No found this cid. |
| 3679 | LOGE("No found cid : %d", cid); |
| 3680 | goto exit; |
| 3681 | } |
| 3682 | at_response_free(response); |
| 3683 | |
| 3684 | // Start active cid. |
| 3685 | cid_active: |
| 3686 | #endif |
| 3687 | |
| 3688 | sprintf(cmd, "AT+CGACT=0,%d", cid); |
| 3689 | err = at_send_command(cmd, &response); |
| 3690 | if (err < 0 || response->success == 0){ |
| 3691 | *cme_err = at_get_cme_error(response); |
| 3692 | goto exit; |
| 3693 | } |
| 3694 | |
| 3695 | exit: |
| 3696 | at_response_free(response); |
| 3697 | return err; |
| 3698 | } |
| 3699 | |
| 3700 | /* |
| 3701 | IPv4 : 10.255.74.26 |
| 3702 | IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 |
| 3703 | */ |
| 3704 | static bool is_ipv4(const char *ip) |
| 3705 | { |
| 3706 | const char *ptr = ip; |
| 3707 | int count = 0; |
| 3708 | while(*ptr) { |
| 3709 | if(*ptr == '.') |
| 3710 | count++; |
| 3711 | ptr++; |
| 3712 | } |
| 3713 | |
| 3714 | if(count == 3) { |
| 3715 | return true; |
| 3716 | } else { |
| 3717 | return false; |
| 3718 | } |
| 3719 | } |
| 3720 | |
| 3721 | /* |
| 3722 | AT+CGCONTRDP=1 |
| 3723 | +CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","10.255.74.26","","223.87.253.100","223.87.253.253","","",0,0 |
| 3724 | +CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239","","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.1","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.2","","",0,0 |
| 3725 | |
| 3726 | OK |
| 3727 | |
| 3728 | */ |
| 3729 | static int req_data_call_state_get(int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6, int *cme_err) |
| 3730 | { |
| 3731 | ATResponse *response = NULL; |
| 3732 | char cmd[50] = {0}; |
| 3733 | int err = 0; |
| 3734 | |
| 3735 | sprintf(cmd, "AT+CGCONTRDP=%d", cid); |
| 3736 | |
| 3737 | err = at_send_command_multiline(cmd, "+CGCONTRDP:", &response); |
| 3738 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3739 | *cme_err = at_get_cme_error(response); |
| 3740 | goto exit; |
| 3741 | } |
| 3742 | ATLine* lines_ptr = response->p_intermediates; |
| 3743 | char *line = NULL; |
| 3744 | int tmp_int; |
| 3745 | char *tmp_ptr = NULL; |
| 3746 | while(lines_ptr) |
| 3747 | { |
| 3748 | line = lines_ptr->line; |
| 3749 | err = at_tok_start(&line); |
| 3750 | if (err < 0) |
| 3751 | { |
| 3752 | goto exit; |
| 3753 | } |
| 3754 | |
| 3755 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3756 | if (err < 0) |
| 3757 | { |
| 3758 | goto exit; |
| 3759 | } |
| 3760 | err = at_tok_nextint(&line, &tmp_int); // bearer_id |
| 3761 | if (err < 0) |
| 3762 | { |
| 3763 | goto exit; |
| 3764 | } |
| 3765 | err = at_tok_nextstr(&line, &tmp_ptr); // APN |
| 3766 | if (err < 0) |
| 3767 | { |
| 3768 | goto exit; |
| 3769 | } |
| 3770 | |
| 3771 | err = at_tok_nextstr(&line, &tmp_ptr); // IP |
| 3772 | if (err < 0 || str_empty(tmp_ptr)) |
| 3773 | { |
| 3774 | goto exit; |
| 3775 | } |
| 3776 | if(is_ipv4(tmp_ptr)) { |
| 3777 | if(inet_pton(AF_INET, tmp_ptr, &(ipv4->IPAddr)) < 0) { |
| 3778 | LOGE("inet_pton() fail."); |
| 3779 | err = -1; |
| 3780 | goto exit; |
| 3781 | } |
| 3782 | |
| 3783 | ipv4->valid = true; |
| 3784 | //log_hex("IPv4", &(ipv4->IPAddr), sizeof(struct in_addr)); |
| 3785 | } else { |
| 3786 | if(str_2_ipv6(tmp_ptr, &(ipv6->IPV6Addr))) { |
| 3787 | LOGE("str_2_ipv6() fail."); |
| 3788 | err = -1; |
| 3789 | goto exit; |
| 3790 | } |
| 3791 | |
| 3792 | ipv6->valid = true; |
| 3793 | //log_hex("IPv6", &(ipv6->IPV6Addr), 16); |
| 3794 | } |
| 3795 | |
| 3796 | err = at_tok_nextstr(&line, &tmp_ptr); // Gateway |
| 3797 | if (err < 0) |
| 3798 | { |
| 3799 | goto exit; |
| 3800 | } |
| 3801 | if(!str_empty(tmp_ptr)) { // No found gateway |
| 3802 | if(is_ipv4(tmp_ptr)) { |
| 3803 | if(inet_pton(AF_INET, tmp_ptr, &(ipv4->GateWay)) < 0) { |
| 3804 | LOGE("inet_pton() fail."); |
| 3805 | err = -1; |
| 3806 | goto exit; |
| 3807 | } |
| 3808 | |
| 3809 | //log_hex("IPv4", &(ipv4->GateWay), sizeof(struct in_addr)); |
| 3810 | } else { |
| 3811 | if(str_2_ipv6(tmp_ptr, &(ipv6->GateWay))) { |
| 3812 | LOGE("str_2_ipv6() fail."); |
| 3813 | err = -1; |
| 3814 | goto exit; |
| 3815 | } |
| 3816 | |
| 3817 | //log_hex("IPv6", &(ipv6->GateWay), 16); |
| 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | err = at_tok_nextstr(&line, &tmp_ptr); // prim_DNS |
| 3822 | if (err < 0) |
| 3823 | { |
| 3824 | goto exit; |
| 3825 | } |
| 3826 | if(!str_empty(tmp_ptr)) { // No found Primary DNS |
| 3827 | if(is_ipv4(tmp_ptr)) { |
| 3828 | if(inet_pton(AF_INET, tmp_ptr, &(ipv4->PrimaryDNS)) < 0) { |
| 3829 | LOGE("inet_pton() fail."); |
| 3830 | err = -1; |
| 3831 | goto exit; |
| 3832 | } |
| 3833 | |
| 3834 | //log_hex("IPv4", &(ipv4->PrimaryDNS), sizeof(struct in_addr)); |
| 3835 | } else { |
| 3836 | if(str_2_ipv6(tmp_ptr, &(ipv6->PrimaryDNS))) { |
| 3837 | LOGE("str_2_ipv6() fail."); |
| 3838 | err = -1; |
| 3839 | goto exit; |
| 3840 | } |
| 3841 | |
| 3842 | //log_hex("IPv6", &(ipv6->PrimaryDNS), 16); |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | err = at_tok_nextstr(&line, &tmp_ptr); // sec_DNS |
| 3847 | if (err < 0) |
| 3848 | { |
| 3849 | goto exit; |
| 3850 | } |
| 3851 | if(!str_empty(tmp_ptr)) { // No found Secondary DNS |
| 3852 | if(is_ipv4(tmp_ptr)) { |
| 3853 | if(inet_pton(AF_INET, tmp_ptr, &(ipv4->SecondaryDNS)) < 0) { |
| 3854 | LOGE("inet_pton() fail."); |
| 3855 | err = -1; |
| 3856 | goto exit; |
| 3857 | } |
| 3858 | |
| 3859 | //log_hex("IPv4", &(ipv4->SecondaryDNS), sizeof(struct in_addr)); |
| 3860 | } else { |
| 3861 | if(str_2_ipv6(tmp_ptr, &(ipv6->SecondaryDNS))) { |
| 3862 | LOGE("str_2_ipv6() fail."); |
| 3863 | err = -1; |
| 3864 | goto exit; |
| 3865 | } |
| 3866 | |
| 3867 | //log_hex("IPv6", &(ipv6->SecondaryDNS), 16); |
| 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | lines_ptr = lines_ptr->p_next; |
| 3872 | } |
| 3873 | |
| 3874 | exit: |
| 3875 | at_response_free(response); |
| 3876 | return err; |
| 3877 | } |
| 3878 | |
| 3879 | /* |
| 3880 | AT+CGCONTRDP |
| 3881 | +CGCONTRDP: 1,5,"cmnet.MNC000.MCC460.GPRS","10.156.238.86","","223.87.253.100","223.87.253.253","","",0,0 |
| 3882 | +CGCONTRDP: 1,5,"cmnet.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.1.181.5.77.221","","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.1","36.9.128.98.32.0.0.2.0,0,0 |
| 3883 | +CGCONTRDP: 8,6,"IMS.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.1.181.5.79.116","","","","36.9.128.98.80.2.0.87.0.0.0.0.0.3.31.1","36.9.128.98.80.2,1,0 |
| 3884 | OK |
| 3885 | |
| 3886 | */ |
| 3887 | static int apn_state_get(list_node_t **apn_list) |
| 3888 | { |
| 3889 | ATResponse *response = NULL; |
| 3890 | int err = 0; |
| 3891 | *apn_list = list_create(NULL); |
| 3892 | if(*apn_list == NULL) |
| 3893 | { |
| 3894 | LOG("list_create() fail."); |
| 3895 | return -1; |
| 3896 | } |
| 3897 | |
| 3898 | err = at_send_command_multiline("AT+CGCONTRDP", "+CGCONTRDP:", &response); |
| 3899 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 3900 | goto exit; |
| 3901 | } |
| 3902 | ATLine* lines_ptr = response->p_intermediates; |
| 3903 | char *line = NULL; |
| 3904 | int tmp_int; |
| 3905 | char *tmp_ptr = NULL; |
| 3906 | int cid_current = 0; |
| 3907 | info_apn_ip_t *apn = NULL; |
| 3908 | while(lines_ptr) |
| 3909 | { |
| 3910 | line = lines_ptr->line; |
| 3911 | err = at_tok_start(&line); |
| 3912 | if (err < 0) |
| 3913 | { |
| 3914 | goto exit; |
| 3915 | } |
| 3916 | |
| 3917 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 3918 | if (err < 0) |
| 3919 | { |
| 3920 | goto exit; |
| 3921 | } |
| 3922 | |
| 3923 | if(tmp_int != 1 && tmp_int != 8) { // Not process cid 1 and 8. |
| 3924 | if(cid_current != tmp_int) { // New cid. |
| 3925 | apn = (info_apn_ip_t*)malloc(sizeof(info_apn_ip_t)); |
| 3926 | if(apn == NULL) { |
| 3927 | goto exit; |
| 3928 | } |
| 3929 | memset(apn, 0, sizeof(info_apn_ip_t)); |
| 3930 | apn->cid = tmp_int; |
| 3931 | cid_current = tmp_int; |
| 3932 | |
| 3933 | list_add(*apn_list, apn); |
| 3934 | } |
| 3935 | err = at_tok_nextint(&line, &tmp_int); // bearer_id |
| 3936 | if (err < 0) |
| 3937 | { |
| 3938 | goto exit; |
| 3939 | } |
| 3940 | err = at_tok_nextstr(&line, &tmp_ptr); // APN |
| 3941 | if (err < 0) |
| 3942 | { |
| 3943 | goto exit; |
| 3944 | } |
| 3945 | |
| 3946 | err = at_tok_nextstr(&line, &tmp_ptr); // IP |
| 3947 | if (err < 0 || str_empty(tmp_ptr)) |
| 3948 | { |
| 3949 | goto exit; |
| 3950 | } |
| 3951 | if(is_ipv4(tmp_ptr)) { |
| 3952 | apn->ipv4_valid = true; |
| 3953 | memcpy(apn->ipv4, tmp_ptr, strlen(tmp_ptr)); |
| 3954 | } else { |
| 3955 | apn->ipv6_valid = true; |
| 3956 | uint8 tmp_ipv6[16]; |
| 3957 | if(str_2_ipv6(tmp_ptr, tmp_ipv6)) { |
| 3958 | LOGE("str_2_ipv6() fail."); |
| 3959 | err = -1; |
| 3960 | goto exit; |
| 3961 | } |
| 3962 | |
| 3963 | if(inet_ntop(AF_INET6, tmp_ipv6, apn->ipv6, 50) == NULL) { |
| 3964 | err = -1; |
| 3965 | LOGE("inet_ntop ipv6 ip fail."); |
| 3966 | goto exit; |
| 3967 | } |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | lines_ptr = lines_ptr->p_next; |
| 3972 | } |
| 3973 | |
| 3974 | exit: |
| 3975 | at_response_free(response); |
| 3976 | return err; |
| 3977 | } |
| 3978 | |
| 3979 | mbtk_info_err_enum call_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack); |
| 3980 | mbtk_info_err_enum sms_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack); |
| 3981 | mbtk_info_err_enum pb_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 3982 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 3983 | //mbtk wyq for data_call_ex add start |
| 3984 | void data_call_bootconn_save(int cid, int bootconn); |
| 3985 | //mbtk wyq for data_call_ex add end |
| 3986 | |
| 3987 | //void net_list_free(void *data); |
| 3988 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 3989 | // Otherwise, do not call pack_error_send(). |
| 3990 | static mbtk_info_err_enum pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack) |
| 3991 | { |
| 3992 | if(pack->info_id > MBTK_INFO_ID_CALL_BEGIN && pack->info_id < MBTK_INFO_ID_CALL_END) { |
| 3993 | return call_pack_req_process(cli_info, pack); |
| 3994 | } else if(pack->info_id > MBTK_INFO_ID_SMS_BEGIN && pack->info_id < MBTK_INFO_ID_SMS_END) { |
| 3995 | return sms_pack_req_process(cli_info, pack); |
| 3996 | } else if(pack->info_id > MBTK_INFO_ID_PB_BEGIN && pack->info_id < MBTK_INFO_ID_PB_END) { |
| 3997 | return pb_pack_req_process(cli_info, pack); |
| 3998 | } else { |
| 3999 | mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS; |
| 4000 | int cme_err = MBTK_INFO_ERR_CME_NON; |
| 4001 | switch(pack->info_id) |
| 4002 | { |
| 4003 | case MBTK_INFO_ID_DEV_IMEI_REQ: // <string> IMEI |
| 4004 | { |
| 4005 | if(pack->data_len == 0 || pack->data == NULL) // Get IMEI |
| 4006 | { |
| 4007 | char imei[20] = {0}; |
| 4008 | if(req_imei_get(imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4009 | { |
| 4010 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4011 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4012 | } else { |
| 4013 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4014 | } |
| 4015 | LOG("Get IMEI fail."); |
| 4016 | } |
| 4017 | else |
| 4018 | { |
| 4019 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_IMEI_RSP, imei, strlen(imei)); |
| 4020 | } |
| 4021 | } |
| 4022 | else // Set IMEI(Unsupport). |
| 4023 | { |
| 4024 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4025 | LOG("Unsupport set IMEI."); |
| 4026 | } |
| 4027 | break; |
| 4028 | } |
| 4029 | case MBTK_INFO_ID_DEV_SN_REQ: // <string> SN |
| 4030 | { |
| 4031 | if(pack->data_len == 0 || pack->data == NULL) // Get SN |
| 4032 | { |
| 4033 | char sn[20] = {0}; |
| 4034 | if(req_sn_get(sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4035 | { |
| 4036 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4037 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4038 | } else { |
| 4039 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4040 | } |
| 4041 | LOG("Get SN fail."); |
| 4042 | } |
| 4043 | else |
| 4044 | { |
| 4045 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_SN_RSP, sn, strlen(sn)); |
| 4046 | } |
| 4047 | } |
| 4048 | else // Set SN(Unsupport). |
| 4049 | { |
| 4050 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4051 | LOG("Unsupport set SN."); |
| 4052 | } |
| 4053 | break; |
| 4054 | } |
| 4055 | case MBTK_INFO_ID_DEV_MEID_REQ: // <string> MEID (Only for CDMA) |
| 4056 | { |
| 4057 | if(pack->data_len == 0 || pack->data == NULL) // Get MEID |
| 4058 | { |
| 4059 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4060 | LOG("Support only for CDMA."); |
| 4061 | } |
| 4062 | else // Set MEID(Unsupport). |
| 4063 | { |
| 4064 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4065 | LOG("Unsupport set MEID."); |
| 4066 | } |
| 4067 | break; |
| 4068 | } |
| 4069 | case MBTK_INFO_ID_DEV_VERSION_REQ: // <string> VERSION |
| 4070 | { |
| 4071 | if(pack->data_len == 0 || pack->data == NULL) // Get VERSION |
| 4072 | { |
| 4073 | char version[50] = {0}; |
| 4074 | if(req_version_get(version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4075 | { |
| 4076 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4077 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4078 | } else { |
| 4079 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4080 | } |
| 4081 | LOG("Get Version fail."); |
| 4082 | } |
| 4083 | else |
| 4084 | { |
| 4085 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VERSION_RSP, version, strlen(version)); |
| 4086 | } |
| 4087 | } |
| 4088 | else // Set VERSION(Unsupport). |
| 4089 | { |
| 4090 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4091 | LOG("Unsupport set VERSION."); |
| 4092 | } |
| 4093 | break; |
| 4094 | } |
| 4095 | case MBTK_INFO_ID_DEV_MODEL_REQ: //MODEL |
| 4096 | { |
| 4097 | if(pack->data_len == 0 || pack->data == NULL) // Get MODEL |
| 4098 | { |
| 4099 | char model[50] = {0}; |
| 4100 | if(req_model_get(model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4101 | { |
| 4102 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4103 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4104 | } else { |
| 4105 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4106 | } |
| 4107 | LOG("Get model fail."); |
| 4108 | } |
| 4109 | else |
| 4110 | { |
| 4111 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VERSION_RSP, model, strlen(model)); |
| 4112 | } |
| 4113 | } |
| 4114 | else // Set model(Unsupport). |
| 4115 | { |
| 4116 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4117 | LOG("Unsupport set model."); |
| 4118 | } |
| 4119 | break; |
| 4120 | } |
| 4121 | case MBTK_INFO_ID_DEV_MODEM_REQ: //MODEM |
| 4122 | { |
| 4123 | if(pack->data_len == 0 || pack->data == NULL) // Get MODEM |
| 4124 | { |
| 4125 | int modem = -1; |
| 4126 | if(req_modem_get(&modem, &cme_err) || modem < 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4127 | { |
| 4128 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4129 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4130 | } else { |
| 4131 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4132 | } |
| 4133 | LOG("Get modem fail."); |
| 4134 | } |
| 4135 | else |
| 4136 | { |
| 4137 | uint8 modem_type = (uint8)modem; |
| 4138 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_MODEM_RSP, &modem_type, sizeof(uint8)); |
| 4139 | } |
| 4140 | } |
| 4141 | else // Set modem |
| 4142 | { |
| 4143 | mbtk_modem_info_t *modem = (mbtk_modem_info_t *)pack->data; |
| 4144 | if(pack->data_len != sizeof(mbtk_modem_info_t)) |
| 4145 | { |
| 4146 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 4147 | LOG("Set modem error."); |
| 4148 | break; |
| 4149 | } |
| 4150 | if(req_modem_set(modem, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4151 | { |
| 4152 | LOG("Set modem fail."); |
| 4153 | err = MBTK_INFO_ERR_FORMAT; |
| 4154 | } else { |
| 4155 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_MODEM_RSP, NULL, 0); |
| 4156 | } |
| 4157 | } |
| 4158 | break; |
| 4159 | } |
| 4160 | case MBTK_INFO_ID_DEV_TIME_REQ: // <uint8><string> YYYY-MM-DD-HH:MM:SS |
| 4161 | { |
| 4162 | if(pack->data_len == 0 || pack->data == NULL) // Get Time |
| 4163 | { |
| 4164 | int type = -1; |
| 4165 | if(req_time_get(&type, &cme_err) || type < 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4166 | { |
| 4167 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4168 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4169 | } else { |
| 4170 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4171 | } |
| 4172 | LOG("Get Time fail."); |
| 4173 | } |
| 4174 | else |
| 4175 | { |
| 4176 | uint8 time_type = (uint8)type; |
| 4177 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, &time_type, sizeof(uint8)); |
| 4178 | } |
| 4179 | } |
| 4180 | else // Set Time |
| 4181 | { |
| 4182 | if(pack->data_len == sizeof(uint8)) { |
| 4183 | if(req_time_set(*(pack->data), NULL, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4184 | { |
| 4185 | LOG("Set Time fail."); |
| 4186 | err = MBTK_INFO_ERR_FORMAT; |
| 4187 | } else { |
| 4188 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, NULL, 0); |
| 4189 | } |
| 4190 | } else { |
| 4191 | char time_ptr[100] = {0}; |
| 4192 | memcpy(time_ptr, pack->data + sizeof(uint8), pack->data_len - sizeof(uint8)); |
| 4193 | if(req_time_set(*(pack->data), time_ptr, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4194 | { |
| 4195 | LOG("Set Time fail."); |
| 4196 | err = MBTK_INFO_ERR_FORMAT; |
| 4197 | } else { |
| 4198 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, NULL, 0); |
| 4199 | } |
| 4200 | } |
| 4201 | } |
| 4202 | break; |
| 4203 | } |
| 4204 | case MBTK_INFO_ID_NET_TIME_REQ: // <string> YYYY-MM-DD-HH:MM:SS |
| 4205 | { |
| 4206 | if(pack->data_len == 0 || pack->data == NULL) // Get Time |
| 4207 | { |
| 4208 | char time[100]; |
| 4209 | if(req_net_time_get(time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4210 | { |
| 4211 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4212 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4213 | } else { |
| 4214 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4215 | } |
| 4216 | LOG("Get Time fail."); |
| 4217 | } |
| 4218 | else |
| 4219 | { |
| 4220 | char time_ser[100]={0}; |
| 4221 | memcpy(time_ser,time,strlen(time)); |
| 4222 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_TIME_RSP, time_ser, strlen(time_ser)); |
| 4223 | } |
| 4224 | } |
| 4225 | else // Set Time |
| 4226 | { |
| 4227 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4228 | LOG("Unsupport set TIME."); |
| 4229 | } |
| 4230 | break; |
| 4231 | } |
| 4232 | case MBTK_INFO_ID_DEV_VOLTE_REQ: // <uint8> 0:Close 1:Open |
| 4233 | { |
| 4234 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 4235 | { |
| 4236 | int state; |
| 4237 | if(req_volte_get(&state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4238 | { |
| 4239 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4240 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4241 | } else { |
| 4242 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4243 | } |
| 4244 | LOG("Get VoLTE state fail."); |
| 4245 | } |
| 4246 | else |
| 4247 | { |
| 4248 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VOLTE_RSP, &state, sizeof(uint8)); |
| 4249 | } |
| 4250 | } |
| 4251 | else // Set VoLTE state. |
| 4252 | { |
| 4253 | uint8 on = *(pack->data); |
| 4254 | if(pack->data_len != sizeof(uint8) || (on != 0 && on != 1)) |
| 4255 | { |
| 4256 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 4257 | LOG("Set VOLTE parameter error."); |
| 4258 | break; |
| 4259 | } |
| 4260 | |
| 4261 | if(req_volte_set(on, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4262 | { |
| 4263 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4264 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4265 | } else { |
| 4266 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4267 | } |
| 4268 | LOG("Set VoLTE state fail."); |
| 4269 | } |
| 4270 | else |
| 4271 | { |
| 4272 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VOLTE_RSP, NULL, 0); |
| 4273 | |
| 4274 | // Restart is required to take effect. |
| 4275 | LOG("Will reboot system..."); |
| 4276 | } |
| 4277 | } |
| 4278 | break; |
| 4279 | } |
| 4280 | case MBTK_INFO_ID_DEV_TEMP_REQ: // <string> Temperature |
| 4281 | { |
| 4282 | if(pack->data_len == sizeof(uint8) && pack->data) { |
| 4283 | int temp; |
| 4284 | if(req_temp_get(*(pack->data), &temp, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4285 | { |
| 4286 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4287 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4288 | } else { |
| 4289 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4290 | } |
| 4291 | LOG("Get temperature fail."); |
| 4292 | } |
| 4293 | else |
| 4294 | { |
| 4295 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TEMP_RSP, &temp, sizeof(uint8)); |
| 4296 | } |
| 4297 | } else { |
| 4298 | err = MBTK_INFO_ERR_FORMAT; |
| 4299 | LOG("Unsupport get Temperature."); |
| 4300 | } |
| 4301 | break; |
| 4302 | } |
| 4303 | case MBTK_INFO_ID_SIM_PLMN_REQ: // plmn |
| 4304 | { |
| 4305 | if(pack->data_len == 0 || pack->data == NULL) // plmn |
| 4306 | { |
| 4307 | mbtk_plmn_info plmn; |
| 4308 | if(req_plmn_get(&plmn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4309 | { |
| 4310 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4311 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4312 | } else { |
| 4313 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4314 | } |
| 4315 | LOG("Get PLMN fail."); |
| 4316 | } |
| 4317 | else |
| 4318 | { |
| 4319 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PLMN_RSP, &plmn, sizeof(mbtk_plmn_info)); |
| 4320 | } |
| 4321 | } |
| 4322 | else // Set |
| 4323 | { |
| 4324 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4325 | LOG("Set sim state fail."); |
| 4326 | } |
| 4327 | break; |
| 4328 | } |
| 4329 | case MBTK_INFO_ID_SIM_STATE_REQ: // mbtk_sim_state_enum |
| 4330 | { |
| 4331 | if(pack->data_len == 0 || pack->data == NULL) // Get sim state. |
| 4332 | { |
| 4333 | uint8 sim_state = (uint8)getSIMStatus(); |
| 4334 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_STATE_RSP, &sim_state, sizeof(uint8)); |
| 4335 | } |
| 4336 | else // Set |
| 4337 | { |
| 4338 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4339 | LOG("Set sim state fail."); |
| 4340 | } |
| 4341 | break; |
| 4342 | } |
| 4343 | case MBTK_INFO_ID_SIM_STYPE_REQ: // mbtk_sim_card_type_enum |
| 4344 | { |
| 4345 | if(pack->data_len == 0 || pack->data == NULL) // Get sim card type |
| 4346 | { |
| 4347 | uint8 sim_card_type; |
| 4348 | if(req_sim_card_type_get(&sim_card_type, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4349 | { |
| 4350 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4351 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4352 | } else { |
| 4353 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4354 | } |
| 4355 | LOG("Get IMSI fail."); |
| 4356 | } |
| 4357 | else |
| 4358 | { |
| 4359 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_STYPE_RSP, &sim_card_type, sizeof(uint8)); |
| 4360 | } |
| 4361 | } |
| 4362 | else // Set |
| 4363 | { |
| 4364 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4365 | LOG("Set sim state fail."); |
| 4366 | } |
| 4367 | break; |
| 4368 | } |
| 4369 | case MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ: // mbtk_pin_puk_last_times |
| 4370 | { |
| 4371 | if(pack->data_len == 0 || pack->data == NULL) // Get sim card type |
| 4372 | { |
| 4373 | mbtk_pin_puk_last_times pin_puk_last_times; |
| 4374 | if(req_pin_puk_last_times_get(&pin_puk_last_times, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4375 | { |
| 4376 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4377 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4378 | } else { |
| 4379 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4380 | } |
| 4381 | LOG("Get IMSI fail."); |
| 4382 | } |
| 4383 | else |
| 4384 | { |
| 4385 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PINPUK_TIMES_RSP, &pin_puk_last_times, sizeof(mbtk_pin_puk_last_times)); |
| 4386 | } |
| 4387 | } |
| 4388 | else // Set |
| 4389 | { |
| 4390 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4391 | LOG("Set sim state fail."); |
| 4392 | } |
| 4393 | break; |
| 4394 | } |
| 4395 | case MBTK_INFO_ID_SIM_ENABLE_PIN_REQ: // <string> PIN |
| 4396 | { |
| 4397 | if(pack->data_len == 0 || pack->data == NULL) // Enable PIN |
| 4398 | { |
| 4399 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4400 | LOG("Unsupport GET PIN."); |
| 4401 | } |
| 4402 | else // Enable PIN |
| 4403 | { |
| 4404 | mbtk_enable_pin_info *pin = NULL; |
| 4405 | pin = (mbtk_enable_pin_info *)pack->data; |
| 4406 | if(req_pin_enable(pin, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4407 | { |
| 4408 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4409 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4410 | } else { |
| 4411 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4412 | } |
| 4413 | LOG("Get IMSI fail."); |
| 4414 | } |
| 4415 | else |
| 4416 | { |
| 4417 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ENABLE_PIN_RSP, NULL, 0); |
| 4418 | } |
| 4419 | } |
| 4420 | break; |
| 4421 | } |
| 4422 | case MBTK_INFO_ID_SIM_PIN_REQ: // <string> PIN |
| 4423 | { |
| 4424 | if(pack->data_len == 0 || pack->data == NULL) // PIN |
| 4425 | { |
| 4426 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4427 | LOG("Unsupport GET PIN."); |
| 4428 | } |
| 4429 | else // Set PIN |
| 4430 | { |
| 4431 | char pin[16] = {0}; |
| 4432 | memcpy(pin, pack->data, pack->data_len); |
| 4433 | if(req_pin_verify(pin, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4434 | { |
| 4435 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4436 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4437 | } else { |
| 4438 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4439 | } |
| 4440 | LOG("Set PIN fail."); |
| 4441 | } |
| 4442 | else |
| 4443 | { |
| 4444 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PIN_RSP, NULL, 0); |
| 4445 | } |
| 4446 | } |
| 4447 | break; |
| 4448 | } |
| 4449 | case MBTK_INFO_ID_SIM_PUK_REQ: // <string> PUK |
| 4450 | { |
| 4451 | if(pack->data_len == 0 || pack->data == NULL) |
| 4452 | { |
| 4453 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4454 | LOG("Unsupport."); |
| 4455 | } |
| 4456 | else // change PIN |
| 4457 | { |
| 4458 | mbtk_unlock_pin_info *pin_info = NULL; |
| 4459 | pin_info = (mbtk_unlock_pin_info *)pack->data; |
| 4460 | if(req_puk_unlock_pin(pin_info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4461 | { |
| 4462 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4463 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4464 | } else { |
| 4465 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4466 | } |
| 4467 | LOG("Get IMSI fail."); |
| 4468 | } |
| 4469 | else |
| 4470 | { |
| 4471 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_CHANGE_PIN_RSP, NULL, 0); |
| 4472 | } |
| 4473 | } |
| 4474 | break; |
| 4475 | } |
| 4476 | case MBTK_INFO_ID_SIM_CHANGE_PIN_REQ: // <string> <string> old_PIN new_PIN |
| 4477 | { |
| 4478 | if(pack->data_len == 0 || pack->data == NULL) |
| 4479 | { |
| 4480 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4481 | LOG("Unsupport."); |
| 4482 | } |
| 4483 | else // change PIN |
| 4484 | { |
| 4485 | mbtk_change_pin_info *pin_info = NULL; |
| 4486 | pin_info = (mbtk_change_pin_info *)pack->data; |
| 4487 | if(req_pin_change(pin_info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4488 | { |
| 4489 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4490 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4491 | } else { |
| 4492 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4493 | } |
| 4494 | LOG("Get IMSI fail."); |
| 4495 | } |
| 4496 | else |
| 4497 | { |
| 4498 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_CHANGE_PIN_RSP, NULL, 0); |
| 4499 | } |
| 4500 | } |
| 4501 | break; |
| 4502 | } |
| 4503 | case MBTK_INFO_ID_SIM_IMSI_REQ: // <string> IMSI |
| 4504 | { |
| 4505 | if(pack->data_len == 0 || pack->data == NULL) // Get IMSI |
| 4506 | { |
| 4507 | char imsi[20] = {0}; |
| 4508 | if(req_imsi_get(imsi, &cme_err) || strlen(imsi) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4509 | { |
| 4510 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4511 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4512 | } else { |
| 4513 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4514 | } |
| 4515 | LOG("Get IMSI fail."); |
| 4516 | } |
| 4517 | else |
| 4518 | { |
| 4519 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_IMSI_RSP, imsi, strlen(imsi)); |
| 4520 | } |
| 4521 | } |
| 4522 | else // Set IMSI(Unsupport). |
| 4523 | { |
| 4524 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4525 | LOG("Unsupport set IMSI."); |
| 4526 | } |
| 4527 | break; |
| 4528 | } |
| 4529 | case MBTK_INFO_ID_SIM_ICCID_REQ: // <string> ICCID |
| 4530 | { |
| 4531 | if(pack->data_len == 0 || pack->data == NULL) // Get ICCID |
| 4532 | { |
| 4533 | //log_hex("pack", pack, sizeof(mbtk_info_pack_t)); |
| 4534 | //sleep(1); |
| 4535 | char iccid[50] = {0}; |
| 4536 | if(req_iccid_get(iccid, &cme_err) || strlen(iccid) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4537 | { |
| 4538 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4539 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4540 | } else { |
| 4541 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4542 | } |
| 4543 | LOG("Get ICCID fail."); |
| 4544 | } |
| 4545 | else |
| 4546 | { |
| 4547 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ICCID_RSP, iccid, strlen(iccid)); |
| 4548 | } |
| 4549 | } |
| 4550 | else // Set ICCID(Unsupport). |
| 4551 | { |
| 4552 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4553 | LOG("Unsupport set ICCID."); |
| 4554 | } |
| 4555 | break; |
| 4556 | } |
| 4557 | case MBTK_INFO_ID_SIM_PN_REQ: // <string> Phone Number |
| 4558 | { |
| 4559 | if(pack->data_len == 0 || pack->data == NULL) // Get Phone Number |
| 4560 | { |
| 4561 | //log_hex("pack", pack, sizeof(mbtk_info_pack_t)); |
| 4562 | //sleep(1); |
| 4563 | char phone_number[50] = {0}; |
| 4564 | if(req_phone_number_get(phone_number, &cme_err) || strlen(phone_number) == 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4565 | { |
| 4566 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4567 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4568 | } else { |
| 4569 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4570 | } |
| 4571 | LOG("Get Phone Number fail."); |
| 4572 | } |
| 4573 | else |
| 4574 | { |
| 4575 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PN_RSP, phone_number, strlen(phone_number)); |
| 4576 | } |
| 4577 | } |
| 4578 | else // Set Phone Number(Unsupport). |
| 4579 | { |
| 4580 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4581 | LOG("Unsupport set Phone Number."); |
| 4582 | } |
| 4583 | break; |
| 4584 | } |
| 4585 | case MBTK_INFO_ID_NET_SEL_MODE_REQ: // <mbtk_net_info_t> Operator |
| 4586 | { |
| 4587 | if(pack->data_len == 0 || pack->data == NULL) // Get |
| 4588 | { |
| 4589 | mbtk_net_info_t info; |
| 4590 | memset(&info, 0, sizeof(mbtk_net_info_t)); |
| 4591 | if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4592 | { |
| 4593 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4594 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4595 | } else { |
| 4596 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4597 | } |
| 4598 | LOG("Get Net select mode fail."); |
| 4599 | } |
| 4600 | else |
| 4601 | { |
| 4602 | LOG("NET : %d, %d, %d, %d", info.net_sel_mode, info.net_type, info.net_state, info.plmn); |
| 4603 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SEL_MODE_RSP, &info, sizeof(mbtk_net_info_t)); |
| 4604 | } |
| 4605 | } |
| 4606 | else // Set |
| 4607 | { |
| 4608 | //LOG("1 pack-%p,data-%p,data_len-%d", pack, pack->data, pack->data_len); |
| 4609 | //log_hex("pack", pack, sizeof(mbtk_info_pack_t)); |
| 4610 | //log_hex("data", pack->data, pack->data_len); |
| 4611 | |
| 4612 | mbtk_net_info_t* info = (mbtk_net_info_t*)pack->data;//(mbtk_net_info_t*)mbtk_info_pack_data_get(pack, NULL); |
| 4613 | if(info == NULL) { |
| 4614 | err = MBTK_INFO_ERR_FORMAT; |
| 4615 | LOG("Get Net select mode fail."); |
| 4616 | } else { |
| 4617 | LOG("NET : %d, %d, %d", info->net_sel_mode, info->net_type, info->plmn); |
| 4618 | if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4619 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4620 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4621 | } else { |
| 4622 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4623 | } |
| 4624 | LOG("Get Net select mode fail."); |
| 4625 | } else { |
| 4626 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SEL_MODE_RSP, NULL, 0); |
| 4627 | } |
| 4628 | } |
| 4629 | } |
| 4630 | break; |
| 4631 | } |
| 4632 | case MBTK_INFO_ID_NET_AVAILABLE_REQ:// sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32) |
| 4633 | { |
| 4634 | if(pack->data_len == 0 || pack->data == NULL) // Get Available Net. |
| 4635 | { |
| 4636 | int buffer_size; |
| 4637 | uint8 buffer[SOCK_MSG_LEN_MAX]; |
| 4638 | memset(buffer, 0, SOCK_MSG_LEN_MAX); |
| 4639 | if((buffer_size = req_available_net_get(buffer, &cme_err)) <= 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4640 | { |
| 4641 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4642 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4643 | } else { |
| 4644 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4645 | } |
| 4646 | LOG("Get Available Net fail."); |
| 4647 | } |
| 4648 | else |
| 4649 | { |
| 4650 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_AVAILABLE_RSP, buffer, buffer_size); |
| 4651 | } |
| 4652 | } |
| 4653 | else // Set Available Net(Unsupport). |
| 4654 | { |
| 4655 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4656 | LOG("Unsupport set available net."); |
| 4657 | } |
| 4658 | break; |
| 4659 | } |
| 4660 | case MBTK_INFO_ID_NET_BAND_REQ: |
| 4661 | { |
| 4662 | if(pack->data_len == 0 || pack->data == NULL) |
| 4663 | { |
| 4664 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 4665 | LOG("No data found."); |
| 4666 | } |
| 4667 | else // Get support/current bands. |
| 4668 | { |
| 4669 | if(pack->data_len == sizeof(uint8)) { |
| 4670 | if(*(pack->data)) { // Get current bands. |
| 4671 | mbtk_band_info_t band; |
| 4672 | if(req_band_get(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4673 | { |
| 4674 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4675 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4676 | } else { |
| 4677 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4678 | } |
| 4679 | LOG("Get net band fail."); |
| 4680 | } |
| 4681 | else |
| 4682 | { |
| 4683 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, &band, sizeof(mbtk_band_info_t)); |
| 4684 | } |
| 4685 | } else { // Get support bands. |
| 4686 | band_support_get(); |
| 4687 | if(band_support.net_pref != 0) |
| 4688 | { |
| 4689 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4690 | LOG("Get support bands fail."); |
| 4691 | } |
| 4692 | else |
| 4693 | { |
| 4694 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, &band_support, sizeof(mbtk_band_info_t)); |
| 4695 | } |
| 4696 | } |
| 4697 | } else { // Set current bands. |
| 4698 | mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data; |
| 4699 | if(pack->data_len != sizeof(mbtk_band_info_t)) |
| 4700 | { |
| 4701 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 4702 | LOG("Set net band error."); |
| 4703 | break; |
| 4704 | } |
| 4705 | |
| 4706 | if(req_band_set(band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4707 | { |
| 4708 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4709 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4710 | } else { |
| 4711 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4712 | } |
| 4713 | LOG("Set net band fail."); |
| 4714 | } |
| 4715 | else |
| 4716 | { |
| 4717 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, NULL, 0); |
| 4718 | } |
| 4719 | } |
| 4720 | } |
| 4721 | break; |
| 4722 | } |
| 4723 | case MBTK_INFO_ID_NET_CELL_REQ: // mbtk_cell_info_t[] |
| 4724 | { |
| 4725 | if(pack->data_len == 0 || pack->data == NULL) // Get net cell. |
| 4726 | { |
| 4727 | if(req_cell_info_get(&cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4728 | { |
| 4729 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4730 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4731 | } else { |
| 4732 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4733 | } |
| 4734 | LOG("Get net cell fail."); |
| 4735 | } |
| 4736 | else |
| 4737 | { |
| 4738 | LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_num); |
| 4739 | //sleep(1); |
| 4740 | // mbtK_cell_pack_info_t |
| 4741 | if(cell_info.cell_num > 0 && cell_info.cell_num <= CELL_NUM_MAX && cell_info.type >= 0 && cell_info.type <= 2) { |
| 4742 | uint8 *data = (uint8*)malloc(sizeof(uint8) + sizeof(mbtk_cell_info_t) * cell_info.cell_num); |
| 4743 | if(data == NULL){ |
| 4744 | err = MBTK_INFO_ERR_MEMORY; |
| 4745 | LOG("Get net cell fail."); |
| 4746 | } else { |
| 4747 | *data = cell_info.type; // Set network type. |
| 4748 | // Copy cell info item. |
| 4749 | #if 0 |
| 4750 | int i = 0; |
| 4751 | while(i < cell_info.cell_num) { |
| 4752 | memcpy(data + sizeof(uint8) + sizeof(mbtk_cell_info_t) * i, |
| 4753 | &(cell_info.cell[i]), |
| 4754 | sizeof(mbtk_cell_info_t)); |
| 4755 | i++; |
| 4756 | } |
| 4757 | #else |
| 4758 | memcpy(data + sizeof(uint8), |
| 4759 | &(cell_info.cell), |
| 4760 | sizeof(mbtk_cell_info_t) * cell_info.cell_num); |
| 4761 | #endif |
| 4762 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, data, sizeof(uint8) + sizeof(mbtk_cell_info_t) * cell_info.cell_num); |
| 4763 | free(data); |
| 4764 | } |
| 4765 | } else { |
| 4766 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4767 | LOG("Get net cell fail."); |
| 4768 | } |
| 4769 | } |
| 4770 | } |
| 4771 | else // Lock cell |
| 4772 | { |
| 4773 | char *mem = (char*)(pack->data); |
| 4774 | int len = pack->data_len; |
| 4775 | char reg[100] = {0}; |
| 4776 | printf("mem:%s, len:%d", pack->data, pack->data_len); |
| 4777 | |
| 4778 | if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4779 | { |
| 4780 | // printf("cpms_set fail\n"); |
| 4781 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4782 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4783 | } else { |
| 4784 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4785 | } |
| 4786 | // LOG("Set req_cell_info_set fail."); |
| 4787 | } |
| 4788 | else |
| 4789 | { |
| 4790 | |
| 4791 | printf("req_cell_info_set success, reg:%s\n", reg); |
| 4792 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, reg, strlen(reg)); |
| 4793 | |
| 4794 | // Restart is required to take effect. |
| 4795 | LOG("Will reboot system..."); |
| 4796 | } |
| 4797 | } |
| 4798 | break; |
| 4799 | } |
| 4800 | case MBTK_INFO_ID_NET_RADIO_REQ: // <uint8> 0:OFF 1:ON |
| 4801 | { |
| 4802 | if(pack->data_len == 0 || pack->data == NULL) // Get |
| 4803 | { |
| 4804 | uint8 radio_on = (uint8)isRadioOn(); |
| 4805 | if(radio_on < 0) |
| 4806 | { |
| 4807 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4808 | LOG("Get radio state fail."); |
| 4809 | } |
| 4810 | else |
| 4811 | { |
| 4812 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_RADIO_RSP, &radio_on, sizeof(uint8)); |
| 4813 | } |
| 4814 | } |
| 4815 | else // Set |
| 4816 | { |
| 4817 | uint8 radio_on = *(pack->data); |
| 4818 | if(radio_on != 0 && radio_on != 1) |
| 4819 | { |
| 4820 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 4821 | LOG("Set radio state fail."); |
| 4822 | } |
| 4823 | else |
| 4824 | { |
| 4825 | setRadioPower(radio_on); |
| 4826 | if((radio_on && net_info.radio_state == MBTK_RADIO_STATE_ON) |
| 4827 | || (!radio_on && net_info.radio_state == MBTK_RADIO_STATE_OFF)) { |
| 4828 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_RADIO_RSP, NULL, 0); |
| 4829 | } else { |
| 4830 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4831 | LOG("Set radio state fail."); |
| 4832 | } |
| 4833 | } |
| 4834 | } |
| 4835 | break; |
| 4836 | } |
| 4837 | case MBTK_INFO_ID_NET_SIGNAL_REQ: // mbtk_signal_info_t |
| 4838 | { |
| 4839 | if(pack->data_len == 0 || pack->data == NULL) // Get net signal. |
| 4840 | { |
| 4841 | mbtk_signal_info_t signal; |
| 4842 | memset(&signal, 0, sizeof(mbtk_signal_info_t)); |
| 4843 | if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4844 | { |
| 4845 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4846 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4847 | } else { |
| 4848 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4849 | } |
| 4850 | LOG("Get net signal fail."); |
| 4851 | } |
| 4852 | else |
| 4853 | { |
| 4854 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SIGNAL_RSP, &signal, sizeof(mbtk_signal_info_t)); |
| 4855 | } |
| 4856 | } |
| 4857 | else // Set |
| 4858 | { |
| 4859 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4860 | LOG("Set net signal fail."); |
| 4861 | } |
| 4862 | break; |
| 4863 | } |
| 4864 | case MBTK_INFO_ID_NET_REG_REQ: // mbtk_net_reg_info_t |
| 4865 | { |
| 4866 | if(pack->data_len == 0 || pack->data == NULL) // Get net reg. |
| 4867 | { |
| 4868 | mbtk_net_reg_info_t reg; |
| 4869 | memset(®, 0, sizeof(mbtk_net_reg_info_t)); |
| 4870 | if(req_net_reg_get(®, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4871 | { |
| 4872 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4873 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4874 | } else { |
| 4875 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4876 | } |
| 4877 | LOG("Get net reg fail."); |
| 4878 | } |
| 4879 | else |
| 4880 | { |
| 4881 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_REG_RSP, ®, sizeof(mbtk_net_reg_info_t)); |
| 4882 | } |
| 4883 | } |
| 4884 | else // Set |
| 4885 | { |
| 4886 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4887 | LOG("Set net reg fail."); |
| 4888 | } |
| 4889 | break; |
| 4890 | } |
| 4891 | case MBTK_INFO_ID_NET_APN_REQ: // mbtk_apn_info_t |
| 4892 | { |
| 4893 | if(pack->data_len == 0 || pack->data == NULL) // Get APN |
| 4894 | { |
| 4895 | uint8 buff[SOCK_MSG_LEN_MAX]; |
| 4896 | memset(buff, 0, SOCK_MSG_LEN_MAX); |
| 4897 | int data_len = 0; |
| 4898 | if(req_apn_get(buff, &data_len, &cme_err) || data_len <= 0 || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4899 | { |
| 4900 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4901 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4902 | } else { |
| 4903 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4904 | } |
| 4905 | LOG("Get APN fail."); |
| 4906 | } |
| 4907 | else |
| 4908 | { |
| 4909 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, buff, data_len); |
| 4910 | } |
| 4911 | } |
| 4912 | else // Set |
| 4913 | { |
| 4914 | // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth> |
| 4915 | const uint8* ptr = pack->data; |
| 4916 | mbtk_apn_info_t apn; |
| 4917 | int len; |
| 4918 | memset(&apn, 0, sizeof(mbtk_apn_info_t)); |
| 4919 | // cid |
| 4920 | apn.cid = *ptr++; |
| 4921 | |
| 4922 | // ip_type |
| 4923 | apn.ip_type = (mbtk_ip_type_enum)(*ptr++); |
| 4924 | |
| 4925 | // apn |
| 4926 | len = byte_2_uint16(ptr, false); |
| 4927 | ptr += sizeof(uint16); |
| 4928 | if(len > 0) { |
| 4929 | memcpy(apn.apn, ptr, len); |
| 4930 | ptr += len; |
| 4931 | } |
| 4932 | |
| 4933 | // user |
| 4934 | len = byte_2_uint16(ptr, false); |
| 4935 | ptr += sizeof(uint16); |
| 4936 | if(len > 0) { |
| 4937 | memcpy(apn.user, ptr, len); |
| 4938 | ptr += len; |
| 4939 | } |
| 4940 | |
| 4941 | // pass |
| 4942 | len = byte_2_uint16(ptr, false); |
| 4943 | ptr += sizeof(uint16); |
| 4944 | if(len > 0) { |
| 4945 | memcpy(apn.pass, ptr, len); |
| 4946 | ptr += len; |
| 4947 | } |
| 4948 | |
| 4949 | // auth |
| 4950 | len = byte_2_uint16(ptr, false); |
| 4951 | ptr += sizeof(uint16); |
| 4952 | if(len > 0) { |
| 4953 | memcpy(apn.auth, ptr, len); |
| 4954 | ptr += len; |
| 4955 | } |
| 4956 | |
| 4957 | LOGD("APN : %d, %d, %s, %s, %s, %s", apn.cid, apn.ip_type, str_empty(apn.apn) ? "NULL" : apn.apn, |
| 4958 | str_empty(apn.user) ? "NULL" : apn.user, str_empty(apn.pass) ? "NULL" : apn.pass, str_empty(apn.auth) ? "NULL" : apn.auth); |
| 4959 | if(req_apn_set(&apn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4960 | { |
| 4961 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4962 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4963 | } else { |
| 4964 | err = MBTK_INFO_ERR_UNKNOWN; |
| 4965 | } |
| 4966 | LOG("Set APN fail."); |
| 4967 | } |
| 4968 | else |
| 4969 | { |
| 4970 | // Save apn. |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 4971 | #ifdef MBTK_AF_SUPPORT |
| 4972 | if(apn.cid == 1) |
| 4973 | { |
| 4974 | default_iptype = apn.ip_type; |
| 4975 | } |
| 4976 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 4977 | apn_prop_set(&apn); |
| 4978 | |
| 4979 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, NULL, 0); |
| 4980 | } |
| 4981 | } |
| 4982 | break; |
| 4983 | } |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 4984 | case MBTK_INFO_ID_NET_APN_DEL_REQ: |
| 4985 | { |
| 4986 | if(pack->data_len == 0 || pack->data == NULL) |
| 4987 | { |
| 4988 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 4989 | LOG("Unsupported delete apn ."); |
| 4990 | } |
| 4991 | else |
| 4992 | { |
liuyang | 1cefd85 | 2024-04-24 18:30:53 +0800 | [diff] [blame] | 4993 | int profile = pack->data[0]; |
liuyang | 0e49d9a | 2024-04-23 21:04:54 +0800 | [diff] [blame] | 4994 | if(req_apn_del(profile, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 4995 | { |
| 4996 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 4997 | err = MBTK_INFO_ERR_CME + cme_err; |
| 4998 | } else { |
| 4999 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5000 | } |
| 5001 | LOG("Delete apn fail."); |
| 5002 | } |
| 5003 | else |
| 5004 | { |
| 5005 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_DEL_RSP, NULL, 0); |
| 5006 | } |
| 5007 | } |
| 5008 | break; |
| 5009 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5010 | case MBTK_INFO_ID_NET_DATA_CALL_REQ: |
| 5011 | { |
| 5012 | if(pack->data_len == 0 || pack->data == NULL) |
| 5013 | { |
| 5014 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 5015 | } |
| 5016 | else |
| 5017 | { |
| 5018 | /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]> |
| 5019 | call_type : mbtk_data_call_type_enum |
| 5020 | cid : 2 - 7 |
| 5021 | timeout : second |
| 5022 | */ |
| 5023 | mbtk_data_call_type_enum call_type = (mbtk_data_call_type_enum)pack->data[0]; |
| 5024 | int cid = pack->data[1]; |
| 5025 | int reconn = 0; |
| 5026 | |
| 5027 | if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { |
| 5028 | err = MBTK_INFO_ERR_CID; |
| 5029 | break; |
| 5030 | } |
| 5031 | |
| 5032 | LOG("cid_active[%d] = %d", cid, cid_active[cid]); |
| 5033 | memset(&cgact_wait, 0, sizeof(info_cgact_wait_t)); |
| 5034 | switch(call_type) { |
| 5035 | case MBTK_DATA_CALL_START: { |
| 5036 | //mbtk wyq for data_call_ex add start |
| 5037 | int auto_conn_interval = pack->data[2]; |
| 5038 | int boot_conn = pack->data[3]; |
| 5039 | int timeout = pack->data[4]; |
| 5040 | data_call_bootconn_save(cid, boot_conn); |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5041 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5042 | if(net_info.net_type != MBTK_RADIO_TECH_E_UTRAN) |
| 5043 | { |
| 5044 | err = MBTK_INFO_ERR_NET_NO_INIT; |
| 5045 | break; |
| 5046 | } |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5047 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5048 | if(cid_active[cid] == 1) |
| 5049 | { |
| 5050 | err = MBTK_INFO_ERR_CID_EXIST; |
| 5051 | break; |
| 5052 | } |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5053 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5054 | data_call_reconn: |
| 5055 | //mbtk wyq for data_call_ex add end |
| 5056 | cgact_wait.waitting = true; |
| 5057 | cgact_wait.cid = cid; |
| 5058 | cgact_wait.act = true; |
| 5059 | if(req_data_call_start(cid, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5060 | { |
| 5061 | //mbtk wyq for data_call_ex add start |
| 5062 | if(reconn < 5 && auto_conn_interval > 0) |
| 5063 | { |
| 5064 | sleep(auto_conn_interval); |
| 5065 | reconn++; |
| 5066 | cme_err = MBTK_INFO_ERR_CME_NON; |
| 5067 | LOG("data_call restart call."); |
| 5068 | goto data_call_reconn; |
| 5069 | } |
| 5070 | //mbtk wyq for data_call_ex add end |
| 5071 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5072 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5073 | } else { |
| 5074 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5075 | } |
| 5076 | LOG("%d active fail.", cid); |
| 5077 | } |
| 5078 | else |
| 5079 | { |
| 5080 | // Wait for "CONNECT" or "+CGEV:" |
| 5081 | if(wait_cgact_complete(timeout)) { // Timeout |
| 5082 | err = MBTK_INFO_ERR_TIMEOUT; |
| 5083 | break; |
| 5084 | } |
| 5085 | |
| 5086 | // Get IP information. |
| 5087 | mbtk_ipv4_info_t ipv4; |
| 5088 | mbtk_ipv6_info_t ipv6; |
| 5089 | memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t)); |
| 5090 | memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t)); |
| 5091 | if(req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5092 | { |
| 5093 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5094 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5095 | } else { |
| 5096 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5097 | } |
| 5098 | LOG("Get %d state fail.", cid); |
| 5099 | } |
| 5100 | else |
| 5101 | { |
| 5102 | // Config IPv4 address. |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 5103 | #ifdef MBTK_AF_SUPPORT |
| 5104 | if(cid == 1) |
| 5105 | { |
| 5106 | //uint8 pdp_data = cid; |
| 5107 | //pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8)); |
| 5108 | ipv4.valid = false; |
| 5109 | ipv6.valid = false; |
| 5110 | if(default_iptype == MBTK_IP_TYPE_IP) |
| 5111 | { |
| 5112 | ipv4.valid = true; |
| 5113 | } |
| 5114 | else if(default_iptype == MBTK_IP_TYPE_IPV6) |
| 5115 | { |
| 5116 | ipv6.valid = true; |
| 5117 | } |
| 5118 | else |
| 5119 | { |
| 5120 | ipv4.valid = true; |
| 5121 | ipv6.valid = true; |
| 5122 | } |
| 5123 | } |
| 5124 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5125 | #if 1 |
| 5126 | if(ipv4.valid) { |
| 5127 | char dev[20] = {0}; |
| 5128 | sprintf(dev, "ccinet%d", cid - 1); |
| 5129 | |
| 5130 | char ip[20] = {0}; |
| 5131 | char gateway[20] = {0}; |
| 5132 | char *gateway_ptr = NULL; |
| 5133 | char netmask[20] = {0}; |
| 5134 | char *netmask_ptr = NULL; |
| 5135 | if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip, 20) == NULL) { |
| 5136 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5137 | LOGE("inet_ntop ipv4 ip fail."); |
| 5138 | log_hex("IPv4", &(ipv4.IPAddr), 4); |
| 5139 | break; |
| 5140 | } |
| 5141 | |
| 5142 | if(ipv4.GateWay) { |
| 5143 | if(inet_ntop(AF_INET, &(ipv4.GateWay), gateway, 20) == NULL) { |
| 5144 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5145 | LOGE("inet_ntop ipv4 gateway fail."); |
| 5146 | log_hex("IPv4", &(ipv4.IPAddr), 4); |
| 5147 | break; |
| 5148 | } else { |
| 5149 | gateway_ptr = gateway; |
| 5150 | } |
| 5151 | } |
| 5152 | |
| 5153 | if(ipv4.NetMask) { |
| 5154 | if(inet_ntop(AF_INET, &(ipv4.NetMask), netmask, 20) == NULL) { |
| 5155 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5156 | LOGE("inet_ntop ipv4 netmask fail."); |
| 5157 | log_hex("IPv4", &(ipv4.IPAddr), 4); |
| 5158 | break; |
| 5159 | } else { |
| 5160 | netmask_ptr = netmask; |
| 5161 | } |
| 5162 | } |
| 5163 | |
| 5164 | if(netmask_ptr == NULL) { |
| 5165 | netmask_ptr = netmask; |
| 5166 | memcpy(netmask_ptr, "255.255.255.0", strlen("255.255.255.0")); |
| 5167 | } |
| 5168 | |
| 5169 | if(mbtk_ifc_configure2(dev, ip, 0, gateway_ptr, netmask_ptr)) { |
| 5170 | LOGD("Config %s IPv4 %s fail.", dev, ip); |
| 5171 | } else { |
| 5172 | LOGD("Config %s IPv4 %s success.", dev, ip); |
| 5173 | } |
| 5174 | |
| 5175 | } |
| 5176 | #endif |
| 5177 | // Config IPv6 address. |
| 5178 | if(ipv6.valid) { |
| 5179 | char ip[50] = {0}; |
| 5180 | char dev[20] = {0}; |
| 5181 | sprintf(dev, "ccinet%d", cid - 1); |
| 5182 | |
| 5183 | if(inet_ntop(AF_INET6, &(ipv6.IPV6Addr), ip, 50) == NULL) { |
| 5184 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5185 | LOGE("inet_ntop ipv6 ip fail."); |
| 5186 | log_hex("IPv6", &(ipv6.IPV6Addr), 16); |
| 5187 | break; |
| 5188 | } |
| 5189 | |
| 5190 | if(mbtk_ipv6_config(dev, ip, 64)) { |
| 5191 | LOGD("Config %s IPv6 %s fail.", dev, ip); |
| 5192 | } else { |
| 5193 | LOGD("Config %s IPv6 %s success.", dev, ip); |
| 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | cid_active[cid] = 1; |
| 5198 | if(cli_info->fd != DATA_CALL_BOOTCONN_FD) |
| 5199 | { |
| 5200 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0); |
| 5201 | } |
| 5202 | else |
| 5203 | { |
| 5204 | free(pack->data); |
| 5205 | free(cli_info); |
| 5206 | LOG("data_call bootconn success."); |
| 5207 | } |
| 5208 | } |
| 5209 | } |
| 5210 | break; |
| 5211 | } |
| 5212 | case MBTK_DATA_CALL_STOP: { |
| 5213 | //mbtk wyq for data_call_ex add start |
| 5214 | if(cid_active[cid] == 0) |
| 5215 | { |
| 5216 | err = MBTK_INFO_ERR_CID_NO_EXIST; |
| 5217 | break; |
| 5218 | } |
| 5219 | |
| 5220 | int timeout = pack->data[2]; |
| 5221 | //mbtk wyq for data_call_ex add end |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 5222 | #if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT)) |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 5223 | if(cid == 1) |
| 5224 | { |
| 5225 | char dev[20] = {0}; |
| 5226 | uint8 pdp_data = cid + 100; |
| 5227 | pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8)); |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5228 | |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 5229 | sprintf(dev, "ccinet%d", cid - 1); |
| 5230 | |
| 5231 | // Config network. |
| 5232 | if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) { |
| 5233 | LOGD("Config %s IPv4 0 fail.", dev); |
| 5234 | } else { |
| 5235 | LOGD("Config %s IPv4 0 success.", dev); |
| 5236 | } |
| 5237 | cid_active[cid] = 0; |
| 5238 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0); |
| 5239 | break; |
| 5240 | } |
| 5241 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5242 | cgact_wait.waitting = true; |
| 5243 | cgact_wait.cid = cid; |
| 5244 | cgact_wait.act = false; |
| 5245 | if(req_data_call_stop(cid, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5246 | { |
| 5247 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5248 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5249 | } else { |
| 5250 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5251 | } |
| 5252 | LOG("%d deactive fail.", cid); |
| 5253 | } |
| 5254 | else |
| 5255 | { |
| 5256 | // Wait for "CONNECT" or "+CGEV:" |
| 5257 | if(wait_cgact_complete(timeout)) { // Timeout |
| 5258 | err = MBTK_INFO_ERR_TIMEOUT; |
| 5259 | break; |
| 5260 | } |
| 5261 | char dev[20] = {0}; |
| 5262 | sprintf(dev, "ccinet%d", cid - 1); |
| 5263 | |
| 5264 | // Config network. |
| 5265 | if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) { |
| 5266 | LOGD("Config %s IPv4 0 fail.", dev); |
| 5267 | } else { |
| 5268 | LOGD("Config %s IPv4 0 success.", dev); |
| 5269 | } |
| 5270 | |
| 5271 | #if 0 |
| 5272 | if(mbtk_ipv6_config(dev, NULL, 64)) { |
| 5273 | LOGD("Config %s IPv6 0 fail.", dev); |
| 5274 | } else { |
| 5275 | LOGD("Config %s IPv6 0 success.", dev); |
| 5276 | } |
| 5277 | #endif |
| 5278 | cid_active[cid] = 0; |
| 5279 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0); |
| 5280 | } |
| 5281 | break; |
| 5282 | } |
| 5283 | case MBTK_DATA_CALL_STATE: { |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 5284 | if(cid_active[cid] == 0) |
| 5285 | { |
| 5286 | err = MBTK_INFO_ERR_CID_NO_EXIST; |
| 5287 | break; |
| 5288 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5289 | mbtk_ipv4_info_t ipv4; |
| 5290 | mbtk_ipv6_info_t ipv6; |
| 5291 | memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t)); |
| 5292 | memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t)); |
| 5293 | if(req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5294 | { |
| 5295 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5296 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5297 | } else { |
| 5298 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5299 | } |
| 5300 | LOG("Get %d state fail.", cid); |
| 5301 | } |
| 5302 | else |
| 5303 | { |
| 5304 | uint8 buff[SOCK_MSG_LEN_MAX] = {0}; |
| 5305 | int buff_len = 0; |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 5306 | #ifdef MBTK_AF_SUPPORT |
| 5307 | if(cid == 1) |
| 5308 | { |
| 5309 | ipv4.valid = false; |
| 5310 | ipv6.valid = false; |
| 5311 | if(default_iptype == MBTK_IP_TYPE_IP) |
| 5312 | { |
| 5313 | ipv4.valid = true; |
| 5314 | } |
| 5315 | else if(default_iptype == MBTK_IP_TYPE_IPV6) |
| 5316 | { |
| 5317 | ipv6.valid = true; |
| 5318 | } |
| 5319 | else |
| 5320 | { |
| 5321 | ipv4.valid = true; |
| 5322 | ipv6.valid = true; |
| 5323 | } |
| 5324 | } |
| 5325 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5326 | if(ipv4.valid && ipv6.valid) { |
| 5327 | buff[0] = (uint8)2; |
| 5328 | buff_len++; |
| 5329 | |
| 5330 | memcpy(buff + buff_len, &ipv4, sizeof(mbtk_ipv4_info_t)); |
| 5331 | buff_len += sizeof(mbtk_ipv4_info_t); |
| 5332 | memcpy(buff + buff_len, &ipv6, sizeof(mbtk_ipv6_info_t)); |
| 5333 | buff_len += sizeof(mbtk_ipv6_info_t); |
| 5334 | } else if(ipv4.valid) { |
| 5335 | buff[0] = (uint8)0; |
| 5336 | buff_len++; |
| 5337 | |
| 5338 | memcpy(buff + buff_len, &ipv4, sizeof(mbtk_ipv4_info_t)); |
| 5339 | buff_len += sizeof(mbtk_ipv4_info_t); |
| 5340 | } else if(ipv6.valid) { |
| 5341 | buff[0] = (uint8)1; |
| 5342 | buff_len++; |
| 5343 | |
| 5344 | memcpy(buff + buff_len, &ipv6, sizeof(mbtk_ipv6_info_t)); |
| 5345 | buff_len += sizeof(mbtk_ipv6_info_t); |
| 5346 | } else { |
| 5347 | LOGE("Get IPv4/IPv6 fail."); |
| 5348 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5349 | break; |
| 5350 | } |
| 5351 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, buff, buff_len); |
| 5352 | } |
| 5353 | break; |
| 5354 | } |
| 5355 | default: { |
| 5356 | err = MBTK_INFO_ERR_FORMAT; |
| 5357 | break; |
| 5358 | } |
| 5359 | } |
| 5360 | } |
| 5361 | break; |
| 5362 | } |
r.xiao | 06db9a1 | 2024-04-14 18:51:15 -0700 | [diff] [blame] | 5363 | case MBTK_INFO_ID_NET_IMS_REQ: |
| 5364 | { |
| 5365 | if(pack->data_len == 0 || pack->data == NULL) //Get |
| 5366 | { |
| 5367 | int reg = -1; |
| 5368 | if(net_ims_get(®, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5369 | { |
| 5370 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5371 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5372 | } else { |
| 5373 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5374 | } |
| 5375 | LOG("Get net ims fail."); |
| 5376 | } |
| 5377 | else |
| 5378 | { |
| 5379 | uint8 reg_type = (uint8)reg; |
| 5380 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_RSP, ®_type, sizeof(uint8)); |
| 5381 | } |
| 5382 | } |
| 5383 | else |
| 5384 | { |
| 5385 | uint8 ims = *(pack->data); |
| 5386 | |
| 5387 | if(net_ims_set(ims, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5388 | { |
| 5389 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5390 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5391 | } else { |
| 5392 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5393 | } |
| 5394 | LOG("Set net ims fail."); |
| 5395 | } |
| 5396 | else |
| 5397 | { |
| 5398 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_RSP, NULL, 0); |
| 5399 | } |
| 5400 | } |
| 5401 | break; |
| 5402 | } |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 5403 | case MBTK_INFO_ID_WAKEUP_STA_REQ: |
| 5404 | { |
| 5405 | if(pack->data_len == 0 || pack->data == NULL) |
| 5406 | { |
| 5407 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 5408 | LOG("Get POWERIND state UNSUPPORTED."); |
| 5409 | } |
| 5410 | else // Set powerind state. |
| 5411 | { |
| 5412 | uint32 state = *(pack->data); |
| 5413 | if(req_powerind_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5414 | { |
| 5415 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5416 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5417 | } else { |
| 5418 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5419 | } |
| 5420 | LOG("Set POWERIND state fail."); |
| 5421 | } |
| 5422 | else |
| 5423 | { |
| 5424 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_WAKEUP_STA_RSP, NULL, 0); |
| 5425 | } |
| 5426 | } |
| 5427 | break; |
| 5428 | } |
| 5429 | case MBTK_INFO_ID_OOS_STA_REQ: |
| 5430 | { |
| 5431 | if(pack->data_len == 0 || pack->data == NULL) |
| 5432 | { |
| 5433 | mbtk_oos_info oos_t; |
| 5434 | if(req_oos_get(&oos_t, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5435 | { |
| 5436 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5437 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5438 | } else { |
| 5439 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5440 | } |
| 5441 | LOG("Get SMS OOS fail."); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 5442 | } |
| 5443 | else |
| 5444 | { |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 5445 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_OOS_STA_RSP, &oos_t, sizeof(mbtk_oos_info)); |
| 5446 | } |
| 5447 | } |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5448 | else // Set OOS |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 5449 | { |
r.xiao | cfd7c68 | 2024-01-22 03:59:46 -0800 | [diff] [blame] | 5450 | mbtk_oos_info *state = (mbtk_oos_info *)pack->data; |
| 5451 | if(pack->data_len != sizeof(mbtk_oos_info)) |
| 5452 | { |
| 5453 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 5454 | LOG("Set oos error."); |
| 5455 | break; |
| 5456 | } |
| 5457 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 5458 | if(req_oos_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 5459 | { |
| 5460 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 5461 | err = MBTK_INFO_ERR_CME + cme_err; |
| 5462 | } else { |
| 5463 | err = MBTK_INFO_ERR_UNKNOWN; |
| 5464 | } |
| 5465 | LOG("Set OOS fail."); |
| 5466 | } |
| 5467 | else |
| 5468 | { |
| 5469 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_OOS_STA_RSP, NULL, 0); |
| 5470 | } |
| 5471 | } |
| 5472 | break; |
| 5473 | } |
wangyouqiang | 38e5336 | 2024-01-23 10:53:48 +0800 | [diff] [blame] | 5474 | case MBTK_INFO_ID_LED_REQ: |
| 5475 | { |
| 5476 | if(pack->data_len == 0 || pack->data == NULL) |
| 5477 | { |
| 5478 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 5479 | LOGE("led param is error."); |
| 5480 | } |
| 5481 | else |
| 5482 | { |
| 5483 | char type = pack->data[0]; |
| 5484 | char status = pack->data[1]; |
| 5485 | LOGE("[set_led] = [%d], [status_led] = [%d].", type, status); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 5486 | |
wangyouqiang | 38e5336 | 2024-01-23 10:53:48 +0800 | [diff] [blame] | 5487 | if(type == MBTK_LED_TYPE_NET) |
| 5488 | { |
| 5489 | if(status == MBTK_LED_STATUS_CLOSE) |
| 5490 | { |
| 5491 | mbtk_net_led_set(MBTK_NET_LED_CLOSE); |
| 5492 | } |
| 5493 | else |
| 5494 | { |
| 5495 | mbtk_net_led_set(MBTK_NET_LED_OPEN); |
| 5496 | } |
| 5497 | } |
| 5498 | else |
| 5499 | { |
| 5500 | if(status == MBTK_LED_STATUS_CLOSE) |
| 5501 | { |
| 5502 | status_led_set(MBTK_STATUS_LED_CLOSE); |
| 5503 | } |
| 5504 | else |
| 5505 | { |
| 5506 | status_led_set(MBTK_STATUS_LED_OPEN); |
| 5507 | } |
| 5508 | } |
| 5509 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_LED_RSP, NULL, 0); |
| 5510 | } |
| 5511 | break; |
| 5512 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5513 | default: |
| 5514 | { |
| 5515 | err = MBTK_INFO_ERR_REQ_UNKNOWN; |
| 5516 | LOG("Unknown request : %s", id2str(pack->info_id)); |
| 5517 | break; |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | return err; |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | // Process AT URC data |
| 5526 | static int send_pack_to_queue(sock_client_info_t* cli_info, void* pack) |
| 5527 | { |
| 5528 | if(info_queue.count >= PACK_PROCESS_QUEUE_MAX) |
| 5529 | { |
| 5530 | LOG("Packet process queue is full"); |
| 5531 | return -1; |
| 5532 | } |
| 5533 | |
| 5534 | info_queue_item_t *item = (info_queue_item_t*)malloc(sizeof(info_queue_item_t)); |
| 5535 | if(!item) |
| 5536 | { |
| 5537 | LOG("malloc() fail[%d].", errno); |
| 5538 | return -1; |
| 5539 | } |
| 5540 | item->cli_info = cli_info; |
| 5541 | item->pack = pack; |
| 5542 | mbtk_queue_put(&info_queue, item); |
| 5543 | |
| 5544 | // If thread is waitting,continue it. |
| 5545 | if(1/*!is_running*/) |
| 5546 | { |
| 5547 | pthread_mutex_lock(&info_mutex); |
| 5548 | pthread_cond_signal(&info_cond); |
| 5549 | pthread_mutex_unlock(&info_mutex); |
| 5550 | } |
| 5551 | else |
| 5552 | { |
| 5553 | LOG("Packet process thread is process..."); |
| 5554 | } |
| 5555 | |
| 5556 | return 0; |
| 5557 | } |
| 5558 | |
| 5559 | static void radio_state_change(void *data, int data_len) |
| 5560 | { |
| 5561 | uint8 *data_ptr = (uint8*)data; |
| 5562 | if(data_ptr[0]) { |
| 5563 | net_info.radio_state = MBTK_RADIO_STATE_ON; |
| 5564 | } else { |
| 5565 | net_info.radio_state = MBTK_RADIO_STATE_OFF; |
| 5566 | } |
| 5567 | |
| 5568 | sock_client_info_t *cli = NULL; |
| 5569 | list_first(sock_client_list); |
| 5570 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5571 | { |
| 5572 | if(cli->ind_num > 0) { |
| 5573 | int i; |
| 5574 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5575 | // Registe MBTK_INFO_ID_IND_RADIO_STATE_CHANGE |
| 5576 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_RADIO_STATE_CHANGE) { |
| 5577 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, data, data_len); |
| 5578 | break; |
| 5579 | } |
| 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | static void pdp_state_change(void *data, int data_len) |
| 5586 | { |
| 5587 | sock_client_info_t *cli = NULL; |
| 5588 | list_first(sock_client_list); |
| 5589 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5590 | { |
| 5591 | if(cli->ind_num > 0) { |
| 5592 | int i; |
| 5593 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5594 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_PDP_STATE_CHANGE) { |
| 5595 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, data, data_len); |
| 5596 | break; |
| 5597 | } |
| 5598 | } |
| 5599 | } |
| 5600 | } |
| 5601 | } |
| 5602 | |
| 5603 | static void net_state_change(void *data, int data_len) |
| 5604 | { |
| 5605 | sock_client_info_t *cli = NULL; |
| 5606 | list_first(sock_client_list); |
| 5607 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5608 | { |
| 5609 | if(cli->ind_num > 0) { |
| 5610 | int i; |
| 5611 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5612 | // Registe MBTK_INFO_ID_IND_NET_STATE_CHANGE |
| 5613 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_NET_STATE_CHANGE) { |
| 5614 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_NET_STATE_CHANGE, data, data_len); |
| 5615 | break; |
| 5616 | } |
| 5617 | } |
| 5618 | } |
| 5619 | } |
| 5620 | } |
| 5621 | |
| 5622 | static void call_state_change(void *data, int data_len) |
| 5623 | { |
| 5624 | sock_client_info_t *cli = NULL; |
| 5625 | list_first(sock_client_list); |
| 5626 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5627 | { |
| 5628 | if(cli->ind_num > 0) { |
| 5629 | int i; |
| 5630 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5631 | // Registed MBTK_INFO_ID_IND_RADIO_STATE_CHANGE |
| 5632 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_CALL_STATE_CHANGE) { |
| 5633 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_CALL_STATE_CHANGE, data, data_len); |
| 5634 | break; |
| 5635 | } |
| 5636 | } |
| 5637 | } |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | static void sim_state_change(void *data, int data_len) |
| 5642 | { |
| 5643 | sock_client_info_t *cli = NULL; |
| 5644 | list_first(sock_client_list); |
| 5645 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5646 | { |
| 5647 | if(cli->ind_num > 0) { |
| 5648 | int i; |
| 5649 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5650 | // Registed MBTK_INFO_ID_IND_RADIO_STATE_CHANGE |
| 5651 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_SIM_STATE_CHANGE) { |
| 5652 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SIM_STATE_CHANGE, data, data_len); |
| 5653 | break; |
| 5654 | } |
| 5655 | } |
| 5656 | } |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | static void sms_state_change(void *data, int data_len) |
| 5661 | { |
| 5662 | sock_client_info_t *cli = NULL; |
| 5663 | list_first(sock_client_list); |
| 5664 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5665 | { |
| 5666 | if(cli->ind_num > 0) { |
| 5667 | int i; |
| 5668 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5669 | // Registed MBTK_INFO_ID_IND_SMS_STATE_CHANGE |
| 5670 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_SMS_STATE_CHANGE) { |
| 5671 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SMS_STATE_CHANGE, data, data_len); |
| 5672 | break; |
| 5673 | } |
| 5674 | } |
| 5675 | } |
| 5676 | } |
| 5677 | } |
| 5678 | |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 5679 | static void signal_state_change(void *data, int data_len) |
| 5680 | { |
| 5681 | sock_client_info_t *cli = NULL; |
| 5682 | list_first(sock_client_list); |
| 5683 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5684 | { |
| 5685 | if(cli->ind_num > 0) { |
| 5686 | int i; |
| 5687 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
| 5688 | // Registe MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE |
| 5689 | if(cli->ind_register[i] == MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE) { |
| 5690 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE, data, data_len); |
| 5691 | break; |
| 5692 | } |
| 5693 | } |
| 5694 | } |
| 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5699 | int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len) |
| 5700 | { |
| 5701 | #if 0 |
| 5702 | if(urc_queue.count >= PACK_PROCESS_QUEUE_MAX) |
| 5703 | { |
| 5704 | LOG("Packet process queue is full"); |
| 5705 | return -1; |
| 5706 | } |
| 5707 | |
| 5708 | info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t)); |
| 5709 | if(!urc) |
| 5710 | { |
| 5711 | LOG("malloc() fail[%d].", errno); |
| 5712 | return -1; |
| 5713 | } |
| 5714 | urc->msg = msg; |
| 5715 | urc->data = memdup(data, data_len); |
| 5716 | urc->data_len = data_len; |
| 5717 | |
| 5718 | mbtk_queue_put(&urc_queue, urc); |
| 5719 | |
| 5720 | // If thread is waitting,continue it. |
| 5721 | if(1/*!is_running*/) |
| 5722 | { |
| 5723 | pthread_mutex_lock(&urc_mutex); |
| 5724 | pthread_cond_signal(&urc_cond); |
| 5725 | pthread_mutex_unlock(&urc_mutex); |
| 5726 | } |
| 5727 | else |
| 5728 | { |
| 5729 | LOG("Packet process thread is process..."); |
| 5730 | } |
| 5731 | |
| 5732 | return 0; |
| 5733 | #else |
| 5734 | if(async_process) { |
| 5735 | info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t)); |
| 5736 | if(!urc) |
| 5737 | { |
| 5738 | LOG("malloc() fail[%d].", errno); |
| 5739 | return -1; |
| 5740 | } |
| 5741 | urc->msg = msg; |
| 5742 | if(data && data_len > 0) { |
| 5743 | urc->data = memdup(data, data_len); |
| 5744 | urc->data_len = data_len; |
| 5745 | } else { |
| 5746 | urc->data = NULL; |
| 5747 | urc->data_len = 0; |
| 5748 | } |
| 5749 | return send_pack_to_queue(NULL, urc); |
| 5750 | } else { |
| 5751 | switch(msg) { |
| 5752 | case INFO_URC_MSG_NET_CS_REG_STATE: |
| 5753 | { |
| 5754 | net_state_change(data, data_len); |
| 5755 | break; |
| 5756 | } |
| 5757 | case INFO_URC_MSG_CALL_STATE: |
| 5758 | { |
| 5759 | call_state_change(data, data_len); |
| 5760 | break; |
| 5761 | } |
| 5762 | case INFO_URC_MSG_SMS_STATE: |
| 5763 | { |
| 5764 | sms_state_change(data, data_len); |
| 5765 | break; |
| 5766 | } |
| 5767 | case INFO_URC_MSG_SIM_STATE: |
| 5768 | { |
| 5769 | sim_state_change(data, data_len); |
| 5770 | break; |
| 5771 | } |
| 5772 | case INFO_URC_MSG_PDP_STATE: |
| 5773 | { |
| 5774 | pdp_state_change(data, data_len); |
| 5775 | break; |
| 5776 | } |
| 5777 | default: { |
| 5778 | LOGE("Unknown msg : %d", msg); |
| 5779 | break; |
| 5780 | } |
| 5781 | } |
| 5782 | |
| 5783 | return 0; |
| 5784 | } |
| 5785 | #endif |
| 5786 | } |
| 5787 | |
| 5788 | |
| 5789 | static void ind_regisger(sock_client_info_t* cli_info, uint16 ind) |
| 5790 | { |
| 5791 | uint32 i = 0; |
| 5792 | while(i < cli_info->ind_num) |
| 5793 | { |
| 5794 | if(cli_info->ind_register[i] == ind) |
| 5795 | break; |
| 5796 | i++; |
| 5797 | } |
| 5798 | |
| 5799 | if(i == cli_info->ind_num) // No found IND |
| 5800 | { |
| 5801 | cli_info->ind_register[i] = ind; |
| 5802 | cli_info->ind_num++; |
| 5803 | LOG("Register IND : %s", id2str(ind)); |
| 5804 | } |
| 5805 | else |
| 5806 | { |
| 5807 | LOG("IND had exist."); |
| 5808 | } |
| 5809 | } |
| 5810 | |
| 5811 | static void pack_distribute(sock_client_info_t* cli_info, mbtk_info_pack_t* pack) |
| 5812 | { |
| 5813 | // Register IND Message. |
| 5814 | if(mbtk_info_type_get(pack->info_id) == MBTK_INFO_TYPE_IND) |
| 5815 | { |
| 5816 | mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS; |
| 5817 | if(cli_info->ind_num >= IND_REGISTER_MAX) |
| 5818 | { |
| 5819 | LOG("IND if full."); |
| 5820 | err = MBTK_INFO_ERR_IND_FULL; |
| 5821 | } |
| 5822 | else |
| 5823 | { |
| 5824 | ind_regisger(cli_info, pack->info_id); |
| 5825 | } |
| 5826 | |
| 5827 | pack_error_send(cli_info->fd, pack->info_id, err); |
| 5828 | |
| 5829 | mbtk_info_pack_free(&pack); |
| 5830 | } |
| 5831 | else // Request Information. |
| 5832 | { |
| 5833 | LOG("Start process REQ(%s), Length : %d", id2str(pack->info_id), pack->data_len); |
| 5834 | if(0 && pack->data_len > 0) |
| 5835 | { |
| 5836 | log_hex("DATA", pack->data, pack->data_len); |
| 5837 | } |
| 5838 | |
| 5839 | // Send to REQ_process_thread process. |
| 5840 | send_pack_to_queue(cli_info, pack); |
| 5841 | |
| 5842 | // For test. |
| 5843 | // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS); |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | static sock_client_info_t* cli_find(int fd) |
| 5848 | { |
| 5849 | sock_client_info_t *result = NULL; |
| 5850 | list_first(sock_client_list); |
| 5851 | while ((result = (sock_client_info_t*) list_next(sock_client_list))) |
| 5852 | { |
| 5853 | if (result->fd == fd) |
| 5854 | return result; |
| 5855 | } |
| 5856 | |
| 5857 | return NULL; |
| 5858 | } |
| 5859 | |
| 5860 | //mbtk wyq for server_ready_status add start |
| 5861 | void server_ready_set(void) |
| 5862 | { |
| 5863 | server_ready_status = 1; |
| 5864 | } |
| 5865 | |
| 5866 | char server_ready_get(void) |
| 5867 | { |
| 5868 | return server_ready_status; |
| 5869 | } |
| 5870 | |
| 5871 | static void server_state_send(void) |
| 5872 | { |
| 5873 | sock_client_info_t *cli = NULL; |
| 5874 | list_first(sock_client_list); |
| 5875 | while ((cli = (sock_client_info_t*) list_next(sock_client_list))) |
| 5876 | { |
| 5877 | if(cli->ind_num > 0) { |
| 5878 | if(cli->ind_register[0] == MBTK_INFO_ID_IND_SERVER_STATE_CHANGE) { |
| 5879 | cli->ind_num = 0; |
| 5880 | cli->ind_register[0] = 0; |
| 5881 | pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SERVER_STATE_CHANGE, "1", 1); |
| 5882 | break; |
| 5883 | } |
| 5884 | } |
| 5885 | else |
| 5886 | { |
| 5887 | break; |
| 5888 | } |
| 5889 | } |
| 5890 | LOG("handshake message send ok."); |
| 5891 | } |
| 5892 | |
| 5893 | //mbtk wyq for server_ready_status add end |
| 5894 | |
| 5895 | //mbtk wyq for data_call_ex add start |
| 5896 | //Save the cid that "DATA_CALL" needs to be automatically connected after startup |
| 5897 | void data_call_bootconn_save(int cid, int bootconn) |
| 5898 | { |
| 5899 | if(cid_bootconn[cid] == bootconn + '0') |
| 5900 | { |
| 5901 | return; |
| 5902 | } |
| 5903 | cid_bootconn[cid] = bootconn + '0'; |
| 5904 | |
| 5905 | LOG("data_call_bootconn_set cid_bootconn = %s", cid_bootconn); |
| 5906 | property_set("persist.mbtk.datacall.bootconn", cid_bootconn); |
| 5907 | } |
| 5908 | |
| 5909 | static void* data_call_bootconn_pthread(void *arg) |
| 5910 | { |
| 5911 | UNUSED(arg); |
| 5912 | LOG("data_call_bootconn_pthread enter."); |
| 5913 | int i = 0; |
| 5914 | int send_sum = 0; |
| 5915 | int bootconn = 0; |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5916 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5917 | while(1) |
| 5918 | { |
| 5919 | if(server_ready_get() && send_sum == 0) |
| 5920 | { |
| 5921 | server_state_send(); |
| 5922 | send_sum = 1; |
| 5923 | } |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5924 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5925 | if(net_info.sim_state == MBTK_SIM_READY && net_info.net_type == MBTK_RADIO_TECH_E_UTRAN && bootconn == 0) |
| 5926 | { |
| 5927 | //data_call_bootconn_exec(); |
| 5928 | property_get("persist.mbtk.datacall.bootconn", cid_bootconn, "00000000"); |
| 5929 | LOG("data_call_bootconn_exec cid_bootconn = %s", cid_bootconn); |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5930 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5931 | for(i = MBTK_APN_CID_MIN; i < MBTK_APN_CID_MAX + 1; i++) |
| 5932 | { |
| 5933 | if(cid_bootconn[i] == '1') |
| 5934 | { |
| 5935 | sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t)); |
| 5936 | if(info == NULL) |
| 5937 | { |
| 5938 | LOG("clinent_info malloc() fail."); |
| 5939 | continue; |
| 5940 | } |
| 5941 | memset(info, 0, sizeof(sock_client_info_t)); |
| 5942 | info->fd = DATA_CALL_BOOTCONN_FD; |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 5943 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 5944 | mbtk_info_pack_t* pack = mbtk_info_pack_creat(MBTK_INFO_ID_NET_DATA_CALL_REQ); |
| 5945 | if(pack == NULL) |
| 5946 | { |
| 5947 | free(info); |
| 5948 | LOG("Packet malloc() fail."); |
| 5949 | continue; |
| 5950 | } |
| 5951 | |
| 5952 | // "info_err" |
| 5953 | //pack->info_err = byte_2_uint16(ptr, false) |
| 5954 | |
| 5955 | // "data_len" |
| 5956 | pack->data_len = 5; |
| 5957 | |
| 5958 | char *p = (char *)malloc(5); |
| 5959 | p[0] = MBTK_DATA_CALL_START; |
| 5960 | p[1] = i; |
| 5961 | p[2] = 0; |
| 5962 | p[3] = 1; |
| 5963 | p[4] = 10; |
| 5964 | pack->data = p; |
| 5965 | send_pack_to_queue(info, pack); |
| 5966 | } |
| 5967 | } |
| 5968 | |
| 5969 | bootconn = 1; |
| 5970 | } |
| 5971 | |
| 5972 | if(bootconn == 1 && send_sum == 1) |
| 5973 | { |
| 5974 | break; |
| 5975 | } |
| 5976 | else |
| 5977 | { |
| 5978 | sleep(1); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | LOG("data_call_bootconn_pthread exit."); |
| 5983 | return NULL; |
| 5984 | } |
| 5985 | |
| 5986 | //mbtk wyq for data_call_ex add end |
| 5987 | |
| 5988 | static void* info_main_pthread(void* arg) |
| 5989 | { |
| 5990 | UNUSED(arg); |
| 5991 | epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1); |
| 5992 | if(epoll_fd < 0) |
| 5993 | { |
| 5994 | LOG("epoll_create() fail[%d].", errno); |
| 5995 | return NULL; |
| 5996 | } |
| 5997 | |
| 5998 | uint32 event = EPOLLIN | EPOLLET; |
| 5999 | struct epoll_event ev; |
| 6000 | ev.data.fd = sock_listen_fd; |
| 6001 | ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET; |
| 6002 | epoll_ctl(epoll_fd,EPOLL_CTL_ADD,sock_listen_fd,&ev); |
| 6003 | |
| 6004 | int nready = -1; |
| 6005 | struct epoll_event epoll_events[EPOLL_LISTEN_MAX]; |
| 6006 | while(1) |
| 6007 | { |
| 6008 | nready = epoll_wait(epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1); |
| 6009 | if(nready > 0) |
| 6010 | { |
| 6011 | sock_client_info_t *cli_info = NULL; |
| 6012 | int i; |
| 6013 | for(i = 0; i < nready; i++) |
| 6014 | { |
| 6015 | LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events); |
| 6016 | if(epoll_events[i].events & EPOLLHUP) // Client Close. |
| 6017 | { |
| 6018 | if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) |
| 6019 | { |
| 6020 | cli_close(cli_info); |
| 6021 | } |
| 6022 | else |
| 6023 | { |
| 6024 | LOG("Unknown client[fd = %d].", epoll_events[i].data.fd); |
| 6025 | } |
| 6026 | } |
| 6027 | else if(epoll_events[i].events & EPOLLIN) |
| 6028 | { |
| 6029 | if(epoll_events[i].data.fd == sock_listen_fd) // New clients connected. |
| 6030 | { |
| 6031 | int client_fd = -1; |
| 6032 | while(1) |
| 6033 | { |
| 6034 | struct sockaddr_in cliaddr; |
| 6035 | socklen_t clilen = sizeof(cliaddr); |
| 6036 | client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen); |
| 6037 | if(client_fd < 0) |
| 6038 | { |
| 6039 | if(errno == EAGAIN) |
| 6040 | { |
| 6041 | LOG("All client connect get."); |
| 6042 | } |
| 6043 | else |
| 6044 | { |
| 6045 | LOG("accept() error[%d].", errno); |
| 6046 | } |
| 6047 | break; |
| 6048 | } |
| 6049 | // Set O_NONBLOCK |
| 6050 | int flags = fcntl(client_fd, F_GETFL, 0); |
| 6051 | if (flags > 0) |
| 6052 | { |
| 6053 | flags |= O_NONBLOCK; |
| 6054 | if (fcntl(client_fd, F_SETFL, flags) < 0) |
| 6055 | { |
| 6056 | LOG("Set flags error:%d", errno); |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | memset(&ev,0,sizeof(struct epoll_event)); |
| 6061 | ev.data.fd = client_fd; |
| 6062 | ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET; |
| 6063 | epoll_ctl(epoll_fd, EPOLL_CTL_ADD, client_fd, &ev); |
| 6064 | |
| 6065 | sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t)); |
| 6066 | if(info) |
| 6067 | { |
| 6068 | memset(info, 0, sizeof(sock_client_info_t)); |
| 6069 | info->fd = client_fd; |
| 6070 | if(server_ready_get() == 1) |
| 6071 | { |
| 6072 | info->ind_num = 0; |
| 6073 | pack_rsp_send(info->fd , MBTK_INFO_ID_IND_SERVER_STATE_CHANGE, "1", 1); |
| 6074 | LOG("server ready ok."); |
| 6075 | } |
| 6076 | else |
| 6077 | { |
| 6078 | info->ind_num = 1; |
| 6079 | info->ind_register[0] = MBTK_INFO_ID_IND_SERVER_STATE_CHANGE; |
| 6080 | LOG("server ready no."); |
| 6081 | } |
| 6082 | list_add(sock_client_list, info); |
| 6083 | LOG("Add New Client FD Into List."); |
| 6084 | } |
| 6085 | else |
| 6086 | { |
| 6087 | LOG("malloc() fail."); |
| 6088 | } |
| 6089 | } |
| 6090 | } |
| 6091 | else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive. |
| 6092 | { |
| 6093 | // Read and process every message. |
| 6094 | mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS; |
| 6095 | mbtk_info_pack_t** pack = mbtk_info_pack_recv(cli_info->fd, true, &err); |
| 6096 | |
| 6097 | // Parse packet error,send error response to client. |
| 6098 | if(pack == NULL) |
| 6099 | { |
| 6100 | if(err != MBTK_INFO_ERR_SUCCESS) |
| 6101 | { |
| 6102 | pack_error_send(cli_info->fd, MBTK_INFO_ID_REQ_UNKNOWN, err); |
| 6103 | } |
| 6104 | } |
| 6105 | else |
| 6106 | { |
| 6107 | #if 0 |
| 6108 | int i = 0; |
| 6109 | while(pack[i] != NULL) |
| 6110 | { |
| 6111 | pack_distribute(cli_info, pack[i]); |
| 6112 | // Not free,will free in pack_process() or packet process thread. |
| 6113 | //mbtk_info_pack_free(&(pack[i])); |
| 6114 | i++; |
| 6115 | } |
| 6116 | free(pack); |
| 6117 | #else |
| 6118 | mbtk_info_pack_t** pack_ptr = pack; |
| 6119 | while(*pack_ptr) |
| 6120 | { |
| 6121 | pack_distribute(cli_info, *pack_ptr); |
| 6122 | // Not free,will free in pack_process() or packet process thread. |
| 6123 | //mbtk_info_pack_free(pack_ptr); |
| 6124 | pack_ptr++; |
| 6125 | } |
| 6126 | |
| 6127 | free(pack); |
| 6128 | #endif |
| 6129 | } |
| 6130 | } |
| 6131 | else |
| 6132 | { |
| 6133 | LOG("Unknown socket : %d", epoll_events[i].data.fd); |
| 6134 | } |
| 6135 | } |
| 6136 | else |
| 6137 | { |
| 6138 | LOG("Unknown event : %x", epoll_events[i].events); |
| 6139 | } |
| 6140 | } |
| 6141 | } |
| 6142 | else |
| 6143 | { |
| 6144 | LOG("epoll_wait() fail[%d].", errno); |
| 6145 | } |
| 6146 | } |
| 6147 | |
| 6148 | return NULL; |
| 6149 | } |
| 6150 | |
| 6151 | static void data_call_restart() |
| 6152 | { |
| 6153 | #if 0 |
| 6154 | // Waitting for network ok. |
| 6155 | mbtk_net_info_t info; |
| 6156 | int cme_err; |
| 6157 | int i = 0; |
| 6158 | while(i < 15) { // 15s timeout |
| 6159 | cme_err = MBTK_INFO_ERR_CME_NON; |
| 6160 | memset(&info, 0, sizeof(mbtk_net_info_t)); |
| 6161 | if(!req_net_sel_mode_get(&info, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON) |
| 6162 | { |
| 6163 | if(info.net_type >= 2) { |
| 6164 | break; |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | sleep(1); |
| 6169 | i++; |
| 6170 | } |
| 6171 | #endif |
| 6172 | // +CGACT |
| 6173 | int cid; |
| 6174 | LOGD("Start active APN."); |
| 6175 | for(cid = MBTK_APN_CID_MIN; cid <= MBTK_APN_CID_MAX && cid_active[cid]; cid++) { |
| 6176 | LOG("Active cid : %d", cid); |
| 6177 | req_data_call_start(cid, NULL); |
| 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | /* |
| 6182 | void mbtk_radio_ready_cb() |
| 6183 | { |
| 6184 | pthread_t radio_pid; |
| 6185 | pthread_attr_t thread_attr; |
| 6186 | pthread_attr_init(&thread_attr); |
| 6187 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 6188 | { |
| 6189 | LOG("pthread_attr_setdetachstate() fail."); |
| 6190 | return; |
| 6191 | } |
| 6192 | |
| 6193 | if(pthread_create(&radio_pid, &thread_attr, radio_ready_thread, NULL)) |
| 6194 | { |
| 6195 | LOG("pthread_create() fail."); |
| 6196 | } |
| 6197 | |
| 6198 | pthread_attr_destroy(&thread_attr); |
| 6199 | } |
| 6200 | */ |
| 6201 | |
| 6202 | static void net_ifc_state_change(bool act, int cid) |
| 6203 | { |
| 6204 | if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { // No nothing for cid 1 and 8 |
| 6205 | return; |
| 6206 | } |
| 6207 | |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 6208 | if(act) |
| 6209 | { |
| 6210 | cid_active[cid] = 1; |
| 6211 | } |
| 6212 | else |
| 6213 | { |
| 6214 | cid_active[cid] = 0; |
| 6215 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6216 | char dev[20] = {0}; |
| 6217 | sprintf(dev, "ccinet%d", cid - 1); |
| 6218 | if(act) { // Config IP. |
| 6219 | // Get IP information. |
| 6220 | mbtk_ipv4_info_t ipv4; |
| 6221 | mbtk_ipv6_info_t ipv6; |
| 6222 | memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t)); |
| 6223 | memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t)); |
| 6224 | int cme_err = MBTK_INFO_ERR_CME_NON; |
| 6225 | if(!req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON) |
| 6226 | { |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 6227 | #ifdef MBTK_AF_SUPPORT |
| 6228 | if(cid == 1) |
| 6229 | { |
| 6230 | ipv4.valid = false; |
| 6231 | ipv6.valid = false; |
| 6232 | if(default_iptype == MBTK_IP_TYPE_IP) |
| 6233 | { |
| 6234 | ipv4.valid = true; |
| 6235 | } |
| 6236 | else if(default_iptype == MBTK_IP_TYPE_IPV6) |
| 6237 | { |
| 6238 | ipv6.valid = true; |
| 6239 | } |
| 6240 | else |
| 6241 | { |
| 6242 | ipv4.valid = true; |
| 6243 | ipv6.valid = true; |
| 6244 | } |
| 6245 | } |
| 6246 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6247 | // Config IPv4 address. |
| 6248 | if(ipv4.valid) { |
| 6249 | char ip[20] = {0}; |
| 6250 | if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip, 20) == NULL) { |
| 6251 | LOGE("inet_ntop ipv4 ip fail."); |
| 6252 | return; |
| 6253 | } |
| 6254 | |
| 6255 | if(mbtk_ifc_configure2(dev, ip, 0, NULL, "255.255.255.0")) { |
| 6256 | LOGD("Config %s IPv4 %s fail.", dev, ip); |
| 6257 | } else { |
| 6258 | LOGD("Config %s IPv4 %s success.", dev, ip); |
| 6259 | } |
| 6260 | } |
| 6261 | |
| 6262 | // Config IPv6 address. |
| 6263 | if(ipv6.valid) { |
| 6264 | char ip[50] = {0}; |
| 6265 | |
| 6266 | if(inet_ntop(AF_INET6, &(ipv6.IPV6Addr), ip, 50) == NULL) { |
| 6267 | LOGE("inet_ntop ipv6 ip fail."); |
| 6268 | return; |
| 6269 | } |
| 6270 | |
| 6271 | if(mbtk_ipv6_config(dev, ip, 64)) { |
| 6272 | LOGD("Config %s IPv6 %s fail.", dev, ip); |
| 6273 | } else { |
| 6274 | LOGD("Config %s IPv6 %s success.", dev, ip); |
| 6275 | } |
| 6276 | } |
| 6277 | } |
| 6278 | } else { // Del IP |
| 6279 | if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) { |
| 6280 | LOGD("Config %s IPv4 0 fail.", dev); |
| 6281 | } else { |
| 6282 | LOGD("Config %s IPv4 0 success.", dev); |
| 6283 | } |
| 6284 | } |
| 6285 | } |
| 6286 | |
| 6287 | static void urc_msg_process(info_urc_msg_t *msg) |
| 6288 | { |
| 6289 | uint8 *data = NULL; |
| 6290 | if(msg->data) { |
| 6291 | data = (uint8*)msg->data; |
| 6292 | } |
| 6293 | switch(msg->msg) { |
| 6294 | case INFO_URC_MSG_RADIO_STATE: |
| 6295 | { |
| 6296 | radio_state_change(msg->data, msg->data_len); |
| 6297 | // Reconfig APN while radio on. |
| 6298 | if(data[0]) { |
| 6299 | apn_prop_get(); |
| 6300 | } |
| 6301 | break; |
| 6302 | } |
| 6303 | case INFO_URC_MSG_CGEV: |
| 6304 | { |
| 6305 | bool act = data[0]; |
| 6306 | int cid = data[1]; |
| 6307 | if(cid > 0) { |
| 6308 | net_ifc_state_change(act, cid); |
| 6309 | } |
| 6310 | break; |
| 6311 | } |
| 6312 | case INFO_URC_MSG_NET_PS_REG_STATE: |
| 6313 | { |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 6314 | uint8 net_data[4]; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6315 | net_data[0] = (uint8)MBTK_NET_PS_STATE; |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 6316 | net_data[1] = data[0]; // act |
| 6317 | net_data[3] = data[1]; // 0 - GSM/WCDMA; 1 - LTE |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6318 | mbtk_net_reg_state_enum state = (mbtk_net_reg_state_enum)data[0]; |
| 6319 | if(state == MBTK_NET_REG_STATE_HOME |
| 6320 | || state == MBTK_NET_REG_STATE_ROAMING) { // Registered, home network or roaming. |
| 6321 | mbtk_net_info_t info; |
| 6322 | int cme_err = MBTK_INFO_ERR_CME_NON; |
| 6323 | memset(&info, 0, sizeof(mbtk_net_info_t)); |
| 6324 | if(!req_net_sel_mode_get(&info, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON) |
| 6325 | { |
| 6326 | net_data[2] = info.net_type; |
| 6327 | net_state_change(net_data, sizeof(net_data)); |
| 6328 | |
| 6329 | if(info.net_type >= MBTK_RADIO_TECH_UTRAN) { |
| 6330 | data_call_restart(); |
| 6331 | } |
| 6332 | } else { |
| 6333 | net_data[2] = (uint8)0xFF; |
| 6334 | net_state_change(net_data, sizeof(net_data)); |
| 6335 | } |
| 6336 | } else { |
| 6337 | net_data[2] = (uint8)0xFF; |
| 6338 | net_state_change(net_data, sizeof(net_data)); |
| 6339 | } |
| 6340 | break; |
| 6341 | } |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6342 | case INFO_URC_MSG_SET_BAND: |
| 6343 | { |
| 6344 | mbtk_band_info_t band; |
| 6345 | int cme_err = MBTK_INFO_ERR_CME_NON; |
| 6346 | |
| 6347 | band.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15 |
| 6348 | band.gsm_band = band_set_info.band_gsm; |
| 6349 | band.umts_band = band_set_info.band_wcdma; |
| 6350 | band.tdlte_band = band_set_info.band_tdlte; |
| 6351 | band.fddlte_band = band_set_info.band_fddlte; |
| 6352 | if(req_band_set(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 6353 | { |
| 6354 | LOG("Set band fail."); |
| 6355 | } |
| 6356 | else // Set band success. |
| 6357 | { |
| 6358 | band_set_info.band_set_success = TRUE; |
| 6359 | if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_CN) { |
| 6360 | property_set("persist.mbtk.band_config", "CN"); |
| 6361 | } else if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_EU) { |
| 6362 | property_set("persist.mbtk.band_config", "EU"); |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame^] | 6363 | } else if(band_set_info.band_area == MBTK_MODEM_BAND_AREA_SA) { |
| 6364 | property_set("persist.mbtk.band_config", "SA"); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6365 | } else { |
| 6366 | property_set("persist.mbtk.band_config", "ALL"); |
| 6367 | } |
| 6368 | LOG("Set band success."); |
| 6369 | } |
| 6370 | break; |
| 6371 | } |
wangyouqiang | ce45a10 | 2024-04-18 18:08:29 +0800 | [diff] [blame] | 6372 | case INFO_URC_MSG_GET_SIM_STATE: |
| 6373 | { |
| 6374 | net_info.sim_state = getSIMStatus(); |
| 6375 | if(net_info.sim_state == MBTK_SIM_READY) |
| 6376 | { |
| 6377 | LOG("SIM READY!"); |
| 6378 | } |
| 6379 | else |
| 6380 | { |
| 6381 | LOG("SIM NOT READY!"); |
| 6382 | } |
| 6383 | break; |
| 6384 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6385 | case INFO_URC_MSG_NET_STATE_LOG: |
| 6386 | { |
| 6387 | // Get network state and signal. |
| 6388 | char buff[256] = {0}; |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 6389 | uint8 data_signal[7]; |
r.xiao | 9ad8263 | 2024-04-24 02:18:13 -0700 | [diff] [blame] | 6390 | mbtk_signal_info_t signal, tmp_signal; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6391 | memset(&signal, 0xFF, sizeof(mbtk_signal_info_t)); |
| 6392 | if(!req_net_signal_get(&signal, NULL)) { |
| 6393 | char tmp[50] = {0}; |
| 6394 | struct timeval log_time; |
| 6395 | gettimeofday(&log_time, NULL); |
| 6396 | struct tm* tm_t = localtime(&(log_time.tv_sec)); |
| 6397 | strftime(tmp, 50, "%F %T", tm_t); |
| 6398 | snprintf(buff, sizeof(buff), "%s:%d,%d,%d,%d,%d,%d,%d,%d", tmp, signal.type, signal.rssi, signal.rxlev, signal.ber, signal.rscp, signal.ecno, |
| 6399 | signal.rsrq, signal.rsrp); |
| 6400 | mbtk_signal_log(buff); |
r.xiao | 9ad8263 | 2024-04-24 02:18:13 -0700 | [diff] [blame] | 6401 | memset(&tmp_signal, 0xFF, sizeof(mbtk_signal_info_t)); |
| 6402 | tmp_signal.type = signal.type; |
| 6403 | tmp_signal.rssi = signal.rssi; |
| 6404 | tmp_signal.rxlev = signal.rxlev; |
| 6405 | tmp_signal.ber = signal.ber; |
| 6406 | tmp_signal.rscp = signal.rscp; |
| 6407 | tmp_signal.ecno = signal.ecno; |
| 6408 | tmp_signal.rsrq = signal.rsrq; |
| 6409 | tmp_signal.rsrp = signal.rsrp; |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 6410 | |
r.xiao | 9ad8263 | 2024-04-24 02:18:13 -0700 | [diff] [blame] | 6411 | if( (signal_globe.type != tmp_signal.type) || (signal_globe.rssi != tmp_signal.rssi) || (signal_globe.rxlev != tmp_signal.rxlev) || |
| 6412 | (signal_globe.ber != tmp_signal.ber) || (signal_globe.rscp != tmp_signal.rscp) || (signal_globe.ecno != tmp_signal.ecno) || |
| 6413 | (signal_globe.rsrq != tmp_signal.rsrq) || (signal_globe.rsrp != tmp_signal.rsrp) ) |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 6414 | |
| 6415 | { |
r.xiao | 9ad8263 | 2024-04-24 02:18:13 -0700 | [diff] [blame] | 6416 | signal_globe.type = signal.type; |
| 6417 | signal_globe.rssi = signal.rssi; |
| 6418 | signal_globe.rxlev = signal.rxlev; |
| 6419 | signal_globe.ber = signal.ber; |
| 6420 | signal_globe.rscp = signal.rscp; |
| 6421 | signal_globe.ecno = signal.ecno; |
| 6422 | signal_globe.rsrq = signal.rsrq; |
| 6423 | signal_globe.rsrp = signal.rsrp; |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 6424 | //ADD SIGANLE CB |
| 6425 | data_signal[0] = signal.type; |
| 6426 | data_signal[1] = signal.rssi; |
| 6427 | data_signal[2] = signal.rxlev; |
| 6428 | data_signal[3] = signal.ber; |
| 6429 | data_signal[4] = signal.rscp; |
| 6430 | data_signal[5] = signal.ecno; |
| 6431 | data_signal[6] = signal.rsrq; |
| 6432 | data_signal[7] = signal.rsrp; |
| 6433 | /* |
| 6434 | LOGE("data[0]=%d data[1]=%d data[2]=%d data[3]=%d data[4]=%d data[5]=%d data[6]=%d data[7]=%d", |
| 6435 | data_signal[0],data_signal[1],data_signal[2],data_signal[3],data_signal[4],data_signal[5],data_signal[6],data_signal[7]); |
| 6436 | */ |
| 6437 | signal_state_change(data_signal, sizeof(data_signal)); |
| 6438 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6439 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6440 | break; |
| 6441 | } |
| 6442 | default: |
| 6443 | { |
| 6444 | LOGE("Unknown URC : %d", msg->msg); |
| 6445 | break; |
| 6446 | } |
| 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | static void* pack_process_thread(void* arg) |
| 6451 | { |
| 6452 | UNUSED(arg); |
| 6453 | info_queue_item_t* item = NULL; |
| 6454 | mbtk_queue_init(&info_queue); |
| 6455 | pthread_mutex_init(&info_mutex, NULL); |
| 6456 | pthread_cond_init(&info_cond, NULL); |
| 6457 | |
| 6458 | memset(&band_support, 0xFF, sizeof(mbtk_band_info_t)); |
| 6459 | |
| 6460 | pthread_mutex_lock(&info_mutex); |
| 6461 | while(TRUE) |
| 6462 | { |
| 6463 | if(mbtk_queue_empty(&info_queue)) |
| 6464 | { |
| 6465 | LOG("Packet process wait..."); |
| 6466 | pthread_cond_wait(&info_cond, &info_mutex); |
| 6467 | LOG("Packet process continue..."); |
| 6468 | } |
| 6469 | else |
| 6470 | { |
| 6471 | LOG("Packet process queue not empty,continue..."); |
| 6472 | } |
| 6473 | |
| 6474 | // Process all information request. |
| 6475 | mbtk_info_err_enum err; |
| 6476 | while((item = (info_queue_item_t*)mbtk_queue_get(&info_queue)) != NULL) |
| 6477 | { |
| 6478 | if(item->cli_info) { // REQ form client. |
| 6479 | mbtk_info_pack_t *pack = (mbtk_info_pack_t*)item->pack; |
| 6480 | LOG("Process REQ %s.", id2str(pack->info_id)); |
| 6481 | at_process = true; |
| 6482 | err = pack_req_process(item->cli_info, pack); |
| 6483 | if(err != MBTK_INFO_ERR_SUCCESS) |
| 6484 | { |
| 6485 | if(item->cli_info->fd != DATA_CALL_BOOTCONN_FD) |
| 6486 | { |
| 6487 | pack_error_send(item->cli_info->fd, pack->info_id + 1, err); |
| 6488 | } |
| 6489 | else |
| 6490 | { |
| 6491 | free(pack->data); |
| 6492 | free(item->cli_info); |
| 6493 | } |
| 6494 | } |
| 6495 | at_process = false; |
| 6496 | mbtk_info_pack_free(&pack); |
| 6497 | free(item); |
| 6498 | } else { // REQ from myself. |
| 6499 | info_urc_msg_t *urc = (info_urc_msg_t*)item->pack; |
| 6500 | LOG("Process URC %d.", urc->msg); |
| 6501 | urc_msg_process(urc); |
| 6502 | if(!urc->data) |
| 6503 | free(urc->data); |
| 6504 | free(urc); |
| 6505 | } |
| 6506 | } |
| 6507 | } |
| 6508 | pthread_mutex_unlock(&info_mutex); |
| 6509 | return NULL; |
| 6510 | } |
| 6511 | |
| 6512 | void apn_prop_get() |
| 6513 | { |
| 6514 | char prop_name[20]; |
| 6515 | char prop_data[300]; |
| 6516 | // cid : 2 - 7 |
| 6517 | int cid = MBTK_APN_CID_MIN; |
| 6518 | mbtk_apn_info_t apn; |
| 6519 | for(; cid <= MBTK_APN_CID_MAX; cid++) { |
| 6520 | memset(prop_name, 0, 20); |
| 6521 | memset(prop_data, 0, 300); |
| 6522 | memset(&apn, 0, sizeof(mbtk_apn_info_t)); |
| 6523 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid); |
| 6524 | if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 6525 | apn.cid = cid; |
| 6526 | char *ptr_1 = prop_data; |
| 6527 | apn.ip_type = (mbtk_ip_type_enum)atoi(ptr_1); |
| 6528 | ptr_1 = strstr(ptr_1, ","); |
| 6529 | if(!ptr_1) { |
| 6530 | continue; |
| 6531 | } |
| 6532 | ptr_1++; // Jump ',' to apn |
| 6533 | |
| 6534 | char *ptr_2 = strstr(ptr_1, ","); |
| 6535 | if(!ptr_2) { |
| 6536 | continue; |
| 6537 | } |
| 6538 | memcpy(apn.apn, ptr_1, ptr_2 - ptr_1); // apn |
| 6539 | |
| 6540 | ptr_2++; // Jump ',' to user |
| 6541 | ptr_1 = strstr(ptr_2, ","); |
| 6542 | if(!ptr_1) { |
| 6543 | continue; |
| 6544 | } |
| 6545 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 6546 | memcpy(apn.user, ptr_2, ptr_1 - ptr_2); // user |
| 6547 | } |
| 6548 | |
| 6549 | ptr_1++; // Jump ',' to pass |
| 6550 | ptr_2 = strstr(ptr_1, ","); |
| 6551 | if(!ptr_2) { |
| 6552 | continue; |
| 6553 | } |
| 6554 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 6555 | memcpy(apn.pass, ptr_1, ptr_2 - ptr_1); // pass |
| 6556 | } |
| 6557 | |
| 6558 | ptr_2++; // Jump ',' to auth (Is last item) |
| 6559 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 6560 | memcpy(apn.auth, ptr_2, strlen(ptr_2)); // auth |
| 6561 | } |
| 6562 | |
| 6563 | req_apn_set(&apn, NULL); |
| 6564 | } |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | /* |
b.liu | e0ab244 | 2024-02-06 18:53:28 +0800 | [diff] [blame] | 6569 | root@OpenWrt:/usrdata# cat /proc/mtd |
| 6570 | dev: size erasesize name |
| 6571 | mtd0: 00040000 00020000 "bootloader" |
| 6572 | mtd1: 00020000 00020000 "cp_reliabledata" |
| 6573 | mtd2: 00020000 00020000 "ap_reliabledata" |
| 6574 | mtd3: 00020000 00020000 "cp_reliabledata_backup" |
| 6575 | mtd4: 00020000 00020000 "ap_reliabledata_backup" |
| 6576 | mtd5: 00020000 00020000 "mep-ota" |
| 6577 | mtd6: 00020000 00020000 "mep-ota_backup" |
| 6578 | mtd7: 00040000 00020000 "dtim" |
| 6579 | mtd8: 00f40000 00020000 "cpimage" |
| 6580 | mtd9: 000c0000 00020000 "u-boot" |
| 6581 | mtd10: 00500000 00020000 "kernel" |
| 6582 | mtd11: 00100000 00020000 "asr_flag" |
| 6583 | mtd12: 01400000 00020000 "rootfs" |
| 6584 | mtd13: 01400000 00020000 "oem_data" |
| 6585 | mtd14: 01e00000 00020000 "OTA" |
| 6586 | mtd15: 01400000 00020000 "rootfs_data" |
| 6587 | mtd16: 081a0000 00020000 "user_data" |
| 6588 | mtd17: 00d20000 00020000 "MRVL_BBM" |
| 6589 | */ |
| 6590 | static int partition_name_2_dev(const char *name, char *dev) { |
| 6591 | if(name == NULL || dev == NULL) { |
| 6592 | LOGE("ARG error."); |
| 6593 | return -1; |
| 6594 | } |
| 6595 | |
| 6596 | int fp = fopen("/proc/mtd", "r"); |
| 6597 | if (fp == NULL) { |
| 6598 | LOGE("Open MTD failed!"); |
| 6599 | return -1; |
| 6600 | } |
| 6601 | |
| 6602 | char buf[1024]; |
| 6603 | while (fgets(buf, 1024, fp) != NULL) { |
| 6604 | if(strstr(buf, name)) { |
| 6605 | int index = atoi(buf + 3); |
| 6606 | sprintf(dev, "/dev/mtdblock%d", index); |
| 6607 | LOGD("%s -> %s", name, dev); |
| 6608 | return 0; |
| 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | return -1; |
| 6613 | } |
| 6614 | |
| 6615 | static int custom_partition_read(const char *name, mbtk_cust_info_t *cust_info) |
| 6616 | { |
| 6617 | int fd = 0, ret = 0; |
| 6618 | unsigned int step = 0, offset = 0, flaglen = 0; |
| 6619 | flaglen = sizeof(mbtk_cust_info_t); |
| 6620 | |
| 6621 | char mtd_path[50] = {0}; |
| 6622 | if(partition_name_2_dev(name, mtd_path)) { |
| 6623 | LOGE("partition_name_2_dev() failed!"); |
| 6624 | return -1; |
| 6625 | } |
| 6626 | |
| 6627 | fd = open(mtd_path, O_RDONLY); |
| 6628 | if (fd < 0) { |
| 6629 | LOGE("Fatal error: can't open cust info %s\n", mtd_path); |
| 6630 | return -1; |
| 6631 | } |
| 6632 | |
| 6633 | if (read(fd, cust_info, flaglen) < 0) |
| 6634 | goto error; |
| 6635 | if (cust_info->header != CUST_INFO_HEADER) { |
| 6636 | LOGE("Cust info partition error."); |
| 6637 | goto error; |
| 6638 | } else { |
| 6639 | if(cust_info->band_type == 1) { // CN |
| 6640 | LOGD("Band : CN"); |
| 6641 | } else if(cust_info->band_type == 2) { // EU |
| 6642 | LOGD("Band : EU"); |
| 6643 | } else { |
| 6644 | LOGE("Unknown band type:%d", cust_info->band_type); |
| 6645 | goto error; |
| 6646 | } |
| 6647 | } |
| 6648 | close(fd); |
| 6649 | return 0; |
| 6650 | error: |
| 6651 | close(fd); |
| 6652 | return -1; |
| 6653 | } |
| 6654 | |
| 6655 | /* |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6656 | AT*BAND=15,78,147,482,134742231 |
| 6657 | |
| 6658 | OK |
| 6659 | */ |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6660 | static void* band_config_thread() |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6661 | { |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6662 | mbtk_device_info_modem_t info_modem; |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6663 | memset(&band_set_info, 0, sizeof(band_set_info_t)); |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6664 | memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t)); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6665 | band_set_info.band_set_success = FALSE; |
| 6666 | if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) { |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6667 | LOGD("mbtk_dev_info_read(MODEM) fail, use default band."); |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6668 | band_set_info.band_area = MBTK_MODEM_BAND_AREA_ALL; |
| 6669 | band_set_info.band_gsm = MBTK_BAND_ALL_GSM_DEFAULT; |
| 6670 | band_set_info.band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT; |
| 6671 | band_set_info.band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT; |
| 6672 | band_set_info.band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT; |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame^] | 6673 | band_set_info.band_lte_ext = 0; |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6674 | } else { |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6675 | band_set_info.band_area = info_modem.band_area; |
| 6676 | band_set_info.band_gsm = info_modem.band_gsm; |
| 6677 | band_set_info.band_wcdma = info_modem.band_wcdma; |
| 6678 | band_set_info.band_tdlte = info_modem.band_tdlte; |
| 6679 | band_set_info.band_fddlte = info_modem.band_fddlte; |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame^] | 6680 | band_set_info.band_lte_ext = info_modem.band_lte_ext; |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6681 | } |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6682 | |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6683 | bool is_first = TRUE; |
| 6684 | while(!band_set_info.band_set_success) { |
| 6685 | info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t)); |
| 6686 | if(!urc) |
| 6687 | { |
| 6688 | LOG("malloc() fail[%d].", errno); |
| 6689 | break; |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6690 | } else { |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6691 | urc->msg = INFO_URC_MSG_SET_BAND; |
| 6692 | urc->data = NULL; |
| 6693 | urc->data_len = 0; |
| 6694 | send_pack_to_queue(NULL, urc); |
| 6695 | |
| 6696 | if(is_first) { |
| 6697 | is_first = FALSE; |
| 6698 | } else { |
| 6699 | LOGE("*BAND exec error, will retry in 3s."); |
| 6700 | } |
| 6701 | sleep(3); |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6702 | } |
| 6703 | } |
| 6704 | |
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 6705 | LOGD("Set Band thread exit."); |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6706 | return NULL; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | static void* net_monitor_thread(void* arg) |
| 6710 | { |
| 6711 | UNUSED(arg); |
| 6712 | // Start network monitor |
| 6713 | int cid; |
| 6714 | while(1) { |
| 6715 | #if 0 |
| 6716 | // Config IP |
| 6717 | list_node_t* apn_list = NULL; |
| 6718 | if(!apn_state_get(&apn_list) && apn_list != NULL) { |
| 6719 | info_apn_ip_t *apn = NULL; |
| 6720 | for(cid = MBTK_APN_CID_MIN; cid <= MBTK_APN_CID_MAX && cid_active[cid]; cid++) { |
| 6721 | bool ip_found = false; |
| 6722 | list_first(apn_list); |
| 6723 | while ((apn = (info_apn_ip_t*) list_next(apn_list))) { |
| 6724 | if(cid == apn->cid) { |
| 6725 | ip_found = true; |
| 6726 | break; |
| 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | char dev[20] = {0}; |
| 6731 | sprintf(dev, "ccinet%d", cid - 1); |
| 6732 | if(ip_found) { // Ip ok,set IP. |
| 6733 | if(apn->ipv4_valid) { |
| 6734 | if(mbtk_ifc_configure2(dev, (char*)apn->ipv4, 0, NULL, "255.255.255.0")) { |
| 6735 | LOGD("Config %s IPv4 %s fail.", dev, apn->ipv4); |
| 6736 | } else { |
| 6737 | LOGD("Config %s IPv4 %s success.", dev, apn->ipv4); |
| 6738 | } |
| 6739 | } |
| 6740 | |
| 6741 | if(apn->ipv6_valid) { |
| 6742 | if(mbtk_ipv6_config(dev, (char*)apn->ipv6, 64)) { |
| 6743 | LOGD("Config %s IPv6 %s fail.", dev, apn->ipv6); |
| 6744 | } else { |
| 6745 | LOGD("Config %s IPv6 %s success.", dev, apn->ipv6); |
| 6746 | } |
| 6747 | } |
| 6748 | } else { // No ip |
| 6749 | if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) { |
| 6750 | LOGD("Config %s IPv4 0 fail.", dev); |
| 6751 | } else { |
| 6752 | LOGD("Config %s IPv4 0 success.", dev); |
| 6753 | } |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | list_free(apn_list); |
| 6758 | } |
| 6759 | #endif |
| 6760 | |
| 6761 | if(net_info.radio_state == MBTK_RADIO_STATE_ON && net_info.sim_state == MBTK_SIM_READY) { |
| 6762 | #if 0 |
| 6763 | urc_msg_distribute(true, INFO_URC_MSG_NET_CS_REG_STATE, NULL, 0); |
| 6764 | #else |
| 6765 | info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t)); |
| 6766 | if(!urc) |
| 6767 | { |
| 6768 | LOG("malloc() fail[%d].", errno); |
| 6769 | } else { |
| 6770 | urc->msg = INFO_URC_MSG_NET_STATE_LOG; |
| 6771 | urc->data = NULL; |
| 6772 | urc->data_len = 0; |
| 6773 | send_pack_to_queue(NULL, urc); |
| 6774 | } |
| 6775 | #endif |
wangyouqiang | ce45a10 | 2024-04-18 18:08:29 +0800 | [diff] [blame] | 6776 | sleep(15); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6777 | } |
wangyouqiang | ce45a10 | 2024-04-18 18:08:29 +0800 | [diff] [blame] | 6778 | else |
| 6779 | { |
| 6780 | info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t)); |
| 6781 | if(!urc) |
| 6782 | { |
| 6783 | LOG("malloc() fail[%d].", errno); |
| 6784 | } |
| 6785 | else |
| 6786 | { |
| 6787 | urc->msg = INFO_URC_MSG_GET_SIM_STATE; |
| 6788 | urc->data = NULL; |
| 6789 | urc->data_len = 0; |
| 6790 | send_pack_to_queue(NULL, urc); |
| 6791 | } |
| 6792 | sleep(2); |
| 6793 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6794 | } |
| 6795 | |
| 6796 | LOGD("monitor_thread exit."); |
| 6797 | return NULL; |
| 6798 | } |
| 6799 | |
| 6800 | static void* urc_process_thread(void* arg) |
| 6801 | { |
| 6802 | UNUSED(arg); |
| 6803 | info_urc_msg_t* item = NULL; |
| 6804 | mbtk_queue_init(&urc_queue); |
| 6805 | pthread_mutex_init(&urc_mutex, NULL); |
| 6806 | pthread_cond_init(&urc_cond, NULL); |
| 6807 | |
| 6808 | pthread_mutex_lock(&urc_mutex); |
| 6809 | while(TRUE) |
| 6810 | { |
| 6811 | if(mbtk_queue_empty(&urc_queue)) |
| 6812 | { |
| 6813 | LOG("URC process wait..."); |
| 6814 | pthread_cond_wait(&urc_cond, &urc_mutex); |
| 6815 | LOG("URC process continue..."); |
| 6816 | } |
| 6817 | else |
| 6818 | { |
| 6819 | LOG("URC process queue not empty,continue..."); |
| 6820 | } |
| 6821 | |
| 6822 | // Process all information request. |
| 6823 | while((item = (info_urc_msg_t*)mbtk_queue_get(&urc_queue)) != NULL) |
| 6824 | { |
| 6825 | LOG("Process URC %d.", item->msg); |
| 6826 | uint8 *data = (uint8*)item->data; |
| 6827 | switch(item->msg) { |
| 6828 | case INFO_URC_MSG_RADIO_STATE: |
| 6829 | { |
| 6830 | radio_state_change(item->data, item->data_len); |
| 6831 | break; |
| 6832 | } |
| 6833 | case INFO_URC_MSG_CGEV: |
| 6834 | { |
| 6835 | bool act = data[0]; |
| 6836 | int cid = data[1]; |
| 6837 | if(cid > 0) { |
| 6838 | net_ifc_state_change(act, cid); |
| 6839 | } |
| 6840 | break; |
| 6841 | } |
| 6842 | default: |
| 6843 | { |
| 6844 | LOGE("Unknown URC : %d", item->msg); |
| 6845 | break; |
| 6846 | } |
| 6847 | } |
| 6848 | if(!item->data) |
| 6849 | free(item->data); |
| 6850 | free(item); |
| 6851 | } |
| 6852 | } |
| 6853 | pthread_mutex_unlock(&urc_mutex); |
| 6854 | |
| 6855 | return NULL; |
| 6856 | } |
| 6857 | |
| 6858 | static void ril_at_ready_process() |
| 6859 | { |
| 6860 | net_info.radio_state = (isRadioOn() == 1) ? MBTK_RADIO_STATE_ON : MBTK_RADIO_STATE_OFF; |
| 6861 | #if 1 |
| 6862 | if (net_info.radio_state != MBTK_RADIO_STATE_ON) |
| 6863 | { |
| 6864 | setRadioPower(1); |
| 6865 | } else { // Radio has ON |
| 6866 | apn_prop_get(); |
| 6867 | } |
| 6868 | |
| 6869 | if(net_info.radio_state == MBTK_RADIO_STATE_ON) |
| 6870 | { |
| 6871 | at_send_command("AT+CEREG=2", NULL); |
| 6872 | } |
| 6873 | |
| 6874 | int count = 0; |
| 6875 | #endif |
| 6876 | net_info.sim_state = getSIMStatus(); |
| 6877 | #if 0 |
| 6878 | while (net_info.sim_state != MBTK_SIM_READY && count < 30) |
| 6879 | { |
| 6880 | if(net_info.radio_state != MBTK_RADIO_STATE_ON) |
| 6881 | { |
| 6882 | setRadioPower(1); |
| 6883 | } |
| 6884 | LOGD("Waitting for SIM READY..."); |
| 6885 | sleep(1); |
| 6886 | net_info.sim_state = getSIMStatus(); |
| 6887 | count++; |
| 6888 | } |
| 6889 | #endif |
| 6890 | if(net_info.sim_state == MBTK_SIM_READY) |
| 6891 | { |
| 6892 | LOGD("SIM READY!"); |
| 6893 | } |
| 6894 | else |
| 6895 | { |
| 6896 | LOGE("SIM NOT READY!"); |
| 6897 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | int mbtk_info_server_start() |
| 6901 | { |
| 6902 | signal(SIGPIPE, SIG_IGN); |
| 6903 | |
wangyouqiang | ce45a10 | 2024-04-18 18:08:29 +0800 | [diff] [blame] | 6904 | //check cfun and sim card status |
| 6905 | ril_at_ready_process(); |
| 6906 | |
| 6907 | //any AT instruction that is not sent through pack_process_thread needs to precede the thread |
| 6908 | //thread create |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 6909 | if(sock_listen_fd > 0) |
| 6910 | { |
| 6911 | LOG("Information Server Has Started."); |
| 6912 | return -1; |
| 6913 | } |
| 6914 | |
| 6915 | struct sockaddr_un server_addr; |
| 6916 | sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0); |
| 6917 | if(sock_listen_fd < 0) |
| 6918 | { |
| 6919 | LOG("socket() fail[%d].", errno); |
| 6920 | return -1; |
| 6921 | } |
| 6922 | |
| 6923 | // Set O_NONBLOCK |
| 6924 | int flags = fcntl(sock_listen_fd, F_GETFL, 0); |
| 6925 | if (flags < 0) |
| 6926 | { |
| 6927 | LOG("Get flags error:%d", errno); |
| 6928 | goto error; |
| 6929 | } |
| 6930 | flags |= O_NONBLOCK; |
| 6931 | if (fcntl(sock_listen_fd, F_SETFL, flags) < 0) |
| 6932 | { |
| 6933 | LOG("Set flags error:%d", errno); |
| 6934 | goto error; |
| 6935 | } |
| 6936 | |
| 6937 | unlink(SOCK_INFO_PATH); |
| 6938 | memset(&server_addr, 0, sizeof(struct sockaddr_un)); |
| 6939 | server_addr.sun_family = AF_LOCAL; |
| 6940 | strcpy(server_addr.sun_path, SOCK_INFO_PATH); |
| 6941 | if(bind(sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr))) |
| 6942 | { |
| 6943 | LOG("bind() fail[%d].", errno); |
| 6944 | goto error; |
| 6945 | } |
| 6946 | |
| 6947 | if(listen(sock_listen_fd, SOCK_CLIENT_MAX)) |
| 6948 | { |
| 6949 | LOG("listen() fail[%d].", errno); |
| 6950 | goto error; |
| 6951 | } |
| 6952 | |
| 6953 | sock_client_list = list_create(sock_cli_free_func); |
| 6954 | if(sock_client_list == NULL) |
| 6955 | { |
| 6956 | LOG("list_create() fail."); |
| 6957 | goto error; |
| 6958 | } |
| 6959 | |
| 6960 | pthread_t info_pid, pack_pid, monitor_pid, urc_pid, bootconn_pid; |
| 6961 | pthread_attr_t thread_attr; |
| 6962 | pthread_attr_init(&thread_attr); |
| 6963 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 6964 | { |
| 6965 | LOG("pthread_attr_setdetachstate() fail."); |
| 6966 | goto error; |
| 6967 | } |
| 6968 | |
| 6969 | if(pthread_create(&info_pid, &thread_attr, info_main_pthread, NULL)) |
| 6970 | { |
| 6971 | LOG("pthread_create() fail."); |
| 6972 | goto error; |
| 6973 | } |
| 6974 | |
| 6975 | if(pthread_create(&pack_pid, &thread_attr, pack_process_thread, NULL)) |
| 6976 | { |
| 6977 | LOG("pthread_create() fail."); |
| 6978 | goto error; |
| 6979 | } |
| 6980 | |
| 6981 | #if 0 |
| 6982 | if(pthread_create(&urc_pid, &thread_attr, urc_process_thread, NULL)) |
| 6983 | { |
| 6984 | LOG("pthread_create() fail."); |
| 6985 | goto error; |
| 6986 | } |
| 6987 | #endif |
| 6988 | |
b.liu | bb5e768 | 2024-02-28 20:13:04 +0800 | [diff] [blame] | 6989 | // Set Band |
| 6990 | // AT*BAND=15,78,147,482,134742231 |
| 6991 | char buff[10]; |
| 6992 | memset(buff, 0, 10); |
| 6993 | property_get("persist.mbtk.band_config", buff, ""); |
| 6994 | if(strlen(buff) == 0) { |
| 6995 | pthread_t band_pid; |
| 6996 | if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL)) |
| 6997 | { |
| 6998 | LOG("pthread_create() fail."); |
| 6999 | } |
| 7000 | } |
| 7001 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 7002 | if(pthread_create(&monitor_pid, &thread_attr, net_monitor_thread, NULL)) |
| 7003 | { |
| 7004 | LOG("pthread_create() fail."); |
| 7005 | } |
| 7006 | |
| 7007 | //mbtk wyq for data_call_ex add start |
| 7008 | if(pthread_create(&bootconn_pid, &thread_attr, data_call_bootconn_pthread, NULL)) |
| 7009 | { |
| 7010 | LOG("pthread_create() fail."); |
| 7011 | } |
| 7012 | //mbtk wyq for data_call_ex add end |
| 7013 | |
| 7014 | pthread_attr_destroy(&thread_attr); |
| 7015 | |
| 7016 | LOG("MBTK Information Server Start..."); |
| 7017 | |
| 7018 | return 0; |
| 7019 | |
| 7020 | error: |
| 7021 | close(sock_listen_fd); |
| 7022 | sock_listen_fd = -1; |
| 7023 | return -1; |
| 7024 | } |
| 7025 | |
| 7026 | #if 0 |
| 7027 | int main(int argc, char *argv[]) |
| 7028 | { |
| 7029 | if(mbtk_info_server_start()) |
| 7030 | { |
| 7031 | return -1; |
| 7032 | } |
| 7033 | |
| 7034 | while(1) |
| 7035 | { |
| 7036 | sleep(24 * 60 * 60); |
| 7037 | } |
| 7038 | |
| 7039 | return 0; |
| 7040 | } |
| 7041 | #endif |
| 7042 | |
| 7043 | |