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 | |
| 13 | #include "mbtk_type.h" |
| 14 | #include "mbtk_info.h" |
| 15 | #include "atchannel.h" |
| 16 | #include "at_tok.h" |
| 17 | #include "mbtk_utils.h" |
| 18 | #include "info_data.h" |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 19 | #include "mbtk_log.h" |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 20 | |
| 21 | void pack_rsp_send(int fd, int info_id, const void* data, int data_len); |
| 22 | |
| 23 | /* |
| 24 | AT+CMGF? |
| 25 | +CMGF: 0 |
| 26 | |
| 27 | OK |
| 28 | |
| 29 | */ |
| 30 | static int req_cmgf_get(int *state, int *cme_err) |
| 31 | { |
| 32 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 33 | // char *tmp_ptr = NULL; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 34 | int err = at_send_command_singleline("AT+CMGF?", "", &response); |
| 35 | |
| 36 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 37 | *cme_err = at_get_cme_error(response); |
| 38 | goto exit; |
| 39 | } |
| 40 | |
| 41 | char *line = response->p_intermediates->line; |
| 42 | printf("req_cmgf_get() ---line:%s\n", line); |
| 43 | char* ptr = strstr(line, "+CMGF: "); |
| 44 | printf("req_cmgf_get() ---ptr:%s\n",ptr); |
| 45 | if(ptr) |
| 46 | { |
| 47 | *state = atoi(ptr + strlen("+CMGF: ")); |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | err = -1; |
| 52 | } |
| 53 | exit: |
| 54 | at_response_free(response); |
| 55 | return err; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | AT+CMGF=0" |
| 60 | or |
| 61 | AT+CMGF=1" |
| 62 | |
| 63 | OK |
| 64 | */ |
| 65 | static int req_cmgf_set(int state, int *cme_err) |
| 66 | { |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 67 | LOGD("req_cmgf_set()-------------start"); |
| 68 | LOGD("state:%d",state); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 69 | ATResponse *response = NULL; |
| 70 | char cmd[30] = {0}; |
| 71 | if(state) |
| 72 | { |
| 73 | strcpy(cmd, "AT+CMGF=1"); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | strcpy(cmd, "AT+CMGF=0"); |
| 78 | } |
| 79 | |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 80 | LOGD("req_cmgf_set()----cmd:%s", cmd); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 81 | int err = at_send_command(cmd, &response); |
| 82 | |
| 83 | if (err < 0 || response->success == 0) { |
| 84 | *cme_err = at_get_cme_error(response); |
| 85 | goto exit; |
| 86 | } |
| 87 | |
| 88 | err = 0; |
| 89 | exit: |
| 90 | at_response_free(response); |
| 91 | return err; |
| 92 | } |
| 93 | |
| 94 | /*set AT+CNMI=1,2*/ |
| 95 | static int req_cnmi_set(int *cme_err) |
| 96 | { |
| 97 | printf("req_cnmi_set()-------------start3\n"); |
| 98 | ATResponse *response = NULL; |
| 99 | char cmd[30] = {0}; |
| 100 | |
| 101 | strcpy(cmd, "AT+CNMI=1,2"); |
| 102 | |
| 103 | printf("req_cnmi_set()----cmd:%s\n", cmd); |
| 104 | int err = at_send_command(cmd, &response); |
| 105 | |
| 106 | if (err < 0 || response->success == 0) { |
| 107 | printf("err:%d, response->success:%d \n", err, response->success); |
| 108 | *cme_err = at_get_cme_error(response); |
| 109 | goto exit; |
| 110 | } |
| 111 | |
| 112 | err = 0; |
| 113 | exit: |
| 114 | at_response_free(response); |
| 115 | printf("exit,err:%d\n", err); |
| 116 | return err; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | AT+CPMS? |
| 121 | |
| 122 | +CPMS: "SM",15,50,"SM",15,50,"SM",15,50 |
| 123 | |
| 124 | OK |
| 125 | |
| 126 | */ |
| 127 | static int req_cpms_get(char *reg, int *cme_err) |
| 128 | { |
| 129 | printf("req_cpms_get------------start(3)\n"); |
| 130 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 131 | // char *tmp_ptr = NULL; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 132 | int err = at_send_command_singleline("AT+CPMS?", "", &response); |
| 133 | |
| 134 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 135 | *cme_err = at_get_cme_error(response); |
| 136 | goto exit; |
| 137 | } |
| 138 | |
| 139 | ATLine* lines_ptr = response->p_intermediates; |
| 140 | char *line = NULL; |
| 141 | int len = 0; |
| 142 | while(lines_ptr) |
| 143 | { |
| 144 | line = lines_ptr->line; |
| 145 | if(line ==NULL) |
| 146 | { |
| 147 | printf("line is null----------------------\n"); |
| 148 | } |
| 149 | |
| 150 | printf("-----------line:%s, strlen:%d, len:%d----------\n", line, strlen(line), len); |
| 151 | memcpy(reg+len, line, strlen(line)); |
| 152 | len += strlen(line); |
| 153 | lines_ptr = lines_ptr->p_next; |
| 154 | } |
| 155 | |
| 156 | printf("cpms_get()------reg:%s\n", reg); |
| 157 | |
| 158 | exit: |
| 159 | at_response_free(response); |
| 160 | return err; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | |
| 165 | /* |
| 166 | AT+CPMS=<mem1>[,<mem2>[,<mem3>]] |
| 167 | AT+CPMS="ME","ME","ME" |
| 168 | |
| 169 | +CPMS: 14,50,14,50,14,50 |
| 170 | |
| 171 | OK |
| 172 | |
| 173 | */ |
| 174 | static int req_cpms_set(const char *mem, char *reg, int len, int *cme_err) |
| 175 | { |
| 176 | printf("req_cpms_set(2)----------------start\n"); |
| 177 | printf("mem:%s\n", mem); |
| 178 | ATResponse *response = NULL; |
| 179 | char cmd[30] = {0}; |
| 180 | int err = 0; |
| 181 | char data[20] = {0}; |
| 182 | |
| 183 | if(mem != NULL) |
| 184 | { |
| 185 | memcpy(data, mem, len); |
| 186 | sprintf(cmd, "AT+CPMS=%s", data); |
| 187 | } |
| 188 | else{ |
| 189 | printf("mem is null\n"); |
| 190 | } |
| 191 | |
| 192 | printf("cmd:%s,data:%s---------\n", cmd,data); |
| 193 | |
| 194 | if(strlen(cmd) > 8) |
| 195 | { |
| 196 | err = at_send_command_multiline(cmd, "+CPMS:", &response); |
| 197 | if (err < 0 || response->success == 0){ |
| 198 | *cme_err = at_get_cme_error(response); |
| 199 | goto exit; |
| 200 | } |
| 201 | |
| 202 | char *line = response->p_intermediates->line; |
| 203 | printf("line:%s, len:%d\n", line, strlen(line)); |
| 204 | |
| 205 | memcpy(reg, line, strlen(line)); |
| 206 | |
| 207 | printf("cpms_reg:%s\n", reg); |
| 208 | } |
| 209 | err = 0; |
| 210 | exit: |
| 211 | printf("goto exit do"); |
| 212 | at_response_free(response); |
| 213 | return err; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | if PDU mode (+CMGF=0): |
| 218 | AT+CMGS=<length><CR> |
| 219 | PDU is given<ctrl-Z/ESC> |
| 220 | if text mode (+CMGF=1): |
| 221 | AT+CMGS=<da>[,<toda>]<CR> |
| 222 | text is entered<ctrl-Z/ESC> |
| 223 | |
| 224 | AT+CMGS=15775690697,hello world |
| 225 | |
| 226 | |
| 227 | */ |
r.xiao | ed20855 | 2024-11-26 23:11:40 -0800 | [diff] [blame] | 228 | |
| 229 | #define MBTK_AT_MAX_SMS_NUM 4 |
| 230 | #define MBTK_AT_SMS_MAX_LEN 160*MBTK_AT_MAX_SMS_NUM |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 231 | static int req_cmgs_set(char *cmgs, char *reg, int len, int *cme_err) |
| 232 | { |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 233 | LOGD("req_cmgs_set()----------------start"); |
| 234 | LOGD("cmgs:%s", cmgs); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 235 | ATResponse *response = NULL; |
| 236 | char cmd[30] = {0}; |
r.xiao | ed20855 | 2024-11-26 23:11:40 -0800 | [diff] [blame] | 237 | char data[MBTK_AT_SMS_MAX_LEN] = {0}; |
r.xiao | 10052d9 | 2024-07-15 02:42:20 -0700 | [diff] [blame] | 238 | char pnum[20] = {0}; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 239 | char *ptr = cmgs; |
| 240 | int err = 0; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 241 | // int data_len = 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 242 | |
| 243 | char *src = strstr(cmgs, ","); |
| 244 | if(src != NULL) |
| 245 | { |
| 246 | memcpy(pnum, ptr, src - ptr); |
| 247 | src++; |
| 248 | int data_len = 0; |
| 249 | data_len = len - (src - ptr); |
| 250 | memcpy(data, src, data_len); |
| 251 | } |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 252 | else |
| 253 | { |
| 254 | LOGD("cmgs param is error"); |
| 255 | return -1; |
| 256 | } |
| 257 | LOGD("num:%s", pnum); |
| 258 | LOGD("data:%s", data); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 259 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 260 | sprintf(cmd, "AT+CMGS=%s", pnum); |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 261 | LOGD("cmd:%s", cmd); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 262 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 263 | if(strlen(cmd) > 0) |
| 264 | { |
| 265 | int err = at_send_command_sms(cmd, data, "+CMGS: ", &response); |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 266 | LOGD("err:%d, response:%d", err, response->success); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 267 | |
| 268 | if (err < 0 || response->success == 0) { |
| 269 | *cme_err = at_get_cme_error(response); |
| 270 | goto exit; |
| 271 | } |
| 272 | char *line; |
| 273 | line = response->p_intermediates->line; |
| 274 | memcpy(reg, line, strlen(line)); |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 275 | LOGD("line:%s", line); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 276 | |
| 277 | } |
| 278 | err = 0; |
| 279 | exit: |
| 280 | at_response_free(response); |
| 281 | return err; |
| 282 | } |
| 283 | |
| 284 | static int req_cmgw_set(char *cmgw,int len, int *cme_err) |
| 285 | { |
| 286 | printf("req_cmgw_set()----------------start\n"); |
| 287 | printf("cmgw:%s\n", cmgw); |
| 288 | ATResponse *response = NULL; |
| 289 | char cmd[30] = {0}; |
| 290 | char data[218] = {0}; |
| 291 | char pnum[13] = {0}; |
| 292 | char *ptr = cmgw; |
| 293 | int err = 0; |
| 294 | |
| 295 | char *src = strstr(cmgw, ","); |
| 296 | if(src != NULL) |
| 297 | { |
| 298 | memcpy(pnum, ptr, src - ptr); |
| 299 | src++; |
| 300 | int data_len = 0; |
| 301 | data_len = len - (src - ptr); |
| 302 | memcpy(data, src, data_len); |
| 303 | } |
| 304 | |
| 305 | sprintf(cmd, "AT+CMGW=%s", pnum); |
| 306 | printf("cmd:%s,data:%s---------\n", cmd,data); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 307 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 308 | if(strlen(cmd) > 0) |
| 309 | { |
| 310 | int err = at_send_command_sms(cmd, data, "+CMGW: ", &response); |
| 311 | printf("err:%d, response:%d\n", err, response->success); |
| 312 | |
| 313 | if (err < 0 || response->success == 0) { |
| 314 | *cme_err = at_get_cme_error(response); |
| 315 | goto exit; |
| 316 | } |
| 317 | char *line; |
| 318 | line = response->p_intermediates->line; |
| 319 | printf("line:%s\n", line); |
| 320 | } |
| 321 | err = 0; |
| 322 | exit: |
| 323 | at_response_free(response); |
| 324 | return err; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | AT+CMGD=25 |
| 329 | OK |
| 330 | |
| 331 | +MMSG: 1, 0 |
| 332 | */ |
| 333 | static int req_cmgd_set(char *cmgd, int len, int *cme_err) |
| 334 | { |
| 335 | printf("0req_cmgd_set()--------------start\n"); |
| 336 | printf("cmgd:%s\n", cmgd); |
| 337 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 338 | char cmd[500] = {0}; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 339 | char data[218] = {0}; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 340 | // char pnum[13] = {0}; |
| 341 | // char *ptr = cmgd; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 342 | int err = 0; |
| 343 | |
| 344 | memcpy(data, cmgd, len ); |
| 345 | sprintf(cmd, "AT+CMGD=%s", data); |
| 346 | printf("cmd:%s,data:%s---------\n", cmd,data); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 347 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 348 | if(strlen(cmd) > 0) |
| 349 | { |
| 350 | int err = at_send_command(cmd, &response); |
| 351 | if (err < 0 || response->success == 0) { |
| 352 | *cme_err = at_get_cme_error(response); |
| 353 | goto exit; |
| 354 | } |
| 355 | |
| 356 | // Format problem caused the crash |
| 357 | // char *line; |
| 358 | // line = response->p_intermediates->line; |
| 359 | // printf("line:%s\n", line); |
| 360 | } |
| 361 | err = 0; |
| 362 | exit: |
| 363 | at_response_free(response); |
| 364 | return err; |
| 365 | } |
| 366 | |
| 367 | /* |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 368 | AT+CMGD=? |
| 369 | |
| 370 | +CMGD: (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37),(0-4) |
| 371 | |
| 372 | OK |
| 373 | |
| 374 | */ |
| 375 | static int req_cmgd_get(char *reg, int *cme_err) |
| 376 | { |
| 377 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 378 | // char *tmp_ptr = NULL; |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 379 | int err = at_send_command_singleline("AT+CMGD=?", "+CMGD:", &response); |
| 380 | |
| 381 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 382 | *cme_err = at_get_cme_error(response); |
| 383 | goto exit; |
| 384 | } |
| 385 | |
| 386 | char *line = response->p_intermediates->line; |
| 387 | |
| 388 | const char* start = strchr(line, '('); |
| 389 | const char* end = strchr(line, ')'); |
| 390 | |
| 391 | if (start && end && end > start) |
| 392 | { |
| 393 | int len_t = end - start - 1; |
| 394 | char substr_t[len_t + 1]; |
| 395 | |
| 396 | strncpy(substr_t, start + 1, len_t); |
| 397 | substr_t[len_t] = '\0'; |
| 398 | strncpy(reg, substr_t, len_t); |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | strcpy(reg, ""); |
| 403 | } |
| 404 | |
| 405 | exit: |
| 406 | at_response_free(response); |
| 407 | return err; |
| 408 | } |
| 409 | |
| 410 | |
| 411 | /* |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 412 | AT+CMGL="ALL" |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 413 | |
| 414 | +CMGL: 1,"REC READ","10658678",,"22.11.14 10:41:44 GMT+8" |
| 415 | |
| 416 | 56DB5DDD62 |
| 417 | |
| 418 | +CMGL: 2,"STO UNSENT","18927467953" |
| 419 | hello world |
| 420 | |
| 421 | */ |
| 422 | |
| 423 | static int req_cmgl_set(const char *cmgl, char *reg, int len, int *cme_err) |
| 424 | { |
| 425 | printf("req_cmgl_set(2)-----------------start\n"); |
| 426 | printf("cmgl:%s\n", cmgl); |
| 427 | ATResponse *response = NULL; |
| 428 | char cmd[30] = {0}; |
| 429 | char data[218] = {0}; |
| 430 | char index_data[256] = {0}; |
| 431 | int s_index = 0, g_index = 0; |
| 432 | bool index_flag = false; |
| 433 | char *ptr_index = index_data; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 434 | // char phone[50]; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 435 | char number[5] = {0}; |
| 436 | int err = 0; |
| 437 | |
| 438 | memcpy(data, cmgl, len); |
| 439 | |
| 440 | char *ptr1 = data; |
| 441 | char *ptr2 = strstr(data, ","); |
| 442 | if(ptr2 != NULL) |
| 443 | { |
| 444 | memcpy(number,ptr1, ptr2-ptr1 ); |
| 445 | s_index = atoi(number); |
| 446 | if(s_index == 0) |
| 447 | { |
| 448 | index_flag = TRUE; |
| 449 | memcpy(ptr_index, "+CMGL:", strlen("+CMGL:")); |
| 450 | } |
| 451 | memset(number, 0, sizeof(number)); |
| 452 | ptr2++; |
| 453 | }else{ |
| 454 | printf("cmgl set data is error\n eg:index,data\n"); |
| 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | sprintf(cmd, "AT+CMGL=%s", ptr2); |
| 459 | printf("cmd:%s\n", cmd); |
| 460 | |
| 461 | ptr1 = NULL; |
| 462 | ptr2 = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 463 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 464 | if(strlen(cmd) > 0) |
| 465 | { |
| 466 | err = at_send_command_multiline(cmd, "", &response); |
| 467 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 468 | *cme_err = at_get_cme_error(response); |
| 469 | printf("at_send_command_multiline() is err-----------------\n"); |
| 470 | goto exit; |
| 471 | } |
| 472 | |
| 473 | ATLine* lines_ptr = response->p_intermediates; |
| 474 | char *line = NULL; |
| 475 | int reg_len = 0; |
| 476 | bool flag = false; |
| 477 | while(lines_ptr) |
| 478 | { |
| 479 | line = lines_ptr->line; |
| 480 | if(line ==NULL) |
| 481 | { |
| 482 | printf("line is null----------------------\n"); |
| 483 | } |
| 484 | |
| 485 | printf("-----line:%s\n", line); |
| 486 | if(!flag) |
| 487 | { |
| 488 | ptr1 = strstr(line, "+CMGL: "); |
| 489 | if(ptr1 != NULL) |
| 490 | { |
| 491 | ptr1 += 7; |
| 492 | ptr2 = strstr(line, ","); |
| 493 | memcpy(number,ptr1, ptr2-ptr1 ); |
| 494 | printf("number:%s, ptr1:%s, ptr2:%s\n", number, ptr1, ptr2); |
| 495 | g_index = atoi(number); |
| 496 | if(index_flag) |
| 497 | { |
| 498 | sprintf(ptr_index+strlen(ptr_index), "%d,", g_index); |
| 499 | } |
| 500 | } |
| 501 | //if( g_index == s_index) |
| 502 | if( g_index == s_index && !index_flag) |
| 503 | { |
| 504 | printf("g_index == s_index, g_index:%d,s_index:%d\n", g_index, s_index); |
| 505 | flag = true; |
| 506 | } |
| 507 | } |
| 508 | if(flag && reg_len <=1024) |
| 509 | { |
| 510 | memcpy(reg+reg_len, line, strlen(line)); |
| 511 | printf("-----memcpy------reg:%s----------\n", reg); |
| 512 | printf("len:%d\n", reg_len); |
| 513 | reg_len += strlen(line); |
| 514 | } |
| 515 | |
| 516 | lines_ptr = lines_ptr->p_next; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | if(index_flag) |
| 521 | { |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 522 | // memset(reg, 0, sizeof(reg)); |
| 523 | memcpy(reg, ptr_index, strlen(ptr_index) + 1); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 524 | } |
| 525 | err = 0; |
| 526 | exit: |
| 527 | at_response_free(response); |
| 528 | printf("req_cmgl_set()-----------------end\n"); |
| 529 | return err; |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | at+csca? |
| 534 | +CSCA: "+8613800280500",145 |
| 535 | OK |
| 536 | */ |
| 537 | static int req_csca_get(char *req, int *cme_err) |
| 538 | { |
| 539 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 540 | // char *tmp_ptr = NULL; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 541 | int err = at_send_command_singleline("AT+CSCA?", "", &response); |
| 542 | |
| 543 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 544 | *cme_err = at_get_cme_error(response); |
| 545 | goto exit; |
| 546 | } |
| 547 | |
| 548 | char *line = response->p_intermediates->line; |
| 549 | printf("req_csca_get() ---line:%s\n", line); |
| 550 | char* ptr = strstr(line, "+CSCA: "); |
| 551 | printf("req_csca_get() ---ptr:%s\n",ptr); |
| 552 | if(ptr) |
| 553 | { |
| 554 | memcpy(req, line, strlen(line)); |
| 555 | printf("err:%d, req:%s\n", err, req); |
| 556 | err = 0; |
| 557 | } |
| 558 | else |
| 559 | { |
| 560 | err = -1; |
| 561 | } |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 562 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 563 | exit: |
| 564 | at_response_free(response); |
| 565 | return err; |
| 566 | } |
| 567 | |
| 568 | static int req_csca_set(char *csca, int len, int *cme_err) |
| 569 | { |
| 570 | printf("req_csca_set()--------------start\n"); |
| 571 | printf("csca:%s\n", csca); |
| 572 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 573 | char cmd[500] = {0}; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 574 | char data[218] = {0}; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 575 | // char pnum[13] = {0}; |
| 576 | // char *ptr = csca; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 577 | int err = 0; |
| 578 | |
| 579 | memcpy(data, csca, len); |
| 580 | sprintf(cmd, "AT+CSCA=%s", data); |
| 581 | printf("cmd:%s,data:%s---------\n", cmd,data); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 582 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 583 | if(strlen(cmd) > 0) |
| 584 | { |
| 585 | int err = at_send_command(cmd, &response); |
| 586 | if (err < 0 || response->success == 0) { |
| 587 | *cme_err = at_get_cme_error(response); |
| 588 | goto exit; |
| 589 | } |
| 590 | |
| 591 | // char *line; |
| 592 | // line = response->p_intermediates->line; |
| 593 | // printf("line:%s\n", line); |
| 594 | } |
| 595 | err = 0; |
| 596 | exit: |
| 597 | at_response_free(response); |
| 598 | return err; |
| 599 | } |
| 600 | |
| 601 | static int req_csmp_set(char *csmp, int len, int *cme_err) |
| 602 | { |
| 603 | printf("req_csmp_set()-------------------start\n"); |
| 604 | printf("csmp:%s\n", csmp); |
| 605 | ATResponse *response = NULL; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 606 | char cmd[500] = {0}; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 607 | char data[218] = {0}; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 608 | // char pnum[13] = {0}; |
| 609 | // char *ptr = csmp; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 610 | int err = 0; |
| 611 | |
| 612 | memcpy(data, csmp, len); |
| 613 | sprintf(cmd, "AT+CSMP=%s", data); |
| 614 | printf("cmd:%s,data:%s---------\n", cmd,data); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 615 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 616 | if(strlen(cmd) > 0) |
| 617 | { |
| 618 | int err = at_send_command(cmd, &response); |
| 619 | if (err < 0 || response->success == 0) { |
| 620 | *cme_err = at_get_cme_error(response); |
| 621 | goto exit; |
| 622 | } |
| 623 | |
| 624 | char *line; |
| 625 | line = response->p_intermediates->line; |
| 626 | printf("line:%s\n", line); |
| 627 | } |
| 628 | err = 0; |
| 629 | exit: |
| 630 | at_response_free(response); |
| 631 | return err; |
| 632 | } |
| 633 | |
| 634 | static int req_cscb_set(char *cscb,int len, int *cme_err) |
| 635 | { |
| 636 | printf("req_cscb_set()----------------start\n"); |
| 637 | printf("cscb:%s\n", cscb); |
| 638 | ATResponse *response = NULL; |
| 639 | char cmd[30] = {0}; |
| 640 | char data[218] = {0}; |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 641 | // char pnum[13] = {0}; |
| 642 | // char *ptr = cscb; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 643 | int err = 0; |
| 644 | |
| 645 | memcpy(data, cscb, len); |
| 646 | sprintf(cmd, "AT+CSCB=%s", cscb); |
| 647 | printf("cmd:%s,data:%s---------\n", cmd,data); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 648 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 649 | if(strlen(cmd) > 0) |
| 650 | { |
| 651 | int err = at_send_command(cmd, &response); |
| 652 | if (err < 0 || response->success == 0) { |
| 653 | *cme_err = at_get_cme_error(response); |
| 654 | goto exit; |
| 655 | } |
| 656 | |
| 657 | char *line; |
| 658 | line = response->p_intermediates->line; |
| 659 | printf("line:%s\n", line); |
| 660 | } |
| 661 | err = 0; |
| 662 | exit: |
| 663 | at_response_free(response); |
| 664 | return err; |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | AT+CMSS=13 |
| 669 | +CMSS: 81 |
| 670 | OK |
| 671 | */ |
| 672 | static int req_cmss_set(const char *cmss, char *reg, int len, int *cme_err) |
| 673 | { |
| 674 | printf("req_cmss_set()----------------start\n"); |
| 675 | printf("cmss:%s\n", cmss); |
| 676 | ATResponse *response = NULL; |
| 677 | char cmd[30] = {0}; |
| 678 | char data[20] = {0}; |
| 679 | int err = 0; |
| 680 | |
| 681 | if(cmss != NULL) |
| 682 | { |
| 683 | memcpy(data, cmss, len); |
| 684 | sprintf(cmd, "AT+CMSS=%s", data); |
| 685 | // sprintf(cmd, "AT+CMSS=%d", 8); |
| 686 | } |
| 687 | else{ |
| 688 | printf("mem is null\n"); |
| 689 | } |
| 690 | |
| 691 | printf("cmss. cmd:%s\n", cmd); |
| 692 | |
| 693 | if(strlen(cmd) > 8) |
| 694 | { |
| 695 | err = at_send_command_multiline(cmd, "+CMSS:", &response); |
| 696 | if (err < 0 || response->success == 0){ |
| 697 | *cme_err = at_get_cme_error(response); |
| 698 | goto exit; |
| 699 | } |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 700 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 701 | char *line = response->p_intermediates->line; |
| 702 | printf("line:%s\n", line); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 703 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 704 | char *tmp_str = NULL; |
| 705 | err = at_tok_nextstr(&line, &tmp_str); // phone_number |
| 706 | if (err < 0) |
| 707 | { |
| 708 | goto exit; |
| 709 | } |
| 710 | memcpy(reg, tmp_str, strlen(tmp_str)); |
| 711 | printf("cmss_reg:%s\n", reg); |
| 712 | /* |
| 713 | int err = at_send_command(cmd, &response); |
| 714 | |
| 715 | if (err < 0 || response->success == 0) { |
| 716 | *cme_err = at_get_cme_error(response); |
| 717 | goto exit; |
| 718 | } |
| 719 | |
| 720 | char *line; |
| 721 | line = response->p_intermediates->line; |
| 722 | printf("line:%s\n", line); |
| 723 | */ |
| 724 | } |
| 725 | err = 0; |
| 726 | exit: |
| 727 | at_response_free(response); |
| 728 | return err; |
| 729 | } |
| 730 | |
| 731 | |
| 732 | /* |
| 733 | AT+CMGR=1 |
| 734 | +CMGR: "REC READ","10658678",,"22.11.14 10:41:44 GMT+8" |
| 735 | |
| 736 | 56DB5DDD624B673A62A5FF039003003400310034003500340035003F0073003D0037003800680061006C00450066 |
| 737 | |
| 738 | OK |
| 739 | */ |
| 740 | static int req_cmgr_set(int index, char *reg, int *cme_err) |
| 741 | { |
| 742 | printf("0req_cmgr_set()-------------------start\n"); |
| 743 | printf("index:%d\n", index); |
| 744 | ATResponse *response = NULL; |
| 745 | char cmd[30] = {0}; |
| 746 | int err = 0; |
| 747 | sprintf(cmd, "AT+CMGR=%d", index); |
| 748 | |
| 749 | printf("req_cmgr_set()----cmd:%s\n", cmd); |
| 750 | |
| 751 | if(strlen(cmd) > 0) |
| 752 | { |
| 753 | err = at_send_command_multiline(cmd, "", &response); |
| 754 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 755 | *cme_err = at_get_cme_error(response); |
| 756 | printf("at_send_command_multiline() is err-----------------\n"); |
| 757 | goto exit; |
| 758 | } |
| 759 | |
| 760 | ATLine* lines_ptr = response->p_intermediates; |
| 761 | char *line = NULL; |
| 762 | int reg_len = 0; |
| 763 | while(lines_ptr) |
| 764 | { |
| 765 | line = lines_ptr->line; |
| 766 | if(line ==NULL) |
| 767 | { |
| 768 | printf("line is null----------------------\n"); |
| 769 | } |
| 770 | |
| 771 | if(reg_len > 0) |
| 772 | { |
| 773 | memcpy(reg+reg_len, "\r\n", strlen("\r\n")); |
| 774 | reg_len += strlen("\r\n"); |
| 775 | } |
| 776 | memcpy(reg+reg_len, line, strlen(line)); |
| 777 | printf("-----memcpy------reg:%s----------\n", reg); |
| 778 | printf("len:%d\n", reg_len); |
| 779 | reg_len += strlen(line); |
| 780 | lines_ptr = lines_ptr->p_next; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | err = 0; |
| 785 | exit: |
| 786 | at_response_free(response); |
| 787 | return err; |
| 788 | } |
| 789 | |
| 790 | |
| 791 | //void net_list_free(void *data); |
| 792 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 793 | // Otherwise, do not call pack_error_send(). |
| 794 | mbtk_info_err_enum sms_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack) |
| 795 | { |
| 796 | mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS; |
| 797 | int cme_err = MBTK_INFO_ERR_CME_NON; |
| 798 | switch(pack->info_id) |
| 799 | { |
| 800 | case MBTK_INFO_ID_SMS_STATE_REQ: |
| 801 | { |
| 802 | if(pack->data_len == 0 || pack->data == NULL) |
| 803 | { |
| 804 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 805 | } |
| 806 | else // Set |
| 807 | { |
| 808 | |
| 809 | } |
| 810 | break; |
| 811 | } |
| 812 | case MBTK_INFO_ID_SMS_CMGF_REQ: |
| 813 | { |
| 814 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 815 | { |
| 816 | int state; |
| 817 | if(req_cmgf_get(&state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 818 | { |
| 819 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 820 | err = MBTK_INFO_ERR_CME + cme_err; |
| 821 | } else { |
| 822 | err = MBTK_INFO_ERR_UNKNOWN; |
| 823 | } |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 824 | LOGD("Get SMS CMGF fail."); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 825 | } |
| 826 | else |
| 827 | { |
| 828 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGF_RSP, &state, sizeof(uint8)); |
| 829 | } |
| 830 | } |
| 831 | else // Set VoLTE state. |
| 832 | { |
| 833 | uint8 mode = *(pack->data); |
| 834 | if(pack->data_len != sizeof(uint8) || (mode != 0 && mode != 1)) |
| 835 | { |
| 836 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 837 | LOGD("Set SMS CMGF parameter error."); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 838 | break; |
| 839 | } |
| 840 | |
| 841 | if(req_cmgf_set(mode, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 842 | { |
| 843 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 844 | err = MBTK_INFO_ERR_CME + cme_err; |
| 845 | } else { |
| 846 | err = MBTK_INFO_ERR_UNKNOWN; |
| 847 | } |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 848 | LOGD("Set SMS CMGF fail."); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 849 | } |
| 850 | else |
| 851 | { |
| 852 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGF_RSP, NULL, 0); |
| 853 | |
| 854 | // Restart is required to take effect. |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 855 | LOGD("Will reboot system..."); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | break; |
| 859 | } |
| 860 | case MBTK_INFO_ID_SMS_CNMI_REQ: |
| 861 | { |
| 862 | if(pack->data_len == 0 || pack->data == NULL) // SET at+cnmi=1,2. |
| 863 | { |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 864 | // int state; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 865 | if(req_cnmi_set(&cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 866 | { |
| 867 | printf("set req_cnmi_set() fail.\n"); |
| 868 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 869 | err = MBTK_INFO_ERR_CME + cme_err; |
| 870 | } else { |
| 871 | err = MBTK_INFO_ERR_UNKNOWN; |
| 872 | } |
| 873 | LOG("set sms cnmi fail."); |
| 874 | } |
| 875 | else |
| 876 | { |
| 877 | printf("req_cnmi_set success\n"); |
| 878 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CNMI_RSP, NULL, 0); |
| 879 | } |
| 880 | } |
| 881 | break; |
| 882 | } |
| 883 | case MBTK_INFO_ID_SMS_CPMS_REQ: |
| 884 | { |
| 885 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 886 | { |
| 887 | char reg[100] = {0}; |
| 888 | if(req_cpms_get(reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 889 | { |
| 890 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 891 | err = MBTK_INFO_ERR_CME + cme_err; |
| 892 | } else { |
| 893 | err = MBTK_INFO_ERR_UNKNOWN; |
| 894 | } |
| 895 | LOG("Get SMS CMGF fail."); |
| 896 | } |
| 897 | else |
| 898 | { |
| 899 | printf("req_cpms_get_ success, reg:%s, len:%d ", reg, strlen(reg)); |
| 900 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CPMS_RSP, reg, strlen(reg)); |
| 901 | } |
| 902 | } |
| 903 | else // Set VoLTE state. |
| 904 | { |
| 905 | char *mem = (char*)(pack->data); |
| 906 | int len = pack->data_len; |
| 907 | char reg[100] = {0}; |
| 908 | printf("mem:%s, len:%d", pack->data, pack->data_len); |
| 909 | |
| 910 | if(req_cpms_set(mem, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 911 | { |
| 912 | printf("cpms_set fail\n"); |
| 913 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 914 | err = MBTK_INFO_ERR_CME + cme_err; |
| 915 | } else { |
| 916 | err = MBTK_INFO_ERR_UNKNOWN; |
| 917 | } |
| 918 | LOG("Set SMS CMGF fail."); |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | printf("cpms_set success, reg:%s\n", reg); |
| 923 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CPMS_RSP, reg, strlen(reg)); |
| 924 | |
| 925 | // Restart is required to take effect. |
| 926 | LOG("Will reboot system..."); |
| 927 | } |
| 928 | } |
| 929 | break; |
| 930 | } |
| 931 | case MBTK_INFO_ID_SMS_CMGS_REQ: |
| 932 | { |
| 933 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 934 | { |
| 935 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 936 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 937 | } |
| 938 | else // Set VoLTE state. |
| 939 | { |
| 940 | char *cmgs = (char*)pack->data; |
| 941 | int len = pack->data_len; |
| 942 | char reg[50] ={0}; |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 943 | LOGD("mbtk_sms,cmgs:%s,len:%d", cmgs, len); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 944 | |
| 945 | if(req_cmgs_set(cmgs,reg,len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 946 | { |
| 947 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 948 | err = MBTK_INFO_ERR_CME + cme_err; |
| 949 | } else { |
| 950 | err = MBTK_INFO_ERR_UNKNOWN; |
| 951 | } |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 952 | LOGD("Set SMS CMGS fail."); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 953 | } |
| 954 | else |
| 955 | { |
| 956 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGS_RSP, reg, strlen(reg)); |
| 957 | |
| 958 | // Restart is required to take effect. |
yq.wang | a9b5dd0 | 2024-10-16 00:25:14 -0700 | [diff] [blame] | 959 | LOGD("Will reboot system..."); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | } |
| 963 | break; |
| 964 | } |
| 965 | case MBTK_INFO_ID_SMS_CMSS_REQ: |
| 966 | { |
| 967 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 968 | { |
| 969 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 970 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 971 | } |
| 972 | else // Set VoLTE state. |
| 973 | { |
| 974 | char *cmss = (char*)pack->data; |
| 975 | int len = pack->data_len; |
| 976 | char reg[128] = {0}; |
| 977 | printf("mbtk_sms,cmgs:%s, len:%d\n", cmss, len); |
| 978 | |
| 979 | if(req_cmss_set(cmss,reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 980 | { |
| 981 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 982 | err = MBTK_INFO_ERR_CME + cme_err; |
| 983 | } else { |
| 984 | err = MBTK_INFO_ERR_UNKNOWN; |
| 985 | } |
| 986 | LOG("Set SMS CMGF fail."); |
| 987 | } |
| 988 | else |
| 989 | { |
| 990 | printf("req_cmss_set success, reg:%s", reg); |
| 991 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMSS_RSP, NULL, 0); |
| 992 | |
| 993 | // Restart is required to take effect. |
| 994 | LOG("Will reboot system..."); |
| 995 | } |
| 996 | |
| 997 | } |
| 998 | break; |
| 999 | } |
| 1000 | case MBTK_INFO_ID_SMS_CMGR_REQ: |
| 1001 | { |
| 1002 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 1003 | { |
| 1004 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 1005 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 1006 | } |
| 1007 | else // Set VoLTE state. |
| 1008 | { |
| 1009 | uint8 index = *(pack->data); |
| 1010 | char reg[1024] = {0}; |
| 1011 | if(pack->data_len != sizeof(uint8) ) |
| 1012 | { |
| 1013 | err = MBTK_INFO_ERR_REQ_PARAMETER; |
| 1014 | LOG("Set SMS CMGF parameter error."); |
| 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | if(req_cmgr_set(index, reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1019 | { |
| 1020 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1021 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1022 | } else { |
| 1023 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1024 | } |
| 1025 | LOG("Set SMS CMGF fail."); |
| 1026 | } |
| 1027 | else |
| 1028 | { |
| 1029 | printf("1req_cmgr_set_success, reg:%s\n", reg); |
| 1030 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGR_RSP, reg, strlen(reg)); |
| 1031 | |
| 1032 | // Restart is required to take effect. |
| 1033 | LOG("Will reboot system..."); |
| 1034 | } |
| 1035 | |
| 1036 | } |
| 1037 | break; |
| 1038 | } |
| 1039 | case MBTK_INFO_ID_SMS_CMGW_REQ: |
| 1040 | { |
| 1041 | if(pack->data_len == 0 || pack->data == NULL) // +CMGW=<oa/da>[,<tooa/toda>[,<stat>]]<CR> |
| 1042 | { |
| 1043 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 1044 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 1045 | } |
| 1046 | else // Set cmgw data. |
| 1047 | { |
| 1048 | char *cmgw = (char*)pack->data; |
| 1049 | int len = pack->data_len; |
| 1050 | printf("mbtk_sms,cmgw:%s,len:%d\n", cmgw, len); |
| 1051 | |
| 1052 | if(req_cmgw_set(cmgw, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1053 | { |
| 1054 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1055 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1056 | } else { |
| 1057 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1058 | } |
| 1059 | LOG("Set SMS CMGF fail."); |
| 1060 | } |
| 1061 | else |
| 1062 | { |
| 1063 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGW_RSP, NULL, 0); |
| 1064 | |
| 1065 | // Restart is required to take effect. |
| 1066 | LOG("Will reboot system..."); |
| 1067 | } |
| 1068 | |
| 1069 | } |
| 1070 | break; |
| 1071 | } |
| 1072 | case MBTK_INFO_ID_SMS_CMGD_REQ: |
| 1073 | { |
| 1074 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 1075 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 1076 | char reg[1024] = {0}; |
| 1077 | if(req_cmgd_get(reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1078 | { |
| 1079 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1080 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1081 | } else { |
| 1082 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1083 | } |
| 1084 | LOG("Get SMS CMGD fail."); |
| 1085 | } |
| 1086 | else |
| 1087 | { |
| 1088 | LOG("req_cmgd_get success, reg:%s, len:%d ", reg, strlen(reg)); |
| 1089 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGD_RSP, reg, strlen(reg)); |
| 1090 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1091 | } |
| 1092 | else // Set VoLTE state. |
| 1093 | { |
| 1094 | char *cmgd = (char*)pack->data; |
| 1095 | int len = pack->data_len; |
| 1096 | printf("mbtk_sms,cmgs:%s,len:%d\n", cmgd, len); |
| 1097 | |
| 1098 | if(req_cmgd_set(cmgd,len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1099 | { |
| 1100 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1101 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1102 | } else { |
| 1103 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1104 | } |
| 1105 | LOG("Set SMS CMGF fail."); |
| 1106 | } |
| 1107 | else |
| 1108 | { |
| 1109 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGD_RSP, NULL, 0); |
| 1110 | |
| 1111 | // Restart is required to take effect. |
| 1112 | LOG("Will reboot system..."); |
| 1113 | } |
| 1114 | |
| 1115 | } |
| 1116 | break; |
| 1117 | } |
| 1118 | case MBTK_INFO_ID_SMS_CMGL_REQ: |
| 1119 | { |
| 1120 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 1121 | { |
| 1122 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 1123 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 1124 | } |
| 1125 | else // Set VoLTE state. |
| 1126 | { |
| 1127 | char *cmgl = (char*)pack->data; |
| 1128 | int len = pack->data_len; |
| 1129 | char reg[5*1024] = {0}; |
| 1130 | char reg1[1024+1] = {0}; |
| 1131 | printf("mbtk_sms,cmgs:%s, len:%d\n", cmgl, len); |
| 1132 | |
| 1133 | if(req_cmgl_set(cmgl, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1134 | { |
| 1135 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1136 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1137 | } else { |
| 1138 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1139 | } |
| 1140 | LOG("Set SMS CMGF fail."); |
| 1141 | } |
| 1142 | else |
| 1143 | { |
| 1144 | // printf("1cmgl_set_success---------len:%d\n reg:%s\n",strlen(reg), reg); |
| 1145 | memcpy(reg1, reg, 1024); |
| 1146 | printf("0len:%d, reg1:%s\n", strlen(reg1), reg1); |
| 1147 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CMGL_RSP, reg1, strlen(reg1)); |
| 1148 | |
| 1149 | // Restart is required to take effect. |
| 1150 | LOG("Will reboot system..."); |
| 1151 | } |
| 1152 | |
| 1153 | } |
| 1154 | break; |
| 1155 | } |
| 1156 | case MBTK_INFO_ID_SMS_CSCA_REQ: |
| 1157 | { |
| 1158 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 1159 | { |
| 1160 | char csca[50]={0}; |
| 1161 | if(req_csca_get(csca, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1162 | { |
| 1163 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1164 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1165 | } else { |
| 1166 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1167 | } |
| 1168 | LOG("Get SMS CSCA fail."); |
| 1169 | printf("get sms csca fail\n"); |
| 1170 | } |
| 1171 | else |
| 1172 | { |
| 1173 | printf("get sms csca suscess\n"); |
| 1174 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CSCA_RSP, csca, strlen(csca)); |
| 1175 | } |
| 1176 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 1177 | } |
| 1178 | else // Set VoLTE state. |
| 1179 | { |
| 1180 | char *csca = (char*)pack->data; |
| 1181 | int len = pack->data_len; |
| 1182 | printf("mbtk_sms,cmgs:%s,len:%d\n", csca, len); |
| 1183 | |
| 1184 | if(req_csca_set(csca, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1185 | { |
| 1186 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1187 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1188 | } else { |
| 1189 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1190 | } |
| 1191 | LOG("Set SMS CMGF fail."); |
| 1192 | } |
| 1193 | else |
| 1194 | { |
| 1195 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CSCA_RSP, NULL, 0); |
| 1196 | |
| 1197 | // Restart is required to take effect. |
| 1198 | LOG("Will reboot system..."); |
| 1199 | } |
| 1200 | |
| 1201 | } |
| 1202 | break; |
| 1203 | } |
| 1204 | case MBTK_INFO_ID_SMS_CSMP_REQ: |
| 1205 | { |
| 1206 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 1207 | { |
| 1208 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 1209 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 1210 | } |
| 1211 | else // Set VoLTE state. |
| 1212 | { |
| 1213 | char *csmp = (char*)pack->data; |
| 1214 | int len = pack->data_len; |
| 1215 | printf("mbtk_sms,cmgs:%s,len:%d\n", csmp, len); |
| 1216 | |
| 1217 | if(req_csmp_set(csmp,len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1218 | { |
| 1219 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1220 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1221 | } else { |
| 1222 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1223 | } |
| 1224 | LOG("Set SMS CMGF fail."); |
| 1225 | } |
| 1226 | else |
| 1227 | { |
| 1228 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CSMP_RSP, NULL, 0); |
| 1229 | |
| 1230 | // Restart is required to take effect. |
| 1231 | LOG("Will reboot system..."); |
| 1232 | } |
| 1233 | |
| 1234 | } |
| 1235 | break; |
| 1236 | } |
| 1237 | case MBTK_INFO_ID_SMS_CSCB_REQ: |
| 1238 | { |
| 1239 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 1240 | { |
| 1241 | printf("pack->data_len:%d,,pack->data:%s\n",pack->data_len, pack->data); |
| 1242 | err = MBTK_INFO_ERR_UNSUPPORTED; |
| 1243 | } |
| 1244 | else // Set VoLTE state. |
| 1245 | { |
| 1246 | char *cscb = (char*)pack->data; |
| 1247 | int len = pack->data_len; |
| 1248 | printf("mbtk_sms,cmgs:%s, len:%d\n", cscb, len); |
| 1249 | |
| 1250 | if(req_cscb_set(cscb,len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) |
| 1251 | { |
| 1252 | if(cme_err != MBTK_INFO_ERR_CME_NON) { |
| 1253 | err = MBTK_INFO_ERR_CME + cme_err; |
| 1254 | } else { |
| 1255 | err = MBTK_INFO_ERR_UNKNOWN; |
| 1256 | } |
| 1257 | LOG("Set SMS CMGF fail."); |
| 1258 | } |
| 1259 | else |
| 1260 | { |
| 1261 | pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SMS_CSCB_RSP, NULL, 0); |
| 1262 | |
| 1263 | // Restart is required to take effect. |
| 1264 | LOG("Will reboot system..."); |
| 1265 | } |
| 1266 | |
| 1267 | } |
| 1268 | break; |
| 1269 | } |
| 1270 | default: |
| 1271 | { |
| 1272 | err = MBTK_INFO_ERR_REQ_UNKNOWN; |
| 1273 | LOG("Unknown request : %s", id2str(pack->info_id)); |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | return err; |
| 1279 | } |