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