16 #define CMD_CLEAR() { \
17 atci.tcmd.op[0] = atci.tcmd.sign = atci.tcmd.arg1[0] = atci.tcmd.arg2[0] = 0; \
18 atci.tcmd.arg3[0] = atci.tcmd.arg4[0] = atci.tcmd.arg5[0] = atci.tcmd.arg6[0] = 0; \
20 #define RESP_CR(type_v) do{CMD_CLEAR(); cmd_resp(type_v, VAL_NONE); return;}while(0)
21 #define RESP_CDR(type_v, dgt_v) do{ \
22 CMD_CLEAR(); sprintf((char*)atci.tcmd.arg1, "%d", dgt_v); \
23 cmd_resp(type_v, VAL_NONE); return; \
26 #define CMP_CHAR_2(str_p, c1_v, c2_v) \
27 (str_p[1] != 0 || ((str_p[0]=toupper(str_p[0]))!=c1_v && str_p[0]!=c2_v))
28 #define CMP_CHAR_3(str_p, c1_v, c2_v, c3_v) \
29 (str_p[1] != 0 || ((str_p[0]=toupper(str_p[0]))!=c1_v && str_p[0]!=c2_v && str_p[0]!=c3_v))
30 #define CHK_DGT_RANGE(str_p, snum_v, minval_v, maxval_v) \
31 ((snum_v=atoi((char*)str_p))>maxval_v || snum_v<minval_v)
32 #define CHK_ARG_LEN(arg_p, maxlen_v, ret_v) { \
34 if(arg_p[0] != 0) RESP_CDR(RET_WRONG_ARG, ret_v); \
35 } else if(strlen((char*)arg_p) > maxlen_v) RESP_CDR(RET_WRONG_ARG, ret_v); \
38 static void cmd_set_prev(uint8 buflen);
39 static int8 cmd_divide(int8 *buf);
40 static void cmd_assign(
void);
41 static void hdl_nset(
void);
42 static void hdl_nstat(
void);
43 static void hdl_nmac(
void);
44 static void hdl_nopen(
void);
45 static void hdl_ncls(
void);
46 static void hdl_nsend(
void);
47 static void hdl_nrecv(
void);
48 static void hdl_nsock(
void);
49 static void hdl_nopt(
void);
51 static void hdl_wset(
void);
52 static void hdl_wstat(
void);
53 static void hdl_wscan(
void);
54 static void hdl_wjoin(
void);
55 static void hdl_wleave(
void);
56 static void hdl_wsec(
void);
57 static void hdl_wwps(
void);
59 static void hdl_mset(
void);
60 static void hdl_mstat(
void);
61 static void hdl_mevt(
void);
62 static void hdl_musart(
void);
63 static void hdl_mspi(
void);
64 static void hdl_mprof(
void);
65 static void hdl_mrst(
void);
66 static void hdl_fdhcpd(
void);
67 static void hdl_fdns(
void);
68 static void hdl_fping(
void);
69 static void hdl_fgpio(
void);
70 static void hdl_eset(
void);
71 static void hdl_estat(
void);
74 #define ATCMD_BUF_SIZE 100
75 #define PREVBUF_MAX_SIZE 250
76 #define PREVBUF_MAX_NUM 10
77 #define PREVBUF_LAST (PREVBUF_MAX_NUM-1)
78 #define CMD_SIGN_NONE 0
79 #define CMD_SIGN_QUEST 1
80 #define CMD_SIGN_INDIV 2
81 #define CMD_SIGN_EQUAL 3
83 static int8 termbuf[ATCMD_BUF_SIZE];
84 static int8 *prevbuf[PREVBUF_MAX_NUM];
85 static uint8 previdx = 0, prevcnt = 0;
86 static int16 prevlen = 0;
100 memset(termbuf, 0, ATCMD_BUF_SIZE);
101 for(i=0; i<PREVBUF_MAX_NUM; i++) prevbuf[i] = NULL;
104 atci.poll = POLL_MODE_SEMI;
114 printf(
"\r\n\r\n\r\n[W,0]\r\n");
128 int8 i, ret, recv_char;
129 static int8 curidx = -1, curcnt = 0;
130 static uint8 buflen = 0;
134 if(recv_char ==
RET_NOK)
return;
146 atci.sendbuf[atci.worklen++] = recv_char;
147 if(atci.worklen >= atci.sendlen) {
148 act_nsend(atci.sendsock, atci.sendbuf, atci.worklen, atci.sendip, &atci.sendport);
158 if(isgraph(recv_char) == 0)
164 if(atci.echo) printf(
"\r\n");
174 if(atci.echo) printf(
"\b \b");
182 if(sec_char ==
'[') {
185 if(curcnt >= prevcnt)
break;
186 if(curidx == -1) curidx = previdx;
187 for(i=0; i<buflen; i++)
if(atci.echo)
PUTCHAR(
'\b');
188 for(i=0; i<buflen; i++)
if(atci.echo)
PUTCHAR(
' ');
189 for(i=0; i<buflen; i++)
if(atci.echo)
PUTCHAR(
'\b');
190 if(curidx == 0) curidx = PREVBUF_LAST;
193 if(prevbuf[curidx]) {
194 buflen = strlen((
char*)prevbuf[curidx]);
195 strcpy((
char*)termbuf, (
char*)prevbuf[curidx]);
196 }
else CRITICAL_ERR(
"prevbuf NULL");
197 if(atci.echo) printf(
"%s", termbuf);
200 if(curcnt <= 0)
break;
201 for(i=0; i<buflen; i++)
if(atci.echo)
PUTCHAR(
'\b');
202 for(i=0; i<buflen; i++)
if(atci.echo)
PUTCHAR(
' ');
203 for(i=0; i<buflen; i++)
if(atci.echo)
PUTCHAR(
'\b');
204 if(curidx == PREVBUF_LAST) curidx = 0;
209 }
else if(prevbuf[curidx]) {
210 buflen = strlen((
char*)prevbuf[curidx]);
211 strcpy((
char*)termbuf, (
char*)prevbuf[curidx]);
212 if(atci.echo) printf(
"%s", termbuf);
213 }
else CRITICAL_ERR(
"prevbuf NULL");
233 else if(buflen < ATCMD_BUF_SIZE-1)
235 termbuf[buflen++] = (uint8)recv_char;
236 if(atci.echo)
PUTCHAR(recv_char);
239 if(recv_char != 0x0a || buflen == 0)
return;
241 cmd_set_prev(buflen);
245 ret = cmd_divide(termbuf);
248 }
else if(ret != RET_DONE) {
253 static void cmd_set_prev(uint8 buflen)
257 while(prevcnt >= PREVBUF_MAX_NUM || (prevcnt && prevlen+buflen > PREVBUF_MAX_SIZE-1)) {
258 idx = (previdx + PREVBUF_MAX_NUM - prevcnt) % PREVBUF_MAX_NUM;
260 prevlen -= strlen((
char*)prevbuf[idx]) + 1;
263 }
else CRITICAL_ERR(
"ring buf 1");
266 prevbuf[previdx] = malloc(buflen+1);
268 while(prevcnt && prevbuf[previdx] == NULL) {
269 idx = (previdx + PREVBUF_MAX_NUM - prevcnt) % PREVBUF_MAX_NUM;
271 prevlen -= strlen((
char*)prevbuf[idx]) + 1;
274 prevbuf[previdx] = malloc(buflen+1);
275 }
else CRITICAL_ERR(
"ring buf 2");
278 if(prevbuf[previdx] == NULL) CRITICAL_ERR(
"malloc fail");
280 strcpy((
char*)prevbuf[previdx], (
char*)termbuf);
281 if(previdx == PREVBUF_LAST) previdx = 0;
284 prevlen += buflen + 1;
288 static int8 cmd_divide(int8 *buf)
290 int8 ret, *split, *noteptr, *tmpptr = buf;
292 if(strchr((
char*)tmpptr,
'=')) atci.tcmd.sign = CMD_SIGN_EQUAL;
293 else if(strchr((
char*)tmpptr,
'?')) atci.tcmd.sign = CMD_SIGN_QUEST;
294 else if(strchr((
char*)tmpptr,
'-')) atci.tcmd.sign = CMD_SIGN_INDIV;
296 split =
strsep(&tmpptr,
"=-?");
299 for (noteptr = split; *noteptr; noteptr++) *noteptr = toupper(*noteptr);
300 if(strlen((
char*)split) > OP_SIZE+3-1 ||
301 split[0] !=
'A' || split[1] !=
'T' || split[2] !=
'+')
303 if(split[0] ==
'A' && split[1] ==
'T' && split[2] == 0) {
304 if(atci.tcmd.sign == CMD_SIGN_QUEST) {
305 if(prevcnt < 2) printf(
"[D,,0]\r\n");
308 if(previdx < 2) idx += PREVBUF_MAX_NUM - 2;
310 printf(
"[D,,%d]\r\n%s\r\n", strlen((
char*)prevbuf[idx]), prevbuf[idx]);
313 else if(atci.tcmd.sign == CMD_SIGN_NONE) printf(
"[S]\r\n");
314 else return RET_WRONG_SIGN;
317 strcpy((
char*)atci.tcmd.op, (
char*)split);
320 strcpy((
char*)atci.tcmd.op, (
char*)&split[3]);
323 else return RET_WRONG_OP;
325 #define ARG_PARSE(arg_v, size_v, dgt_v) \
327 split = strsep(&tmpptr, ","); \
328 if(split != NULL) { \
329 if(strlen((char*)split) > size_v-1) { \
330 ret = RET_WRONG_ARG; \
332 sprintf((char*)atci.tcmd.arg1, "%d", dgt_v); \
334 } else strcpy((char*)arg_v, (char*)split); \
335 } else goto OK_END; \
338 ARG_PARSE(atci.tcmd.arg1, ARG_1_SIZE, 1);
339 ARG_PARSE(atci.tcmd.arg2, ARG_2_SIZE, 2);
340 ARG_PARSE(atci.tcmd.arg3, ARG_3_SIZE, 3);
341 ARG_PARSE(atci.tcmd.arg4, ARG_4_SIZE, 4);
342 ARG_PARSE(atci.tcmd.arg5, ARG_5_SIZE, 5);
343 ARG_PARSE(atci.tcmd.arg6, ARG_6_SIZE, 6);
353 DBGA(
"[%s] S(%d),OP(%s),A1(%s),A2(%s),A3(%s),A4(%s),A5(%s),A6(%s)",
354 ret==
RET_OK?
"OK":
"ERR", atci.tcmd.sign, atci.tcmd.op?atci.tcmd.op:
"<N>", atci.tcmd.arg1?atci.tcmd.arg1:
"<N>",
355 atci.tcmd.arg2?atci.tcmd.arg2:
"<N>", atci.tcmd.arg3?atci.tcmd.arg3:
"<N>", atci.tcmd.arg4?atci.tcmd.arg4:
"<N>",
356 atci.tcmd.arg5?atci.tcmd.arg5:
"<N>", atci.tcmd.arg6?atci.tcmd.arg6:
"<N>");
360 static void cmd_assign(
void)
362 #define CMD_NOT_FOUND() do{CMD_CLEAR(); cmd_resp(RET_WRONG_OP, VAL_NONE);}while(0)
364 if(atci.tcmd.op[0] ==
'N')
366 if(strcmp((
char*)&atci.tcmd.op[1],
"SET")==0) hdl_nset();
367 else if(strcmp((
char*)&atci.tcmd.op[1],
"STAT")==0) hdl_nstat();
368 else if(strcmp((
char*)&atci.tcmd.op[1],
"MAC")==0) hdl_nmac();
369 else if(strcmp((
char*)&atci.tcmd.op[1],
"OPEN")==0) hdl_nopen();
370 else if(strcmp((
char*)&atci.tcmd.op[1],
"CLS")==0) hdl_ncls();
371 else if(strcmp((
char*)&atci.tcmd.op[1],
"SEND")==0) hdl_nsend();
372 else if(strcmp((
char*)&atci.tcmd.op[1],
"RECV")==0) hdl_nrecv();
373 else if(strcmp((
char*)&atci.tcmd.op[1],
"SOCK")==0) hdl_nsock();
374 else if(strcmp((
char*)&atci.tcmd.op[1],
"OPT")==0) hdl_nopt();
375 else CMD_NOT_FOUND();
378 else if(atci.tcmd.op[0] ==
'W')
380 if(strcmp((
char*)&atci.tcmd.op[1],
"SET")==0) hdl_wset();
381 else if(strcmp((
char*)&atci.tcmd.op[1],
"STAT")==0) hdl_wstat();
382 else if(strcmp((
char*)&atci.tcmd.op[1],
"SCAN")==0) hdl_wscan();
383 else if(strcmp((
char*)&atci.tcmd.op[1],
"JOIN")==0) hdl_wjoin();
384 else if(strcmp((
char*)&atci.tcmd.op[1],
"LEAVE")==0) hdl_wleave();
385 else if(strcmp((
char*)&atci.tcmd.op[1],
"SEC")==0) hdl_wsec();
386 else if(strcmp((
char*)&atci.tcmd.op[1],
"WPS")==0) hdl_wwps();
387 else CMD_NOT_FOUND();
390 else if(atci.tcmd.op[0] ==
'M')
392 if(strcmp((
char*)&atci.tcmd.op[1],
"SET")==0) hdl_mset();
393 else if(strcmp((
char*)&atci.tcmd.op[1],
"STAT")==0) hdl_mstat();
394 else if(strcmp((
char*)&atci.tcmd.op[1],
"EVT")==0) hdl_mevt();
395 else if(strcmp((
char*)&atci.tcmd.op[1],
"USART")==0) hdl_musart();
396 else if(strcmp((
char*)&atci.tcmd.op[1],
"SPI")==0) hdl_mspi();
397 else if(strcmp((
char*)&atci.tcmd.op[1],
"PROF")==0) hdl_mprof();
398 else if(strcmp((
char*)&atci.tcmd.op[1],
"RST")==0) hdl_mrst();
399 else CMD_NOT_FOUND();
401 else if(atci.tcmd.op[0] ==
'F')
403 if(strcmp((
char*)&atci.tcmd.op[1],
"DHCPD")==0) hdl_fdhcpd();
404 else if(strcmp((
char*)&atci.tcmd.op[1],
"DNS")==0) hdl_fdns();
405 else if(strcmp((
char*)&atci.tcmd.op[1],
"PING")==0) hdl_fping();
406 else if(strcmp((
char*)&atci.tcmd.op[1],
"GPIO")==0) hdl_fgpio();
407 else CMD_NOT_FOUND();
409 else if(atci.tcmd.op[0] ==
'E')
411 if(strcmp((
char*)&atci.tcmd.op[1],
"SET")==0) hdl_eset();
412 else if(strcmp((
char*)&atci.tcmd.op[1],
"STAT")==0) hdl_estat();
413 else CMD_NOT_FOUND();
415 else CMD_NOT_FOUND();
418 void cmd_resp_dump(int8 idval, int8 *dump)
420 uint16 len = dump!=NULL?strlen((
char*)dump):0;
423 if(idval ==
VAL_NONE) printf(
"[D,,0]\r\n");
424 else printf(
"[D,%d,0]\r\n", idval);
426 if(idval ==
VAL_NONE) printf(
"[D,,%d]\r\n%s\r\n", len, dump);
427 else printf(
"[D,%d,%d]\r\n%s\r\n", idval, len, dump);
428 DBG(
"going to free");
434 void cmd_resp(int8 retval, int8 idval)
436 uint8 cnt, len, idx = 0;
438 DBGA(
"ret(%d), id(%d)", retval, idval);
439 cnt = (atci.tcmd.arg1[0] != 0) + (atci.tcmd.arg2[0] != 0) + (atci.tcmd.arg3[0] != 0) +
440 (atci.tcmd.arg4[0] != 0) + (atci.tcmd.arg5[0] != 0) + (atci.tcmd.arg6[0] != 0);
441 #define MAKE_RESP(item_v, size_v) \
443 if(item_v[0] != 0) { \
444 termbuf[idx++] = ','; \
445 len = strlen((char*)item_v); \
446 if(len > size_v-1) CRITICAL_ERR("resp buf overflow"); \
447 memcpy((char*)&termbuf[idx], (char*)item_v, len); \
451 termbuf[idx++] = ','; \
453 }//printf("MakeResp-(%s)(%d)", item_v, len);
454 termbuf[idx++] =
'[';
456 if(retval ==
RET_OK) termbuf[idx++] =
'S';
457 else if(retval == RET_OK_DUMP) CRITICAL_ERR(
"use cmd_resp_dump for dump");
458 else if(retval == RET_ASYNC) termbuf[idx++] =
'W';
459 else if(retval == RET_RECV) termbuf[idx++] =
'R';
460 else CRITICAL_ERRA(
"undefined return value (%d)", retval);
463 termbuf[idx++] =
',';
467 sprintf((
char*)&termbuf[idx],
"%d", idval);
470 }
else if(cnt) termbuf[idx++] =
',';
472 termbuf[idx++] =
'F';
473 termbuf[idx++] =
',';
478 sprintf((
char*)&termbuf[idx],
"%d", idval);
482 termbuf[idx++] =
',';
483 #define CMD_SWT_DEF(errval_v) termbuf[idx++] = errval_v; break;
484 #define CMD_SWT_EXT(base_v, errval_v) termbuf[idx++]=base_v;termbuf[idx++] = errval_v; break;
486 case RET_UNSPECIFIED: CMD_SWT_DEF(ERRVAL_UNSPECIFIED);
487 case RET_WRONG_OP: CMD_SWT_DEF(ERRVAL_WRONG_OP);
488 case RET_WRONG_SIGN: CMD_SWT_DEF(ERRVAL_WRONG_SIGN);
489 case RET_WRONG_ARG: CMD_SWT_DEF(ERRVAL_WRONG_ARG);
490 case RET_RANGE_OUT: CMD_SWT_DEF(ERRVAL_RANGE_OUT);
491 case RET_DISABLED: CMD_SWT_DEF(ERRVAL_DISABLED);
492 case RET_NOT_ALLOWED: CMD_SWT_DEF(ERRVAL_NOT_ALLOWED);
493 case RET_BUSY: CMD_SWT_DEF(ERRVAL_BUSY);
494 case RET_TIMEOUT: CMD_SWT_DEF(ERRVAL_TIMEOUT);
495 case RET_NO_SOCK: CMD_SWT_EXT(
'1', ERRVAL_NO_SOCK);
496 case RET_SOCK_CLS: CMD_SWT_EXT(
'1', ERRVAL_SOCK_CLS);
497 case RET_USING_PORT: CMD_SWT_EXT(
'1', ERRVAL_USING_PORT);
498 case RET_NOT_CONN: CMD_SWT_EXT(
'1', ERRVAL_NOT_CONN);
499 case RET_WRONG_ADDR: CMD_SWT_EXT(
'1', ERRVAL_WRONG_ADDR);
500 case RET_NO_DATA: CMD_SWT_EXT(
'1', ERRVAL_NO_DATA);
501 case RET_NO_FREEMEM: CMD_SWT_EXT(
'2', ERRVAL_NO_FREEMEM);
502 default:termbuf[idx++] =
'0';
break;
505 MAKE_RESP(atci.tcmd.arg1, ARG_1_SIZE);
506 MAKE_RESP(atci.tcmd.arg2, ARG_2_SIZE);
507 MAKE_RESP(atci.tcmd.arg3, ARG_3_SIZE);
508 MAKE_RESP(atci.tcmd.arg4, ARG_4_SIZE);
509 MAKE_RESP(atci.tcmd.arg5, ARG_5_SIZE);
510 MAKE_RESP(atci.tcmd.arg6, ARG_6_SIZE);
511 termbuf[idx++] =
']';
513 printf(
"%s\r\n", termbuf);
516 static void hdl_nset(
void)
521 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
522 if(atci.tcmd.sign == CMD_SIGN_QUEST)
524 if(atci.tcmd.arg1[0] != 0) {
525 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
526 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 6)) RESP_CDR(RET_RANGE_OUT, 1);
531 else if(atci.tcmd.sign == CMD_SIGN_INDIV)
533 if(atci.tcmd.arg1[0] != 0) {
534 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
535 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 6)) RESP_CDR(RET_RANGE_OUT, 1);
537 if(CMP_CHAR_2(atci.tcmd.arg2,
'D',
'S')) RESP_CDR(RET_WRONG_ARG, 2);
538 mode = atci.tcmd.arg2[0];
540 act_nset_a(mode, NULL, NULL, NULL, NULL, NULL);
542 if(
ip_check(atci.tcmd.arg2, ip) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 2);
545 case 2: act_nset_a(0, ip, NULL, NULL, NULL, NULL);
return;
546 case 3: act_nset_a(0, NULL, ip, NULL, NULL, NULL);
return;
547 case 4: act_nset_a(0, NULL, NULL, ip, NULL, NULL);
return;
548 case 5: act_nset_a(0, NULL, NULL, NULL, ip, NULL);
return;
549 case 6: act_nset_a(0, NULL, NULL, NULL, NULL, ip);
return;
550 default: CRITICAL_ERR(
"nset wrong num");
553 }
else RESP_CDR(RET_WRONG_ARG, 1);
555 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
557 uint8 sn[4], gw[4], dns1[4], dns2[4], *ptr[5];
559 if(atci.tcmd.arg1[0] != 0) {
560 if(CMP_CHAR_2(atci.tcmd.arg1,
'D',
'S')) RESP_CDR(RET_WRONG_ARG, 1);
564 #define NSET_ARG_SET(arg_p, addr_p, idx_v, ret_v) \
565 if(arg_p[0] != 0) { \
567 if(ip_check(arg_p, addr_p) != RET_OK) RESP_CDR(RET_WRONG_ARG, ret_v); \
568 ptr[idx_v] = addr_p; \
569 } else ptr[idx_v] = NULL
571 NSET_ARG_SET(atci.tcmd.arg2, ip, 0, 2);
572 NSET_ARG_SET(atci.tcmd.arg3, sn, 1, 3);
573 NSET_ARG_SET(atci.tcmd.arg4, gw, 2, 4);
574 NSET_ARG_SET(atci.tcmd.arg5, dns1, 3, 5);
575 NSET_ARG_SET(atci.tcmd.arg6, dns2, 4, 6);
576 if(num == 0) RESP_CR(RET_NOT_ALLOWED);
577 mode = atci.tcmd.arg1[0];
579 act_nset_a(mode, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4]);
581 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
584 static void hdl_nstat(
void)
588 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
589 if(atci.tcmd.sign == CMD_SIGN_QUEST)
591 if(atci.tcmd.arg1[0] != 0) {
592 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
593 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 6)) RESP_CDR(RET_RANGE_OUT, 1);
598 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
599 else if(atci.tcmd.sign == CMD_SIGN_EQUAL) RESP_CR(RET_WRONG_SIGN);
600 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
603 static void hdl_nmac(
void)
608 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
609 if(atci.tcmd.sign == CMD_SIGN_QUEST)
611 if(atci.tcmd.arg1[0] != 0) {
612 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
613 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 1)) RESP_CDR(RET_RANGE_OUT, 1);
618 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
619 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
621 if(
mac_check(atci.tcmd.arg1, mac) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
625 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
628 static void hdl_nopen(
void)
631 uint8 DstIP[4], *dip = NULL;
632 uint16 SrcPort, DstPort = 0;
634 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
635 if(atci.tcmd.sign == CMD_SIGN_QUEST)
640 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
641 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
643 if(CMP_CHAR_3(atci.tcmd.arg1,
'S',
'C',
'U')) RESP_CDR(RET_WRONG_ARG, 1);
644 if(
port_check(atci.tcmd.arg2, &SrcPort) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 2);
646 if(atci.tcmd.arg1[0] ==
'C') {
647 if(
ip_check(atci.tcmd.arg3, DstIP) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 3);
648 if(
port_check(atci.tcmd.arg4, &DstPort) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 4);
650 }
else if(atci.tcmd.arg1[0] ==
'U') {
651 if(atci.tcmd.arg3[0] != 0 && atci.tcmd.arg4[0] != 0) {
652 if(
ip_check(atci.tcmd.arg3, DstIP) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 3);
653 if(
port_check(atci.tcmd.arg4, &DstPort) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 4);
656 CHK_ARG_LEN(atci.tcmd.arg3, 0, 3);
657 CHK_ARG_LEN(atci.tcmd.arg4, 0, 4);
660 CHK_ARG_LEN(atci.tcmd.arg3, 0, 3);
661 CHK_ARG_LEN(atci.tcmd.arg4, 0, 4);
664 CHK_ARG_LEN(atci.tcmd.arg5, 0, 5);
665 type = atci.tcmd.arg1[0];
667 act_nopen_a(type, SrcPort, dip, DstPort);
669 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
672 static void hdl_ncls(
void)
676 if(atci.tcmd.sign == CMD_SIGN_NONE) RESP_CR(RET_WRONG_SIGN);
677 if(atci.tcmd.sign == CMD_SIGN_QUEST) RESP_CR(RET_WRONG_SIGN);
678 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
679 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
681 if(atci.tcmd.arg1[0] != 0) {
682 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
683 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, ATC_SOCK_NUM_START, ATC_SOCK_NUM_END))
684 RESP_CDR(RET_RANGE_OUT, 1);
689 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
692 static void hdl_nsend(
void)
697 uint16 *dport = NULL;
699 if(atci.tcmd.sign == CMD_SIGN_NONE) RESP_CR(RET_WRONG_SIGN);
700 if(atci.tcmd.sign == CMD_SIGN_QUEST) RESP_CR(RET_WRONG_SIGN);
701 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
702 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
704 if(atci.tcmd.arg1[0] != 0) {
705 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
706 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, ATC_SOCK_NUM_START, ATC_SOCK_NUM_END))
707 RESP_CDR(RET_RANGE_OUT, 1);
710 (atci.sendlen = atoi((
char*)atci.tcmd.arg2)) < 1 ||
711 atci.sendlen > WORK_BUF_SIZE) RESP_CDR(RET_RANGE_OUT, 2);
713 if(atci.tcmd.arg3[0]) {
714 if(
ip_check(atci.tcmd.arg3, atci.sendip) ==
RET_OK) dip = atci.sendip;
715 else RESP_CDR(RET_WRONG_ARG, 3);
717 if(atci.tcmd.arg4[0]) {
718 if(
port_check(atci.tcmd.arg4, &atci.sendport)==
RET_OK) dport = &atci.sendport;
719 else RESP_CDR(RET_WRONG_ARG, 4);
722 CHK_ARG_LEN(atci.tcmd.arg5, 0, 5);
723 CHK_ARG_LEN(atci.tcmd.arg6, 0, 6);
725 ret = act_nsend_chk(num, &atci.sendlen, dip, dport);
730 cmd_resp(RET_ASYNC, num);
732 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
735 static void hdl_nrecv(
void)
740 if(atci.poll == POLL_MODE_NONE) RESP_CR(RET_DISABLED);
741 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_EQUAL;
742 if(atci.tcmd.sign == CMD_SIGN_QUEST) RESP_CR(RET_WRONG_SIGN);
743 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
744 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
746 if(atci.tcmd.arg1[0] != 0) {
747 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
748 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, ATC_SOCK_NUM_START, ATC_SOCK_NUM_END))
749 RESP_CDR(RET_RANGE_OUT, 1);
751 if(atci.tcmd.arg2[0] == 0) maxlen = WORK_BUF_SIZE;
752 else if(
str_check(isdigit, atci.tcmd.arg2) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 2);
753 else if((maxlen = atoi((
char*)atci.tcmd.arg2)) < 1 || maxlen > WORK_BUF_SIZE)
754 RESP_CDR(RET_RANGE_OUT, 2);
756 act_nrecv(num, maxlen);
758 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
761 static void hdl_nsock(
void)
766 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
767 if(atci.tcmd.sign == CMD_SIGN_QUEST)
772 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
773 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
775 if(atci.tcmd.arg1[0] != 0) {
776 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
777 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, ATC_SOCK_NUM_START, ATC_SOCK_NUM_END))
778 RESP_CDR(RET_RANGE_OUT, 1);
783 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
786 static void hdl_nopt(
void)
789 RESP_CR(RET_NOT_ALLOWED);
792 static void hdl_wset(
void)
797 static void hdl_wstat(
void)
802 static void hdl_wscan(
void)
807 static void hdl_wjoin(
void)
812 static void hdl_wleave(
void)
817 static void hdl_wsec(
void)
822 static void hdl_wwps(
void)
827 static void hdl_mset(
void)
829 int8 echo, poll, num = -1;
831 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
832 if(atci.tcmd.sign == CMD_SIGN_QUEST)
834 if(atci.tcmd.arg1[0] != 0) {
835 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
836 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 4)) RESP_CDR(RET_RANGE_OUT, 1);
841 else if(atci.tcmd.sign == CMD_SIGN_INDIV)
843 if(atci.tcmd.arg1[0] != 0) {
844 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
845 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 4)) RESP_CDR(RET_RANGE_OUT, 1);
847 if(CMP_CHAR_2(atci.tcmd.arg2,
'E',
'D')) RESP_CDR(RET_WRONG_ARG, 2);
848 echo = atci.tcmd.arg2[0];
850 act_mset_a(echo, 0, 0, 0);
851 }
else if(num == 2) {
852 RESP_CDR(RET_NOT_ALLOWED, 2);
853 }
else if(num == 3) {
854 if(CMP_CHAR_3(atci.tcmd.arg2,
'F',
'S',
'D')) RESP_CDR(RET_WRONG_ARG, 2);
855 poll = atci.tcmd.arg2[0];
857 act_mset_a(0, 0, poll, 0);
858 }
else RESP_CDR(RET_NOT_ALLOWED, 2);
859 }
else RESP_CDR(RET_WRONG_ARG, 1);
861 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
864 if(atci.tcmd.arg1[0] != 0) {
866 if(CMP_CHAR_2(atci.tcmd.arg1,
'E',
'D')) RESP_CDR(RET_WRONG_ARG, 1);
868 if(atci.tcmd.arg3[0] != 0) {
870 if(CMP_CHAR_3(atci.tcmd.arg3,
'F',
'S',
'D')) RESP_CDR(RET_WRONG_ARG, 3);
873 if(num == 0) RESP_CR(RET_NOT_ALLOWED);
874 echo = atci.tcmd.arg1[0];
875 poll = atci.tcmd.arg3[0];
877 act_mset_a(echo, 0, poll, 0);
879 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
882 static void hdl_mstat(
void)
886 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_QUEST;
887 if(atci.tcmd.sign == CMD_SIGN_QUEST)
889 if(atci.tcmd.arg1[0] != 0) {
890 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
891 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, 1, 1)) RESP_CDR(RET_RANGE_OUT, 1);
896 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
897 else if(atci.tcmd.sign == CMD_SIGN_EQUAL) RESP_CR(RET_WRONG_SIGN);
898 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
901 static void hdl_mevt(
void)
905 if(atci.poll != POLL_MODE_FULL) RESP_CR(RET_DISABLED);
906 if(atci.tcmd.sign == CMD_SIGN_NONE) atci.tcmd.sign = CMD_SIGN_EQUAL;
907 if(atci.tcmd.sign == CMD_SIGN_QUEST)
912 else if(atci.tcmd.sign == CMD_SIGN_INDIV) RESP_CR(RET_WRONG_SIGN);
913 else if(atci.tcmd.sign == CMD_SIGN_EQUAL)
915 if(atci.tcmd.arg1[0] != 0) {
916 if(
str_check(isdigit, atci.tcmd.arg1) !=
RET_OK) RESP_CDR(RET_WRONG_ARG, 1);
917 if(CHK_DGT_RANGE(atci.tcmd.arg1, num, ATC_SOCK_NUM_START, ATC_SOCK_NUM_END))
918 RESP_CDR(RET_RANGE_OUT, 1);
923 else CRITICAL_ERRA(
"wrong sign(%d)", atci.tcmd.sign);
926 static void hdl_musart(
void)
928 RESP_CR(RET_NOT_ALLOWED);
931 static void hdl_mspi(
void)
933 RESP_CR(RET_NOT_ALLOWED);
936 static void hdl_mprof(
void)
938 RESP_CR(RET_NOT_ALLOWED);
941 static void hdl_mrst(
void)
948 static void hdl_fdhcpd(
void)
950 RESP_CR(RET_NOT_ALLOWED);
953 static void hdl_fdns(
void)
955 RESP_CR(RET_NOT_ALLOWED);
958 static void hdl_fping(
void)
960 RESP_CR(RET_NOT_ALLOWED);
963 static void hdl_fgpio(
void)
965 RESP_CR(RET_NOT_ALLOWED);
968 static void hdl_eset(
void)
970 RESP_CR(RET_NOT_ALLOWED);
973 static void hdl_estat(
void)
975 RESP_CR(RET_NOT_ALLOWED);