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