b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame^] | 1 | #include "mbtk_at.h" |
| 2 | //#include <sys/statfs.h> |
| 3 | #include <sys/vfs.h> |
| 4 | #include <errno.h> |
| 5 | #include <linux/magic.h> |
| 6 | #include <time.h> |
| 7 | #include <sys/time.h> |
| 8 | #include <signal.h> |
| 9 | #include <pthread.h> |
| 10 | #include <time.h> |
| 11 | #include <sys/time.h> |
| 12 | #include <cutils/properties.h> |
| 13 | #include "configwrapper.h" |
| 14 | #include<linux/msg.h> |
| 15 | |
| 16 | #include "atcmdsvr_ubus.h" |
| 17 | |
| 18 | |
| 19 | int http_handle = -1; |
| 20 | int http_session = -1; |
| 21 | int http_type = 0; |
| 22 | int file_fd = -1; |
| 23 | |
| 24 | #define MODEM_FACTORY_TEST_TERM_DEVICE "/dev/ttyGS0" |
| 25 | |
| 26 | typedef struct mbtk_http_header { |
| 27 | char name[30]; |
| 28 | char *value; |
| 29 | } mbtk_http_header_t; |
| 30 | |
| 31 | mbtk_http_header_t req_h[30] ={0}; |
| 32 | |
| 33 | |
| 34 | |
| 35 | typedef enum { |
| 36 | MBTK_HTTP_DATA_NON = 0, |
| 37 | MBTK_HTTP_DATA_HEADER, |
| 38 | MBTK_HTTP_DATA_CONTENT, |
| 39 | MBTK_HTTP_DATA_COMPLETE |
| 40 | } mbtk_http_data_type_enum; |
| 41 | |
| 42 | typedef enum { |
| 43 | MBTK_HTTP_DATA_EFS_BUF = 0, |
| 44 | MBTK_HTTP_DATA_EFS_SIZE, |
| 45 | MBTK_HTTP_DATA_EFS_BUF_SIZE |
| 46 | } mbtk_http_data_file_type_enum; |
| 47 | |
| 48 | |
| 49 | typedef enum { |
| 50 | HTTP_VERSION_1_0 = 0, |
| 51 | HTTP_VERSION_1_1, |
| 52 | HTTP_VERSION_2, |
| 53 | HTTP_VERSION_3 |
| 54 | } mbtk_http_version_enum; |
| 55 | |
| 56 | typedef enum { |
| 57 | HTTP_OPTION_HEAD = 0, |
| 58 | HTTP_OPTION_GET, |
| 59 | HTTP_OPTION_POST, |
| 60 | HTTP_OPTION_PUT, |
| 61 | HTTP_OPTION_DELETE, |
| 62 | HTTP_OPTION_OPTIONS, |
| 63 | HTTP_OPTION_TRACE, |
| 64 | HTTP_OPTION_CONNECT, |
| 65 | HTTP_OPTION_LINK, |
| 66 | HTTP_OPTION_UNLINK |
| 67 | } mbtk_http_option_enum; |
| 68 | |
| 69 | typedef enum { |
| 70 | HTTP_TYPE_URC = 0, |
| 71 | HTTP_TYPE_EFS |
| 72 | } mbtk_http_type_enum; |
| 73 | |
| 74 | typedef enum { |
| 75 | HTTP_SESSION_STATE_NON = 0, |
| 76 | HTTP_SESSION_STATE_CONN, |
| 77 | HTTP_SESSION_STATE_WRITE_HEADER, |
| 78 | HTTP_SESSION_STATE_WRITE_CONTENT, |
| 79 | HTTP_SESSION_STATE_WRITE_END, |
| 80 | HTTP_SESSION_STATE_READ_HEADER, |
| 81 | HTTP_SESSION_STATE_READ_CONTENT, |
| 82 | HTTP_SESSION_STATE_READ_END |
| 83 | } http_session_state_e; |
| 84 | |
| 85 | typedef struct { |
| 86 | int header_cnt; |
| 87 | mbtk_http_header_t *req_h[30]; |
| 88 | |
| 89 | int content_len; // Post content lenght |
| 90 | int content_len_send; // Post content lenght for send. |
| 91 | char *content; |
| 92 | } mbtk_http_session_req_t; |
| 93 | |
| 94 | typedef struct { |
| 95 | int state_code; |
| 96 | mbtk_http_version_enum version; |
| 97 | |
| 98 | int content_length; |
| 99 | bool is_chunked; |
| 100 | int header_cnt; |
| 101 | mbtk_http_header_t *rsp_h[30]; |
| 102 | } mbtk_http_session_rsp_t; |
| 103 | |
| 104 | typedef struct mbtk_http_session{ |
| 105 | int handle_id; |
| 106 | int id; |
| 107 | int sock_fd; |
| 108 | int file_fd; |
| 109 | http_session_state_e state; |
| 110 | char host[50 + 1]; |
| 111 | mbtk_http_option_enum option; |
| 112 | mbtk_http_type_enum type; |
| 113 | mbtk_http_version_enum version; |
| 114 | char uri[205 + 1]; |
| 115 | int port; |
| 116 | bool is_ssl; |
| 117 | |
| 118 | mbtk_http_session_req_t req; |
| 119 | mbtk_http_session_rsp_t rsp; |
| 120 | } mbtk_http_session_t; |
| 121 | |
| 122 | |
| 123 | #define CS8 0000060 |
| 124 | #define B115200 0010002 |
| 125 | |
| 126 | #define DATABITS CS8 |
| 127 | #define BAUD B115200 |
| 128 | #define STOPBITS 0 |
| 129 | #define PARITYON 0 |
| 130 | #define PARITY 0 |
| 131 | #define FILTER_INFO_NUM 12 |
| 132 | #define CRTSCTS 020000000000 /* flow control */ |
| 133 | #define VERASE 2 |
| 134 | #define VEOF 4 |
| 135 | #define VMIN 6 |
| 136 | #define VEOL 11 |
| 137 | #define IGNPAR 0000004 |
| 138 | #define CREAD 0000200 |
| 139 | #define CLOCAL 0004000 |
| 140 | |
| 141 | #define TCSANOW 0 |
| 142 | |
| 143 | typedef unsigned char cc_t; |
| 144 | typedef unsigned int speed_t; |
| 145 | typedef unsigned int tcflag_t; |
| 146 | |
| 147 | /* tcflush() and TCFLSH use these */ |
| 148 | #define TCIFLUSH 0 |
| 149 | #define TCOFLUSH 1 |
| 150 | #define TCIOFLUSH 2 |
| 151 | |
| 152 | |
| 153 | #define NCCS 19 |
| 154 | struct termios { |
| 155 | tcflag_t c_iflag; /* input mode flags */ |
| 156 | tcflag_t c_oflag; /* output mode flags */ |
| 157 | tcflag_t c_cflag; /* control mode flags */ |
| 158 | tcflag_t c_lflag; /* local mode flags */ |
| 159 | cc_t c_line; /* line discipline */ |
| 160 | cc_t c_cc[NCCS]; /* control characters */ |
| 161 | }; |
| 162 | |
| 163 | |
| 164 | |
| 165 | int mbtk_http_port_fd = -1; |
| 166 | |
| 167 | static int mbtk_http_open_device(int *fd_ptr, const char *file_path, int flag, int tty) |
| 168 | { |
| 169 | |
| 170 | int fd = -1; |
| 171 | |
| 172 | if((fd = open(file_path, flag)) < 0) |
| 173 | { |
| 174 | LOG("Open %s fail.", file_path); |
| 175 | return -1; |
| 176 | } |
| 177 | |
| 178 | LOG("Open %s success.", file_path); |
| 179 | if (tty) { |
| 180 | /* set newtio */ |
| 181 | struct termios newtio; |
| 182 | memset(&newtio, 0, sizeof(newtio)); |
| 183 | //(void)fcntl(fd, F_SETFL, 0); |
| 184 | #ifdef UART2_AT |
| 185 | /* no flow control for uart by default */ |
| 186 | newtio.c_cflag = BAUD | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD; |
| 187 | #else |
| 188 | newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD; |
| 189 | #endif |
| 190 | newtio.c_iflag = IGNPAR; |
| 191 | //newtio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); |
| 192 | newtio.c_oflag = 0; |
| 193 | newtio.c_lflag = 0; /* disable ECHO, ICANON, etc... */ |
| 194 | |
| 195 | newtio.c_cc[VERASE] = 0x8; /* del */ |
| 196 | newtio.c_cc[VEOF] = 4; /* Ctrl-d */ |
| 197 | newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives */ |
| 198 | newtio.c_cc[VEOL] = 0xD; /* '\0' */ |
| 199 | |
| 200 | tcflush(fd, TCIFLUSH); |
| 201 | tcsetattr(fd, TCSANOW, &newtio); |
| 202 | } |
| 203 | |
| 204 | *fd_ptr = fd; |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | int mbtk_http_open_port(void) |
| 210 | { |
| 211 | if(mbtk_http_port_fd < 0) |
| 212 | { |
| 213 | return mbtk_http_open_device(&mbtk_http_port_fd, MODEM_FACTORY_TEST_TERM_DEVICE, O_RDWR | O_NONBLOCK | O_NOCTTY, 0); |
| 214 | } |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | void mbtk_http_close_port(void) |
| 219 | { |
| 220 | if(mbtk_http_port_fd >= 0) |
| 221 | { |
| 222 | tcflush(mbtk_http_port_fd, TCIOFLUSH); |
| 223 | close(mbtk_http_port_fd); |
| 224 | mbtk_http_port_fd = -1; |
| 225 | } |
| 226 | |
| 227 | } |
| 228 | |
| 229 | int mbtk_http_write_data(void *data,int data_len) |
| 230 | { |
| 231 | int ret = write(mbtk_http_port_fd, data, data_len); |
| 232 | if(ret < 0) |
| 233 | { |
| 234 | LOG("gnss_factory_test_port_fd write fail"); |
| 235 | return -1; |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static void http_data_cb_func( |
| 242 | int session_id, mbtk_http_data_type_enum type, |
| 243 | void *data,int data_len) |
| 244 | { |
| 245 | LOG("2type:%d,data_len:%d,data:%s ",type, data_len, data); |
| 246 | |
| 247 | if(http_type) |
| 248 | { |
| 249 | if(type == MBTK_HTTP_DATA_HEADER) { |
| 250 | |
| 251 | } else if(type == MBTK_HTTP_DATA_CONTENT){ |
| 252 | |
| 253 | if(file_fd >= 0) |
| 254 | { |
| 255 | int write_len = write(file_fd, data, data_len); |
| 256 | if(write_len < data_len) { |
| 257 | LOG("write() fail."); |
| 258 | // return -1; |
| 259 | } |
| 260 | } |
| 261 | } else { |
| 262 | LOG(">>>>>Complete<<<<<\n"); |
| 263 | } |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | char buf[50]={0}; |
| 268 | sprintf(buf, "$HTTPRECV: DATA,%d",data_len); |
| 269 | mbtk_http_write_data("\r\n", strlen("\r\n")); |
| 270 | mbtk_http_write_data(buf, strlen(buf)); |
| 271 | mbtk_http_write_data("\r\n", strlen("\r\n")); |
| 272 | |
| 273 | if(type == MBTK_HTTP_DATA_HEADER) { |
| 274 | |
| 275 | mbtk_http_write_data(data, data_len); |
| 276 | |
| 277 | LOG("Header(%d):%s\n",data_len,(char*)data); |
| 278 | |
| 279 | } else if(type == MBTK_HTTP_DATA_CONTENT) { |
| 280 | mbtk_http_write_data(data, data_len); |
| 281 | |
| 282 | } else { |
| 283 | LOG(">>>>>Complete<<<<<\n"); |
| 284 | } |
| 285 | |
| 286 | } |
| 287 | |
| 288 | } |
| 289 | |
| 290 | static void http_data_file_cb_func(mbtk_http_data_file_type_enum type,void *data,int data_len) |
| 291 | { |
| 292 | if(type == MBTK_HTTP_DATA_EFS_BUF) { //read file data |
| 293 | |
| 294 | char buf[50]={0}; |
| 295 | sprintf(buf, "$HTTPRECV: DATA,%d",data_len); |
| 296 | mbtk_http_write_data("\r\n", strlen("\r\n")); |
| 297 | mbtk_http_write_data(buf, strlen(buf)); |
| 298 | mbtk_http_write_data("\r\n", strlen("\r\n")); |
| 299 | |
| 300 | mbtk_http_write_data(data, data_len); |
| 301 | LOG("Header(%d):%s\n",data_len,(char*)data); |
| 302 | |
| 303 | } else if(type == MBTK_HTTP_DATA_EFS_SIZE) { //read file size |
| 304 | |
| 305 | char buf[50]={0}; |
| 306 | sprintf(buf, "$HTTPREAD:%d",data_len); |
| 307 | ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, buf); |
| 308 | |
| 309 | LOG("mbtk data_len(%d)\n",data_len); |
| 310 | } else { |
| 311 | LOG(">>>>>Complete<<<<<\n"); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | static int http_header_value_get(mbtk_http_header_t *header,char *header_str,int header_str_len) |
| 316 | { |
| 317 | if(header == NULL || header->value == NULL |
| 318 | || header_str == NULL) |
| 319 | return 0; |
| 320 | |
| 321 | int len = 0; |
| 322 | len = snprintf(header_str,header_str_len,"%s: %s", |
| 323 | header->name, header->value); |
| 324 | |
| 325 | return len; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | int mbtk_http_get_file_size(char *file_name) |
| 330 | { |
| 331 | int ret; |
| 332 | int fd = -1; |
| 333 | struct stat file_stat; |
| 334 | |
| 335 | LOG("mbtk_http_get_file_size() start\n"); |
| 336 | |
| 337 | fd = open(file_name, O_RDONLY); |
| 338 | if (fd == -1) { |
| 339 | printf("Open file %s failed\n", file_name); |
| 340 | return -1; |
| 341 | } |
| 342 | ret = fstat(fd, &file_stat); |
| 343 | if (ret == -1) { |
| 344 | printf("Get file %s stat failed\n", file_name); |
| 345 | close(fd); |
| 346 | return -1; |
| 347 | } |
| 348 | close(fd); |
| 349 | LOG("mbtk_http_get_file_size() end\n"); |
| 350 | return file_stat.st_size; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | int mbtk_http_read_file_data1(mbtk_http_data_file_type_enum type,int offset) |
| 355 | { |
| 356 | |
| 357 | if(type) //1 read file size |
| 358 | { |
| 359 | int size = mbtk_http_get_file_size("/http_test.txt"); |
| 360 | |
| 361 | http_data_file_cb_func(MBTK_HTTP_DATA_EFS_SIZE, NULL, size); |
| 362 | }else //read file data |
| 363 | { |
| 364 | char buf[1024+1] = {0}; |
| 365 | int ret = 0; |
| 366 | |
| 367 | int fd = open("/http_test.txt", O_RDONLY); |
| 368 | if (fd == -1) { |
| 369 | printf("Open file %s failed\n", "/http_test.txt"); |
| 370 | return -1; |
| 371 | } |
| 372 | |
| 373 | if(offset) |
| 374 | { |
| 375 | lseek(fd, offset, SEEK_SET); |
| 376 | } |
| 377 | // usleep(500000); |
| 378 | int index = 0; |
| 379 | while(1) |
| 380 | { |
| 381 | memset(buf,0, sizeof(buf)); |
| 382 | ret = read(fd, buf, 1024); |
| 383 | printf("ret = %d , ", ret); |
| 384 | usleep(100000); |
| 385 | LOG("mbtk, read file:%s\n", buf); |
| 386 | if(ret <= 0) |
| 387 | break; |
| 388 | |
| 389 | http_data_file_cb_func(MBTK_HTTP_DATA_EFS_BUF, buf, ret); |
| 390 | index++; |
| 391 | } |
| 392 | close(fd); |
| 393 | printf("%d\n", index); |
| 394 | |
| 395 | LOG("read()end index;:%d, ret:%d",index,ret); |
| 396 | } |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | |
| 403 | utlReturnCode_T MBTK_AT_HTTPOPEN_PROCESS(const utlAtParameterOp_T op, |
| 404 | const char *command_name_p, |
| 405 | const utlAtParameterValue_P2c parameter_values_p, |
| 406 | const size_t num_parameters, |
| 407 | const char *info_text_p, |
| 408 | unsigned int *xid_p, |
| 409 | void *arg_p) |
| 410 | { |
| 411 | UNUSEDPARAM(command_name_p); |
| 412 | UNUSEDPARAM(num_parameters); |
| 413 | UNUSEDPARAM(info_text_p); |
| 414 | |
| 415 | utlReturnCode_T ret = utlFAILED; |
| 416 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 417 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 418 | *xid_p = at_handle; |
| 419 | |
| 420 | LOG("%s enter with command_op [%s]", command_name_p, op2str(op)); |
| 421 | |
| 422 | switch(op) |
| 423 | { |
| 424 | case TEL_EXT_ACTION_CMD : |
| 425 | { |
| 426 | if(http_handle >= 0) |
| 427 | { |
| 428 | LOG("http is open"); |
| 429 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | if(mbtk_http_open_port()) |
| 434 | { |
| 435 | LOG("http open device port fail\n"); |
| 436 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | http_handle = MBTK_FUNC(mbtk_http_handle_get)(TRUE, http_data_cb_func); |
| 441 | |
| 442 | if(http_handle < 0) |
| 443 | { |
| 444 | LOG("mbtk_http_handle_get() fail."); |
| 445 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 446 | }else{ |
| 447 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 448 | } |
| 449 | |
| 450 | break; |
| 451 | } |
| 452 | case TEL_EXT_GET_CMD : |
| 453 | { |
| 454 | char resp_buf[50] ={0}; |
| 455 | if(http_handle < 0) |
| 456 | { |
| 457 | sprintf(resp_buf, "$HTTPOPEN:%d", 0); |
| 458 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 459 | }else{ |
| 460 | |
| 461 | sprintf(resp_buf, "$HTTPOPEN:%d", 1); |
| 462 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 463 | }; |
| 464 | |
| 465 | break; |
| 466 | |
| 467 | } |
| 468 | default: |
| 469 | { |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | |
| 478 | |
| 479 | utlReturnCode_T MBTK_AT_HTTPCLOSE_PROCESS(const utlAtParameterOp_T op, |
| 480 | const char *command_name_p, |
| 481 | const utlAtParameterValue_P2c parameter_values_p, |
| 482 | const size_t num_parameters, |
| 483 | const char *info_text_p, |
| 484 | unsigned int *xid_p, |
| 485 | void *arg_p) |
| 486 | { |
| 487 | UNUSEDPARAM(command_name_p); |
| 488 | UNUSEDPARAM(num_parameters); |
| 489 | UNUSEDPARAM(info_text_p); |
| 490 | |
| 491 | utlReturnCode_T ret = utlFAILED; |
| 492 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 493 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 494 | *xid_p = at_handle; |
| 495 | |
| 496 | LOG("%s enter with command_op [%s]", command_name_p, op2str(op)); |
| 497 | |
| 498 | switch(op) |
| 499 | { |
| 500 | case TEL_EXT_ACTION_CMD : |
| 501 | { |
| 502 | int i = 0; |
| 503 | if(http_handle < 0) |
| 504 | { |
| 505 | LOG("http close handle is < 0"); |
| 506 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 507 | break; |
| 508 | } |
| 509 | |
| 510 | mbtk_http_close_port(); |
| 511 | for(i = 0; i < 30; i++) |
| 512 | { |
| 513 | if(req_h[i].value) |
| 514 | { |
| 515 | free(req_h[i].value); |
| 516 | req_h[i].value = NULL; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | ret = MBTK_FUNC(mbtk_http_handle_free)(http_handle); |
| 521 | |
| 522 | if(ret ) |
| 523 | { |
| 524 | LOG("mbtk_http_handle_free() fail."); |
| 525 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 526 | }else{ |
| 527 | http_handle = -1; |
| 528 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 529 | } |
| 530 | break; |
| 531 | } |
| 532 | case TEL_EXT_GET_CMD : |
| 533 | { |
| 534 | char resp_buf[50] ={0}; |
| 535 | if(http_handle >= 0) |
| 536 | { |
| 537 | sprintf(resp_buf, "$HTTPCLOSE:%d", 1); |
| 538 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 539 | }else{ |
| 540 | |
| 541 | sprintf(resp_buf, "$HTTPCLOSE:%d", 0); |
| 542 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 543 | }; |
| 544 | |
| 545 | break; |
| 546 | |
| 547 | } |
| 548 | default: |
| 549 | { |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | //$HTTPPARA="",(0-65535),(0-1), (0-1) |
| 558 | utlReturnCode_T MBTK_AT_HTTPPARA_PROCESS(const utlAtParameterOp_T op, |
| 559 | const char *command_name_p, |
| 560 | const utlAtParameterValue_P2c parameter_values_p, |
| 561 | const size_t num_parameters, |
| 562 | const char *info_text_p, |
| 563 | unsigned int *xid_p, |
| 564 | void *arg_p) |
| 565 | { |
| 566 | UNUSEDPARAM(command_name_p); |
| 567 | UNUSEDPARAM(num_parameters); |
| 568 | UNUSEDPARAM(info_text_p); |
| 569 | |
| 570 | utlReturnCode_T ret = utlFAILED; |
| 571 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 572 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 573 | *xid_p = at_handle; |
| 574 | |
| 575 | LOG("%s enter with command_op [%s]", command_name_p, op2str(op)); |
| 576 | |
| 577 | switch(op) |
| 578 | { |
| 579 | case TEL_EXT_SET_CMD : |
| 580 | { |
| 581 | const static int cmd_len_max = MBTK_AT_RESP_LEN_MAX; |
| 582 | static char cmd[MBTK_AT_RESP_LEN_MAX] ={0}; |
| 583 | char url[255] ={0}; |
| 584 | char resp_buf[100] = {0}; |
| 585 | bool ingnore_cert = TRUE; |
| 586 | |
| 587 | int arg3 = 0, port = 0, is_ssl = 0; |
| 588 | int len = 0; |
| 589 | if(!getExtString(parameter_values_p, 0, cmd, cmd_len_max, &len, "")) |
| 590 | { |
| 591 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 592 | break; |
| 593 | } |
| 594 | |
| 595 | if(!getExtValue(parameter_values_p, 1, &port, 0, 65535, 0)) |
| 596 | { |
| 597 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 598 | break; |
| 599 | } |
| 600 | |
| 601 | if(!getExtValue(parameter_values_p, 2, &is_ssl, 0, 2, 0)) |
| 602 | { |
| 603 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | if(!getExtValue(parameter_values_p, 3, &arg3, 0, 2, 0)) |
| 608 | { |
| 609 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 610 | break; |
| 611 | } |
| 612 | |
| 613 | if(is_ssl) |
| 614 | { |
| 615 | if(!memcmp(cmd,"https://",8)) |
| 616 | { |
| 617 | sprintf(url, "%s:%d", cmd, port); |
| 618 | } |
| 619 | else if(!memcmp(cmd,"http://",7)) |
| 620 | { |
| 621 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 622 | break; |
| 623 | } |
| 624 | else |
| 625 | { |
| 626 | sprintf(url, "https://%s:%d", cmd, port); |
| 627 | } |
| 628 | } |
| 629 | else |
| 630 | { |
| 631 | sprintf(url, "%s:%d", cmd, port); |
| 632 | } |
| 633 | |
| 634 | if(http_handle < 0) |
| 635 | { |
| 636 | LOG("http is not open"); |
| 637 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 638 | break; |
| 639 | } |
| 640 | |
| 641 | http_session = MBTK_FUNC(mbtk_http_session_create)(http_handle,1,1); |
| 642 | if(http_session < 0) |
| 643 | { |
| 644 | LOG("mbtk_http_handle_get() fail."); |
| 645 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 646 | break; |
| 647 | } |
| 648 | else |
| 649 | { |
| 650 | ret = MBTK_FUNC(mbtk_http_session_url_set)(http_handle,http_session,url); |
| 651 | if(ret ) |
| 652 | { |
| 653 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 654 | } |
| 655 | else |
| 656 | { |
| 657 | if(arg3) |
| 658 | ingnore_cert = FALSE; |
| 659 | |
| 660 | if(!ingnore_cert) |
| 661 | { |
| 662 | ret = MBTK_FUNC(mbtk_http_session_ingnore_cert_set)(http_handle,http_session,ingnore_cert); |
| 663 | if(ret) |
| 664 | { |
| 665 | LOG("mbtk_http_session_ingnore_cert_set() fail."); |
| 666 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 667 | break; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | break; |
| 676 | } |
| 677 | case TEL_EXT_GET_CMD : |
| 678 | { |
| 679 | char resp_buf[1024] ={0}; |
| 680 | const mbtk_http_session_t* session = MBTK_FUNC(mbtk_http_session_get)(http_handle, http_session); |
| 681 | if(session != NULL) |
| 682 | { |
| 683 | sprintf(resp_buf, "Host:\"%s\"\r\nURI:\"%s\"\r\nport:%d\r\nCert:%d",\ |
| 684 | session->host,session->uri, session->port,session->is_ssl); |
| 685 | } |
| 686 | |
| 687 | ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, resp_buf); |
| 688 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 689 | break; |
| 690 | } |
| 691 | case TEL_EXT_TEST_CMD : |
| 692 | { |
| 693 | char resp_buf[50] ={0}; |
| 694 | memcpy(resp_buf, "$HTTPPARA=\"\",(0-65535),(0-1), (0-1)", strlen("$HTTPPARA=\"\",(0-65535),(0-1), (0-1)")); |
| 695 | |
| 696 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 697 | break; |
| 698 | |
| 699 | } |
| 700 | default: |
| 701 | { |
| 702 | break; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | utlReturnCode_T MBTK_AT_HTTPSEND_PROCESS(const utlAtParameterOp_T op, |
| 710 | const char *command_name_p, |
| 711 | const utlAtParameterValue_P2c parameter_values_p, |
| 712 | const size_t num_parameters, |
| 713 | const char *info_text_p, |
| 714 | unsigned int *xid_p, |
| 715 | void *arg_p) |
| 716 | { |
| 717 | UNUSEDPARAM(command_name_p); |
| 718 | UNUSEDPARAM(num_parameters); |
| 719 | UNUSEDPARAM(info_text_p); |
| 720 | |
| 721 | utlReturnCode_T ret = utlFAILED; |
| 722 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 723 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 724 | *xid_p = at_handle; |
| 725 | |
| 726 | LOG("%s enter with command_op [%s]", command_name_p, op2str(op)); |
| 727 | |
| 728 | switch(op) |
| 729 | { |
| 730 | case TEL_EXT_ACTION_CMD : |
| 731 | { |
| 732 | printf("MBTK HTTP Version 1.1"); |
| 733 | char resp_buf[150] ={0}; |
| 734 | |
| 735 | if(http_handle < 0) |
| 736 | { |
| 737 | printf("mbtk_http_handle_get() fail."); |
| 738 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 739 | }else{ |
| 740 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 741 | } |
| 742 | |
| 743 | break; |
| 744 | } |
| 745 | default: |
| 746 | { |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | return ret; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | |
| 756 | utlReturnCode_T MBTK_AT_HTTPRQH_PROCESS(const utlAtParameterOp_T op, |
| 757 | const char *command_name_p, |
| 758 | const utlAtParameterValue_P2c parameter_values_p, |
| 759 | const size_t num_parameters, |
| 760 | const char *info_text_p, |
| 761 | unsigned int *xid_p, |
| 762 | void *arg_p) |
| 763 | { |
| 764 | UNUSEDPARAM(command_name_p); |
| 765 | UNUSEDPARAM(num_parameters); |
| 766 | UNUSEDPARAM(info_text_p); |
| 767 | |
| 768 | utlReturnCode_T ret = utlFAILED; |
| 769 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 770 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 771 | *xid_p = at_handle; |
| 772 | |
| 773 | LOG("%s 11111111111111enter with command_op [%s]", command_name_p, op2str(op)); |
| 774 | |
| 775 | switch(op) |
| 776 | { |
| 777 | case TEL_EXT_SET_CMD : |
| 778 | { |
| 779 | const static int rqh_head_len_max = MBTK_AT_RESP_LEN_MAX; |
| 780 | static char rqh_head[MBTK_AT_RESP_LEN_MAX]; |
| 781 | char rqh_buf[100] = {0}; |
| 782 | char buf_test[100] ={0}; |
| 783 | char *p = buf_test; |
| 784 | int len = 0; |
| 785 | memset(rqh_head, 0x0, MBTK_AT_RESP_LEN_MAX); |
| 786 | if(!getExtString(parameter_values_p, 0, rqh_head, rqh_head_len_max, &len, "")) |
| 787 | { |
| 788 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, "MBTK_AT_HTTPRQH_PROCESS1"); |
| 789 | LOG("Get CMD Fail."); |
| 790 | break; |
| 791 | } |
| 792 | else{ |
| 793 | memcpy(buf_test,rqh_head, strlen(rqh_head) ); |
| 794 | } |
| 795 | |
| 796 | len = 0; |
| 797 | if(!getExtString(parameter_values_p, 1, rqh_buf, rqh_head_len_max, &len, "")) |
| 798 | { |
| 799 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, "MBTK_AT_HTTPRQH_PROCESS1_buf"); |
| 800 | LOG("Get CMD Fail."); |
| 801 | break; |
| 802 | } |
| 803 | |
| 804 | if(http_handle < 0) |
| 805 | { |
| 806 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | ret = MBTK_FUNC(mbtk_http_session_head_add)(http_handle, http_session, rqh_head, rqh_buf); |
| 811 | |
| 812 | if(ret) |
| 813 | { |
| 814 | LOG("mbtk_http_handle_get() fail."); |
| 815 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 816 | }else{ |
| 817 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 818 | |
| 819 | int i = 0; |
| 820 | for(i = 0; i < 30; i++) |
| 821 | { |
| 822 | if( !strcmp(req_h[i].name, rqh_head) ) |
| 823 | { |
| 824 | if(req_h[i].value) |
| 825 | { |
| 826 | free(req_h[i].value); |
| 827 | } |
| 828 | |
| 829 | req_h[i].value = (char*)malloc(strlen(rqh_buf) + 1); |
| 830 | if(req_h[i].value == NULL) |
| 831 | { |
| 832 | return -1; |
| 833 | } |
| 834 | memset(req_h[i].value, 0x0, strlen(rqh_buf) + 1); |
| 835 | memcpy(req_h[i].value, rqh_buf, strlen(rqh_buf)); |
| 836 | |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | for(i = 0; i < 30; i++) |
| 841 | { |
| 842 | if(req_h[i].value == NULL) |
| 843 | { |
| 844 | break; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | memcpy(req_h[i].name, rqh_head, strlen(rqh_head)); |
| 849 | req_h[i].value = (char*)malloc(strlen(rqh_buf) + 1); |
| 850 | if(req_h[i].value == NULL) |
| 851 | { |
| 852 | // return -1; |
| 853 | break; |
| 854 | } |
| 855 | memset(req_h[i].value, 0x0, strlen(rqh_buf) + 1); |
| 856 | memcpy(req_h[i].value, rqh_buf, strlen(rqh_buf)); |
| 857 | |
| 858 | } |
| 859 | |
| 860 | break; |
| 861 | } |
| 862 | case TEL_EXT_GET_CMD : |
| 863 | { |
| 864 | char resp_buf[1024] ={0}; |
| 865 | int index = 0; |
| 866 | int len = 0; |
| 867 | int i = 0; |
| 868 | |
| 869 | for(i = 0; i < 30; i++) |
| 870 | { |
| 871 | if(req_h[i].value == NULL) |
| 872 | { |
| 873 | break; |
| 874 | } |
| 875 | |
| 876 | sprintf(resp_buf, "%s:%s\n", req_h[i].name, req_h[i].value); |
| 877 | ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, resp_buf); |
| 878 | memset(resp_buf, 0, sizeof(resp_buf)); |
| 879 | } |
| 880 | |
| 881 | if(i == 0) |
| 882 | { |
| 883 | ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, "$HTTPRQH: \"\""); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 888 | } |
| 889 | |
| 890 | break; |
| 891 | } |
| 892 | default: |
| 893 | { |
| 894 | break; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | return ret; |
| 899 | } |
| 900 | |
| 901 | |
| 902 | utlReturnCode_T MBTK_AT_HTTPACTION_PROCESS(const utlAtParameterOp_T op, |
| 903 | const char *command_name_p, |
| 904 | const utlAtParameterValue_P2c parameter_values_p, |
| 905 | const size_t num_parameters, |
| 906 | const char *info_text_p, |
| 907 | unsigned int *xid_p, |
| 908 | void *arg_p) |
| 909 | { |
| 910 | UNUSEDPARAM(command_name_p); |
| 911 | UNUSEDPARAM(num_parameters); |
| 912 | UNUSEDPARAM(info_text_p); |
| 913 | |
| 914 | utlReturnCode_T ret = utlFAILED; |
| 915 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 916 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 917 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0}; |
| 918 | int arg1 = 0; |
| 919 | int type = 0; |
| 920 | *xid_p = at_handle; |
| 921 | |
| 922 | LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op)); |
| 923 | |
| 924 | switch(op) |
| 925 | { |
| 926 | case TEL_EXT_TEST_CMD : |
| 927 | { |
| 928 | char resp_buf[50] ={0}; |
| 929 | memcpy(resp_buf, "$HTTPACTION: (0-3) ", strlen("$HTTPACTION: (0-3) ")); |
| 930 | |
| 931 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 932 | break; |
| 933 | } |
| 934 | case TEL_EXT_SET_CMD : |
| 935 | { |
| 936 | int gnss_ret; |
| 937 | |
| 938 | if(!getExtValue(parameter_values_p, 0, &arg1, 0, 3, 0)) |
| 939 | { |
| 940 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | if(arg1 == 0){ type = 1;} |
| 945 | else if(arg1== 2){type = 0; } |
| 946 | else if(arg1== 3){type = 2; } |
| 947 | else{ |
| 948 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 949 | break; |
| 950 | } |
| 951 | |
| 952 | ret = MBTK_FUNC(mbtk_http_session_option_reset)(http_handle,http_session,type); |
| 953 | if(ret) |
| 954 | { |
| 955 | LOG("mbtk_http_handle_get() fail."); |
| 956 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 957 | } |
| 958 | else |
| 959 | { |
| 960 | |
| 961 | if(http_type) |
| 962 | { |
| 963 | file_fd = open("/http_test.txt", O_WRONLY|O_TRUNC|O_CREAT|O_APPEND, 0666); |
| 964 | if(file_fd < 0) |
| 965 | { |
| 966 | LOG("mbtk_http_session_type_set fail"); |
| 967 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | ret = MBTK_FUNC(mbtk_http_session_start)(http_handle, http_session); |
| 973 | if(ret) |
| 974 | { |
| 975 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 976 | }else{ |
| 977 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 978 | } |
| 979 | |
| 980 | if(file_fd >= 0) |
| 981 | { |
| 982 | if(close(file_fd)) |
| 983 | { |
| 984 | LOG("close() fail file_fd:%d",file_fd); |
| 985 | } |
| 986 | file_fd = -1; |
| 987 | } |
| 988 | |
| 989 | // mbtk_http_close_port(); |
| 990 | } |
| 991 | |
| 992 | break; |
| 993 | } |
| 994 | default: |
| 995 | { |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | return ret; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | utlReturnCode_T MBTK_AT_HTTPTYPE_PROCESS(const utlAtParameterOp_T op, |
| 1005 | const char *command_name_p, |
| 1006 | const utlAtParameterValue_P2c parameter_values_p, |
| 1007 | const size_t num_parameters, |
| 1008 | const char *info_text_p, |
| 1009 | unsigned int *xid_p, |
| 1010 | void *arg_p) |
| 1011 | { |
| 1012 | UNUSEDPARAM(command_name_p); |
| 1013 | UNUSEDPARAM(num_parameters); |
| 1014 | UNUSEDPARAM(info_text_p); |
| 1015 | |
| 1016 | utlReturnCode_T ret = utlFAILED; |
| 1017 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 1018 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 1019 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0}; |
| 1020 | int arg1 = 0; |
| 1021 | *xid_p = at_handle; |
| 1022 | |
| 1023 | LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op)); |
| 1024 | |
| 1025 | switch(op) |
| 1026 | { |
| 1027 | case TEL_EXT_TEST_CMD : |
| 1028 | { |
| 1029 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, "$HTTPTYPE: (0-1)"); |
| 1030 | break; |
| 1031 | |
| 1032 | } |
| 1033 | case TEL_EXT_GET_CMD : |
| 1034 | { |
| 1035 | char resp_buf[50] ={0}; |
| 1036 | const mbtk_http_session_t* session = MBTK_FUNC(mbtk_http_session_get)(http_handle, http_session); |
| 1037 | if(session != NULL) |
| 1038 | { |
| 1039 | sprintf(resp_buf, "$HTTPTYPE:%d",session->type); |
| 1040 | } |
| 1041 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 1042 | break; |
| 1043 | } |
| 1044 | case TEL_EXT_SET_CMD : |
| 1045 | { |
| 1046 | int gnss_ret; |
| 1047 | |
| 1048 | if(!getExtValue(parameter_values_p, 0, &arg1, 0, 1, 0)) |
| 1049 | { |
| 1050 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1051 | break; |
| 1052 | } |
| 1053 | |
| 1054 | http_type = arg1; |
| 1055 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 1056 | |
| 1057 | } |
| 1058 | default: |
| 1059 | { |
| 1060 | break; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | return ret; |
| 1065 | } |
| 1066 | |
| 1067 | //$HTTPDATAEX: (0-500) ,"" |
| 1068 | utlReturnCode_T MBTK_AT_HTTPDATAEX_PROCESS(const utlAtParameterOp_T op, |
| 1069 | const char *command_name_p, |
| 1070 | const utlAtParameterValue_P2c parameter_values_p, |
| 1071 | const size_t num_parameters, |
| 1072 | const char *info_text_p, |
| 1073 | unsigned int *xid_p, |
| 1074 | void *arg_p) |
| 1075 | { |
| 1076 | UNUSEDPARAM(command_name_p); |
| 1077 | UNUSEDPARAM(num_parameters); |
| 1078 | UNUSEDPARAM(info_text_p); |
| 1079 | |
| 1080 | utlReturnCode_T ret = utlFAILED; |
| 1081 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 1082 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 1083 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0}; |
| 1084 | int arg1 = 0, arg2 = 0; |
| 1085 | *xid_p = at_handle; |
| 1086 | |
| 1087 | LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op)); |
| 1088 | |
| 1089 | switch(op) |
| 1090 | { |
| 1091 | case TEL_EXT_TEST_CMD : |
| 1092 | { |
| 1093 | char resp_buf[50] ={0}; |
| 1094 | memcpy(resp_buf, "$HTTPDATAEX: (0-500) ,\"\"",strlen("$HTTPDATAEX: (0-500) ,\"\"")); |
| 1095 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, resp_buf); |
| 1096 | break; |
| 1097 | } |
| 1098 | case TEL_EXT_SET_CMD : |
| 1099 | { |
| 1100 | int gnss_ret; |
| 1101 | |
| 1102 | const static int cmd_len_max = MBTK_AT_RESP_LEN_MAX; |
| 1103 | static char cmd[MBTK_AT_RESP_LEN_MAX]; |
| 1104 | int len = 0; |
| 1105 | |
| 1106 | if(!getExtValue(parameter_values_p, 0, &arg1, 0, 501, 0)) |
| 1107 | { |
| 1108 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1109 | break; |
| 1110 | } |
| 1111 | |
| 1112 | memset(cmd, 0x0, MBTK_AT_RESP_LEN_MAX); |
| 1113 | if(!getExtString(parameter_values_p, 1, cmd, cmd_len_max, &len, "")) |
| 1114 | { |
| 1115 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1116 | LOG("Get CMD Fail."); |
| 1117 | break; |
| 1118 | } |
| 1119 | |
| 1120 | ret = MBTK_FUNC(mbtk_http_session_option_reset)(http_handle,http_session,2); |
| 1121 | if(ret) |
| 1122 | { |
| 1123 | LOG("mbtk_http_session_option_reset fail"); |
| 1124 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1125 | |
| 1126 | } |
| 1127 | else |
| 1128 | { |
| 1129 | |
| 1130 | ret = MBTK_FUNC(mbtk_http_session_content_set)(http_handle,http_session,cmd,arg1); |
| 1131 | if(ret) |
| 1132 | { |
| 1133 | sprintf(resp_buf, "mbtk_http_session_content_set fail,arg1:%d, len:%d, cmd:%s\r\n", arg1,len, cmd); |
| 1134 | LOG(resp_buf); |
| 1135 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1136 | } |
| 1137 | else |
| 1138 | { |
| 1139 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | break; |
| 1144 | } |
| 1145 | default: |
| 1146 | { |
| 1147 | break; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | return ret; |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | //$HTTPREAD: (0-1),(0-512000) |
| 1156 | utlReturnCode_T MBTK_AT_HTTPREAD_PROCESS(const utlAtParameterOp_T op, |
| 1157 | const char *command_name_p, |
| 1158 | const utlAtParameterValue_P2c parameter_values_p, |
| 1159 | const size_t num_parameters, |
| 1160 | const char *info_text_p, |
| 1161 | unsigned int *xid_p, |
| 1162 | void *arg_p) |
| 1163 | { |
| 1164 | UNUSEDPARAM(command_name_p); |
| 1165 | UNUSEDPARAM(num_parameters); |
| 1166 | UNUSEDPARAM(info_text_p); |
| 1167 | |
| 1168 | utlReturnCode_T ret = utlFAILED; |
| 1169 | TelAtParserID sAtp_index = *(TelAtParserID *)arg_p; |
| 1170 | unsigned int at_handle = MAKE_AT_HANDLE(sAtp_index); |
| 1171 | char resp_buf[MBTK_AT_RESP_LEN_MAX] = {0}; |
| 1172 | int arg1 = 0, arg2 = 0; |
| 1173 | *xid_p = at_handle; |
| 1174 | |
| 1175 | LOG("%s enter with command_op [%s]", __FUNCTION__, op2str(op)); |
| 1176 | |
| 1177 | switch(op) |
| 1178 | { |
| 1179 | case TEL_EXT_TEST_CMD : |
| 1180 | { |
| 1181 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, "$HTTPREAD: (0-1),(0-512000) "); |
| 1182 | break; |
| 1183 | } |
| 1184 | case TEL_EXT_GET_CMD: |
| 1185 | { |
| 1186 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 1187 | break; |
| 1188 | } |
| 1189 | case TEL_EXT_SET_CMD : |
| 1190 | { |
| 1191 | int gnss_ret; |
| 1192 | |
| 1193 | if(!getExtValue(parameter_values_p, 0, &arg1, 0, 2, 0)) |
| 1194 | { |
| 1195 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1196 | break; |
| 1197 | } |
| 1198 | |
| 1199 | if(!getExtValue(parameter_values_p, 1, &arg2, 0, 512001, 0)) |
| 1200 | { |
| 1201 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1202 | break; |
| 1203 | } |
| 1204 | |
| 1205 | // char buf[100] ={0}; |
| 1206 | // sprintf(buf, "arg1:%d, arg2%d\n", arg1, arg2); |
| 1207 | |
| 1208 | // ATRESP(IND_REQ_HANDLE , ATCI_RESULT_CODE_NULL, 0, buf); |
| 1209 | |
| 1210 | |
| 1211 | if(arg1 == 0) // read data |
| 1212 | { |
| 1213 | if(arg2 < 1) |
| 1214 | arg2 = 0; |
| 1215 | |
| 1216 | } |
| 1217 | else if(arg1 == 1){ // read file size |
| 1218 | arg2 = 0; |
| 1219 | } |
| 1220 | else{ |
| 1221 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1222 | break; |
| 1223 | } |
| 1224 | |
| 1225 | ret = mbtk_http_read_file_data1(arg1,arg2); |
| 1226 | if(ret) |
| 1227 | { |
| 1228 | LOG("mbtk_http_read_file_data fail"); |
| 1229 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_ERROR, 0, NULL); |
| 1230 | }else{ |
| 1231 | ret = ATRESP(at_handle, ATCI_RESULT_CODE_OK, 0, NULL); |
| 1232 | } |
| 1233 | |
| 1234 | break; |
| 1235 | } |
| 1236 | default: |
| 1237 | { |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | return ret; |
| 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | |