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