16 #define SOCK_STAT_TCP_MASK 0x2
17 #define SOCK_STAT_PROTMASK 0x3
18 #define SOCK_STAT_IDLE 0x0
19 #define SOCK_STAT_UDP 0x1
20 #define SOCK_STAT_TCP_SRV 0x2
21 #define SOCK_STAT_TCP_CLT 0x3
22 #define SOCK_STAT_CONNECTED 0x4
24 #define EVENT_RESP(id_v, evt_v) printf("[V,%d,%d]\r\n", id_v, evt_v)
25 #define EVENT_RESP_SIZE(id_v, evt_v, size_v) printf("[V,%d,%d,%d]\r\n", id_v, evt_v, size_v)
26 #define CMD_RESP_RET(type_v, id_v) do{DBG("#");cmd_resp(type_v, id_v); return;}while(0)
27 #define MAKE_TCMD_DIGIT(arg_p, dgt_p) sprintf((char*)arg_p, "%d", dgt_p)
28 #define MAKE_TCMD_CHAR(arg_p, char_p) sprintf((char*)arg_p, "%c", char_p)
29 #define MAKE_TCMD_ADDR(arg_p, a1_p, a2_p, a3_p, a4_p) \
30 sprintf((char*)arg_p, "%d.%d.%d.%d", a1_p, a2_p, a3_p, a4_p)
31 #define MAKE_TCMD_STRING(arg_p, argsize_v, str_p) do { \
32 uint8 len = strlen((char*)str_p); \
33 if(len > argsize_v-1) {memcpy((char*)arg_p, (char*)str_p, argsize_v-1); arg_p[argsize_v-1]=0;} \
34 else {memcpy((char*)arg_p, (char*)str_p, len); arg_p[len]=0;} \
45 struct atc_eventq *next;
50 extern void cmd_resp(int8 retval, int8 idval);
52 static int8 sockstat[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO] = {0,};
53 static int8 sockbusy[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO] = {0,};
54 static uint16 sockport[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO] = {0,};
55 static uint8 udpip[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO][4] = {0,};
56 static uint16 udpport[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO] = {0,};
57 static uint16 tcpleft[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO] = {0,};
58 static int8 recvord[ATC_SOCK_NUM_TOTAL+ATC_SOCK_AO] = {0,};
59 static int8 recvnum = 0;
60 struct atc_eventq *eventqueue;
64 static int8 sock_get(int8 initval, uint16 srcport)
68 DBGCRTCA(initval<1||initval>3,
"wrong init value(%d)", initval);
70 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
71 if(sockstat[i] == SOCK_STAT_IDLE) {
72 sockstat[i] = initval;
73 sockport[i] = srcport;
81 static int8 sock_put(uint8 sock)
83 DBGCRTCA(sock<ATC_SOCK_NUM_START||sock>ATC_SOCK_NUM_END,
"wrong sock(%d)", sock);
85 if(sockstat[sock] & SOCK_STAT_UDP) {
86 udpip[sock][0] = udpip[sock][1] = udpip[sock][2] = 0;
87 udpip[sock][3] = udpport[sock] = 0;
89 sockstat[sock] = SOCK_STAT_IDLE;
95 static int8 event_enqueue(int8
id, int8 event)
98 struct atc_eventq **eqdp;
102 struct atc_eventq *tmp1 = eventqueue;
103 DBGFA(
"EVT1-cnt(%d)", eqp_cnt);
105 LOGFA(
", (%d-%d)", tmp1->id, tmp1->event);
116 if(eqp_cnt >= EVENT_QUEUE_SIZE-1) {
117 while((*eqdp)->next) eqdp = &(*eqdp)->next;
118 if((*eqdp)->event != QFULL) {
119 eqdp = &(*eqdp)->next;
120 *eqdp = malloc(
sizeof(
struct atc_eventq));
122 ERRA(
"malloc fail - size(%d)",
sizeof(
struct atc_eventq));
126 (*eqdp)->event = QFULL;
133 while(*eqdp) eqdp = &(*eqdp)->next;
135 *eqdp = malloc(
sizeof(
struct atc_eventq));
137 ERRA(
"malloc fail - size(%d)",
sizeof(
struct atc_eventq));
142 (*eqdp)->event = event;
146 struct atc_eventq *tmp2 = eventqueue;
147 DBGFA(
"EVT2-cnt(%d)", eqp_cnt);
149 LOGFA(
", (%d-%d)", tmp2->id, tmp2->event);
158 static int8 event_dequeue(int8 *
id, int8 *event)
160 struct atc_eventq *eqp, **eqdp;
162 if(
id == NULL || event == NULL)
return RET_NOK;
165 struct atc_eventq *tmp3 = eventqueue;
166 DBGFA(
"EVT3-cnt(%d)", eqp_cnt);
168 LOGFA(
", (%d-%d)", tmp3->id, tmp3->event);
176 if(eqp_cnt == 0)
return RET_NOK;
178 eventqueue = eventqueue->next;
184 struct atc_eventq *tmp44 = eventqueue;
185 DBGFA(
"EVT4-cnt(%d)", eqp_cnt);
187 LOGFA(
", (%d-%d)", tmp44->id, tmp44->event);
196 if((*eqdp)->id == *
id) {
197 *
event = (*eqdp)->event;
199 *eqdp = (*eqdp)->next;
204 struct atc_eventq *tmp5 = eventqueue;
205 DBGFA(
"EVT5-cnt(%d)", eqp_cnt);
207 LOGFA(
", (%d-%d)", tmp5->id, tmp5->event);
219 static void atc_resend_alarm(int8 arg)
226 alarm_set(WINDOWFULL_WAIT_TIME, atc_resend_alarm, arg);
229 DBGA(
"WATCH_SOCK_TCP_SEND fail - ret(%d)", ret);
230 cmd_resp(RET_TIMEOUT, arg);
233 DBGA(
"WATCH_SOCK_TCP_SEND fail - ret(%d)", ret);
234 cmd_resp(RET_TIMEOUT, arg);
236 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(arg, SOCKEVENT_CLS);
237 else event_enqueue(arg, SOCKEVENT_CLS);
242 void atc_async_cb(uint8 sock, uint8 item, int32 ret)
244 DBGCRTCA(sock<ATC_SOCK_NUM_START||sock>ATC_SOCK_NUM_END,
"wrong sock(%d)", sock);
252 DBGA(
"WATCH_SOCK_UDP_SEND fail - ret(%d)", ret);
253 cmd_resp(RET_TIMEOUT, sock);
259 DBGA(
"WATCH_SOCK_TCP_SEND fail - ret(%d)", ret);
260 cmd_resp(RET_TIMEOUT, sock);
262 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(sock, SOCKEVENT_CLS);
263 else event_enqueue(sock, SOCKEVENT_CLS);
265 tcpleft[sock] -= ret;
266 if(tcpleft[sock] > 0) {
270 alarm_set(WINDOWFULL_WAIT_TIME, atc_resend_alarm, sock);
273 DBGA(
"WATCH_SOCK_TCP_SEND fail - ret(%d)", ret);
274 cmd_resp(RET_TIMEOUT, sock);
277 DBGA(
"WATCH_SOCK_TCP_SEND fail - ret(%d)", ret);
278 cmd_resp(RET_TIMEOUT, sock);
280 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(sock, SOCKEVENT_CLS);
281 else event_enqueue(sock, SOCKEVENT_CLS);
293 BITSET(sockstat[sock], SOCK_STAT_CONNECTED);
298 DBGA(
"WATCH_SOCK_CONN_EVT fail - ret(%d)", ret);
299 cmd_resp(RET_TIMEOUT, sock);
309 CRITICAL_ERRA(
"WATCH_SOCK_CONN_EVT fail - ret(%d)", ret);
314 BITSET(sockstat[sock], SOCK_STAT_CONNECTED);
317 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(sock, SOCKEVENT_CONN);
318 else event_enqueue(sock, SOCKEVENT_CONN);
320 CRITICAL_ERRA(
"WATCH_SOCK_CONN_EVT fail - ret(%d)", ret);
328 if((sockstat[sock] & SOCK_STAT_PROTMASK) == SOCK_STAT_TCP_SRV) {
329 DBGA(
"Conn(%d) Closed - back to the Listen state", sock);
330 BITCLR(sockstat[sock], SOCK_STAT_CONNECTED);
335 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(sock, SOCKEVENT_DISCON);
336 else event_enqueue(sock, SOCKEVENT_DISCON);
339 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(sock, SOCKEVENT_CLS);
340 else event_enqueue(sock, SOCKEVENT_CLS);
344 if(atci.poll != POLL_MODE_FULL) EVENT_RESP(sock, SOCKEVENT_CLS);
345 else event_enqueue(sock, SOCKEVENT_CLS);
348 CRITICAL_ERRA(
"WATCH_SOCK_CONN_EVT fail - ret(%d)", ret);
355 DBGA(
"WATCH1-sock(%d),recvnum(%d),recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0],
356 recvord[1], recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
358 if(atci.poll != POLL_MODE_NONE) {
359 if(recvord[sock] == 0) {
362 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++)
363 if(i != sock && recvord[i] != 0) recvord[i]++;
368 if(atci.poll != POLL_MODE_FULL)
370 else event_enqueue(sock, SOCKEVENT_RECV);
372 act_nrecv(sock, WORK_BUF_SIZE);
375 DBGA(
"WATCH2-sock(%d),recvnum(%d),recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0],
376 recvord[1], recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
379 default: CRITICAL_ERRA(
"wrong item(0x%x)", item);
383 void act_nset_q(int8 num)
390 MAKE_TCMD_CHAR(atci.tcmd.arg1,
'D');
391 else MAKE_TCMD_CHAR(atci.tcmd.arg1,
'S');
396 case 2: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
ip[0], ni.
ip[1], ni.
ip[2], ni.
ip[3]);
break;
397 case 3: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
sn[0], ni.
sn[1], ni.
sn[2], ni.
sn[3]);
break;
398 case 4: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
gw[0], ni.
gw[1], ni.
gw[2], ni.
gw[3]);
break;
399 case 5: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
dns[0], ni.
dns[1], ni.
dns[2], ni.
dns[3]);
break;
400 case 6: CMD_RESP_RET(RET_NOT_ALLOWED,
VAL_NONE);
406 MAKE_TCMD_CHAR(atci.tcmd.arg1,
'D');
407 else MAKE_TCMD_CHAR(atci.tcmd.arg1,
'S');
409 MAKE_TCMD_ADDR(atci.tcmd.arg2, ni.
ip[0], ni.
ip[1], ni.
ip[2], ni.
ip[3]);
410 MAKE_TCMD_ADDR(atci.tcmd.arg3, ni.
sn[0], ni.
sn[1], ni.
sn[2], ni.
sn[3]);
411 MAKE_TCMD_ADDR(atci.tcmd.arg4, ni.
gw[0], ni.
gw[1], ni.
gw[2], ni.
gw[3]);
412 MAKE_TCMD_ADDR(atci.tcmd.arg5, ni.
dns[0], ni.
dns[1], ni.
dns[2], ni.
dns[3]);
417 void act_nset_a(int8 mode, uint8 *ip, uint8 *sn,
418 uint8 *gw, uint8 *dns1, uint8 *dns2)
422 if(ip) memcpy(ni.
ip, ip, 4);
423 if(sn) memcpy(ni.
sn, sn, 4);
424 if(gw) memcpy(ni.
gw, gw, 4);
425 if(dns1) memcpy(ni.
dns, dns1, 4);
427 MAKE_TCMD_DIGIT(atci.tcmd.arg1, 6);
428 CMD_RESP_RET(RET_NOT_ALLOWED,
VAL_NONE);
435 }
else if(mode ==
'D') {
446 void act_nstat(int8 num)
453 MAKE_TCMD_CHAR(atci.tcmd.arg1,
'D');
454 else MAKE_TCMD_CHAR(atci.tcmd.arg1,
'S');
458 case 2: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
ip[0], ni.
ip[1], ni.
ip[2], ni.
ip[3]);
break;
459 case 3: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
sn[0], ni.
sn[1], ni.
sn[2], ni.
sn[3]);
break;
460 case 4: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
gw[0], ni.
gw[1], ni.
gw[2], ni.
gw[3]);
break;
461 case 5: MAKE_TCMD_ADDR(atci.tcmd.arg1, ni.
dns[0], ni.
dns[1], ni.
dns[2], ni.
dns[3]);
break;
462 case 6: CMD_RESP_RET(RET_NOT_ALLOWED,
VAL_NONE);
467 MAKE_TCMD_CHAR(atci.tcmd.arg1,
'D');
468 else MAKE_TCMD_CHAR(atci.tcmd.arg1,
'S');
469 MAKE_TCMD_ADDR(atci.tcmd.arg2, ni.
ip[0], ni.
ip[1], ni.
ip[2], ni.
ip[3]);
470 MAKE_TCMD_ADDR(atci.tcmd.arg3, ni.
sn[0], ni.
sn[1], ni.
sn[2], ni.
sn[3]);
471 MAKE_TCMD_ADDR(atci.tcmd.arg4, ni.
gw[0], ni.
gw[1], ni.
gw[2], ni.
gw[3]);
472 MAKE_TCMD_ADDR(atci.tcmd.arg5, ni.
dns[0], ni.
dns[1], ni.
dns[2], ni.
dns[3]);
477 void act_nmac_q(
void)
482 sprintf((
char*)atci.tcmd.arg1,
"%d:%d:%d:%d:%d:%d",
487 void act_nmac_a(uint8 *mac)
489 #if 1 // Enable MAC change
492 memcpy(ni.
mac, mac, 6);
496 CMD_RESP_RET(RET_NOT_ALLOWED,
VAL_NONE);
500 void act_nopen_q(
void)
502 cmd_resp(RET_NOT_ALLOWED,
VAL_NONE);
505 void act_nopen_a(int8 type, uint16 sport, uint8 *dip, uint16 dport)
509 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
510 if(sockstat[i] != SOCK_STAT_IDLE && sockport[i] == sport) {
511 DBGA(
"src port(%d) is using now by sock(%d)", sport, i);
512 MAKE_TCMD_DIGIT(atci.tcmd.arg1, 2);
513 CMD_RESP_RET(RET_USING_PORT,
VAL_NONE);
518 sock = sock_get(SOCK_STAT_TCP_SRV, sport);
523 MAKE_TCMD_DIGIT(atci.tcmd.arg1, sock);
525 }
else if(type ==
'C') {
526 sock = sock_get(SOCK_STAT_TCP_CLT, sport);
530 DBGA(
"TCPCltOpenNB fail - ret(%d)", ret);
531 CMD_RESP_RET(RET_WRONG_ADDR,
VAL_NONE);
535 CMD_RESP_RET(RET_ASYNC, sock);
537 sock = sock_get(SOCK_STAT_UDP, sport);
540 memcpy(udpip[sock], dip, 4);
541 udpport[sock] = dport;
545 MAKE_TCMD_DIGIT(atci.tcmd.arg1, sock);
550 void act_ncls(uint8 sock)
555 if(sockstat[sock] == SOCK_STAT_IDLE) CMD_RESP_RET(RET_SOCK_CLS,
VAL_NONE);
556 if(sockstat[sock] & SOCK_STAT_TCP_MASK) {
562 CMD_RESP_RET(RET_ASYNC, sock);
570 int8 act_nsend_chk(uint8 sock, uint16 *len, uint8 *dip, uint16 *dport)
578 if(sockstat[sock] == SOCK_STAT_IDLE) {
583 if(sockstat[sock] & SOCK_STAT_TCP_MASK) {
584 if(!(sockstat[sock] & SOCK_STAT_CONNECTED)) {
590 if(dip) MAKE_TCMD_DIGIT(atci.tcmd.arg1, 3);
591 else MAKE_TCMD_DIGIT(atci.tcmd.arg1, 4);
596 if(udpip[sock][0]==0 && udpip[sock][1]==0 &&
597 udpip[sock][2]==0 && udpip[sock][3]==0) {
598 DBG(
"No Predefined Dst IP");
599 MAKE_TCMD_DIGIT(atci.tcmd.arg1, 3);
602 }
else memcpy(atci.sendip, udpip[sock], 4);
605 if(udpport[sock] == 0) {
606 DBG(
"No Predefined Dst Port");
607 MAKE_TCMD_DIGIT(atci.tcmd.arg1, 4);
610 }
else atci.sendport = udpport[sock];
615 if(*len > availlen) {
616 DBGA(
"tx buf busy - req(%d), avail(%d)", *len, availlen);
617 MAKE_TCMD_DIGIT(atci.tcmd.arg1, availlen);
625 void act_nsend(uint8 sock, int8 *buf, uint16 len, uint8 *dip, uint16 *dport)
629 if(sockstat[sock] & SOCK_STAT_TCP_MASK) {
632 CRITICAL_ERRA(
"Impossible TCP send busy - len(%d), avail(%d)",
639 ret =
UDPSendNB(sock, buf, len, dip, *dport);
641 CRITICAL_ERRA(
"Impossible UDP send busy - len(%d), avail(%d)",
644 DBGA(
"UDPSendNB fail - ret(%d)", ret);
645 CMD_RESP_RET(RET_WRONG_ADDR,
VAL_NONE);
647 DBGA(
"UDPSendNB SUCC - len(%d),sent(%d)", len, ret);
654 void act_nrecv(int8 sock, uint16 maxlen)
659 int32 len=0, offset=0;
661 DBGA(
"DBG1-sock(%d),recvnum(%d),recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0],
662 recvord[1], recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
666 DBGA(
"no data - sock(%d)", sock);
670 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
671 if(recvord[i] == recvnum) {
676 DBGCRTCA(sock < 0,
"wrong recv order - sock(%d),recvnum(%d),"
677 "recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0], recvord[1],
678 recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
681 DBGA(
"DBG2-sock(%d),recvnum(%d),recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0],
682 recvord[1], recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
684 if(sockstat[sock] == SOCK_STAT_IDLE) {
688 if(sockstat[sock] & SOCK_STAT_TCP_MASK) {
690 if(!(sockstat[sock] & SOCK_STAT_CONNECTED)) {
691 DBGA(
"not connected - sock(%d)", sock);
696 DBGA(
"no data - sock(%d)", sock);
702 uint16 bufleft = maxlen;
704 DBGA(
"no data - sock(%d)", sock);
710 DBGCRTC(len + bufleft > WORK_BUF_SIZE,
"buf not enough");
711 offset =
UDPRecv(sock, &atci.recvbuf[len], bufleft, dstip, &dstport);
712 if(offset <= 0 || offset > (int32)bufleft) {
713 if(offset > (int32)bufleft) {
714 ERRA(
"buf overflw - off(%d), maxlen(%d)", offset, bufleft);
716 ret = RET_UNSPECIFIED;
721 ERRA(
"wrong reaction - ret(%d)", offset);
726 }
else if(offset < 0) {
727 ret = RET_UNSPECIFIED;
736 DBGA(
"UDP Recv - off(%d), len(%d), maxlen(%d)", offset, len, bufleft);
744 atci.recvbuf[len] = 0;
745 DBGA(
"RECV prt-len(%d), max(%d)", len, maxlen);
747 MAKE_TCMD_DIGIT(atci.tcmd.arg1, len);
748 if((sockstat[sock] & SOCK_STAT_PROTMASK) == SOCK_STAT_UDP) {
749 MAKE_TCMD_ADDR(atci.tcmd.arg2, dstip[0], dstip[1], dstip[2], dstip[3]);
750 MAKE_TCMD_DIGIT(atci.tcmd.arg3, dstport);
754 if(recvord[sock] < recvnum) {
755 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++)
756 if(recvord[i] > recvord[sock]) recvord[i]--;
761 if((sockstat[sock] & SOCK_STAT_PROTMASK) == SOCK_STAT_IDLE) {
762 CRITICAL_ERRA(
"Impossible status - recv from closed sock(%d)", sock);
763 }
else if(sockstat[sock] & SOCK_STAT_TCP_MASK) {
764 if(sockstat[sock] & SOCK_STAT_CONNECTED)
766 }
else if(sockstat[sock] & SOCK_STAT_UDP) {
768 }
else CRITICAL_ERRA(
"Impossible status - wrong sock state(0x%x)", sockstat[sock]);
770 cmd_resp(RET_RECV, sock);
771 printf(
"%s\r\n", atci.recvbuf);
773 cmd_resp(RET_RECV, sock);
774 printf(
"%s\r\n", atci.recvbuf);
782 DBGA(
"DBG3^1-sock(%d),recvnum(%d),recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0],
783 recvord[1], recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
813 DBGA(
"DBG3^2-sock(%d),recvnum(%d),recvord(%d,%d,%d,%d,%d,%d,%d,%d)", sock, recvnum, recvord[0],
814 recvord[1], recvord[2], recvord[3], recvord[4], recvord[5], recvord[6], recvord[7]);
819 void act_nsock(int8 sock)
824 if(sock < ATC_SOCK_NUM_START)
826 int8 *dump, i, type, cnt_con=0, cnt_notcon=0;
829 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
830 if(sockstat[i] != SOCK_STAT_IDLE) {
831 if((sockstat[i] & SOCK_STAT_PROTMASK) == SOCK_STAT_UDP) {
832 if(udpport[i] != 0) cnt_con++;
835 if(sockstat[i] & SOCK_STAT_CONNECTED) cnt_con++;
841 if(cnt_con+cnt_notcon == 0) {
845 dump = malloc((34*cnt_con)+(12*cnt_notcon)+1);
846 if(dump == NULL) CMD_RESP_RET(RET_NO_FREEMEM,
VAL_NONE);
848 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
849 if(sockstat[i] == SOCK_STAT_IDLE)
continue;
851 dump[cnt_con++] =
'\r';
852 dump[cnt_con++] =
'\n';
855 if((sockstat[i]&SOCK_STAT_PROTMASK)==SOCK_STAT_UDP) {
857 sprintf((
char*)&dump[cnt_con],
"%d,%c,%d,%d.%d.%d.%d,%d", i,
'U', sockport[i],
858 udpip[i][0], udpip[i][1], udpip[i][2], udpip[i][3], udpport[i]);
860 sprintf((
char*)&dump[cnt_con],
"%d,%c,%d", i,
'U', sockport[i]);
863 if((sockstat[i]&SOCK_STAT_PROTMASK)==SOCK_STAT_TCP_SRV) type =
'S';
865 if(sockstat[i] & SOCK_STAT_CONNECTED) {
867 sprintf((
char*)&dump[cnt_con],
"%d,%c,%d,%d.%d.%d.%d,%d", i, type,
868 sockport[i], tip[0], tip[1], tip[2], tip[3], tport);
870 sprintf((
char*)&dump[cnt_con],
"%d,%c,%d", i, type, sockport[i]);
873 cnt_con += strlen((
char*)&dump[cnt_con]);
877 else if(sock <= ATC_SOCK_NUM_END)
879 if(sockstat[sock] == SOCK_STAT_IDLE) {
880 sprintf((
char*)atci.tcmd.arg1,
"%c",
'I');
882 if((sockstat[sock] & SOCK_STAT_PROTMASK) == SOCK_STAT_UDP) {
883 sprintf((
char*)atci.tcmd.arg1,
"%c",
'U');
884 sprintf((
char*)atci.tcmd.arg2,
"%d", sockport[sock]);
886 sprintf((
char*)atci.tcmd.arg3,
"%d.%d.%d.%d",
887 udpip[sock][0], udpip[sock][1], udpip[sock][2], udpip[sock][3]);
888 sprintf((
char*)atci.tcmd.arg4,
"%d", udpport[sock]);
891 if((sockstat[sock] & SOCK_STAT_PROTMASK) == SOCK_STAT_TCP_SRV)
892 sprintf((
char*)atci.tcmd.arg1,
"%c",
'S');
893 else if((sockstat[sock] & SOCK_STAT_PROTMASK) == SOCK_STAT_TCP_CLT)
894 sprintf((
char*)atci.tcmd.arg1,
"%c",
'C');
895 else CRITICAL_ERRA(
"wrong sock state(0x%d)", sockstat[sock]);
896 sprintf((
char*)atci.tcmd.arg2,
"%d", sockport[sock]);
897 if(sockstat[sock] & SOCK_STAT_CONNECTED) {
899 sprintf((
char*)atci.tcmd.arg3,
"%d.%d.%d.%d",
900 tip[0], tip[1], tip[2], tip[3]);
901 sprintf((
char*)atci.tcmd.arg4,
"%d", tport);
907 else CMD_RESP_RET(RET_WRONG_ARG,
VAL_NONE);
935 void act_wleave(
void)
950 void act_mset_q(int8 num)
953 MAKE_TCMD_CHAR(atci.tcmd.arg1,
'E');
954 else MAKE_TCMD_CHAR(atci.tcmd.arg1,
'D');
956 if(atci.poll == POLL_MODE_FULL)
957 MAKE_TCMD_CHAR(atci.tcmd.arg3,
'F');
958 else if(atci.poll == POLL_MODE_SEMI)
959 MAKE_TCMD_CHAR(atci.tcmd.arg3,
'S');
960 else MAKE_TCMD_CHAR(atci.tcmd.arg3,
'D');
965 void act_mset_a(int8 echo, int8 mode, int8 poll, int8 country)
967 DBGA(
"Set: echo(%c), poll(%c)", echo, poll);
971 if(poll ==
'F') atci.poll = POLL_MODE_FULL;
972 else if(poll ==
'S') atci.poll = POLL_MODE_SEMI;
973 else if(poll ==
'D') atci.poll = POLL_MODE_NONE;
974 DBGA(
"echo(%d), poll(%d)", atci.echo, atci.poll);
980 MAKE_TCMD_STRING(atci.tcmd.arg1, ARG_3_SIZE, ATC_VERSION);
985 void act_mevt_q(
void)
989 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
990 if(sockstat[i] != SOCK_STAT_IDLE) cnt++;
995 tbuf = malloc(cnt+1);
997 MAKE_TCMD_DIGIT(atci.tcmd.arg1, cnt+1);
998 CMD_RESP_RET(RET_NO_FREEMEM,
VAL_NONE);
1000 for(i=ATC_SOCK_NUM_START; i<=ATC_SOCK_NUM_END; i++) {
1001 if(sockstat[i] != SOCK_STAT_IDLE)
1002 sprintf((
char*)&tbuf[7*(i-ATC_SOCK_NUM_START)],
"%1d,sock\r\n", i);
1004 MAKE_TCMD_DIGIT(atci.tcmd.arg1, cnt);
1008 void act_mevt_a(int8
id)
1012 if(event_dequeue(&
id, &event) !=
RET_OK) {
1013 CMD_RESP_RET(RET_NO_DATA,
VAL_NONE);
1016 if(
id <= ATC_SOCK_NUM_END && event == SOCKEVENT_RECV)
1018 else EVENT_RESP(
id, event);