17 static uint16_t local_port = 0xC000;
28 ERRA(
"wrong socket number(%d)", s);
33 if(local_port == 0xffff) local_port = 0xc000;
54 int8_t
TCPClientOpen(uint8_t s, uint16_t sport, uint8_t *dip, uint16_t dport)
60 if(ret !=
RET_OK)
return ret;
69 int8_t
TCPCltOpenNB(uint8_t s, uint16_t sport, uint8_t *dip, uint16_t dport)
71 uint8_t srcip[4], snmask[4];
74 ERRA(
"wrong socket number(%d)", s);
76 }
else if(dip == NULL) {
82 if(local_port == 0xffff) local_port = 0xc000;
97 if( ((dip[0] == 0xFF) && (dip[1] == 0xFF) &&
98 (dip[2] == 0xFF) && (dip[3] == 0xFF)) ||
99 ((dip[0] == 0x00) && (dip[1] == 0x00) &&
100 (dip[2] == 0x00) && (dip[3] == 0x00)) || (sport == 0x00) )
102 DBG(
"invalid ip or port");
103 DBGA(
"SOCK(%d)-[%02x.%02x.%02x.%02x, %d]",s,
104 dip[0], dip[1], dip[2], dip[3] , sport);
107 else if( (srcip[0]==0 && srcip[1]==0 && srcip[2]==0 && srcip[3]==0) &&
108 (snmask[0]!=0 || snmask[1]!=0 || snmask[2]!=0 || snmask[3]!=0) )
110 DBG(
"Source IP is NULL while SN Mask is Not NULL");
130 ERRA(
"wrong socket number(%d)", s);
151 ERR(
"Not implemented yet");
155 ERRA(
"wrong socket number(%d)", s);
171 if(ret !=
RET_OK)
return ret;
185 ERRA(
"wrong socket number(%d)", s);
198 #define TIMEOUT_CLOSE_WAIT 200
202 ERRA(
"wrong socket number(%d)", s);
219 #define TIMEOUT_CLOSE_WAIT 200
223 ERRA(
"wrong socket number(%d)", s);
239 int32_t
TCPSend(uint8_t s,
const int8_t *buf, uint16_t len)
257 int8_t
TCPSendNB(uint8_t s,
const int8_t *buf, uint16_t len)
262 ERRA(
"wrong socket number(%d)", s);
264 }
else if(len == 0) {
312 ERRA(
"wrong socket number(%d)", s);
350 if(txrd > txrd_checker[s])
return txrd - txrd_checker[s];
351 else return (0xffff - txrd_checker[s]) + txrd + 1;
354 int32_t
TCPRecv(uint8_t s, int8_t *buf, uint16_t len)
357 uint16_t RSR_len = 0;
360 ERRA(
"wrong socket number(%d)", s);
362 }
else if(len == 0) {
376 if(len < RSR_len) RSR_len = len;
388 ERRA(
"wrong socket number(%d)", s);
393 if(local_port == 0xffff) local_port = 0xc000;
413 ERRA(
"wrong socket number(%d)", s);
424 int32_t
UDPSend(uint8_t s,
const int8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
428 ret =
UDPSendNB(s, buf, len, addr, port);
429 if(ret <
RET_OK)
return ret;
434 if(ret ==
RET_OK)
return len;
439 int32_t
UDPSendNB(uint8_t s,
const int8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
441 uint8_t srcip[4], snmask[4], status = 0;
444 ERRA(
"wrong socket number(%d)", s);
446 }
else if(len == 0 || addr == NULL) {
447 if(len == 0)
ERR(
"Zero length");
448 else ERR(
"NULL Dst IP");
462 if((addr[0]==0x00 && addr[1]==0x00 && addr[2]==0x00 &&
463 addr[3]==0x00) || (port==0x00))
465 DBG(
"invalid ip or port");
466 DBGA(
"SOCK(%d)-[%02x.%02x.%02x.%02x, %d, %d]",s,
467 addr[0], addr[1], addr[2], addr[3] , port, len);
470 else if( (srcip[0]==0 && srcip[1]==0 && srcip[2]==0 && srcip[3]==0) &&
471 (snmask[0]!=0 || snmask[1]!=0 || snmask[2]!=0 || snmask[3]!=0) )
473 DBG(
"Source IP is NULL while SN Mask is Not NULL");
499 setSn_IR(s, (Sn_IR_SENDOK | Sn_IR_TIMEOUT));
509 int32_t
UDPRecv(uint8_t s, int8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
511 uint8_t prebuf[8], status = 0;
512 uint16_t tmp_len = 0, RSR_len = 0;
515 ERRA(
"wrong socket number(%d)", s);
517 }
else if(len == 0) {
529 DBGA(
"wrong data received (%d)", RSR_len);
547 *port = (*port << 8) + prebuf[5];
550 tmp_len = (tmp_len << 8) + prebuf[7];
553 DBGA(
"UDP Recv - addr(%d.%d.%d.%d:%d), t(%d), R(%d)",
554 addr[0], addr[1], addr[2], addr[3], *port, tmp_len, RSR_len);
556 ERR(
"UDP Recv len Zero - remove rest all");
565 tmp_len = RSR_len - len;
567 DBGA(
"Recv buffer not enough - len(%d)", len);
578 DBG(
"Ignore rest data");
583 if(tmp_len)
DBGA(
"another rest data(%d)", tmp_len);
584 else DBG(
"No rest data");