lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #ifndef CONFIG_MIN_8M_VERSION |
| 2 | #include "softap_api.h" |
| 3 | #include "ext_socket_func.h" |
| 4 | #include <math.h> |
| 5 | #include "at_com.h" |
| 6 | |
| 7 | struct netsrv_msg netsrv = {0}; |
| 8 | |
| 9 | //IPµØÖ·¸ñʽ¼ì²é |
| 10 | int check_ipaddr_legal(char* ipaddr) |
| 11 | { |
| 12 | char* pointer_tmp_start = NULL; |
| 13 | char* pointer_tmp_end = NULL; |
| 14 | char str_tmp[64] = {0}; |
| 15 | int ipaddr_len = strlen(ipaddr); |
| 16 | int num = 0; |
| 17 | int i = 0; |
| 18 | |
| 19 | pointer_tmp_end = strchr(ipaddr, '.'); |
| 20 | if (pointer_tmp_end == NULL) { |
| 21 | return 0; |
| 22 | } |
| 23 | if((int)(pointer_tmp_end - ipaddr) < sizeof(str_tmp)) |
| 24 | snprintf(str_tmp,(int)(pointer_tmp_end - ipaddr)+1,"%s",ipaddr); |
| 25 | //strncpy(str_tmp, ipaddr, (int)(pointer_tmp_end - ipaddr)); |
| 26 | num = atoi(str_tmp); |
| 27 | |
| 28 | if (num < 0 || num > 255) { |
| 29 | return 0; |
| 30 | } |
| 31 | for (i = 0; i < 2; i++) { |
| 32 | pointer_tmp_start = pointer_tmp_end + 1; |
| 33 | if (pointer_tmp_start >= ipaddr + ipaddr_len) { |
| 34 | return 0; |
| 35 | } |
| 36 | pointer_tmp_end = strchr(pointer_tmp_start, '.'); |
| 37 | if (pointer_tmp_end == NULL) { |
| 38 | return 0; |
| 39 | } |
| 40 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 41 | if((int)(pointer_tmp_end - pointer_tmp_start) < sizeof(str_tmp)) |
| 42 | snprintf(str_tmp,(int)(pointer_tmp_end - pointer_tmp_start)+1,"%s",pointer_tmp_start); |
| 43 | //strncpy(str_tmp, pointer_tmp_start, (int)(pointer_tmp_end - pointer_tmp_start)); |
| 44 | num = atoi(str_tmp); |
| 45 | if (num < 0 || num > 255) { |
| 46 | return 0; |
| 47 | } |
| 48 | } |
| 49 | pointer_tmp_start = pointer_tmp_end + 1; |
| 50 | if (pointer_tmp_start >= ipaddr + ipaddr_len) { |
| 51 | return 0; |
| 52 | } |
| 53 | pointer_tmp_end = ipaddr + ipaddr_len; |
| 54 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 55 | if((int)(ipaddr + ipaddr_len - pointer_tmp_start) < sizeof(str_tmp)) |
| 56 | snprintf(str_tmp,(int)(ipaddr + ipaddr_len - pointer_tmp_start)+1,"%s",pointer_tmp_start); |
| 57 | //strncpy(str_tmp, pointer_tmp_start, (int)(ipaddr + ipaddr_len - pointer_tmp_start)); |
| 58 | num = atoi(str_tmp); |
| 59 | if (num < 0 || num > 255) { |
| 60 | return 0; |
| 61 | } |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | //========================================================================================================// |
| 66 | //¹úµçsocket·½°¸º¯ÊýʵÏÖÇø |
| 67 | //========================================================================================================// |
| 68 | /* |
| 69 | at+mynetsrv=1,2,2,0,"192.168.30.201:5100¡± |
| 70 | */ |
| 71 | int ext_netsrv_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 72 | { |
| 73 | struct netsrv_msg *srv = malloc(sizeof(struct netsrv_msg)); |
| 74 | assert(srv); |
| 75 | char * pos_colon = NULL; |
| 76 | char * port = NULL; |
| 77 | char *at_str = NULL; |
| 78 | char *p[5] = {&srv->ch_id, &srv->socketid, &srv->conn_type, &srv->viewMode, srv->ipport}; |
| 79 | char *c = NULL; |
| 80 | char ipport[128]; |
| 81 | memset(srv, 0x00, sizeof(struct netsrv_msg)); |
| 82 | if(5 != parse_param2("%d,%d,%d,%d,%s", at_paras, p)){ |
| 83 | goto error; |
| 84 | } |
| 85 | //²ÎÊý¼ì²é |
| 86 | memcpy(ipport, srv->ipport, sizeof(ipport)); |
| 87 | pos_colon = strchr(ipport, ':'); |
| 88 | port = pos_colon + 1; |
| 89 | if ((srv->socketid < 0 || srv->socketid >= 6) |
| 90 | || (srv->viewMode != 0 && srv->viewMode != 1) |
| 91 | || (srv->conn_type < 0 || srv->conn_type > 2) |
| 92 | || (srv->ch_id < 0 || srv->ch_id >= 6) |
| 93 | || pos_colon == NULL |
| 94 | || (atoi(port) < 0 || atoi(port) > 65535)) { |
| 95 | goto error; |
| 96 | } |
| 97 | *pos_colon = '\0'; |
| 98 | c = ipport; |
| 99 | //°´×Ö½ÚÑ»·¼ì²éÊÇ·ñº¬ÓÐ×Öĸ£¬ÈçÓÐÔòbreak |
| 100 | while (*c) { |
| 101 | if (isalpha(*c)) |
| 102 | break; |
| 103 | c++; |
| 104 | } |
| 105 | if (!*c) { |
| 106 | if (check_ipaddr_legal(ipport) == 0) { |
| 107 | goto error; |
| 108 | } |
| 109 | } |
| 110 | netsrv = *srv;//Ϊ²éѯÓà |
| 111 | *res_msg = srv; |
| 112 | *res_msglen = sizeof(struct netsrv_msg); |
| 113 | return AT_CONTINUE; |
| 114 | |
| 115 | error: |
| 116 | free(srv); |
| 117 | at_str = malloc(32); |
| 118 | assert(at_str); |
| 119 | memset(at_str, 0x00, 32); |
| 120 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 121 | *res_msg = at_str; |
| 122 | *res_msglen = strlen(at_str); |
| 123 | return AT_END; |
| 124 | } |
| 125 | int ext_netsrv_rsp(void *rsp_msg, void**ret, int *retlen) |
| 126 | { |
| 127 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 128 | char *at_str = malloc(32); |
| 129 | assert(at_str); |
| 130 | memset(at_str, 0x00, 32); |
| 131 | |
| 132 | if (msg->ret < 0) { |
| 133 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 134 | } else { |
| 135 | sprintf(at_str, "\r\nOK\r\n"); |
| 136 | } |
| 137 | *ret = at_str; |
| 138 | *retlen = strlen(at_str); |
| 139 | return AT_END; |
| 140 | } |
| 141 | int ext_netopen_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 142 | { |
| 143 | struct comm_reqmsg *reqmsg = malloc(sizeof(struct comm_reqmsg)); |
| 144 | assert(reqmsg); |
| 145 | char *at_str = NULL; |
| 146 | char *p[1] = {&reqmsg->socketid}; |
| 147 | memset(reqmsg, 0x00, sizeof(struct comm_reqmsg)); |
| 148 | if(1 != parse_param2("%d", at_paras, p)){ |
| 149 | free(reqmsg); |
| 150 | at_str = malloc(32); |
| 151 | assert(at_str); |
| 152 | memset(at_str, 0x00, 32); |
| 153 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 154 | *res_msg = at_str; |
| 155 | *res_msglen = strlen(at_str); |
| 156 | return AT_END; |
| 157 | } |
| 158 | |
| 159 | *res_msg = reqmsg; |
| 160 | *res_msglen = sizeof(struct comm_reqmsg); |
| 161 | return AT_CONTINUE; |
| 162 | } |
| 163 | int ext_netopen_rsp(void *rsp_msg, void**ret, int *retlen) |
| 164 | { |
| 165 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 166 | char *at_str = malloc(64); |
| 167 | assert(at_str); |
| 168 | char param[10] = {0}; |
| 169 | int offset = 0; |
| 170 | memset(at_str, 0x00, 64); |
| 171 | |
| 172 | if (msg->ret < 0) { |
| 173 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 174 | } else { |
| 175 | if (msg->remote_mss) { |
| 176 | offset += sprintf(at_str + offset, "\r\n$MYNETOPEN: %d,%d\r\n", msg->socketid, msg->remote_mss); |
| 177 | } else { |
| 178 | offset += sprintf(at_str + offset, "\r\n$MYNETOPEN: %d\r\n", msg->socketid); |
| 179 | } |
| 180 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 181 | } |
| 182 | *ret = at_str; |
| 183 | *retlen = strlen(at_str); |
| 184 | return AT_END; |
| 185 | |
| 186 | } |
| 187 | int ext_netread_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 188 | { |
| 189 | struct comm_reqmsg *reqmsg = malloc(sizeof(struct comm_reqmsg)); |
| 190 | assert(reqmsg); |
| 191 | char *at_str = NULL; |
| 192 | char *p[2] = {&reqmsg->socketid, &reqmsg->len}; |
| 193 | memset(reqmsg, 0x00, sizeof(struct comm_reqmsg)); |
| 194 | if(2 != parse_param2("%d,%d", at_paras, p)){ |
| 195 | free(reqmsg); |
| 196 | at_str = malloc(32); |
| 197 | assert(at_str); |
| 198 | memset(at_str, 0x00, 32); |
| 199 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 200 | *res_msg = at_str; |
| 201 | *res_msglen = strlen(at_str); |
| 202 | return AT_END; |
| 203 | } |
| 204 | |
| 205 | *res_msg = reqmsg; |
| 206 | *res_msglen = sizeof(struct comm_reqmsg); |
| 207 | return AT_CONTINUE; |
| 208 | |
| 209 | } |
| 210 | int ext_netread_rsp(void *rsp_msg, void**ret, int *retlen) |
| 211 | { |
| 212 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 213 | char *at_str = NULL; |
| 214 | int offset = 0; |
| 215 | |
| 216 | if (msg->ret < 0) { |
| 217 | at_str = malloc(32); |
| 218 | assert(at_str); |
| 219 | memset(at_str, 0x00, 32); |
| 220 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 221 | offset = strlen(at_str); |
| 222 | } else if (msg->len == 0) { |
| 223 | at_str = malloc(64); |
| 224 | assert(at_str); |
| 225 | memset(at_str, 0x00, 64); |
| 226 | sprintf(at_str, "\r\n$MYNETREAD: %d,0\r\n\r\nOK\r\n", msg->socketid); |
| 227 | offset = strlen(at_str); |
| 228 | } else { |
| 229 | int viewmode = msg->viewmode; |
| 230 | char *data = ((char *)rsp_msg + sizeof(struct comm_rspmsg)); |
| 231 | if (viewmode == 0) { //hexģʽ |
| 232 | int i = 0; |
| 233 | at_str = malloc(64 + msg->len); |
| 234 | assert(at_str); |
| 235 | memset(at_str, 0x00, 64 + msg->len); |
| 236 | offset += sprintf(at_str + offset, "\r\n$MYNETREAD: %d,%d\r\n", msg->socketid, msg->len); |
| 237 | memcpy(at_str + offset, data, msg->len); |
| 238 | offset += msg->len; |
| 239 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 240 | } else { //textģʽ |
| 241 | //int i = 0; |
| 242 | at_str = malloc(64 + msg->len * 2); |
| 243 | assert(at_str); |
| 244 | memset(at_str, 0x00, 64 + msg->len * 2); |
| 245 | offset += sprintf(at_str + offset, "\r\n$MYNETREAD: %d,%d\r\n", msg->socketid, msg->len); |
| 246 | memcpy(at_str + offset, data, msg->len); |
| 247 | offset += msg->len; |
| 248 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 249 | } |
| 250 | } |
| 251 | *ret = at_str; |
| 252 | *retlen = offset; |
| 253 | return AT_END; |
| 254 | |
| 255 | } |
| 256 | |
| 257 | int ext_sendbuf_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 258 | { |
| 259 | struct comm_reqmsg *reqmsg = malloc(sizeof(struct comm_reqmsg)); |
| 260 | assert(reqmsg); |
| 261 | char *at_str = NULL; |
| 262 | char *p[2] = {&reqmsg->socketid, &reqmsg->len}; |
| 263 | memset(reqmsg, 0x00, sizeof(struct comm_reqmsg)); |
| 264 | if(2 != parse_param2("%d,%d", at_paras, p)){ |
| 265 | free(reqmsg); |
| 266 | at_str = malloc(32); |
| 267 | assert(at_str); |
| 268 | memset(at_str, 0x00, 32); |
| 269 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 270 | *res_msg = at_str; |
| 271 | *res_msglen = strlen(at_str); |
| 272 | return AT_END; |
| 273 | } |
| 274 | |
| 275 | *res_msg = reqmsg; |
| 276 | *res_msglen = sizeof(struct comm_reqmsg); |
| 277 | return AT_CONTINUE; |
| 278 | |
| 279 | } |
| 280 | int ext_sendbuf_rsp(void *rsp_msg, void**ret, int *retlen) |
| 281 | { |
| 282 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 283 | char *at_str = NULL; |
| 284 | |
| 285 | if (msg->ret < 0) { |
| 286 | at_str = malloc(32); |
| 287 | assert(at_str); |
| 288 | memset(at_str, 0x00, 32); |
| 289 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 290 | } else { |
| 291 | at_str = malloc(64); |
| 292 | assert(at_str); |
| 293 | memset(at_str, 0x00, 64); |
| 294 | sprintf(at_str, "\r\n$MYNETWRITE: %d,%d\r\n", msg->socketid, msg->len); |
| 295 | } |
| 296 | *ret = at_str; |
| 297 | *retlen = strlen(at_str); |
| 298 | return AT_END; |
| 299 | } |
| 300 | |
| 301 | int ext_netwrite_rsp(void *rsp_msg, void**ret, int *retlen) |
| 302 | { |
| 303 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 304 | char *at_str = NULL; |
| 305 | |
| 306 | at_str = malloc(32); |
| 307 | assert(at_str); |
| 308 | memset(at_str, 0x00, 32); |
| 309 | |
| 310 | if (msg->ret < 0) { |
| 311 | sprintf(at_str, "\r\nERROR:%d\r\n", msg->err); |
| 312 | } else { |
| 313 | sprintf(at_str, "\r\nOK\r\n"); |
| 314 | } |
| 315 | *ret = at_str; |
| 316 | *retlen = strlen(at_str); |
| 317 | return AT_END; |
| 318 | |
| 319 | } |
| 320 | |
| 321 | int ext_netclose_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 322 | { |
| 323 | struct comm_reqmsg *reqmsg = malloc(sizeof(struct comm_reqmsg)); |
| 324 | assert(reqmsg); |
| 325 | char *at_str = NULL; |
| 326 | char *p[1] = {&reqmsg->socketid}; |
| 327 | memset(reqmsg, 0x00, sizeof(struct comm_reqmsg)); |
| 328 | if(1 != parse_param2("%d", at_paras, p)){ |
| 329 | free(reqmsg); |
| 330 | at_str = malloc(32); |
| 331 | assert(at_str); |
| 332 | memset(at_str, 0x00, 32); |
| 333 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 334 | *res_msg = at_str; |
| 335 | *res_msglen = strlen(at_str); |
| 336 | return AT_END; |
| 337 | } |
| 338 | |
| 339 | *res_msg = reqmsg; |
| 340 | *res_msglen = sizeof(struct comm_reqmsg); |
| 341 | return AT_CONTINUE; |
| 342 | |
| 343 | } |
| 344 | int ext_netclose_rsp(void *rsp_msg, void**ret, int *retlen) |
| 345 | { |
| 346 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 347 | char *at_str = NULL; |
| 348 | |
| 349 | if (msg->ret < 0) { |
| 350 | at_str = malloc(32); |
| 351 | assert(at_str); |
| 352 | memset(at_str, 0x00, 32); |
| 353 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 354 | } else { |
| 355 | at_str = malloc(64); |
| 356 | assert(at_str); |
| 357 | memset(at_str, 0x00, 64); |
| 358 | sprintf(at_str, "\r\n$MYNETCLOSE: %d\r\n\r\nOK\r\n", msg->socketid); |
| 359 | } |
| 360 | *ret = at_str; |
| 361 | *retlen = strlen(at_str); |
| 362 | return AT_END; |
| 363 | } |
| 364 | /* |
| 365 | at+mynetping="192.168.30.201",5,40 |
| 366 | */ |
| 367 | int ext_netping_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 368 | { |
| 369 | struct netping_reqmsg *ping = malloc(sizeof(struct netping_reqmsg)); |
| 370 | assert(ping); |
| 371 | char *p[3] = {&ping->remote_ip, &ping->try_count, &ping->packet_size}; |
| 372 | memset(ping, 0x00, sizeof(struct netping_reqmsg)); |
| 373 | parse_param2("%s,%d,%d", at_paras, p); |
| 374 | ping->try_count = ping->try_count == 0 ? 4 : ping->try_count; |
| 375 | ping->packet_size = ping->packet_size == 0 ? 32 : ping->packet_size; |
| 376 | *res_msg = ping; |
| 377 | *res_msglen = sizeof(struct netping_reqmsg); |
| 378 | return AT_CONTINUE; |
| 379 | } |
| 380 | int ext_netping_rsp(void *rsp_msg, void**ret, int *retlen) |
| 381 | { |
| 382 | struct netping_rspmsg *msg = (struct netping_rspmsg*)rsp_msg; |
| 383 | char *at_str = NULL; |
| 384 | |
| 385 | if (msg->ret < 0) { |
| 386 | at_str = malloc(32); |
| 387 | assert(at_str); |
| 388 | memset(at_str, 0x00, 32); |
| 389 | sprintf(at_str, "\r\nERROR:%d\r\n", msg->err); |
| 390 | } else { |
| 391 | at_str = malloc(64); |
| 392 | assert(at_str); |
| 393 | memset(at_str, 0x00, 64); |
| 394 | snprintf(at_str, 64,"\r\n$MYNETPING:%d,%d,\"%s\"\r\n", |
| 395 | msg->total_recv, msg->echo_rep_ttl, msg->round_trip_sta); |
| 396 | } |
| 397 | *ret = at_str; |
| 398 | *retlen = strlen(at_str); |
| 399 | return AT_END; |
| 400 | } |
| 401 | int ext_netaccept_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 402 | { |
| 403 | struct netaccept_reqmsg *reqmsg = malloc(sizeof(struct netaccept_reqmsg)); |
| 404 | assert(reqmsg); |
| 405 | char *at_str = NULL; |
| 406 | memset(reqmsg, 0x00, sizeof(struct netaccept_reqmsg)); |
| 407 | char *p[3] = {&reqmsg->socketid, &reqmsg->action, &reqmsg->transportMode}; |
| 408 | char *p1[2] = {&reqmsg->socketid, &reqmsg->action}; |
| 409 | if (g_customer_type == CUSTOMER_GUODIAN){ |
| 410 | if(3 != parse_param2("%d,%d,%d", at_paras, p)){ |
| 411 | free(reqmsg); |
| 412 | at_str = malloc(32); |
| 413 | assert(at_str); |
| 414 | memset(at_str, 0x00, 32); |
| 415 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 416 | *res_msg = at_str; |
| 417 | *res_msglen = strlen(at_str); |
| 418 | return AT_END; |
| 419 | } |
| 420 | } |
| 421 | else if (g_customer_type == CUSTOMER_NANDIAN){ |
| 422 | if(2 != parse_param2("%d,%d", at_paras, p1)){ |
| 423 | free(reqmsg); |
| 424 | at_str = malloc(32); |
| 425 | assert(at_str); |
| 426 | memset(at_str, 0x00, 32); |
| 427 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 428 | *res_msg = at_str; |
| 429 | *res_msglen = strlen(at_str); |
| 430 | return AT_END; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | *res_msg = reqmsg; |
| 435 | *res_msglen = sizeof(struct netaccept_reqmsg); |
| 436 | return AT_CONTINUE; |
| 437 | |
| 438 | } |
| 439 | int ext_netaccept_rsp(void *rsp_msg, void**ret, int *retlen) |
| 440 | { |
| 441 | struct netaccept_rspmsg *msg = (struct netaccept_rspmsg*)rsp_msg; |
| 442 | char *at_str = NULL; |
| 443 | |
| 444 | if (msg->ret < 0) { |
| 445 | at_str = malloc(32); |
| 446 | assert(at_str); |
| 447 | memset(at_str, 0x00, 32); |
| 448 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 449 | } else { |
| 450 | at_str = malloc(32); |
| 451 | assert(at_str); |
| 452 | memset(at_str, 0x00, 32); |
| 453 | if (msg->transportMode == NON_TRANSPARENT_MODE) { |
| 454 | sprintf(at_str, "\r\nOK\r\n"); |
| 455 | } else { |
| 456 | sprintf(at_str, "\r\nCONNECT\r\n"); |
| 457 | } |
| 458 | } |
| 459 | *ret = at_str; |
| 460 | *retlen = strlen(at_str); |
| 461 | return AT_END; |
| 462 | } |
| 463 | int ext_netcreate_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 464 | { |
| 465 | struct netcreate_msg *netcreate = malloc(sizeof(struct netcreate_msg)); |
| 466 | assert(netcreate); |
| 467 | char *at_str = NULL; |
| 468 | char *p[6] = {&netcreate->ch_id, &netcreate->mode, &netcreate->socketid, netcreate->remote_ip, &netcreate->remote_port, &netcreate->local_port}; |
| 469 | memset(netcreate, 0x00, sizeof(struct netcreate_msg)); |
| 470 | if(5 > parse_param2("%d,%d,%d,%s,%d,%d", at_paras, p)){ |
| 471 | free(netcreate); |
| 472 | at_str = malloc(32); |
| 473 | assert(at_str); |
| 474 | memset(at_str, 0x00, 32); |
| 475 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 476 | *res_msg = at_str; |
| 477 | *res_msglen = strlen(at_str); |
| 478 | return AT_END; |
| 479 | } |
| 480 | *res_msg = netcreate; |
| 481 | *res_msglen = sizeof(struct netcreate_msg); |
| 482 | return AT_CONTINUE; |
| 483 | } |
| 484 | int ext_netcreate_rsp(void *rsp_msg, void**ret, int *retlen) |
| 485 | { |
| 486 | struct netcreate_rspmsg *msg = (struct netcreate_rspmsg*)rsp_msg; |
| 487 | char *at_str = malloc(64); |
| 488 | assert(at_str); |
| 489 | char param[10] = {0}; |
| 490 | int offset = 0; |
| 491 | |
| 492 | memset(at_str, 0x00, 64); |
| 493 | |
| 494 | if (msg->ret < 0) { |
| 495 | sprintf(at_str, "\r\nERROR:%d\r\n", msg->err); |
| 496 | } else { |
| 497 | if (msg->mode == CONN_TYPE_TCP_S) { |
| 498 | sprintf(at_str, "\r\nOK\r\n"); |
| 499 | } else { |
| 500 | sprintf(at_str, "\r\nCONNECT\r\n"); |
| 501 | } |
| 502 | } |
| 503 | *ret = at_str; |
| 504 | *retlen = strlen(at_str); |
| 505 | return AT_END; |
| 506 | |
| 507 | } |
| 508 | |
| 509 | int ext_neturc_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 510 | { |
| 511 | struct neturc_reqmsg *reqmsg = malloc(sizeof(struct neturc_reqmsg)); |
| 512 | assert(reqmsg); |
| 513 | char *at_str = NULL; |
| 514 | memset(reqmsg, 0x00, sizeof(struct neturc_reqmsg)); |
| 515 | char *p[1] = {&reqmsg->on_off}; |
| 516 | if(1 != parse_param2("%d", at_paras, p)){ |
| 517 | free(reqmsg); |
| 518 | at_str = malloc(32); |
| 519 | assert(at_str); |
| 520 | memset(at_str, 0x00, 32); |
| 521 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 522 | *res_msg = at_str; |
| 523 | *res_msglen = strlen(at_str); |
| 524 | return AT_END; |
| 525 | } |
| 526 | |
| 527 | *res_msg = reqmsg; |
| 528 | *res_msglen = sizeof(struct neturc_reqmsg); |
| 529 | return AT_CONTINUE; |
| 530 | |
| 531 | } |
| 532 | int ext_neturc_rsp(void *rsp_msg, void**ret, int *retlen) |
| 533 | { |
| 534 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 535 | char *at_str = NULL; |
| 536 | |
| 537 | at_str = malloc(32); |
| 538 | assert(at_str); |
| 539 | memset(at_str, 0x00, 32); |
| 540 | if (msg->ret < 0) { |
| 541 | sprintf(at_str, "\r\nERROR\r\n"); |
| 542 | } else { |
| 543 | sprintf(at_str, "\r\nOK\r\n"); |
| 544 | } |
| 545 | *ret = at_str; |
| 546 | *retlen = strlen(at_str); |
| 547 | return AT_END; |
| 548 | } |
| 549 | int ext_ipfilter_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 550 | { |
| 551 | struct ipfilter_reqmsg *reqmsg = malloc(sizeof(struct ipfilter_reqmsg)); |
| 552 | assert(reqmsg); |
| 553 | char *at_str = NULL; |
| 554 | memset(reqmsg, 0x00, sizeof(struct ipfilter_reqmsg)); |
| 555 | char *p[4] = {&reqmsg->id, &reqmsg->action, reqmsg->ip_address, reqmsg->net_mask}; |
| 556 | if(2 > parse_param2("%d,%d,%s,%s", at_paras, p)){ |
| 557 | free(reqmsg); |
| 558 | at_str = malloc(32); |
| 559 | assert(at_str); |
| 560 | memset(at_str, 0x00, 32); |
| 561 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 562 | *res_msg = at_str; |
| 563 | *res_msglen = strlen(at_str); |
| 564 | return AT_END; |
| 565 | } |
| 566 | //ipfilter = *reqmsg; |
| 567 | *res_msg = reqmsg; |
| 568 | *res_msglen = sizeof(struct ipfilter_reqmsg); |
| 569 | return AT_CONTINUE; |
| 570 | |
| 571 | } |
| 572 | int ext_ipfilter_rsp(void *rsp_msg, void**ret, int *retlen) |
| 573 | { |
| 574 | struct comm_rspmsg *msg = (struct comm_rspmsg*)rsp_msg; |
| 575 | char *at_str = NULL; |
| 576 | |
| 577 | at_str = malloc(32); |
| 578 | assert(at_str); |
| 579 | memset(at_str, 0x00, 32); |
| 580 | if (msg->ret < 0) { |
| 581 | sprintf(at_str, "\r\nERROR: %d\r\n", msg->err); |
| 582 | } else { |
| 583 | sprintf(at_str, "\r\nOK\r\n"); |
| 584 | } |
| 585 | *ret = at_str; |
| 586 | *retlen = strlen(at_str); |
| 587 | return AT_END; |
| 588 | } |
| 589 | int ext_netack_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 590 | { |
| 591 | struct comm_reqmsg *reqmsg = malloc(sizeof(struct comm_reqmsg)); |
| 592 | assert(reqmsg); |
| 593 | char *at_str = NULL; |
| 594 | memset(reqmsg, 0x00, sizeof(struct comm_reqmsg)); |
| 595 | char *p[1] = {&reqmsg->socketid}; |
| 596 | if(1 != parse_param2("%d", at_paras, p)){ |
| 597 | free(reqmsg); |
| 598 | at_str = malloc(32); |
| 599 | assert(at_str); |
| 600 | memset(at_str, 0x00, 32); |
| 601 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 602 | *res_msg = at_str; |
| 603 | *res_msglen = strlen(at_str); |
| 604 | return AT_END; |
| 605 | } |
| 606 | |
| 607 | *res_msg = reqmsg; |
| 608 | *res_msglen = sizeof(struct comm_reqmsg); |
| 609 | return AT_CONTINUE; |
| 610 | |
| 611 | } |
| 612 | int ext_netack_rsp(void *rsp_msg, void**ret, int *retlen) |
| 613 | { |
| 614 | struct netack_rspmsg *msg = (struct netack_rspmsg*)rsp_msg; |
| 615 | char *at_str = NULL; |
| 616 | |
| 617 | at_str = malloc(32); |
| 618 | assert(at_str); |
| 619 | memset(at_str, 0x00, 32); |
| 620 | |
| 621 | if (msg->ret < 0) { |
| 622 | snprintf(at_str, 32,"\r\nERROR: %d\r\n", msg->err); |
| 623 | } else { |
| 624 | snprintf(at_str, 32,"\r\n$MYNETACK: %d,%d,%d\r\n\r\nOK\r\n", msg->socketid, msg->unacked_datalen, msg->rest_bufferlen); |
| 625 | } |
| 626 | |
| 627 | *ret = at_str; |
| 628 | *retlen = strlen(at_str); |
| 629 | return AT_END; |
| 630 | } |
| 631 | int ext_type_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 632 | { |
| 633 | *res_msg = NULL; |
| 634 | *res_msglen = 0; |
| 635 | return AT_CONTINUE; |
| 636 | |
| 637 | } |
| 638 | int ext_type_rsp(void *rsp_msg, void**ret, int *retlen) |
| 639 | { |
| 640 | struct type_rspmsg *msg = (struct type_rspmsg*)rsp_msg; |
| 641 | char *at_str = NULL; |
| 642 | |
| 643 | at_str = malloc(32); |
| 644 | assert(at_str); |
| 645 | memset(at_str, 0x00, 32); |
| 646 | if (g_customer_type == CUSTOMER_GUODIAN) |
| 647 | snprintf(at_str, 32,"\r\n$MYTYPE:%.2x,%.2x,%.2x\r\n\r\nOK\r\n", msg->mode, msg->network_type, msg->extended_feature); |
| 648 | else if (g_customer_type == CUSTOMER_NANDIAN) |
| 649 | snprintf(at_str, 32,"\r\n$MYMODEM: %.2x,%.4x\r\n\r\nOK\r\n", msg->mode, msg->network_type); |
| 650 | *ret = at_str; |
| 651 | *retlen = strlen(at_str); |
| 652 | return AT_END; |
| 653 | } |
| 654 | int ext_netact_query_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 655 | { |
| 656 | *res_msg = NULL; |
| 657 | *res_msglen = 0; |
| 658 | return AT_CONTINUE; |
| 659 | |
| 660 | } |
| 661 | |
| 662 | int ext_netact_query_rsp(void *rsp_msg, void**ret, int *retlen) |
| 663 | { |
| 664 | struct netact_query_rspmsg *msg = (struct netact_query_rspmsg*)rsp_msg; |
| 665 | char *at_str = NULL; |
| 666 | |
| 667 | at_str = malloc(64); |
| 668 | assert(at_str); |
| 669 | memset(at_str, 0x00, 64); |
| 670 | |
| 671 | snprintf(at_str, 64,"\r\n$MYNETACT: %d,%d,\"%s\"\r\n\r\nOK\r\n", msg->channel, msg->status, msg->ip); |
| 672 | |
| 673 | *ret = at_str; |
| 674 | *retlen = strlen(at_str); |
| 675 | return AT_END; |
| 676 | } |
| 677 | |
| 678 | int ext_netact_equal_query_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 679 | { |
| 680 | char *at_str = NULL; |
| 681 | |
| 682 | at_str = malloc(64); |
| 683 | assert(at_str); |
| 684 | memset(at_str, 0, 64); |
| 685 | sprintf((char*)at_str, "\r\n$MYNETACT: (0-1),(0-5)\r\nOK\r\n"); |
| 686 | *res_msg = at_str; |
| 687 | *res_msglen = strlen(*res_msg); |
| 688 | return AT_END; |
| 689 | |
| 690 | } |
| 691 | |
| 692 | int ext_neturc_query_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 693 | { |
| 694 | *res_msg = NULL; |
| 695 | *res_msglen = 0; |
| 696 | return AT_CONTINUE; |
| 697 | |
| 698 | } |
| 699 | int ext_neturc_query_rsp(void *rsp_msg, void**ret, int *retlen) |
| 700 | { |
| 701 | struct neturc_query_rspmsg *msg = (struct neturc_query_rspmsg*)rsp_msg; |
| 702 | char *at_str = NULL; |
| 703 | |
| 704 | at_str = malloc(32); |
| 705 | assert(at_str); |
| 706 | memset(at_str, 0x00, 32); |
| 707 | |
| 708 | sprintf(at_str, "\r\n$MYNETURC: %d\r\nOK\r\n", msg->on_off); |
| 709 | |
| 710 | *ret = at_str; |
| 711 | *retlen = strlen(at_str); |
| 712 | return AT_END; |
| 713 | } |
| 714 | int ext_ipfilter_query_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 715 | { |
| 716 | *res_msg = NULL; |
| 717 | *res_msglen = 0; |
| 718 | return AT_CONTINUE; |
| 719 | |
| 720 | } |
| 721 | int ext_ipfilter_query_rsp(void *rsp_msg, void**ret, int *retlen) |
| 722 | { |
| 723 | struct ipfilter_query_rspmsg *msg = (struct ipfilter_query_rspmsg*)rsp_msg; |
| 724 | char *at_str = NULL; |
| 725 | int i,j = 0; |
| 726 | int offset = 0; |
| 727 | |
| 728 | at_str = malloc(32 + IP_FILTER_NUM*sizeof(struct ipfilter_query_rspmsg)); |
| 729 | assert(at_str); |
| 730 | memset(at_str, 0x00, 32 + IP_FILTER_NUM*sizeof(struct ipfilter_query_rspmsg)); |
| 731 | |
| 732 | for (i = 0; i < IP_FILTER_NUM; i++) { |
| 733 | for(j = 0; j < msg->num; j++) { |
| 734 | if(i == msg->ipfilter_info[j].id){ |
| 735 | break; |
| 736 | } |
| 737 | } |
| 738 | if(j == msg->num){ |
| 739 | offset += sprintf(at_str + offset, "\r\n$MYIPFILTER: %d,\"\",\"\"", i); |
| 740 | }else{ |
| 741 | offset += sprintf(at_str + offset, "\r\n$MYIPFILTER: %d,\"%s\",\"%s\"", msg->ipfilter_info[j].id, msg->ipfilter_info[j].ip_address, msg->ipfilter_info[j].net_mask); |
| 742 | } |
| 743 | } |
| 744 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 745 | |
| 746 | *ret = at_str; |
| 747 | *retlen = offset; |
| 748 | return AT_END; |
| 749 | } |
| 750 | int ext_netsrv_query_rsp(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 751 | { |
| 752 | char *at_str = NULL; |
| 753 | int offset = 0; |
| 754 | |
| 755 | at_str = malloc(32 + sizeof(netsrv)); |
| 756 | assert(at_str); |
| 757 | memset(at_str, 0, 32 + sizeof(netsrv)); |
| 758 | offset += snprintf(at_str, 32 + sizeof(netsrv),"\r\n$MYNETSRV: %d,%d,%d,%d,\"%s\"", netsrv.ch_id, netsrv.socketid, netsrv.conn_type, netsrv.viewMode, netsrv.ipport); |
| 759 | offset += snprintf(at_str + offset,32 + sizeof(netsrv)-offset, "\r\nOK\r\n"); |
| 760 | *res_msg = at_str; |
| 761 | *res_msglen = offset; |
| 762 | return AT_END; |
| 763 | |
| 764 | } |
| 765 | int ext_ipfilter_equal_query_rsp(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 766 | { |
| 767 | char *at_str = NULL; |
| 768 | int offset = 0; |
| 769 | |
| 770 | at_str = malloc(64); |
| 771 | assert(at_str); |
| 772 | memset(at_str, 0, 64); |
| 773 | offset += sprintf(at_str, "\r\n$MYIPFILTER: (0-4),(0-2),\"\",\"\""); |
| 774 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 775 | *res_msg = at_str; |
| 776 | *res_msglen = offset; |
| 777 | return AT_END; |
| 778 | |
| 779 | } |
| 780 | int ext_netopen_query_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 781 | { |
| 782 | *res_msg = NULL; |
| 783 | *res_msglen = 0; |
| 784 | return AT_CONTINUE; |
| 785 | |
| 786 | } |
| 787 | int ext_netopen_query_rsp(void *rsp_msg, void**ret, int *retlen) |
| 788 | { |
| 789 | struct netopen_query_rspmsg *msg = (struct netopen_query_rspmsg*)rsp_msg; |
| 790 | char *at_str = NULL; |
| 791 | |
| 792 | if (msg->ret == -1) { |
| 793 | at_str = malloc(32); |
| 794 | assert(at_str); |
| 795 | memset(at_str, 0x00, 32); |
| 796 | sprintf(at_str, "\r\nERROR\r\n"); |
| 797 | } else { |
| 798 | at_str = malloc(32 + sizeof(struct netopen_query_rspmsg)); |
| 799 | assert(at_str); |
| 800 | memset(at_str, 0x00, 32 + sizeof(struct netopen_query_rspmsg)); |
| 801 | |
| 802 | snprintf(at_str,32 + sizeof(struct netopen_query_rspmsg), "\r\n$MYNETOPEN: %d,\"%s\",%d,\"%s\",\"%s\",\"%s\",%d,\"%s\",%d\r\nOK\r\n", |
| 803 | msg->socket_id, msg->local_ip, msg->local_port, msg->gate, msg->dns1, msg->dns2, msg->type, msg->dest_ip, msg->dest_prot); |
| 804 | } |
| 805 | *ret = at_str; |
| 806 | *retlen = strlen(at_str); |
| 807 | return AT_END; |
| 808 | } |
| 809 | int ext_ok_rsp(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 810 | { |
| 811 | char *at_str = NULL; |
| 812 | |
| 813 | at_str = malloc(32); |
| 814 | assert(at_str); |
| 815 | memset(at_str, 0, 32); |
| 816 | sprintf((char*)at_str, "\r\nOK\r\n"); |
| 817 | *res_msg = at_str; |
| 818 | *res_msglen = strlen(*res_msg); |
| 819 | return AT_END; |
| 820 | |
| 821 | } |
| 822 | |
| 823 | char * csq_format(char *at_str) |
| 824 | { |
| 825 | int rssi = 0, ber = 0, act = 0; |
| 826 | char *at_new = malloc(strlen(at_str) + 1); |
| 827 | assert(at_new); |
| 828 | void *p[3] = {&rssi, &ber, &act}; |
| 829 | char str_tmp[64] = {0}; |
| 830 | char *pchrstart = NULL; |
| 831 | |
| 832 | pchrstart = at_str + 1; |
| 833 | |
| 834 | char *pchrend = strstr(pchrstart, "\r\n"); |
| 835 | if(pchrend && (pchrend - pchrstart) < sizeof(str_tmp)) |
| 836 | snprintf(str_tmp,(pchrend - pchrstart)+1, "%s",pchrstart); |
| 837 | //strncpy(str_tmp, pchrstart, (int)(pchrend - pchrstart)); |
| 838 | |
| 839 | //if (at_new == NULL) |
| 840 | // softap_assert(""); |
| 841 | |
| 842 | parse_param2("%d,%d,%d", str_tmp, p); |
| 843 | |
| 844 | if (act == 5 || act == 15) { //W TD |
| 845 | if (rssi == 199) { |
| 846 | rssi = rssi - 100; |
| 847 | } else { |
| 848 | rssi = floor((((rssi - 100 - 116) * (100.0 / 91.0) + 127.4) * 31) / 100 + 0.1); |
| 849 | } |
| 850 | } else if (act == 17) { //LTE |
| 851 | if (rssi == 199) { |
| 852 | rssi = rssi - 100; |
| 853 | } else { |
| 854 | rssi = floor((((rssi - 100 - 141) * (100.0 / 97.0) + 145.3) * 31) / 100 + 0.1); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | |
| 859 | memset(at_new, 0, strlen(at_str) + 1); |
| 860 | sprintf(at_new, ": %ld,%ld", rssi, ber); |
| 861 | printf("csq_format at_new = %s\n", at_new); |
| 862 | return at_new; |
| 863 | } |
| 864 | |
| 865 | char * xreg_format(char *at_str) |
| 866 | { |
| 867 | char *at_new = malloc(strlen(at_str) + 1); |
| 868 | assert(at_new); |
| 869 | char str_tmp[64] = {0}; |
| 870 | char *pchrstart = NULL; |
| 871 | int offset = 0; |
| 872 | |
| 873 | //if (at_new == NULL) |
| 874 | // softap_assert(""); |
| 875 | memset(at_new, 0, strlen(at_str) + 1); |
| 876 | |
| 877 | pchrstart = at_str + 2; |
| 878 | char *pchrend = strstr(pchrstart, "\r\n"); |
| 879 | if (pchrend == NULL){ |
| 880 | softap_assert(""); |
| 881 | return at_new; |
| 882 | } |
| 883 | if (strstr(pchrstart, "OK") == NULL) { |
| 884 | memcpy(at_new, at_str, pchrend - at_str); |
| 885 | } else if (strchr(pchrstart, '(') != NULL) { |
| 886 | memcpy(at_new, at_str, pchrend - at_str); |
| 887 | } else { |
| 888 | int n = 0; |
| 889 | int stat = 0; |
| 890 | char cereg_stat[20] = {0}; |
| 891 | |
| 892 | offset += sprintf(at_new, ": %d", 0); |
| 893 | |
| 894 | get_at_cmd_param_int(pchrstart, &n, &pchrstart); |
| 895 | |
| 896 | move_to_next_param(pchrstart, &pchrstart); |
| 897 | |
| 898 | get_at_cmd_param_int(pchrstart, &stat, &pchrstart); |
| 899 | |
| 900 | sc_cfg_get("cereg_stat", cereg_stat, sizeof(cereg_stat)); |
| 901 | if (stat != 1 && stat != 5 && (1 == atoi(cereg_stat) || 5 == atoi(cereg_stat))) { |
| 902 | offset += sprintf(at_new + offset, ",%d", 1); |
| 903 | } else { |
| 904 | offset += sprintf(at_new + offset, ",%d", stat); |
| 905 | } |
| 906 | |
| 907 | //ºóÃæ»¹ÓвÎÊý |
| 908 | if (!is_at_cmd_end(pchrstart)) { |
| 909 | strncpy(at_new + offset, pchrstart - 1, (int)(pchrend - pchrstart + 1)); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | //printf("xreg_format at_new = %s\n", at_new); |
| 914 | return at_new; |
| 915 | } |
| 916 | |
| 917 | char * cgatt_format(char *at_str) |
| 918 | { |
| 919 | char *at_new = malloc(strlen(at_str) + 1); |
| 920 | assert(at_new); |
| 921 | //if (at_new == NULL) |
| 922 | // softap_assert(""); |
| 923 | |
| 924 | memset(at_new, 0, strlen(at_str) + 1); |
| 925 | sprintf(at_new, ": %d", 1); |
| 926 | |
| 927 | printf("cgatt_format at_new = %s\n", at_new); |
| 928 | return at_new; |
| 929 | } |
| 930 | |
| 931 | char * cgsn_format(char *at_str) |
| 932 | { |
| 933 | char *at_new = malloc(strlen(at_str) + 3); |
| 934 | assert(at_new); |
| 935 | char str_tmp[32] = {0}; |
| 936 | char *pchrstart = NULL; |
| 937 | |
| 938 | pchrstart = at_str + 2; |
| 939 | |
| 940 | char *pchrend = strstr(pchrstart, "\r\n"); |
| 941 | if(pchrend && (pchrend - pchrstart) < sizeof(str_tmp)) |
| 942 | snprintf(str_tmp,(pchrend - pchrstart)+1, "%s",pchrstart); |
| 943 | //strncpy(str_tmp, pchrstart, (int)(pchrend - pchrstart)); |
| 944 | //if (at_new == NULL) |
| 945 | // softap_assert(""); |
| 946 | |
| 947 | memset(at_new, 0, strlen(at_str) + 1); |
| 948 | sprintf(at_new, ": \"%s\"", str_tmp); |
| 949 | |
| 950 | printf("cgsn_format at_new = %s\n", at_new); |
| 951 | return at_new; |
| 952 | } |
| 953 | |
| 954 | #ifdef AT_QUECTEL |
| 955 | //========================================================================================================// |
| 956 | //quectel socket·½°¸º¯ÊýʵÏÖÇø |
| 957 | //========================================================================================================// |
| 958 | /* |
| 959 | at+qiopen=1,0,"TCP","192.168.30.201",5100,0,0 |
| 960 | */ |
| 961 | int ext_qiopen_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 962 | { |
| 963 | struct quectel_qiopen_msg *qiopen = malloc(sizeof(struct quectel_qiopen_msg)); |
| 964 | char *p[7] = {&qiopen->context_id, &qiopen->connect_id, qiopen->service_type, qiopen->ip_addr, qiopen->remote_port, qiopen->local_port, qiopen->access_mode}; |
| 965 | memset(qiopen, 0x00, sizeof(struct quectel_qiopen_msg)); |
| 966 | parse_param2("%d,%d,%s,%s,%d,%d,%d", at_paras, p); |
| 967 | *res_msg = qiopen; |
| 968 | *res_msglen = sizeof(struct quectel_qiopen_msg); |
| 969 | return AT_CONTINUE; |
| 970 | } |
| 971 | int ext_qiopen_rsp(void *rsp_msg, void**ret, int *retlen) |
| 972 | { |
| 973 | struct quectel_comm_rspmsg *msg = (struct quectel_comm_rspmsg*)rsp_msg; |
| 974 | char *at_str = malloc(32); |
| 975 | memset(at_str, 0x00, 32); |
| 976 | |
| 977 | if (msg->access_mode == BUFFER_ACCESS_MODE || msg->access_mode == DIRECT_PUSH_MODE) { |
| 978 | sprintf(at_str, "\r\nOK\r\n+QIOPEN: %d,%d\r\n", msg->connect_id, msg->err); |
| 979 | } else if (msg->access_mode == TRANSPARENT_ACCESS_MODE) { |
| 980 | if (msg->ret < 0) { |
| 981 | sprintf(at_str, "\r\nERROR\r\n"); |
| 982 | } else { |
| 983 | sprintf(at_str, "\r\nCONNECT\r\n"); |
| 984 | } |
| 985 | } |
| 986 | *ret = at_str; |
| 987 | *retlen = strlen(at_str); |
| 988 | return AT_END; |
| 989 | } |
| 990 | int ext_qiclose_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 991 | { |
| 992 | struct quectel_qiclose_reqmsg *reqmsg = malloc(sizeof(struct quectel_qiclose_reqmsg)); |
| 993 | char *p[2] = {&reqmsg->connect_id, &reqmsg->timeout}; |
| 994 | memset(reqmsg, 0x00, sizeof(struct quectel_qiclose_reqmsg)); |
| 995 | parse_param2("%d,%d", at_paras, p); |
| 996 | |
| 997 | *res_msg = reqmsg; |
| 998 | *res_msglen = sizeof(struct quectel_qiclose_reqmsg); |
| 999 | return AT_CONTINUE; |
| 1000 | } |
| 1001 | int ext_qiclose_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1002 | { |
| 1003 | struct quectel_comm_rspmsg *msg = (struct quectel_comm_rspmsg*)rsp_msg; |
| 1004 | char *at_str = malloc(32); |
| 1005 | memset(at_str, 0x00, 32); |
| 1006 | |
| 1007 | if (msg->ret < 0) { |
| 1008 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1009 | } else { |
| 1010 | sprintf(at_str, "\r\nOK\r\n"); |
| 1011 | } |
| 1012 | *ret = at_str; |
| 1013 | *retlen = strlen(at_str); |
| 1014 | return AT_END; |
| 1015 | |
| 1016 | } |
| 1017 | int ext_qistate_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1018 | { |
| 1019 | struct quectel_qistate_reqmsg *reqmsg = malloc(sizeof(struct quectel_qistate_reqmsg)); |
| 1020 | char *p[2] = {&reqmsg->query_type, &reqmsg->query_id}; |
| 1021 | memset(reqmsg, 0x00, sizeof(struct quectel_qistate_reqmsg)); |
| 1022 | parse_param2("%d,%d", at_paras, p); |
| 1023 | |
| 1024 | *res_msg = reqmsg; |
| 1025 | *res_msglen = sizeof(struct quectel_qistate_reqmsg); |
| 1026 | return AT_CONTINUE; |
| 1027 | |
| 1028 | } |
| 1029 | int ext_qistate_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1030 | { |
| 1031 | struct quectel_qistate_rspmsg *msg = (struct quectel_qistate_rspmsg*)rsp_msg; |
| 1032 | char *at_str = NULL; |
| 1033 | int offset = 0; |
| 1034 | int i = 0; |
| 1035 | |
| 1036 | if (msg->num == 0) { |
| 1037 | at_str = malloc(32); |
| 1038 | memset(at_str, 0x00, 32); |
| 1039 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1040 | offset = strlen(at_str); |
| 1041 | } else if (msg->query_type == QUERY_CONNECTION_STATUS_BY_CONNECTID) { |
| 1042 | at_str = malloc(64 + sizeof(struct quectel_sock_info)); |
| 1043 | memset(at_str, 0x00, 64 + sizeof(struct quectel_sock_info)); |
| 1044 | offset += sprintf(at_str, "\r\n+QISTATE:\n"); |
| 1045 | offset += sprintf(at_str + offset, "%d,%d,%s,%d,%d,%d,%d,%d,%d,%d\r\n", |
| 1046 | msg->query_status_info[0].connect_id, |
| 1047 | msg->query_status_info[0].service_type, |
| 1048 | msg->query_status_info[0].ip_addr, |
| 1049 | msg->query_status_info[0].remote_port, |
| 1050 | msg->query_status_info[0].local_port, |
| 1051 | msg->query_status_info[0].socket_state, |
| 1052 | msg->query_status_info[0].context_id, |
| 1053 | msg->query_status_info[0].server_id, |
| 1054 | msg->query_status_info[0].access_mode, |
| 1055 | msg->query_status_info[0].at_port); |
| 1056 | } else { |
| 1057 | at_str = malloc(64 + msg->num * sizeof(struct quectel_sock_info)); |
| 1058 | memset(at_str, 0x00, 64 + msg->num * sizeof(struct quectel_sock_info)); |
| 1059 | offset += sprintf(at_str, "\r\nList of(+QISTATE:\n"); |
| 1060 | for (i = 0; i < msg->num; i++) { |
| 1061 | offset += sprintf(at_str + offset, "%d,%d,%s,%d,%d,%d,%d,%d,%d,%d\r\n", |
| 1062 | msg->query_status_info[i].connect_id, |
| 1063 | msg->query_status_info[i].service_type, |
| 1064 | msg->query_status_info[i].ip_addr, |
| 1065 | msg->query_status_info[i].remote_port, |
| 1066 | msg->query_status_info[i].local_port, |
| 1067 | msg->query_status_info[i].socket_state, |
| 1068 | msg->query_status_info[i].context_id, |
| 1069 | msg->query_status_info[i].server_id, |
| 1070 | msg->query_status_info[i].access_mode, |
| 1071 | msg->query_status_info[i].at_port); |
| 1072 | } |
| 1073 | offset += sprintf(at_str + offset, ")\n"); |
| 1074 | } |
| 1075 | *ret = at_str; |
| 1076 | *retlen = offset; |
| 1077 | return AT_END; |
| 1078 | |
| 1079 | } |
| 1080 | int ext_qisend_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1081 | { |
| 1082 | int ret = 0; |
| 1083 | struct quectel_qisend_reqmsg *reqmsg = malloc(sizeof(struct quectel_qisend_reqmsg)); |
| 1084 | char *p[4] = {&reqmsg->connect_id, &reqmsg->len, reqmsg->ip_addr, &reqmsg->remote_port}; |
| 1085 | memset(reqmsg, 0x00, sizeof(struct quectel_qisend_reqmsg)); |
| 1086 | ret = parse_param2("%d,%d,%s,%d", at_paras, p); |
| 1087 | if (ret == 1) { |
| 1088 | reqmsg->send_type = CHANGEABLE_LENGTH; |
| 1089 | } else if (ret == 2) { |
| 1090 | if (reqmsg->len == 0) { |
| 1091 | reqmsg->send_type = QUERY_DATA_INFO; |
| 1092 | } else { |
| 1093 | reqmsg->send_type = FIXED_LENGTH; |
| 1094 | } |
| 1095 | } else if (ret == 4) { |
| 1096 | reqmsg->send_type = UDP_DATA; |
| 1097 | } |
| 1098 | |
| 1099 | *res_msg = reqmsg; |
| 1100 | *res_msglen = sizeof(struct quectel_qisend_reqmsg); |
| 1101 | return AT_CONTINUE; |
| 1102 | |
| 1103 | } |
| 1104 | int ext_qisend_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1105 | { |
| 1106 | struct quectel_qisend_rspmsg *msg = (struct quectel_qisend_rspmsg*)rsp_msg; |
| 1107 | char *at_str = NULL; |
| 1108 | int offset = 0; |
| 1109 | |
| 1110 | at_str = malloc(32); |
| 1111 | memset(at_str, 0x00, 32); |
| 1112 | |
| 1113 | if (msg->send_type == QUERY_DATA_INFO) { |
| 1114 | if (msg->ret == CONNECTION_EXIST) { |
| 1115 | offset += sprintf(at_str, "\r\n+QISEND:\n"); |
| 1116 | offset += sprintf(at_str + offset, "%d,%d,%d\r\n", msg->total_send_length, msg->ackedbytes, msg->unackedbytes); |
| 1117 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1118 | } else if (msg->ret == CONNECTION_NOT_EXIST) { |
| 1119 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1120 | } |
| 1121 | } else { |
| 1122 | if (msg->ret == READY_TO_SEND) { |
| 1123 | sprintf(at_str, "\r\nSEND OK\r\n"); |
| 1124 | } else if (msg->ret == SEND_OK) { |
| 1125 | sprintf(at_str, "\r\n"); |
| 1126 | } else if (msg->ret == SEND_FAIL) { |
| 1127 | sprintf(at_str, "\r\nSEND FAIL\r\n"); |
| 1128 | } else if (msg->ret == SEND_ERROR || msg->ret == CONNECTION_NOT_EXIST) { |
| 1129 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1130 | } |
| 1131 | } |
| 1132 | *ret = at_str; |
| 1133 | *retlen = strlen(at_str); |
| 1134 | return AT_END; |
| 1135 | } |
| 1136 | |
| 1137 | int ext_qisendex_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1138 | { |
| 1139 | struct quectel_qisendex_reqmsg *reqmsg = malloc(sizeof(struct quectel_qisendex_reqmsg)); |
| 1140 | char *p[2] = {&reqmsg->connect_id, reqmsg->hex_data}; |
| 1141 | memset(reqmsg, 0x00, sizeof(struct quectel_qisendex_reqmsg)); |
| 1142 | parse_param2("%d,%s", at_paras, p); |
| 1143 | |
| 1144 | *res_msg = reqmsg; |
| 1145 | *res_msglen = sizeof(struct quectel_qisendex_reqmsg); |
| 1146 | return AT_CONTINUE; |
| 1147 | |
| 1148 | } |
| 1149 | int ext_qisendex_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1150 | { |
| 1151 | struct quectel_comm_rspmsg *msg = (struct quectel_comm_rspmsg*)rsp_msg; |
| 1152 | char *at_str = NULL; |
| 1153 | |
| 1154 | at_str = malloc(32); |
| 1155 | memset(at_str, 0x00, 32); |
| 1156 | |
| 1157 | if (msg->ret == SEND_OK) { |
| 1158 | sprintf(at_str, "\r\nSEND OK\r\n"); |
| 1159 | } else if (msg->ret == SEND_FAIL) { |
| 1160 | sprintf(at_str, "\r\nSEND FAIL\r\n"); |
| 1161 | } else if (msg->ret == SEND_ERROR) { |
| 1162 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1163 | } |
| 1164 | *ret = at_str; |
| 1165 | *retlen = strlen(at_str); |
| 1166 | return AT_END; |
| 1167 | |
| 1168 | } |
| 1169 | int ext_qird_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1170 | { |
| 1171 | int ret = 0; |
| 1172 | struct quectel_qird_reqmsg *reqmsg = malloc(sizeof(struct quectel_qird_reqmsg)); |
| 1173 | char *p[2] = {&reqmsg->connect_id, &reqmsg->len}; |
| 1174 | memset(reqmsg, 0x00, sizeof(struct quectel_qird_reqmsg)); |
| 1175 | |
| 1176 | ret = parse_param2("%d,%d", at_paras, p); |
| 1177 | if (ret == 1) { |
| 1178 | reqmsg->read_type = CHANGEABLE_LENGTH; |
| 1179 | } else if (ret == 2) { |
| 1180 | if (reqmsg->len == 0) { |
| 1181 | reqmsg->read_type = QUERY_DATA_INFO; |
| 1182 | } else { |
| 1183 | reqmsg->read_type = FIXED_LENGTH; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | *res_msg = reqmsg; |
| 1188 | *res_msglen = sizeof(struct quectel_qird_reqmsg); |
| 1189 | return AT_CONTINUE; |
| 1190 | |
| 1191 | } |
| 1192 | int ext_qird_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1193 | { |
| 1194 | int offset = 0; |
| 1195 | struct quectel_qird_rspmsg *msg = (struct quectel_qird_rspmsg*)rsp_msg; |
| 1196 | char *at_str = NULL; |
| 1197 | |
| 1198 | if (msg->read_type == QUERY_DATA_INFO) { |
| 1199 | if (msg->ret == CONNECTION_EXIST) { |
| 1200 | at_str = malloc(32); |
| 1201 | memset(at_str, 0x00, 32); |
| 1202 | offset += sprintf(at_str, "\r\n+QIRD:\n"); |
| 1203 | offset += sprintf(at_str + offset, "%d,%d,%d\r\n", msg->total_rcv_length, msg->have_read_length, msg->unread_length); |
| 1204 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1205 | } else if (msg->ret == CONNECTION_NOT_EXIST) { |
| 1206 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1207 | } |
| 1208 | } else { |
| 1209 | if (msg->service_type == TCP || msg->service_type == UDP || msg->service_type == TCP_LISTENER) { |
| 1210 | if (msg->ret == READ_OK) { |
| 1211 | at_str = malloc(32 + msg->read_actual_length); |
| 1212 | memset(at_str, 0x00, 32 + msg->read_actual_length); |
| 1213 | offset += sprintf(at_str, "\r\n+QIRD:%d\r\n", msg->read_actual_length); |
| 1214 | memcpy(at_str + offset, msg->data, msg->read_actual_length); |
| 1215 | offset += msg->read_actual_length; |
| 1216 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1217 | } else if (msg->ret == NODATA_READ) { |
| 1218 | at_str = malloc(32); |
| 1219 | memset(at_str, 0x00, 32); |
| 1220 | offset += sprintf(at_str, "\r\n+QIRD:0\n"); |
| 1221 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1222 | } else if (msg->ret == CONNECTION_NOT_EXIST) { |
| 1223 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1224 | } |
| 1225 | } else if (msg->service_type == UDP_SERVICE) { |
| 1226 | if (msg->ret == READ_OK) { |
| 1227 | at_str = malloc(32 + msg->read_actual_length); |
| 1228 | memset(at_str, 0x00, 32 + msg->read_actual_length); |
| 1229 | offset += sprintf(at_str, "\r\n+QIRD:%d,%s,%d\r\n", msg->read_actual_length, msg->remote_ipaddr, msg->remote_port); |
| 1230 | memcpy(at_str + offset, msg->data, msg->read_actual_length); |
| 1231 | offset += msg->read_actual_length; |
| 1232 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1233 | } else if (msg->ret == NODATA_READ) { |
| 1234 | at_str = malloc(32); |
| 1235 | memset(at_str, 0x00, 32); |
| 1236 | offset += sprintf(at_str, "\r\n+QIRD:0\n"); |
| 1237 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1238 | } else if (msg->ret == CONNECTION_NOT_EXIST) { |
| 1239 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | *ret = at_str; |
| 1244 | *retlen = strlen(at_str); |
| 1245 | return AT_END; |
| 1246 | } |
| 1247 | int ext_qiswtmd_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1248 | { |
| 1249 | struct quectel_qiswtmd_reqmsg *reqmsg = malloc(sizeof(struct quectel_qiswtmd_reqmsg)); |
| 1250 | char *p[2] = {&reqmsg->connect_id, &reqmsg->access_mode}; |
| 1251 | memset(reqmsg, 0x00, sizeof(struct quectel_qiswtmd_reqmsg)); |
| 1252 | parse_param2("%d,%d", at_paras, p); |
| 1253 | *res_msg = reqmsg; |
| 1254 | *res_msglen = sizeof(struct quectel_qiswtmd_reqmsg); |
| 1255 | return AT_CONTINUE; |
| 1256 | } |
| 1257 | int ext_qiswtmd_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1258 | { |
| 1259 | struct quectel_qiswtmd_rspmsg *msg = (struct quectel_qiswtmd_rspmsg*)rsp_msg; |
| 1260 | char *at_str = malloc(32); |
| 1261 | memset(at_str, 0x00, 32); |
| 1262 | |
| 1263 | if (msg->ret == SW_SUCC) { |
| 1264 | if (msg->access_mode == BUFFER_ACCESS_MODE || msg->access_mode == DIRECT_PUSH_MODE) { |
| 1265 | sprintf(at_str, "\r\nOK\r\n"); |
| 1266 | } else if (msg->access_mode == BUFFER_ACCESS_MODE || msg->access_mode == DIRECT_PUSH_MODE) { |
| 1267 | sprintf(at_str, "\r\nCONNECT\r\n"); |
| 1268 | } |
| 1269 | } else if (msg->ret == SW_FAIL) { |
| 1270 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1271 | } |
| 1272 | *ret = at_str; |
| 1273 | *retlen = strlen(at_str); |
| 1274 | return AT_END; |
| 1275 | } |
| 1276 | ext_qidnscfg_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1277 | { |
| 1278 | int ret = 0; |
| 1279 | struct quectel_qidnscfg_reqmsg *reqmsg = malloc(sizeof(struct quectel_qidnscfg_reqmsg)); |
| 1280 | char *p[3] = {&reqmsg->context_id, reqmsg->pri_dns_addr, reqmsg->sec_dns_addr}; |
| 1281 | memset(reqmsg, 0x00, sizeof(struct quectel_qidnscfg_reqmsg)); |
| 1282 | |
| 1283 | ret = parse_param2("%d,%d", at_paras, p); |
| 1284 | if (ret == 1) { |
| 1285 | reqmsg->action_type = DNS_QUERY; |
| 1286 | } else if (ret == 2) { |
| 1287 | reqmsg->action_type = DNS_CFG_NO_SECDNSADDR; |
| 1288 | } else if (ret == 3) { |
| 1289 | reqmsg->action_type = DNS_CFG_WITH_SECDNSADDR; |
| 1290 | } |
| 1291 | |
| 1292 | *res_msg = reqmsg; |
| 1293 | *res_msglen = sizeof(struct quectel_qird_reqmsg); |
| 1294 | return AT_CONTINUE; |
| 1295 | |
| 1296 | } |
| 1297 | int ext_qidnscfg_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1298 | { |
| 1299 | int offset = 0; |
| 1300 | struct quectel_qidnscfg_rspmsg *msg = (struct quectel_qidnscfg_rspmsg*)rsp_msg; |
| 1301 | char *at_str = NULL; |
| 1302 | |
| 1303 | if (msg->action_type == DNS_CFG_WITH_SECDNSADDR || msg->action_type == DNS_CFG_NO_SECDNSADDR) { |
| 1304 | if (msg->ret == DNS_ACTION_SUCC) { |
| 1305 | sprintf(at_str, "\r\nOK\r\n"); |
| 1306 | } else if (msg->ret == DNS_ACTION_FAIL) { |
| 1307 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1308 | } |
| 1309 | } else if (msg->action_type == DNS_QUERY) { |
| 1310 | if (msg->ret == DNS_ACTION_SUCC) { |
| 1311 | at_str = malloc(32 + sizeof(msg->pri_dns_addr) + sizeof(msg->sec_dns_addr)); |
| 1312 | memset(at_str, 0x00, 32 + sizeof(msg->pri_dns_addr) + sizeof(msg->sec_dns_addr)); |
| 1313 | offset += sprintf(at_str, "\r\n+QIDNSCFG:%d,%s,%s\r\n", msg->context_id, msg->pri_dns_addr, msg->sec_dns_addr); |
| 1314 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1315 | } else if (msg->ret == DNS_ACTION_FAIL) { |
| 1316 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1317 | } |
| 1318 | |
| 1319 | } |
| 1320 | *ret = at_str; |
| 1321 | *retlen = strlen(at_str); |
| 1322 | return AT_END; |
| 1323 | } |
| 1324 | ext_qidnsgip_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1325 | { |
| 1326 | int ret = 0; |
| 1327 | struct quectel_qidnsgip_reqmsg *reqmsg = malloc(sizeof(struct quectel_qidnsgip_reqmsg)); |
| 1328 | char *p[2] = {&reqmsg->context_id, reqmsg->host_name}; |
| 1329 | memset(reqmsg, 0x00, sizeof(struct quectel_qidnsgip_reqmsg)); |
| 1330 | |
| 1331 | ret = parse_param2("%d,%s", at_paras, p); |
| 1332 | |
| 1333 | *res_msg = reqmsg; |
| 1334 | *res_msglen = sizeof(struct quectel_qidnsgip_reqmsg); |
| 1335 | return AT_CONTINUE; |
| 1336 | |
| 1337 | } |
| 1338 | int ext_qidnsgip_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1339 | { |
| 1340 | int offset = 0; |
| 1341 | struct quectel_qidnscfg_rspmsg *msg = (struct quectel_qidnscfg_rspmsg*)rsp_msg; |
| 1342 | char *at_str = NULL; |
| 1343 | |
| 1344 | if (msg->action_type == DNS_CFG_WITH_SECDNSADDR || msg->action_type == DNS_CFG_NO_SECDNSADDR) { |
| 1345 | if (msg->ret == DNS_ACTION_SUCC) { |
| 1346 | sprintf(at_str, "\r\nOK\r\n"); |
| 1347 | } else if (msg->ret == DNS_ACTION_FAIL) { |
| 1348 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1349 | } |
| 1350 | } else if (msg->action_type == DNS_QUERY) { |
| 1351 | if (msg->ret == DNS_ACTION_SUCC) { |
| 1352 | at_str = malloc(32 + sizeof(msg->pri_dns_addr) + sizeof(msg->sec_dns_addr)); |
| 1353 | memset(at_str, 0x00, 32 + sizeof(msg->pri_dns_addr) + sizeof(msg->sec_dns_addr)); |
| 1354 | offset += sprintf(at_str, "\r\n+QIDNSCFG:%d,%s,%s\r\n", msg->context_id, msg->pri_dns_addr, msg->sec_dns_addr); |
| 1355 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1356 | } else if (msg->ret == DNS_ACTION_FAIL) { |
| 1357 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1358 | } |
| 1359 | |
| 1360 | } |
| 1361 | *ret = at_str; |
| 1362 | *retlen = strlen(at_str); |
| 1363 | return AT_END; |
| 1364 | } |
| 1365 | int ext_qigeterror_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1366 | { |
| 1367 | *res_msg = NULL; |
| 1368 | *res_msglen = 0; |
| 1369 | return AT_CONTINUE; |
| 1370 | } |
| 1371 | int ext_qigeterror_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1372 | { |
| 1373 | struct quectel_qigeterror_rspmsg *msg = (struct quectel_qigeterror_rspmsg*)rsp_msg; |
| 1374 | int offset = 0; |
| 1375 | char *at_str = malloc(64); |
| 1376 | memset(at_str, 0x00, 64); |
| 1377 | |
| 1378 | offset += sprintf(at_str, "\r\n+QIGETERROR:%d,%s\r\n", msg->err, msg->errcode_description); |
| 1379 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1380 | |
| 1381 | *ret = at_str; |
| 1382 | *retlen = strlen(at_str); |
| 1383 | return AT_END; |
| 1384 | |
| 1385 | } |
| 1386 | int ext_qping_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1387 | { |
| 1388 | struct qping_reqmsg *ping = malloc(sizeof(struct qping_reqmsg)); |
| 1389 | char *p[4] = {&ping->context, ping->remote_ip, &ping->timeout, &ping->ping_num}; |
| 1390 | memset(ping, 0x00, sizeof(struct netping_reqmsg)); |
| 1391 | parse_param2("%d,%s,%d,%d", at_paras, p); |
| 1392 | ping->timeout = ping->timeout == 0 ? 4 : ping->timeout; |
| 1393 | ping->ping_num = ping->ping_num == 0 ? 4 : ping->ping_num; |
| 1394 | *res_msg = ping; |
| 1395 | *res_msglen = sizeof(struct qping_reqmsg); |
| 1396 | return AT_CONTINUE; |
| 1397 | } |
| 1398 | int ext_qping_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1399 | { |
| 1400 | struct qping_rspmsg *msg = (struct qping_rspmsg*)rsp_msg; |
| 1401 | char *at_str = NULL; |
| 1402 | int offset = 0; |
| 1403 | int i = 0; |
| 1404 | |
| 1405 | if (msg->ret < 0) { |
| 1406 | at_str = malloc(32); |
| 1407 | memset(at_str, 0x00, 32); |
| 1408 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1409 | } else { |
| 1410 | at_str = malloc(32 + sizeof(struct qping_rspmsg)); |
| 1411 | memset(at_str, 0x00, 32 + sizeof(struct qping_rspmsg)); |
| 1412 | offset += sprintf(at_str + offset, "\r\nOK\r\n"); |
| 1413 | for (i = 0; i < msg->ping_num; i++) { |
| 1414 | if (msg->each_ping_result[i].result == 0) { |
| 1415 | offset += sprintf(at_str + offset, "\r\n$QPING:\r\n%d,%s,%d,%d,%d\r\n", |
| 1416 | msg->each_ping_result[i].result, |
| 1417 | msg->each_ping_result[i].remote_ip, |
| 1418 | msg->each_ping_result[i].ping_len, |
| 1419 | msg->each_ping_result[i].response_time, |
| 1420 | msg->each_ping_result[i].ttl); |
| 1421 | } else { |
| 1422 | offset += sprintf(at_str + offset, "\r\n$QPING:\r\n%d\r\n", msg->each_ping_result[i].result); |
| 1423 | } |
| 1424 | } |
| 1425 | if (msg->finresult == 0) { |
| 1426 | offset += sprintf(at_str + offset, "\r\n$QPING:\r\n%d,%d,%d,%d,%d,%d,%d\r\n", |
| 1427 | msg->finresult, msg->sent, msg->rcvd, msg->lost, msg->min, msg->max, msg->avg); |
| 1428 | } else { |
| 1429 | offset += sprintf(at_str + offset, "\r\n$QPING:\r\n%d\r\n", msg->finresult); |
| 1430 | } |
| 1431 | |
| 1432 | } |
| 1433 | *ret = at_str; |
| 1434 | *retlen = strlen(at_str); |
| 1435 | return AT_END; |
| 1436 | } |
| 1437 | #endif |
| 1438 | |
| 1439 | /* |
| 1440 | at$MYSOCKETLED=<ONOFF> |
| 1441 | */ |
| 1442 | static int ext_socketled_req(int at_fd, char *at_paras, void ** res_msg, int *res_msglen) |
| 1443 | { |
| 1444 | struct zteftp_socketled_reqmsg *reqmsg = malloc(sizeof(struct zteftp_socketled_reqmsg)); |
| 1445 | assert(reqmsg); |
| 1446 | char *at_str = NULL; |
| 1447 | char *p[1] = {&reqmsg->iswitch}; |
| 1448 | memset(reqmsg, 0x00, sizeof(struct zteftp_socketled_reqmsg)); |
| 1449 | if(1 != parse_param2("%d", at_paras, p)){ |
| 1450 | free(reqmsg); |
| 1451 | at_str = malloc(32); |
| 1452 | assert(at_str); |
| 1453 | memset(at_str, 0x00, 32); |
| 1454 | sprintf(at_str, "\r\nERROR: 980\r\n"); |
| 1455 | *res_msg = at_str; |
| 1456 | *res_msglen = strlen(at_str); |
| 1457 | return AT_END; |
| 1458 | } |
| 1459 | //at_print(AT_NORMAL,"zteftp_socketled_reqmsg %d\n", reqmsg->iswitch); |
| 1460 | *res_msg = reqmsg; |
| 1461 | *res_msglen = sizeof(struct zteftp_socketled_reqmsg); |
| 1462 | return AT_CONTINUE; |
| 1463 | } |
| 1464 | /* |
| 1465 | <CR><LF>OK<CR><LF> |
| 1466 | <CR><LF>ERROR<CR><LF> |
| 1467 | */ |
| 1468 | static int ext_socketled_rsp(void *rsp_msg, void**ret, int *retlen) |
| 1469 | { |
| 1470 | struct zteftp_socketled_rspmsg *rspmsg = (struct zteftp_socketled_rspmsg*)rsp_msg; |
| 1471 | char *at_str = malloc(32); |
| 1472 | assert(at_str); |
| 1473 | memset(at_str, 0x00, 32); |
| 1474 | |
| 1475 | if (rspmsg->result < 0) { |
| 1476 | sprintf(at_str, "\r\nERROR\r\n"); |
| 1477 | } else { |
| 1478 | sprintf(at_str, "\r\nOK\r\n"); |
| 1479 | } |
| 1480 | |
| 1481 | *ret = at_str; |
| 1482 | *retlen = strlen(at_str); |
| 1483 | return AT_END; |
| 1484 | } |
| 1485 | |
| 1486 | int ext_enpwrsave_set_func(char *at_paras, void ** res_msg) |
| 1487 | { |
| 1488 | int enpwrsave = 0; |
| 1489 | void *p[] = {&enpwrsave}; |
| 1490 | int ret = 0; |
| 1491 | char *at_str = NULL; |
| 1492 | at_str = malloc(16); |
| 1493 | assert(at_str); |
| 1494 | memset(at_str,0,16); |
| 1495 | |
| 1496 | ret = parse_param("%d",at_paras, p); |
| 1497 | if(ret != AT_PARSE_OK) |
| 1498 | { |
| 1499 | sprintf(at_str,"\r\nERROR: 980\r\n"); |
| 1500 | *res_msg = at_str; |
| 1501 | return AT_END; |
| 1502 | } |
| 1503 | |
| 1504 | if(0 == enpwrsave) //²»ÔÊÐí½øÈëÐÝÃßģʽ |
| 1505 | { |
| 1506 | set_wake_lock(AP_LOCK); |
| 1507 | g_ap_lock = 0; |
| 1508 | } |
| 1509 | else if(1 == enpwrsave) //ÔÊÐí½øÈëÐÝÃßģʽ |
| 1510 | { |
| 1511 | set_wake_unlock(AP_LOCK); |
| 1512 | g_ap_lock = 1; |
| 1513 | } |
| 1514 | else |
| 1515 | { |
| 1516 | sprintf(at_str,"\r\nERROR: 980\r\n"); |
| 1517 | *res_msg = at_str; |
| 1518 | return AT_END; |
| 1519 | } |
| 1520 | |
| 1521 | sprintf(at_str,"\r\nOK\r\n"); |
| 1522 | *res_msg = at_str; |
| 1523 | return AT_END; |
| 1524 | |
| 1525 | } |
| 1526 | |
| 1527 | int ext_enpwrsave_query_func(char *at_paras, void ** res_msg) |
| 1528 | { |
| 1529 | char *at_str = NULL; |
| 1530 | at_str = malloc(32); |
| 1531 | assert(at_str); |
| 1532 | memset(at_str,0,32); |
| 1533 | |
| 1534 | sprintf(at_str,"\r\n+ENPWRSAVE: %d\r\nOK\r\n",g_ap_lock); |
| 1535 | *res_msg = at_str; |
| 1536 | return AT_END; |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | int ext_socket_regist(void) |
| 1541 | { |
| 1542 | if (g_customer_type == CUSTOMER_GUODIAN) { |
| 1543 | //SOCKET´´½¨¡¢Êý¾ÝÊÕ·¢ |
| 1544 | register_serv_func2("MYNETSRV=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETSRV_REQ, MSG_CMD_NETSRV_RSP, ext_netsrv_req, ext_netsrv_rsp); |
| 1545 | register_serv_func2("MYNETOPEN=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETOPEN_REQ, MSG_CMD_NETOPEN_RSP, ext_netopen_req, ext_netopen_rsp); |
| 1546 | register_serv_func2("MYNETREAD=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETREAD_REQ, MSG_CMD_NETREAD_RSP, ext_netread_req, ext_netread_rsp); |
| 1547 | register_serv_func2("MYNETWRITE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_SENDBUF_REQ, MSG_CMD_SENDBUF_RSP, ext_sendbuf_req, ext_sendbuf_rsp); |
| 1548 | register_serv_func2("MYNETCLOSE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETCLOSE_REQ, MSG_CMD_NETCLOSE_RSP, ext_netclose_req, ext_netclose_rsp); |
| 1549 | register_serv_func2("MYNETPING=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETPING_REQ, MSG_CMD_NETPING_RSP, ext_netping_req, ext_netping_rsp); |
| 1550 | register_serv_func2("MYNETACCEPT=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETACCEPT_REQ, MSG_CMD_NETACCEPT_RSP, ext_netaccept_req, ext_netaccept_rsp); |
| 1551 | register_serv_func2("MYNETCREATE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETCREATE_REQ, MSG_CMD_NETCREATE_RSP, ext_netcreate_req, ext_netcreate_rsp); |
| 1552 | register_serv_func2("MYNETURC=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETURC_REQ, MSG_CMD_NETURC_RSP, ext_neturc_req, ext_neturc_rsp); |
| 1553 | register_serv_func2("MYIPFILTER=", MODULE_ID_SOCKET_PROXY, MSG_CMD_IPFILTER_REQ, MSG_CMD_IPFILTER_RSP, ext_ipfilter_req, ext_ipfilter_rsp); |
| 1554 | register_serv_func2("MYNETACK=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETACK_REQ, MSG_CMD_NETACK_RSP, ext_netack_req, ext_netack_rsp); |
| 1555 | register_serv_func2("MYSOCKETLED=", MODULE_ID_SOCKET_PROXY, MSG_CMD_SOCKETLED_REQ, MSG_CMD_SOCKETLED_RSP, ext_socketled_req, ext_socketled_rsp); |
| 1556 | register_serv_func2("MYTYPE?", MODULE_ID_SOCKET_PROXY, MSG_CMD_TYPE_REQ, MSG_CMD_TYPE_RSP, ext_type_req, ext_type_rsp); |
| 1557 | register_serv_func2("MYNETACT?", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETACT_QUERY_REQ, MSG_CMD_NETACT_QUERY_RSP, ext_netact_query_req, ext_netact_query_rsp); |
| 1558 | register_serv_func2("MYNETURC?", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETURC_QUERY_REQ, MSG_CMD_NETURC_QUERY_RSP, ext_neturc_query_req, ext_neturc_query_rsp); |
| 1559 | register_serv_func2("MYNETACT=?", 0, 0, 0, ext_netact_equal_query_req, NULL); |
| 1560 | register_serv_func2("MYIPFILTER?", MODULE_ID_SOCKET_PROXY, MSG_CMD_IPFILTER_QUERY_REQ, MSG_CMD_IPFILTER_QUERY_RSP, ext_ipfilter_query_req, ext_ipfilter_query_rsp); |
| 1561 | register_serv_func2("MYIPFILTER=?", 0, 0, 0, ext_ipfilter_equal_query_rsp, NULL); |
| 1562 | register_serv_func2("MYNETSRV?", 0, 0, 0, ext_netsrv_query_rsp, NULL); |
| 1563 | register_serv_func2("MYNETSRV=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1564 | register_serv_func2("MYNETOPEN?", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETOPEN_QUERY_REQ, MSG_CMD_NETOPEN_QUERY_RSP, ext_netopen_query_req, ext_netopen_query_rsp); |
| 1565 | register_serv_func2("MYNETOPEN=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1566 | register_serv_func2("MYNETREAD=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1567 | register_serv_func2("MYNETWRITE=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1568 | register_serv_func2("MYNETCLOSE?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1569 | register_serv_func2("MYNETCLOSE=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1570 | register_serv_func2("MYNETACCEPT?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1571 | register_serv_func2("MYNETACCEPT=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1572 | register_serv_func2("MYNETCREATE?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1573 | register_serv_func2("MYNETCREATE=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1574 | register_serv_func("ENPWRSAVE=",0,ext_enpwrsave_set_func); |
| 1575 | register_serv_func("ENPWRSAVE?",0,ext_enpwrsave_query_func); |
| 1576 | |
| 1577 | register_formatInform_func("+CSQ", csq_format); |
| 1578 | register_formatInform_func("+CREG", xreg_format); |
| 1579 | register_formatInform_func("+CGREG", xreg_format); |
| 1580 | register_formatInform_func("+CEREG", xreg_format); |
| 1581 | register_formatInform_func("+CGATT", cgatt_format); |
| 1582 | register_formatInform_func("+CGSN", cgsn_format); |
| 1583 | } else if (g_customer_type == CUSTOMER_NANDIAN) { |
| 1584 | register_serv_func2("MYNETACT?", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETACT_QUERY_REQ, MSG_CMD_NETACT_QUERY_RSP, ext_netact_query_req, ext_netact_query_rsp); |
| 1585 | register_serv_func2("MYNETACT=?", 0, 0, 0, ext_netact_equal_query_req, NULL); |
| 1586 | register_serv_func2("MYIPFILTER=", MODULE_ID_SOCKET_PROXY, MSG_CMD_IPFILTER_REQ, MSG_CMD_IPFILTER_RSP, ext_ipfilter_req, ext_ipfilter_rsp); |
| 1587 | register_serv_func2("MYIPFILTER?", MODULE_ID_SOCKET_PROXY, MSG_CMD_IPFILTER_QUERY_REQ, MSG_CMD_IPFILTER_QUERY_RSP, ext_ipfilter_query_req, ext_ipfilter_query_rsp); |
| 1588 | register_serv_func2("MYIPFILTER=?", 0, 0, 0, ext_ipfilter_equal_query_rsp, NULL); |
| 1589 | register_serv_func2("MYNETSRV=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETSRV_REQ, MSG_CMD_NETSRV_RSP, ext_netsrv_req, ext_netsrv_rsp); |
| 1590 | register_serv_func2("MYNETSRV?", 0, 0, 0, ext_netsrv_query_rsp, NULL); |
| 1591 | register_serv_func2("MYNETSRV=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1592 | register_serv_func2("MYNETOPEN=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETOPEN_REQ, MSG_CMD_NETOPEN_RSP, ext_netopen_req, ext_netopen_rsp); |
| 1593 | register_serv_func2("MYNETOPEN?", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETOPEN_QUERY_REQ, MSG_CMD_NETOPEN_QUERY_RSP, ext_netopen_query_req, ext_netopen_query_rsp); |
| 1594 | register_serv_func2("MYNETOPEN=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1595 | register_serv_func2("MYNETREAD=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETREAD_REQ, MSG_CMD_NETREAD_RSP, ext_netread_req, ext_netread_rsp); |
| 1596 | register_serv_func2("MYNETREAD=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1597 | register_serv_func2("MYNETWRITE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_SENDBUF_REQ, MSG_CMD_SENDBUF_RSP, ext_sendbuf_req, ext_sendbuf_rsp); |
| 1598 | register_serv_func2("MYNETWRITE=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1599 | register_serv_func2("MYNETCLOSE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETCLOSE_REQ, MSG_CMD_NETCLOSE_RSP, ext_netclose_req, ext_netclose_rsp); |
| 1600 | register_serv_func2("MYNETCLOSE?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1601 | register_serv_func2("MYNETCLOSE=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1602 | register_serv_func2("MYNETACK=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETACK_REQ, MSG_CMD_NETACK_RSP, ext_netack_req, ext_netack_rsp); |
| 1603 | register_serv_func2("MYNETACCEPT=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETACCEPT_REQ, MSG_CMD_NETACCEPT_RSP, ext_netaccept_req, ext_netaccept_rsp); |
| 1604 | register_serv_func2("MYNETACCEPT?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1605 | register_serv_func2("MYNETACCEPT=?", 0, 0, 0, ext_ok_rsp, NULL); |
| 1606 | register_serv_func2("MYNETURC=", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETURC_REQ, MSG_CMD_NETURC_RSP, ext_neturc_req, ext_neturc_rsp); |
| 1607 | register_serv_func2("MYNETURC?", MODULE_ID_SOCKET_PROXY, MSG_CMD_NETURC_QUERY_REQ, MSG_CMD_NETURC_QUERY_RSP, ext_neturc_query_req, ext_neturc_query_rsp); |
| 1608 | register_serv_func2("MYMODEM?", MODULE_ID_SOCKET_PROXY, MSG_CMD_TYPE_REQ, MSG_CMD_TYPE_RSP, ext_type_req, ext_type_rsp); |
| 1609 | register_serv_func("ENPWRSAVE=",0,ext_enpwrsave_set_func); |
| 1610 | register_serv_func("ENPWRSAVE?",0,ext_enpwrsave_query_func); |
| 1611 | |
| 1612 | register_formatInform_func("+CSQ", csq_format); |
| 1613 | register_formatInform_func("+CGATT", cgatt_format); |
| 1614 | register_formatInform_func("+CGSN", cgsn_format); |
| 1615 | |
| 1616 | } |
| 1617 | |
| 1618 | #ifdef AT_QUECTEL |
| 1619 | register_serv_func2("QIOPEN=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QIOPEN_REQ, MSG_CMD_QIOPEN_RSP, ext_qiopen_req, ext_qiopen_rsp); |
| 1620 | register_serv_func2("QICLOSE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QICLOSE_REQ, MSG_CMD_QICLOSE_RSP, ext_qiclose_req, ext_qiclose_rsp); |
| 1621 | register_serv_func2("QISTATE=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QISTATE_REQ, MSG_CMD_QISTATE_RSP, ext_qistate_req, ext_qistate_rsp); |
| 1622 | register_serv_func2("QISEND=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QISEND_REQ, MSG_CMD_QISEND_RSP, ext_qisend_req, ext_qisend_rsp); |
| 1623 | register_serv_func2("QIRD=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QIRD_REQ, MSG_CMD_QIRD_RSP, ext_qird_req, ext_qird_rsp); |
| 1624 | register_serv_func2("QISENDEX=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QISENDEX_REQ, MSG_CMD_QISENDEX_RSP, ext_qisendex_req, ext_qisendex_rsp); |
| 1625 | register_serv_func2("QISWTMD=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QISWTMD_REQ, MSG_CMD_QISWTMD_RSP, ext_qiswtmd_req, ext_qiswtmd_rsp); |
| 1626 | register_serv_func2("QIDNSCFG=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QIDNSCFG_REQ, MSG_CMD_QIDNSCFG_RSP, ext_qidnscfg_req, ext_qidnscfg_rsp); |
| 1627 | register_serv_func2("QIDNSGIP=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QIDNSGIP_REQ, MSG_CMD_QIDNSGIP_RSP, ext_qidnsgip_req, ext_qidnsgip_rsp); |
| 1628 | register_serv_func2("QIGETERROR=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QIGETERROR_REQ, MSG_CMD_QIGETERROR_RSP, ext_qigeterror_req, ext_qigeterror_rsp); |
| 1629 | register_serv_func2("QPING=", MODULE_ID_SOCKET_PROXY, MSG_CMD_QPING_REQ, MSG_CMD_QPING_RSP, ext_qping_req, ext_qping_rsp); |
| 1630 | #endif |
| 1631 | |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
| 1635 | #endif |