mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Merge remote-tracking branch 'mlafauci/wifishield-bugfix' into HEAD
This commit is contained in:
commit
1b0bff6f2c
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -326,12 +326,8 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
|
|||||||
{
|
{
|
||||||
uint16_t _len = 0;
|
uint16_t _len = 0;
|
||||||
unsigned short dummy=0;
|
unsigned short dummy=0;
|
||||||
bool streamExit = false;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (*stream == END_CMD)
|
|
||||||
streamExit = true;
|
|
||||||
|
|
||||||
//SIGN1_DN();
|
//SIGN1_DN();
|
||||||
if (spi_write(spi, *stream) == SPI_ERROR_TIMEOUT)
|
if (spi_write(spi, *stream) == SPI_ERROR_TIMEOUT)
|
||||||
{
|
{
|
||||||
@ -350,16 +346,7 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
|
|||||||
spi_read(spi,&dummy);
|
spi_read(spi,&dummy);
|
||||||
}
|
}
|
||||||
//SIGN1_UP();
|
//SIGN1_UP();
|
||||||
}while ((!streamExit)&&(_len <= len));
|
}while (_len < len);
|
||||||
|
|
||||||
if (!streamExit)
|
|
||||||
{
|
|
||||||
#ifdef _SPI_STATS_
|
|
||||||
statSpi.wrongFrame++;
|
|
||||||
statSpi.lastError = SPI_ERROR_ARGUMENT;
|
|
||||||
#endif
|
|
||||||
return SPI_ERROR_ARGUMENT;
|
|
||||||
}
|
|
||||||
return SPI_OK;
|
return SPI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1640,6 +1627,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int err = SPI_OK;
|
int err = SPI_OK;
|
||||||
state = SPI_CMD_INPUT;
|
state = SPI_CMD_INPUT;
|
||||||
|
bool endOfFrame = false;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned int timeout = SPI_TIMEOUT;
|
unsigned int timeout = SPI_TIMEOUT;
|
||||||
@ -1680,7 +1668,31 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
|
|||||||
err = SPI_ERROR_OVERRUN_AND_MODE_FAULT;
|
err = SPI_ERROR_OVERRUN_AND_MODE_FAULT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (_receiveBuffer[index - 1] != END_CMD);
|
|
||||||
|
if (_receiveBuffer[index - 1] == END_CMD)
|
||||||
|
{
|
||||||
|
int8_t numParams = 0;
|
||||||
|
int idx = PARAM_LEN_POS+1;
|
||||||
|
bool islen16bit = _receiveBuffer[CMD_POS] & DATA_FLAG;
|
||||||
|
if (index >= idx)
|
||||||
|
{
|
||||||
|
numParams = _receiveBuffer[PARAM_LEN_POS];
|
||||||
|
while (((index-1) > idx)&&(numParams>0))
|
||||||
|
{
|
||||||
|
if (islen16bit)
|
||||||
|
idx += (_receiveBuffer[idx]<<8) + _receiveBuffer[idx+1]+2;
|
||||||
|
else
|
||||||
|
idx += _receiveBuffer[idx]+1;
|
||||||
|
--numParams;
|
||||||
|
}
|
||||||
|
if (((index-1) == idx) && (numParams == 0))
|
||||||
|
endOfFrame = true;
|
||||||
|
}
|
||||||
|
if (!endOfFrame){
|
||||||
|
WARN("Wrong termination index:%d nParam:%d idx:%d 16bit:%d\n", index, numParams, idx, islen16bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!endOfFrame);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,6 @@ extern bool ifStatus;
|
|||||||
|
|
||||||
static int isDataSentCount = 0;
|
static int isDataSentCount = 0;
|
||||||
|
|
||||||
bool pending_accept = false;
|
|
||||||
|
|
||||||
static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len);
|
static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len);
|
||||||
|
|
||||||
static void atcp_init_pend_flags(struct ttcp* _ttcp)
|
static void atcp_init_pend_flags(struct ttcp* _ttcp)
|
||||||
@ -44,7 +42,6 @@ static void atcp_init_pend_flags(struct ttcp* _ttcp)
|
|||||||
{
|
{
|
||||||
if (_ttcp) _ttcp->pending_close[i] = false;
|
if (_ttcp) _ttcp->pending_close[i] = false;
|
||||||
}
|
}
|
||||||
pending_accept = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +115,7 @@ static err_t tcp_send_data(struct ttcp *ttcp) {
|
|||||||
len = ttcp->left;
|
len = ttcp->left;
|
||||||
ttcp->buff_sent = 0;
|
ttcp->buff_sent = 0;
|
||||||
|
|
||||||
if (len == 0) return;
|
if (len == 0) return ERR_MEM;
|
||||||
|
|
||||||
INFO_TCP_VER("left=%d len:%d\n", ttcp->left, len);
|
INFO_TCP_VER("left=%d len:%d\n", ttcp->left, len);
|
||||||
|
|
||||||
@ -126,19 +123,20 @@ static err_t tcp_send_data(struct ttcp *ttcp) {
|
|||||||
if (len > ttcp->buflen)
|
if (len > ttcp->buflen)
|
||||||
len = ttcp->buflen;
|
len = ttcp->buflen;
|
||||||
|
|
||||||
|
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP_NV(ttcp);
|
||||||
/* We cannot send more data than space available in the send
|
/* We cannot send more data than space available in the send
|
||||||
buffer. */
|
buffer. */
|
||||||
if (len > tcp_sndbuf(GET_FIRST_CLIENT_TCP(ttcp)))
|
if (len > tcp_sndbuf(pcb))
|
||||||
len = tcp_sndbuf(GET_FIRST_CLIENT_TCP(ttcp));
|
len = tcp_sndbuf(pcb);
|
||||||
|
|
||||||
orig_len = len;
|
orig_len = len;
|
||||||
|
|
||||||
IF_TCP(startTime = timer_get_ms());
|
IF_TCP(startTime = timer_get_ms());
|
||||||
err = tcp_write(GET_FIRST_CLIENT_TCP(ttcp), ttcp->payload, len, TCP_WRITE_FLAG_COPY);
|
err = tcp_write(pcb, ttcp->payload, len, TCP_WRITE_FLAG_COPY);
|
||||||
if (err != ERR_OK)
|
if (err != ERR_OK)
|
||||||
{
|
{
|
||||||
INFO_TCP("tcp_write failed %p state:%d len:%d err:%d\n",
|
INFO_TCP("tcp_write failed %p state:%d len:%d err:%d\n",
|
||||||
GET_FIRST_CLIENT_TCP(ttcp), GET_FIRST_CLIENT_TCP(ttcp)->state, len, err);
|
pcb, pcb->state, len, err);
|
||||||
ttcp->buff_sent = 0;
|
ttcp->buff_sent = 0;
|
||||||
}else{
|
}else{
|
||||||
ttcp->buff_sent = 1;
|
ttcp->buff_sent = 1;
|
||||||
@ -235,10 +233,10 @@ static void atcp_conn_cli_err_cb(void *arg, err_t err) {
|
|||||||
|
|
||||||
static err_t close_conn(struct ttcp *_ttcp, struct tcp_pcb* tpcb) {
|
static err_t close_conn(struct ttcp *_ttcp, struct tcp_pcb* tpcb) {
|
||||||
|
|
||||||
if (_ttcp == NULL) return;
|
if (_ttcp == NULL) return ERR_MEM;
|
||||||
|
|
||||||
int8_t id = getNewClientConnId(_ttcp, tpcb);
|
int8_t id = getNewClientConnId(_ttcp, tpcb);
|
||||||
if (id == NO_VALID_ID) return;
|
if (id == NO_VALID_ID) return ERR_MEM;
|
||||||
err_t err = close_conn_pcb(_ttcp->tpcb[id]);
|
err_t err = close_conn_pcb(_ttcp->tpcb[id]);
|
||||||
|
|
||||||
if (err == ERR_MEM)
|
if (err == ERR_MEM)
|
||||||
@ -336,13 +334,13 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
|
|||||||
INFO_TCP_POLL("keepAliveCnt:%d keep_idle:%d persist_cnt:%d\n",
|
INFO_TCP_POLL("keepAliveCnt:%d keep_idle:%d persist_cnt:%d\n",
|
||||||
pcb->keep_cnt_sent, pcb->keep_idle, pcb->persist_cnt);
|
pcb->keep_cnt_sent, pcb->keep_idle, pcb->persist_cnt);
|
||||||
|
|
||||||
|
int8_t id = getNewClientConnId(_ttcp, pcb);
|
||||||
if (_ttcp->left > 0)
|
if (_ttcp->left > 0)
|
||||||
INFO_TCP("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d len:%d\n",
|
INFO_TCP("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d len:%d\n",
|
||||||
(_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0, pcb, arg,
|
(_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0, pcb, arg,
|
||||||
_ttcp->tcp_poll_retries, _ttcp->pending_close, (_ttcp)?_ttcp->left:0);
|
_ttcp->tcp_poll_retries, _ttcp->pending_close[id], (_ttcp)?_ttcp->left:0);
|
||||||
tcp_send_data(_ttcp);
|
tcp_send_data(_ttcp);
|
||||||
|
|
||||||
int8_t id = getNewClientConnId(_ttcp, pcb);
|
|
||||||
if ((id != NO_VALID_ID) && (_ttcp->pending_close[id]))
|
if ((id != NO_VALID_ID) && (_ttcp->pending_close[id]))
|
||||||
{
|
{
|
||||||
err_t err = ERR_OK;
|
err_t err = ERR_OK;
|
||||||
@ -411,23 +409,50 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t currConnId = 0;
|
||||||
|
#define GET_IDX_CONN(I) ((I+currConnId)<MAX_CLIENT_ACCEPTED ? (I+currConnId) : (I+currConnId-MAX_CLIENT_ACCEPTED))
|
||||||
|
|
||||||
|
int8_t getCurrClientConnId() { return currConnId;}
|
||||||
|
|
||||||
int8_t getNewClientConnId(struct ttcp* _ttcp, struct tcp_pcb *newpcb)
|
int8_t getNewClientConnId(struct ttcp* _ttcp, struct tcp_pcb *newpcb)
|
||||||
{
|
{
|
||||||
if (_ttcp != NULL){
|
if (_ttcp != NULL){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
||||||
{
|
{
|
||||||
if (_ttcp->tpcb[i] == newpcb)
|
int idx = GET_IDX_CONN(i);
|
||||||
|
|
||||||
|
if (_ttcp->tpcb[idx] == newpcb)
|
||||||
{
|
{
|
||||||
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, i, newpcb);
|
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, idx, newpcb);
|
||||||
return i;
|
return idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WARN("No Valid Id for ttcp:%p pcb:%p\n");
|
WARN("No Valid Id for ttcp:%p pcb:%p\n", _ttcp, newpcb);
|
||||||
return NO_VALID_ID;
|
return NO_VALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct tcp_pcb * getFirstClient(struct ttcp* _ttcp, bool verbose)
|
||||||
|
{
|
||||||
|
if (_ttcp != NULL){
|
||||||
|
int i = 0;
|
||||||
|
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
||||||
|
{
|
||||||
|
int idx = GET_IDX_CONN(i);
|
||||||
|
if (_ttcp->tpcb[idx] != NULL)
|
||||||
|
{
|
||||||
|
if (verbose) INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, idx, _ttcp->tpcb[idx]);
|
||||||
|
currConnId = idx;
|
||||||
|
return _ttcp->tpcb[idx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (verbose) WARN("No Valid client for ttcp:%p\n", _ttcp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int8_t setNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb, uint8_t id)
|
int8_t setNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb, uint8_t id)
|
||||||
{
|
{
|
||||||
if ((_ttcp != NULL)&&(id>=0)&&(id<MAX_CLIENT_ACCEPTED)){
|
if ((_ttcp != NULL)&&(id>=0)&&(id<MAX_CLIENT_ACCEPTED)){
|
||||||
@ -444,11 +469,12 @@ int8_t insertNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
||||||
{
|
{
|
||||||
if ((_ttcp->tpcb[i] == NULL)||(_ttcp->tpcb[i] == newpcb))
|
int idx = GET_IDX_CONN(i);
|
||||||
|
if ((_ttcp->tpcb[idx] == NULL)||(_ttcp->tpcb[idx] == newpcb))
|
||||||
{
|
{
|
||||||
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, i, newpcb);
|
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, idx, newpcb);
|
||||||
_ttcp->tpcb[i] = newpcb;
|
_ttcp->tpcb[idx] = newpcb;
|
||||||
return i;
|
return idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,11 +487,12 @@ int8_t removeNewClientConn(struct ttcp* _ttcp, struct tcp_pcb *newpcb)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
||||||
{
|
{
|
||||||
if (_ttcp->tpcb[i] == newpcb)
|
int idx = GET_IDX_CONN(i);
|
||||||
|
if (_ttcp->tpcb[idx] == newpcb)
|
||||||
{
|
{
|
||||||
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, i, newpcb);
|
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, idx, newpcb);
|
||||||
_ttcp->tpcb[i] = NULL;
|
_ttcp->tpcb[idx] = NULL;
|
||||||
return i;
|
return idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,27 +521,7 @@ static err_t atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
|||||||
|
|
||||||
INFO_TCP("ARD TCP [%p]: accept new [%p]\n", _ttcp, newpcb);
|
INFO_TCP("ARD TCP [%p]: accept new [%p]\n", _ttcp, newpcb);
|
||||||
INFO_TCP("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
|
INFO_TCP("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
|
||||||
/*
|
|
||||||
if (pending_accept)
|
|
||||||
{
|
|
||||||
WARN("Accepting another connection: %p-%p\n", ttcp->tpcb, newpcb);
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
|
||||||
pending_accept = true;
|
|
||||||
tcp_setprio(newpcb, TCP_PRIO_MIN);
|
|
||||||
tcp_poll_retries = 0;
|
|
||||||
ttcp->tpcb = newpcb;
|
|
||||||
tcp_recv(ttcp->tpcb, atcp_recv_cb);
|
|
||||||
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
|
||||||
tcp_poll(ttcp->tpcb, atcp_poll, 4);
|
|
||||||
|
|
||||||
_ttcp->tcp_poll_retries = 0;
|
|
||||||
/*
|
|
||||||
if (_ttcp->tpcb == NULL)
|
|
||||||
{
|
|
||||||
WARN("Replace previous tpcb=0x%x with the new one 0x%x\n", _ttcp->tpcb, newpcb);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
int8_t id = insertNewClientConn(_ttcp, newpcb);
|
int8_t id = insertNewClientConn(_ttcp, newpcb);
|
||||||
tcp_arg(_ttcp->tpcb[id], _ttcp);
|
tcp_arg(_ttcp->tpcb[id], _ttcp);
|
||||||
tcp_recv(_ttcp->tpcb[id], atcp_recv_cb);
|
tcp_recv(_ttcp->tpcb[id], atcp_recv_cb);
|
||||||
@ -552,14 +559,15 @@ static int atcp_start(struct ttcp* ttcp) {
|
|||||||
|
|
||||||
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
||||||
setNewClientConn(ttcp, p, 0);
|
setNewClientConn(ttcp, p, 0);
|
||||||
tcp_err(GET_FIRST_CLIENT_TCP(ttcp), atcp_conn_cli_err_cb);
|
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP(ttcp);
|
||||||
tcp_recv(GET_FIRST_CLIENT_TCP(ttcp), atcp_recv_cb);
|
tcp_err(pcb, atcp_conn_cli_err_cb);
|
||||||
tcp_sent(GET_FIRST_CLIENT_TCP(ttcp), tcp_data_sent);
|
tcp_recv(pcb, atcp_recv_cb);
|
||||||
tcp_poll(GET_FIRST_CLIENT_TCP(ttcp), atcp_poll_conn, 4);
|
tcp_sent(pcb, tcp_data_sent);
|
||||||
|
tcp_poll(pcb, atcp_poll_conn, 4);
|
||||||
_connected = false;
|
_connected = false;
|
||||||
INFO_TCP("[tpcb]-%p payload:%p\n", GET_FIRST_CLIENT_TCP(ttcp), ttcp->payload);
|
INFO_TCP("[tpcb]-%p payload:%p\n", pcb, ttcp->payload);
|
||||||
DUMP_TCP_STATE(ttcp);
|
DUMP_TCP_STATE(ttcp);
|
||||||
if (tcp_connect(GET_FIRST_CLIENT_TCP(ttcp), &ttcp->addr, ttcp->port, tcp_connect_cb)
|
if (tcp_connect(pcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
|
||||||
!= ERR_OK) {
|
!= ERR_OK) {
|
||||||
WARN("TTCP [%p]: tcp connect failed\n", ttcp);
|
WARN("TTCP [%p]: tcp connect failed\n", ttcp);
|
||||||
return -1;
|
return -1;
|
||||||
@ -690,12 +698,13 @@ static int udp_start(struct ttcp* ttcp) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("%s, upcb:%p %s:%d\n", __FUNCTION__, ttcp->upcb, ip2str(ttcp->addr), ttcp->port);
|
INFO_TCP("%s, upcb:%p %s:%d\n", __FUNCTION__, ttcp->upcb, ip2str(ttcp->addr), ttcp->port);
|
||||||
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
||||||
if (udp_connect(ttcp->upcb, &(ttcp->addr), ttcp->port) != ERR_OK) {
|
if (udp_connect(ttcp->upcb, &(ttcp->addr), ttcp->port) != ERR_OK) {
|
||||||
WARN("TTCP [%p]: udp connect failed\n", ttcp);
|
WARN("TTCP [%p]: udp connect failed\n", ttcp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
udp_recv(ttcp->upcb, audp_recv_cb, ttcp);
|
||||||
} else {
|
} else {
|
||||||
/* bind to any IP address on port specified */
|
/* bind to any IP address on port specified */
|
||||||
err = udp_bind(ttcp->upcb, IP_ADDR_ANY, ttcp->port);
|
err = udp_bind(ttcp->upcb, IP_ADDR_ANY, ttcp->port);
|
||||||
@ -707,7 +716,7 @@ static int udp_start(struct ttcp* ttcp) {
|
|||||||
setRemoteClient(ttcp->sock, 0, 0);
|
setRemoteClient(ttcp->sock, 0, 0);
|
||||||
udp_recv(ttcp->upcb, audp_recv_cb, ttcp);
|
udp_recv(ttcp->upcb, audp_recv_cb, ttcp);
|
||||||
}
|
}
|
||||||
printk("%s, loc:0x%x-%d rem:0x%x-%d\n", __FUNCTION__,
|
INFO_TCP("%s, loc:0x%x-%d rem:0x%x-%d\n", __FUNCTION__,
|
||||||
ttcp->upcb->local_ip.addr, ttcp->upcb->local_port,
|
ttcp->upcb->local_ip.addr, ttcp->upcb->local_port,
|
||||||
ttcp->upcb->remote_ip.addr, ttcp->upcb->remote_port);
|
ttcp->upcb->remote_ip.addr, ttcp->upcb->remote_port);
|
||||||
return 0;
|
return 0;
|
||||||
@ -777,7 +786,6 @@ int ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
//fail: ard_tcp_abort(ttcp);
|
|
||||||
fail: ard_tcp_destroy(ttcp);
|
fail: ard_tcp_destroy(ttcp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -796,21 +804,16 @@ void ard_tcp_stop(void* ttcp) {
|
|||||||
}else{
|
}else{
|
||||||
DUMP_TCP_STATE(_ttcp);
|
DUMP_TCP_STATE(_ttcp);
|
||||||
|
|
||||||
int i = 0;
|
int i = getCurrClientConnId();
|
||||||
for (; i<MAX_CLIENT_ACCEPTED; ++i)
|
|
||||||
{
|
|
||||||
if ((_ttcp)&&(_ttcp->tpcb[i])&&(_ttcp->tpcb[i]->state!=LAST_ACK)&&(_ttcp->tpcb[i]->state!=CLOSED))
|
if ((_ttcp)&&(_ttcp->tpcb[i])&&(_ttcp->tpcb[i]->state!=LAST_ACK)&&(_ttcp->tpcb[i]->state!=CLOSED))
|
||||||
{
|
{
|
||||||
// Flush all the data
|
// Flush all the data
|
||||||
err_t err=tcp_output(_ttcp->tpcb[i]);
|
err_t err=tcp_output(_ttcp->tpcb[i]);
|
||||||
INFO_TCP("flush data: tpcb:%p err:%d\n", _ttcp->tpcb[i], err);
|
INFO_TCP("flush data: tpcb:%p err:%d\n", _ttcp->tpcb[i], err);
|
||||||
// if any socket cannot be close stop the close connection
|
// if any socket cannot be close stop the close connection
|
||||||
if (close_conn(_ttcp, _ttcp->tpcb[i]) != ERR_OK) break;
|
close_conn(_ttcp, _ttcp->tpcb[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pending_accept = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getStateTcp(void* p, bool client) {
|
uint8_t getStateTcp(void* p, bool client) {
|
||||||
@ -818,15 +821,16 @@ uint8_t getStateTcp(void* p, bool client) {
|
|||||||
|
|
||||||
if (ifStatus == false)
|
if (ifStatus == false)
|
||||||
return CLOSED;
|
return CLOSED;
|
||||||
if ((_ttcp != NULL) && ((GET_FIRST_CLIENT_TCP(_ttcp) != NULL) || (client==0))) {
|
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP_NV(_ttcp);
|
||||||
|
if ((_ttcp != NULL) && ((pcb != NULL) || (client==0))) {
|
||||||
IF_SPI_POLL(DUMP_TCP_STATE(_ttcp));
|
IF_SPI_POLL(DUMP_TCP_STATE(_ttcp));
|
||||||
if (client)
|
if (client)
|
||||||
return GET_FIRST_CLIENT_TCP(_ttcp)->state;
|
return pcb->state;
|
||||||
else
|
else
|
||||||
return _ttcp->lpcb->state;
|
return _ttcp->lpcb->state;
|
||||||
} else {
|
} else {
|
||||||
WARN_POLL("TCP not initialized ttcp:%p tpcb:%p lpcb:%p\n",
|
WARN_POLL("TCP not initialized ttcp:%p tpcb:%p lpcb:%p\n",
|
||||||
_ttcp, ((_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0), ((_ttcp)?_ttcp->lpcb:0));
|
_ttcp, ((_ttcp)?pcb:0), ((_ttcp)?_ttcp->lpcb:0));
|
||||||
}
|
}
|
||||||
return CLOSED;
|
return CLOSED;
|
||||||
}
|
}
|
||||||
@ -886,23 +890,21 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len)
|
|||||||
return WL_FAILURE;
|
return WL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO_TCP_VER("ttcp:%p pcb:%p buf:%p len:%d\n", _ttcp,
|
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP_NV(_ttcp);
|
||||||
GET_FIRST_CLIENT_TCP(_ttcp), buf, len);
|
INFO_TCP_VER("ttcp:%p pcb:%p buf:%p len:%d\n", _ttcp, pcb, buf, len);
|
||||||
DUMP_TCP(buf,len);
|
DUMP_TCP(buf,len);
|
||||||
IF_TCP_VER(DUMP_TCP_STATE(_ttcp));
|
IF_TCP_VER(DUMP_TCP_STATE(_ttcp));
|
||||||
|
|
||||||
if ((_ttcp != NULL) && (GET_FIRST_CLIENT_TCP(_ttcp) != NULL) &&
|
if ((_ttcp != NULL) && (pcb != NULL) &&
|
||||||
(buf != NULL) && (len != 0) && (_ttcp->payload != NULL)) {
|
(buf != NULL) && (len != 0) && (_ttcp->payload != NULL)) {
|
||||||
if (GET_FIRST_CLIENT_TCP(_ttcp)->state == ESTABLISHED ||
|
if (pcb->state == ESTABLISHED || pcb->state == CLOSE_WAIT ||
|
||||||
GET_FIRST_CLIENT_TCP(_ttcp)->state == CLOSE_WAIT ||
|
pcb->state == SYN_SENT || pcb->state == SYN_RCVD) {
|
||||||
GET_FIRST_CLIENT_TCP(_ttcp)->state == SYN_SENT ||
|
|
||||||
GET_FIRST_CLIENT_TCP(_ttcp)->state == SYN_RCVD) {
|
|
||||||
|
|
||||||
memcpy(_ttcp->payload, buf, len);
|
memcpy(_ttcp->payload, buf, len);
|
||||||
_ttcp->payload[len]='\0';
|
_ttcp->payload[len]='\0';
|
||||||
INFO_TCP_VER("'%s'\n", _ttcp->payload);
|
INFO_TCP_VER("'%s'\n", _ttcp->payload);
|
||||||
_ttcp->left = len;
|
_ttcp->left = len;
|
||||||
tcp_sent(GET_FIRST_CLIENT_TCP(_ttcp), tcp_data_sent);
|
tcp_sent(pcb, tcp_data_sent);
|
||||||
tcp_send_data(_ttcp);
|
tcp_send_data(_ttcp);
|
||||||
|
|
||||||
return WL_SUCCESS;
|
return WL_SUCCESS;
|
||||||
|
@ -24,7 +24,9 @@ typedef void (ard_tcp_done_cb_t)(void *opaque, int result);
|
|||||||
// Maximum number of client connection accepted by server
|
// Maximum number of client connection accepted by server
|
||||||
#define MAX_CLIENT_ACCEPTED 4
|
#define MAX_CLIENT_ACCEPTED 4
|
||||||
#define NO_VALID_ID -1
|
#define NO_VALID_ID -1
|
||||||
#define GET_FIRST_CLIENT_TCP(TTCP) ((TTCP!=NULL)?TTCP->tpcb[0] : NULL)
|
|
||||||
|
#define GET_FIRST_CLIENT_TCP(TTCP) getFirstClient(TTCP, 1)
|
||||||
|
#define GET_FIRST_CLIENT_TCP_NV(TTCP) getFirstClient(TTCP, 0)
|
||||||
#define GET_CLIENT_TCP(TTCP,ID) (((TTCP!=NULL)&&(ID>=0)&&(ID<MAX_CLIENT_ACCEPTED))?TTCP->tpcb[ID] : NULL)
|
#define GET_CLIENT_TCP(TTCP,ID) (((TTCP!=NULL)&&(ID>=0)&&(ID<MAX_CLIENT_ACCEPTED))?TTCP->tpcb[ID] : NULL)
|
||||||
|
|
||||||
|
|
||||||
@ -92,6 +94,10 @@ bool cleanNewClientConn(struct ttcp* _ttcp);
|
|||||||
|
|
||||||
int8_t getNewClientConnId(struct ttcp* _ttcp, struct tcp_pcb *newpcb);
|
int8_t getNewClientConnId(struct ttcp* _ttcp, struct tcp_pcb *newpcb);
|
||||||
|
|
||||||
|
int8_t getCurrClientConnId();
|
||||||
|
|
||||||
|
struct tcp_pcb * getFirstClient(struct ttcp* _ttcp, bool verbose);
|
||||||
|
|
||||||
void closeConnections();
|
void closeConnections();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,6 +78,8 @@ uint16_t calcMergeLen(uint8_t sock)
|
|||||||
if (pBufStore[index][sock].data != NULL)
|
if (pBufStore[index][sock].data != NULL)
|
||||||
{
|
{
|
||||||
len += pBufStore[index][sock].len;
|
len += pBufStore[index][sock].len;
|
||||||
|
len -= pBufStore[index][sock].idx;
|
||||||
|
INFO_UTIL_VER(" [%d]: len:%d idx:%d tot:%d\n", sock, pBufStore[index][sock].len, pBufStore[index][sock].idx, len);
|
||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
if (index == MAX_PBUF_STORED)
|
if (index == MAX_PBUF_STORED)
|
||||||
@ -179,7 +181,8 @@ void dumpPbuf(uint8_t sock)
|
|||||||
do {
|
do {
|
||||||
if (pBufStore[index][sock].data != NULL)
|
if (pBufStore[index][sock].data != NULL)
|
||||||
{
|
{
|
||||||
printk("Buf: %p Len:%d\n", pBufStore[index][sock].data, pBufStore[index][sock].len);
|
printk("%d] pcb:%p Buf: %p Len:%d\n", pBufStore[index][sock].idx, pBufStore[index][sock].pcb,
|
||||||
|
pBufStore[index][sock].data, pBufStore[index][sock].len);
|
||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
if (index == MAX_PBUF_STORED)
|
if (index == MAX_PBUF_STORED)
|
||||||
@ -245,7 +248,7 @@ void ack_recved(void* pcb, int len);
|
|||||||
|
|
||||||
void ackAndFreeData(void* pcb, int len, uint8_t sock, uint8_t* data)
|
void ackAndFreeData(void* pcb, int len, uint8_t sock, uint8_t* data)
|
||||||
{
|
{
|
||||||
INFO_UTIL("Ack pcb:%p len:%d sock:%d data:%p\n", pcb, len, sock, data);
|
INFO_TCP("Ack pcb:%p len:%d sock:%d data:%p\n", pcb, len, sock, data);
|
||||||
if (!IS_UDP_SOCK(sock))
|
if (!IS_UDP_SOCK(sock))
|
||||||
ack_recved(pcb, len);
|
ack_recved(pcb, len);
|
||||||
if (data != NULL)
|
if (data != NULL)
|
||||||
@ -276,7 +279,7 @@ bool isAvailTcpDataByte(uint8_t sock)
|
|||||||
uint16_t getAvailTcpDataByte(uint8_t sock)
|
uint16_t getAvailTcpDataByte(uint8_t sock)
|
||||||
{
|
{
|
||||||
uint16_t len = calcMergeLen(sock);
|
uint16_t len = calcMergeLen(sock);
|
||||||
INFO_UTIL("Availabled data: %d\n", len);
|
INFO_UTIL_VER("Availabled data: %d\n", len);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,6 +299,8 @@ bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek)
|
|||||||
else
|
else
|
||||||
*payload = buf[p->idx++];
|
*payload = buf[p->idx++];
|
||||||
INFO_UTIL_VER("get:%d %p %d\n",p->idx, p->data, *payload);
|
INFO_UTIL_VER("get:%d %p %d\n",p->idx, p->data, *payload);
|
||||||
|
if (p->idx == p->len)
|
||||||
|
ackAndFreeData(p->pcb, p->len, sock, p->data);
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
ackAndFreeData(p->pcb, p->len, sock, p->data);
|
ackAndFreeData(p->pcb, p->len, sock, p->data);
|
||||||
|
@ -281,6 +281,7 @@ void initShell()
|
|||||||
console_add_cmd("status", cmd_status, NULL);
|
console_add_cmd("status", cmd_status, NULL);
|
||||||
console_add_cmd("debug", cmd_debug, NULL);
|
console_add_cmd("debug", cmd_debug, NULL);
|
||||||
console_add_cmd("dumpBuf", cmd_dumpBuf, NULL);
|
console_add_cmd("dumpBuf", cmd_dumpBuf, NULL);
|
||||||
|
console_add_cmd("ipconfig", cmd_set_ip, NULL);
|
||||||
|
|
||||||
#ifdef ADD_CMDS
|
#ifdef ADD_CMDS
|
||||||
console_add_cmd("powersave", cmd_power, NULL);
|
console_add_cmd("powersave", cmd_power, NULL);
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#define START_CMD 0xE0
|
#define START_CMD 0xE0
|
||||||
#define END_CMD 0xEE
|
#define END_CMD 0xEE
|
||||||
#define ERR_CMD 0xEF
|
#define ERR_CMD 0xEF
|
||||||
|
#define CMD_POS 1 // Position of Command OpCode on SPI stream
|
||||||
|
#define PARAM_LEN_POS 2 // Position of Param len on SPI stream
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SET_NET_CMD = 0x10,
|
SET_NET_CMD = 0x10,
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
#define START_CMD 0xE0
|
#define START_CMD 0xE0
|
||||||
#define END_CMD 0xEE
|
#define END_CMD 0xEE
|
||||||
#define ERR_CMD 0xEF
|
#define ERR_CMD 0xEF
|
||||||
|
#define CMD_POS 1 // Position of Command OpCode on SPI stream
|
||||||
|
#define PARAM_LEN_POS 2 // Position of Param len on SPI stream
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SET_NET_CMD = 0x10,
|
SET_NET_CMD = 0x10,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user