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