1
0
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:
Cristian Maglie 2013-03-28 12:10:48 +01:00
commit 83dbd395f3
19 changed files with 16321 additions and 16000 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@
#include <board_init.h> #include <board_init.h>
#include "util.h" #include "util.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip_setup.h"
extern const char* fwVersion; extern const char* fwVersion;
@ -94,7 +95,7 @@ bool end_write = false; //TODO only for debug
// Signal indicating a new command is coming from SPI interface // Signal indicating a new command is coming from SPI interface
static volatile Bool startRecvCmdSignal = FALSE; static volatile Bool startRecvCmdSignal = FALSE;
#define MAX_CMD_NUM 34 #define MAX_CMD_NUM 36
typedef struct sCmd_spi_list{ typedef struct sCmd_spi_list{
cmd_spi_cb_t cb; cmd_spi_cb_t cb;
char cmd_id; char cmd_id;
@ -535,6 +536,114 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
RETURN_ERR(err) RETURN_ERR(err)
} }
int set_ip_config_cmd_cb(int numParam, char* buf, void* ctx) {
struct ip_addr lwip_addr;
struct ctx_server *hs = ctx;
struct net_cfg *ncfg = &(hs->net_cfg);
struct netif *nif = ncfg->netif;
uint8_t parmsToChange=0;
const uint8_t MAX_IP_CONFIG_PARAMS = 3;
wl_err_t err = WL_SUCCESS;
tParam* params = (tParam*) buf;
if (params->paramLen == 1)
{
GET_PARAM_NEXT(BYTE, params, _parmsToChange);
parmsToChange = _parmsToChange;
}
else
RETURN_ERR(WL_FAILURE)
INFO_SPI("%p numParam=%d parmsToChange=%d\n", ctx, numParam, parmsToChange);
if (parmsToChange <= MAX_IP_CONFIG_PARAMS)
{
int i=0;
for (; i<parmsToChange; ++i)
{
if (params->paramLen == 4)
{
GET_PARAM_NEXT(LONG, params, _ip_addr);
lwip_addr.addr = _ip_addr;
INFO_SPI("%d] nif:%p lwip_addr=0x%x\n", i, nif, lwip_addr.addr);
switch (i)
{
case 0: // local_ip
{
netif_set_ipaddr(nif, &lwip_addr);
break;
}
case 1: // gateway
{
netif_set_gw(nif, &lwip_addr);
break;
}
case 2: // subnet
{
netif_set_netmask(nif, &lwip_addr);
break;
}
}
}else{
RETURN_ERR(WL_FAILURE)
}
}
/* Disable DHCP */
ncfg->dhcp_enabled = STATIC_IP_CONFIG;
}else
RETURN_ERR(WL_FAILURE)
RETURN_ERR(err)
}
int set_dns_config_cmd_cb(int numParam, char* buf, void* ctx) {
struct ip_addr lwip_addr;
struct ctx_server *hs = ctx;
struct net_cfg *ncfg = &(hs->net_cfg);
struct netif *nif = ncfg->netif;
uint8_t parmsToChange=0;
const uint8_t MAX_DNS_CONFIG_PARAMS = 2;
wl_err_t err = WL_SUCCESS;
tParam* params = (tParam*) buf;
if (params->paramLen == 1)
{
GET_PARAM_NEXT(BYTE, params, _parmsToChange);
parmsToChange = _parmsToChange;
}
else
RETURN_ERR(WL_FAILURE)
INFO_SPI("%p numParam=%d parmsToChange=%d\n", ctx, numParam, parmsToChange);
if (parmsToChange <= MAX_DNS_CONFIG_PARAMS)
{
int i=0;
for (; i<parmsToChange; ++i)
{
if (params->paramLen == 4)
{
GET_PARAM_NEXT(LONG, params, _ip_addr);
lwip_addr.addr = _ip_addr;
INFO_SPI("%d] nif:%p lwip_addr=0x%x\n", i, nif, lwip_addr.addr);
dns_setserver(i, &lwip_addr);
}else{
RETURN_ERR(WL_FAILURE)
}
}
/* Disable DHCP */
ncfg->dhcp_enabled = STATIC_IP_CONFIG;
}else
RETURN_ERR(WL_FAILURE)
RETURN_ERR(err)
}
void set_result(wl_status_t _status) void set_result(wl_status_t _status)
{ {
result = _status; result = _status;
@ -1402,12 +1511,12 @@ int call_reply_cb(char* recv, char* reply) {
{ {
tSpiMsg* spiMsg = (tSpiMsg*) recv; tSpiMsg* spiMsg = (tSpiMsg*) recv;
_result = cmd_spi_list[i].cb(spiMsg->nParam, _result = cmd_spi_list[i].cb(spiMsg->nParam,
(char*) &(spiMsg->params[0]), NULL); (char*) &(spiMsg->params[0]), cmd_spi_list[i].ctx);
}else }else
{ {
tSpiMsgData* spiMsg = (tSpiMsgData*) recv; tSpiMsgData* spiMsg = (tSpiMsgData*) recv;
_result = cmd_spi_list[i].cb(spiMsg->nParam, _result = cmd_spi_list[i].cb(spiMsg->nParam,
(char*) &(spiMsg->params[0]), NULL); (char*) &(spiMsg->params[0]), cmd_spi_list[i].ctx);
} }
if (_result != WIFI_SPI_ACK) if (_result != WIFI_SPI_ACK)
@ -1452,10 +1561,12 @@ int call_reply_cb(char* recv, char* reply) {
return REPLY_NO_ERR; return REPLY_NO_ERR;
} }
void init_spi_cmds() { void init_spi_cmds(void* ctx) {
spi_add_cmd(SET_NET_CMD, set_net_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG); spi_add_cmd(SET_NET_CMD, set_net_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
spi_add_cmd(SET_PASSPHRASE_CMD, set_passphrase_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG); spi_add_cmd(SET_PASSPHRASE_CMD, set_passphrase_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
spi_add_cmd(SET_KEY_CMD, set_key_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG); spi_add_cmd(SET_KEY_CMD, set_key_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
spi_add_cmd(SET_IP_CONFIG_CMD, set_ip_config_cmd_cb, ack_reply_cb, ctx, CMD_SET_FLAG);
spi_add_cmd(SET_DNS_CONFIG_CMD, set_dns_config_cmd_cb, ack_reply_cb, ctx, CMD_SET_FLAG);
spi_add_cmd(GET_CONN_STATUS_CMD, get_result_cmd_cb, get_reply_cb, NULL, CMD_GET_FLAG); spi_add_cmd(GET_CONN_STATUS_CMD, get_result_cmd_cb, get_reply_cb, NULL, CMD_GET_FLAG);
spi_add_cmd(GET_IPADDR_CMD, ack_cmd_cb, get_reply_ipaddr_cb, NULL, CMD_GET_FLAG); spi_add_cmd(GET_IPADDR_CMD, ack_cmd_cb, get_reply_ipaddr_cb, NULL, CMD_GET_FLAG);
spi_add_cmd(GET_MACADDR_CMD, ack_cmd_cb, get_reply_mac_cb, NULL, CMD_GET_FLAG); spi_add_cmd(GET_MACADDR_CMD, ack_cmd_cb, get_reply_mac_cb, NULL, CMD_GET_FLAG);
@ -1673,7 +1784,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
{ {
int8_t numParams = 0; int8_t numParams = 0;
int idx = PARAM_LEN_POS+1; int idx = PARAM_LEN_POS+1;
bool islen16bit = _receiveBuffer[CMD_POS] & DATA_FLAG; bool islen16bit = ((_receiveBuffer[CMD_POS] & DATA_FLAG) == DATA_FLAG);
if (index >= idx) if (index >= idx)
{ {
numParams = _receiveBuffer[PARAM_LEN_POS]; numParams = _receiveBuffer[PARAM_LEN_POS];
@ -1690,6 +1801,10 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
} }
if (!endOfFrame){ if (!endOfFrame){
WARN("Wrong termination index:%d nParam:%d idx:%d 16bit:%d\n", index, numParams, idx, islen16bit); WARN("Wrong termination index:%d nParam:%d idx:%d 16bit:%d\n", index, numParams, idx, islen16bit);
#ifdef _DEBUG_
dump((char*)_receiveBuffer, receivedChars);
while(0);
#endif
} }
} }
} while (!endOfFrame); } while (!endOfFrame);
@ -1786,7 +1901,7 @@ void initExtInt()
Enable_global_interrupt(); Enable_global_interrupt();
} }
int initSpi() int initSpi(void* ctx)
{ {
volatile avr32_spi_t *spi = &AVR32_SPI0; volatile avr32_spi_t *spi = &AVR32_SPI0;
gpio_map_t spi_piomap = { \ gpio_map_t spi_piomap = { \
@ -1838,7 +1953,7 @@ int initSpi()
#ifdef _SPI_STATS_ #ifdef _SPI_STATS_
initStatSpi(); initStatSpi();
#endif #endif
init_spi_cmds(); init_spi_cmds(ctx);
memset(_receiveBuffer, 0, sizeof(_receiveBuffer)); memset(_receiveBuffer, 0, sizeof(_receiveBuffer));
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));

View File

@ -57,7 +57,7 @@ void set_result_cmd(int err) ;
void set_result(wl_status_t _status); void set_result(wl_status_t _status);
int initSpi(void); int initSpi(void* ctx);
void initExtInt(); void initExtInt();

View File

@ -27,12 +27,11 @@
#include "getopt.h" #include "getopt.h"
#include "ard_utils.h" #include "ard_utils.h"
#include "debug.h" #include "debug.h"
#include "trace.h"
unsigned int startTime = 0; unsigned int startTime = 0;
extern bool ifStatus; extern bool ifStatus;
static int isDataSentCount = 0;
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)
@ -82,9 +81,7 @@ static void ard_tcp_destroy(struct ttcp* ttcp) {
udp_remove(ttcp->upcb); udp_remove(ttcp->upcb);
} }
if (ttcp->payload) FREE_PAYLOAD(ttcp);
free(ttcp->payload);
free(ttcp); free(ttcp);
} }
@ -108,45 +105,44 @@ static void ard_tcp_done(struct ttcp* ttcp, int result) {
* Called upon connect and when there's space available in the TCP send window * Called upon connect and when there's space available in the TCP send window
* *
*/ */
static err_t tcp_send_data(struct ttcp *ttcp) { static err_t tcp_send_data_pcb(struct ttcp *ttcp, struct tcp_pcb *pcb) {
err_t err = ERR_OK; err_t err = ERR_OK;
uint32_t len, orig_len; uint32_t len;
len = ttcp->left; GET_CLIENT_ID(ttcp, pcb);
ttcp->buff_sent = 0;
len = ttcp->left[id];
ttcp->buff_sent[id] = 0;
if (len == 0) return ERR_MEM; 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[id], len);
/* don't send more than we have in the payload */ /* don't send more than we have in the payload */
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(pcb)) if (len > tcp_sndbuf(pcb))
len = tcp_sndbuf(pcb); len = tcp_sndbuf(pcb);
orig_len = len;
IF_TCP(startTime = timer_get_ms()); IF_TCP(startTime = timer_get_ms());
err = tcp_write(pcb, ttcp->payload, len, TCP_WRITE_FLAG_COPY); err = tcp_write(pcb, ttcp->payload[id], 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",
pcb, pcb->state, len, err); pcb, pcb->state, len, err);
ttcp->buff_sent = 0; ttcp->buff_sent[id] = 0;
}else{ }else{
ttcp->buff_sent = 1; ttcp->buff_sent[id] = 1;
isDataSentCount = 0; ttcp->left[id] -= len;
ttcp->left -= len;
} }
return err; return err;
} }
/** /**
* Only used in TCP mode. * Only used in TCP mode.
*/ */
@ -155,10 +151,11 @@ static err_t tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err) {
if (_ttcp == NULL) return ERR_ARG; if (_ttcp == NULL) return ERR_ARG;
GET_CLIENT_ID(_ttcp, tpcb);
INFO_TCP("TTCP [%p-%p]: connect %d %d\n", _ttcp, tpcb, err, tpcb->state); INFO_TCP("TTCP [%p-%p]: connect %d %d\n", _ttcp, tpcb, err, tpcb->state);
_connected = ( tpcb->state == ESTABLISHED) ? 1 : 0; _connected = ( tpcb->state == ESTABLISHED) ? 1 : 0;
_ttcp->tcp_poll_retries = 0; _ttcp->tcp_poll_retries[id] = 0;
_ttcp->start_time = timer_get_ms(); _ttcp->start_time = timer_get_ms();
@ -198,13 +195,17 @@ static err_t close_conn_pcb(struct tcp_pcb* tpcb) {
static void atcp_conn_err_cb(void *arg, err_t err) { static void atcp_conn_err_cb(void *arg, err_t err) {
struct ttcp* _ttcp = arg; struct ttcp* _ttcp = arg;
WARN("TTCP [%p]: connection error: %d\n", WARN("TTCP [%p]: connection error: %d currId:%d\n",
_ttcp, err); _ttcp, err, getCurrClientConnId());
if (ifStatus == false) if (ifStatus == false)
printk("Abort connection\n"); printk("Abort connection\n");
atcp_init_pend_flags(_ttcp); if (err == ERR_ABRT)
{
removeNewClientConn(_ttcp, GET_CURR_PCB(_ttcp));
FREE_PAYLOAD_ID(_ttcp, getCurrClientConnId());
}
} }
static void atcp_conn_cli_err_cb(void *arg, err_t err) { static void atcp_conn_cli_err_cb(void *arg, err_t err) {
@ -221,30 +222,32 @@ static void atcp_conn_cli_err_cb(void *arg, err_t err) {
if ((_ttcp)&&(err == ERR_ABRT)) if ((_ttcp)&&(err == ERR_ABRT))
{ {
WARN("TTCP [%p]: free memory\n", _ttcp); WARN("TTCP [%p]: free memory\n", _ttcp);
_ttcp->tcp_poll_retries = 0;
cleanSockState_cb(_ttcp); cleanSockState_cb(_ttcp);
if (_ttcp->payload) // TODO
free(_ttcp->payload); FREE_PAYLOAD(_ttcp);
free(_ttcp);
} }
atcp_init_pend_flags(_ttcp); //atcp_init_pend_flags(_ttcp);
} }
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 ERR_MEM; if (_ttcp == NULL) return ERR_MEM;
int8_t id = getNewClientConnId(_ttcp, tpcb); GET_CLIENT_ID(_ttcp, tpcb);
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)
{
WARN("Cannot close id:%d-%p put pending\n", id, _ttcp->tpcb[id]);
_ttcp->pending_close[id] = true; _ttcp->pending_close[id] = true;
}
else{ else{
atcp_init_pend_flags(_ttcp); _ttcp->pending_close[id] = false;
removeNewClientConn(_ttcp, _ttcp->tpcb[id]); removeNewClientConn(_ttcp, _ttcp->tpcb[id]);
WARN("----------------------\n"); FREE_PAYLOAD_ID(_ttcp, id);
INFO_TCP("----------------------\n");
} }
return err; return err;
} }
@ -318,15 +321,17 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
if (_ttcp == NULL) return ERR_ARG; if (_ttcp == NULL) return ERR_ARG;
if (_ttcp->left>0) GET_CLIENT_ID(_ttcp, pcb);
++_ttcp->tcp_poll_retries;
if (_ttcp->tcp_poll_retries > 4) { if (_ttcp->left[id]>0)
WARN("ARD TCP [%p] arg=%p retries=%d\n", ++_ttcp->tcp_poll_retries[id];
pcb, arg, _ttcp->tcp_poll_retries);
_ttcp->tcp_poll_retries = 0; if (_ttcp->tcp_poll_retries[id] > 4) {
WARN("ARD TCP [%p] arg=%p retries=%d abort\n",
pcb, arg, _ttcp->tcp_poll_retries[id]);
_ttcp->tcp_poll_retries[id] = 0;
tcp_abort(pcb); tcp_abort(pcb);
atcp_init_pend_flags(_ttcp); _ttcp->pending_close[id] = false;
return ERR_ABRT; return ERR_ABRT;
} }
@ -334,14 +339,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[id] > 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[id], (_ttcp)?_ttcp->left:0); _ttcp->tcp_poll_retries[id], _ttcp->pending_close[id], (_ttcp)?_ttcp->left[id]:0);
tcp_send_data(_ttcp); tcp_send_data_pcb(_ttcp, pcb);
if ((id != NO_VALID_ID) && (_ttcp->pending_close[id])) if (_ttcp->pending_close[id])
{ {
err_t err = ERR_OK; err_t err = ERR_OK;
if (id >=0){ if (id >=0){
@ -352,7 +356,10 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
} }
else else
{ {
atcp_init_pend_flags(_ttcp); _ttcp->pending_close[id] = false;
removeNewClientConn(_ttcp, _ttcp->tpcb[id]);
FREE_PAYLOAD_ID(_ttcp, id);
INFO_TCP("----------------------\n");
} }
} }
INFO_TCP("ARD TCP [%p-%p] try to close pending:%d err:%d id:%d\n", pcb, INFO_TCP("ARD TCP [%p-%p] try to close pending:%d err:%d id:%d\n", pcb,
@ -366,26 +373,27 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
if (_ttcp == NULL) return ERR_ARG; if (_ttcp == NULL) return ERR_ARG;
int8_t id = getNewClientConnId(_ttcp, pcb); GET_CLIENT_ID(_ttcp, pcb)
INFO_TCP_POLL("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d conn:%d\n",
(_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0, pcb, arg,
_ttcp->tcp_poll_retries[id], _ttcp->pending_close[id], _connected);
if (id != NO_VALID_ID) if (id != NO_VALID_ID)
{ {
if (_ttcp->pending_close[id]) if (_ttcp->pending_close[id])
++(_ttcp->tcp_poll_retries); ++(_ttcp->tcp_poll_retries[id]);
} }
if (_ttcp->tcp_poll_retries > 8) { if (_ttcp->tcp_poll_retries[id] > 8) {
WARN("ARD TCP [%p-%p] arg=%p retries=%d\n", WARN("ARD TCP [%p-%p] arg=%p retries=%d\n",
pcb, GET_FIRST_CLIENT_TCP(_ttcp), arg, _ttcp->tcp_poll_retries); pcb, GET_FIRST_CLIENT_TCP(_ttcp), arg, _ttcp->tcp_poll_retries[id]);
_ttcp->tcp_poll_retries = 0; _ttcp->tcp_poll_retries[id] = 0;
tcp_abort(pcb); tcp_abort(pcb);
return ERR_ABRT; return ERR_ABRT;
} }
INFO_TCP_POLL("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d conn:%d\n", if ((_ttcp)&&(_connected)) tcp_send_data_pcb(_ttcp, pcb);
(_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0, pcb, arg,
_ttcp->tcp_poll_retries, _ttcp->pending_close[id], _connected);
if ((_ttcp)&&(_connected)) tcp_send_data(_ttcp);
if ((id != NO_VALID_ID) && (_ttcp->pending_close[id])) if ((id != NO_VALID_ID) && (_ttcp->pending_close[id]))
{ {
@ -397,11 +405,8 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
else else
{ {
cleanSockState_cb(_ttcp); cleanSockState_cb(_ttcp);
if (_ttcp->payload) FREE_PAYLOAD_ID(_ttcp, id);
free(_ttcp->payload);
free(_ttcp);
_ttcp->pending_close[id] = false; _ttcp->pending_close[id] = false;
} }
INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, (_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0, _ttcp->pending_close[id]); INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, (_ttcp)?GET_FIRST_CLIENT_TCP(_ttcp):0, _ttcp->pending_close[id]);
@ -410,7 +415,6 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
} }
int8_t currConnId = 0; 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 getCurrClientConnId() { return currConnId;}
@ -424,7 +428,7 @@ int8_t getNewClientConnId(struct ttcp* _ttcp, struct tcp_pcb *newpcb)
if (_ttcp->tpcb[idx] == newpcb) if (_ttcp->tpcb[idx] == newpcb)
{ {
INFO_TCP("ttcp:%p id=%d, tpcb=%p\n", _ttcp, idx, newpcb); INFO_TCP_VER("ttcp:%p id=%d, tpcb=%p\n", _ttcp, idx, newpcb);
return idx; return idx;
} }
} }
@ -523,6 +527,14 @@ static err_t atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) {
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);
int8_t id = insertNewClientConn(_ttcp, newpcb); int8_t id = insertNewClientConn(_ttcp, newpcb);
ASSERT((_ttcp->payload[id]==NULL), "payload not freed!");
_ttcp->payload[id] = malloc(_ttcp->buflen);
INFO_TCP("Alloc payload %d-%p\n", id, _ttcp->payload[id]);
if (_ttcp->payload[id] == NULL) {
WARN("TTCP [%p]: could not allocate payload\n", _ttcp);
return -1;
}
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);
tcp_err(_ttcp->tpcb[id], atcp_conn_err_cb); tcp_err(_ttcp->tpcb[id], atcp_conn_err_cb);
@ -548,24 +560,26 @@ static int atcp_start(struct ttcp* ttcp) {
return -1; return -1;
} }
ttcp->payload = malloc(ttcp->buflen); currConnId = 0;
if (ttcp->payload == NULL) {
WARN("TTCP [%p]: could not allocate payload\n", ttcp);
return -1;
}
tcp_arg(p, ttcp); tcp_arg(p, ttcp);
atcp_init_pend_flags(ttcp); atcp_init_pend_flags(ttcp);
if (ttcp->mode == TTCP_MODE_TRANSMIT) { if (ttcp->mode == TTCP_MODE_TRANSMIT) {
setNewClientConn(ttcp, p, 0); int8_t id = insertNewClientConn(ttcp, p);
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP(ttcp); ttcp->payload[id] = malloc(ttcp->buflen);
INFO_TCP("Alloc payload %d-%p\n", id, ttcp->payload[id]);
if (ttcp->payload[id] == NULL) {
WARN("TTCP [%p]: could not allocate payload\n", ttcp);
return -1;
}
struct tcp_pcb * pcb = p;
tcp_err(pcb, atcp_conn_cli_err_cb); tcp_err(pcb, atcp_conn_cli_err_cb);
tcp_recv(pcb, atcp_recv_cb); tcp_recv(pcb, atcp_recv_cb);
tcp_sent(pcb, tcp_data_sent); tcp_sent(pcb, tcp_data_sent);
tcp_poll(pcb, atcp_poll_conn, 4); tcp_poll(pcb, atcp_poll_conn, 4);
_connected = false; _connected = false;
INFO_TCP("[tpcb]-%p payload:%p\n", pcb, ttcp->payload); INFO_TCP("[tpcb]-%p payload:%p\n", pcb, ttcp->payload[id]);
DUMP_TCP_STATE(ttcp); DUMP_TCP_STATE(ttcp);
if (tcp_connect(pcb, &ttcp->addr, ttcp->port, tcp_connect_cb) if (tcp_connect(pcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
!= ERR_OK) { != ERR_OK) {
@ -595,72 +609,6 @@ static int atcp_start(struct ttcp* ttcp) {
return 0; return 0;
} }
static void
udp_send_data(struct ttcp* ttcp);
/**
* Only used in UDP mode. Scheduled after data has been sent in udp_send_data()
* if we have more data to send.
*/
static void udp_timeout_cb(void *ctx) {
struct ttcp* ttcp = ctx;
udp_send_data(ttcp);
}
static int udp_send_bytes(struct ttcp* ttcp, uint32_t len) {
struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
if (p == NULL) {
WARN("TTCP [%p]: could not allocate pbuf\n", ttcp);
return -1;
}
if (udp_send(ttcp->upcb, p) != ERR_OK) {
WARN("TTCP [%p]: udp_send() failed\n", ttcp);
pbuf_free(p);
return -1;
}
pbuf_free(p);
return 0;
}
/**
* Only used in UDP mode. First call will send the start marker. When all
* ttcp data has been sent, a number of end markers will be sent. After
* end marker transmission, this function will complete the ttcp process.
*/
static void udp_send_data(struct ttcp* ttcp) {
/* send start marker first time */
if (!ttcp->udp_started) {
if (udp_send_bytes(ttcp, 4) == 0) {
ttcp->udp_started = 1;
ttcp->start_time = timer_get_ms();
}
}
/* normal case */
else if (ttcp->left) {
/* send data */
if (udp_send_bytes(ttcp, ttcp->buflen) == 0)
ttcp->left -= ttcp->buflen;
}
/* end marker? */
else if (ttcp->left == 0 && ttcp->udp_end_marker_left) {
if (udp_send_bytes(ttcp, 4) == 0)
ttcp->udp_end_marker_left--;
}
/* all end markers sent */
else if (ttcp->left == 0) {
ard_tcp_done(ttcp, 0);
return;
}
ttcp->tid
= timer_sched_timeout_cb(0, TIMEOUT_ONESHOT, udp_timeout_cb, ttcp);
}
/** /**
* Only used in UDP mode. Will finalize the ttcp process when an end marker * Only used in UDP mode. Will finalize the ttcp process when an end marker
* is seen. * is seen.
@ -759,7 +707,6 @@ int ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
ttcp->port = port; ttcp->port = port;
ttcp->nbuf = nbuf; ttcp->nbuf = nbuf;
ttcp->mode = mode; ttcp->mode = mode;
ttcp->left = 0;
ttcp->done_cb = done_cb; ttcp->done_cb = done_cb;
ttcp->opaque = opaque; ttcp->opaque = opaque;
ttcp->udp = udp; ttcp->udp = udp;
@ -782,7 +729,6 @@ int ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
*_ttcp = (void*) ttcp; *_ttcp = (void*) ttcp;
ttcp->sock = sock; ttcp->sock = sock;
ttcp->buff_sent = 1;
return 0; return 0;
@ -798,9 +744,10 @@ void ard_tcp_stop(void* ttcp) {
return; return;
} }
if (_ttcp->mode == TTCP_MODE_TRANSMIT) { if (_ttcp->mode == TTCP_MODE_TRANSMIT) {
int i = getCurrClientConnId();
ard_tcp_destroy(_ttcp); ard_tcp_destroy(_ttcp);
clearMapSockTcp(getSock(_ttcp), GET_TCP_MODE(_ttcp)); clearMapSockTcp(getSock(_ttcp), GET_TCP_MODE(_ttcp));
_ttcp->tcp_poll_retries = 0; _ttcp->tcp_poll_retries[i] = 0;
}else{ }else{
DUMP_TCP_STATE(_ttcp); DUMP_TCP_STATE(_ttcp);
@ -825,9 +772,15 @@ uint8_t getStateTcp(void* p, bool client) {
if ((_ttcp != NULL) && ((pcb != NULL) || (client==0))) { 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)
{
if ((pcb->state != ESTABLISHED)&&(pcb->state != CLOSED))
DUMP_TCP_STATE(_ttcp);
return pcb->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)?pcb:0), ((_ttcp)?_ttcp->lpcb:0)); _ttcp, ((_ttcp)?pcb:0), ((_ttcp)?_ttcp->lpcb:0));
@ -846,9 +799,9 @@ uint8_t getModeTcp(void* p) {
uint8_t isDataSent(void* p) { uint8_t isDataSent(void* p) {
struct ttcp *_ttcp = (struct ttcp *)p; struct ttcp *_ttcp = (struct ttcp *)p;
if ((_ttcp)&&(!_ttcp->buff_sent)) int8_t id = getCurrClientConnId();
if ((_ttcp)&&(!_ttcp->buff_sent[id]))
{ {
INFO_TCP_VER("%d) Wait to send data\n", ++isDataSentCount);
return 0; return 0;
} }
@ -864,17 +817,15 @@ static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len) {
if (_ttcp == NULL) return ERR_ARG; if (_ttcp == NULL) return ERR_ARG;
_ttcp->tcp_poll_retries = 0; GET_CLIENT_ID(_ttcp, pcb);
if (_ttcp) _ttcp->buff_sent = 1; _ttcp->tcp_poll_retries[id] = 0;
_ttcp->buff_sent[id] = 1;
INFO_TCP("Packet sent pcb:%p len:%d dur:%d left:%d\n", pcb, len, timer_get_ms() - startTime,
(_ttcp)?(_ttcp->left[id]):0);
INFO_TCP("Packet sent pcb:%p len:%d dur:%d left:%d count:%d\n", pcb, len, timer_get_ms() - startTime, if ((_ttcp)&&(_ttcp->left[id] > 0)) {
(_ttcp)?(_ttcp->left):0, isDataSentCount); tcp_send_data_pcb(_ttcp, pcb);
isDataSentCount = 0;
if ((_ttcp)&&(_ttcp->left > 0)) {
tcp_send_data(_ttcp);
} }
return ERR_OK; return ERR_OK;
@ -891,21 +842,23 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len)
} }
struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP_NV(_ttcp); struct tcp_pcb * pcb = GET_FIRST_CLIENT_TCP_NV(_ttcp);
GET_CLIENT_ID(_ttcp, pcb);
INFO_TCP_VER("ttcp:%p pcb:%p buf:%p len:%d\n", _ttcp, pcb, 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) && (pcb != NULL) && if ((_ttcp != NULL) && (pcb != NULL) &&
(buf != NULL) && (len != 0) && (_ttcp->payload != NULL)) { (buf != NULL) && (len != 0) && (_ttcp->payload[id] != NULL)) {
if (pcb->state == ESTABLISHED || pcb->state == CLOSE_WAIT || if (pcb->state == ESTABLISHED || pcb->state == CLOSE_WAIT ||
pcb->state == SYN_SENT || pcb->state == SYN_RCVD) { pcb->state == SYN_SENT || pcb->state == SYN_RCVD) {
memcpy(_ttcp->payload, buf, len); memcpy(_ttcp->payload[id], buf, len);
_ttcp->payload[len]='\0'; _ttcp->payload[id][len]='\0';
INFO_TCP_VER("'%s'\n", _ttcp->payload); INFO_TCP_VER("'%s'\n", _ttcp->payload[id]);
_ttcp->left = len; _ttcp->left[id] = len;
tcp_sent(pcb, tcp_data_sent); tcp_sent(pcb, tcp_data_sent);
tcp_send_data(_ttcp); tcp_send_data_pcb(_ttcp, pcb);
return WL_SUCCESS; return WL_SUCCESS;
} }

View File

@ -23,11 +23,32 @@ 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 0xff
#define GET_FIRST_CLIENT_TCP(TTCP) getFirstClient(TTCP, 1) #define GET_FIRST_CLIENT_TCP(TTCP) getFirstClient(TTCP, 1)
#define GET_FIRST_CLIENT_TCP_NV(TTCP) getFirstClient(TTCP, 0) #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)
#define GET_CLIENT_ID(TTCP, PCB) uint8_t id = NO_VALID_ID; do { \
id = getNewClientConnId(TTCP, PCB); \
if (id == NO_VALID_ID) return ERR_MEM; \
}while(0);
#define GET_IDX_CONN(I) ((I+currConnId)<MAX_CLIENT_ACCEPTED ? (I+currConnId) : (I+currConnId-MAX_CLIENT_ACCEPTED))
#define GET_CURR_PCB(TTCP) GET_CLIENT_TCP(TTCP,getCurrClientConnId())
#define FREE_PAYLOAD(TTCP) do { \
int id = getCurrClientConnId(); \
INFO_TCP("Freeing payload %d-%p\n", id, TTCP->payload[id]); \
if (TTCP->payload[id]) { \
free(TTCP->payload[id]); \
TTCP->payload[id] = NULL; } \
}while(0);
#define FREE_PAYLOAD_ID(TTCP,ID) do { \
INFO_TCP("Freeing payload %d-%p\n", ID, TTCP->payload[ID]); \
if (TTCP->payload[ID]) { \
free(TTCP->payload[ID]); \
TTCP->payload[ID] = NULL; } \
}while(0);
typedef struct ttcp { typedef struct ttcp {
@ -40,12 +61,12 @@ typedef struct ttcp {
int verbose; /* -v */ int verbose; /* -v */
int udp; /* -u */ int udp; /* -u */
uint8_t sock; uint8_t sock;
uint8_t buff_sent; uint8_t buff_sent[MAX_CLIENT_ACCEPTED];
/* common */ /* common */
uint16_t print_cnt; uint16_t print_cnt;
uint32_t start_time; uint32_t start_time;
uint32_t left; uint32_t left[MAX_CLIENT_ACCEPTED];
uint32_t recved; uint32_t recved;
ard_tcp_done_cb_t* done_cb; ard_tcp_done_cb_t* done_cb;
void* opaque; void* opaque;
@ -55,8 +76,8 @@ typedef struct ttcp {
/* TCP specific */ /* TCP specific */
struct tcp_pcb* tpcb[MAX_CLIENT_ACCEPTED]; struct tcp_pcb* tpcb[MAX_CLIENT_ACCEPTED];
struct tcp_pcb* lpcb; struct tcp_pcb* lpcb;
char* payload; char* payload[MAX_CLIENT_ACCEPTED];
uint8_t tcp_poll_retries; uint8_t tcp_poll_retries[MAX_CLIENT_ACCEPTED];
bool pending_close[MAX_CLIENT_ACCEPTED]; bool pending_close[MAX_CLIENT_ACCEPTED];
/* UDP specific */ /* UDP specific */

View File

@ -242,10 +242,11 @@
#endif #endif
#define DUMP_TCP_STATE(TTCP) do {\ #define DUMP_TCP_STATE(TTCP) do {\
INFO_TCP("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d left:%d sent:%d\n", \ int i = getCurrClientConnId(); \
TTCP, TTCP->tpcb[0], (TTCP->tpcb[0])?TTCP->tpcb[0]->state:0, \ INFO_TCP("%d] ttcp:%p tpcb:%p state:%d lpcb:%p state:%d left:%d sent:%d\n", \
i, TTCP, TTCP->tpcb[i], (TTCP->tpcb[i])?TTCP->tpcb[i]->state:0, \
TTCP->lpcb, (TTCP->lpcb)?TTCP->lpcb->state:0, \ TTCP->lpcb, (TTCP->lpcb)?TTCP->lpcb->state:0, \
(TTCP)?TTCP->left:0, (TTCP)?TTCP->buff_sent:0); \ (TTCP->tpcb[i])?TTCP->left[i]:0, (TTCP->tpcb[i])?TTCP->buff_sent[i]:0); \
} while(0); } while(0);
#define Mode2Str(_Mode) ((_Mode==0)?"TRANSMIT":"RECEIVE") #define Mode2Str(_Mode) ((_Mode==0)?"TRANSMIT":"RECEIVE")

View File

@ -182,23 +182,26 @@ cmd_ibss(int argc, char* argv[], void* ctx)
cmd_state_t cmd_state_t
cmd_set_ip(int argc, char* argv[], void* ctx) cmd_set_ip(int argc, char* argv[], void* ctx)
{ {
struct net_cfg *ncfg = ctx; struct ctx_server *hs = ctx;
struct net_cfg *ncfg = &(hs->net_cfg);
struct ip_addr lwip_addr; struct ip_addr lwip_addr;
struct netif *nif = ncfg->netif; struct netif *nif = ncfg->netif;
if (argc == 2 && if (argc == 2 &&
(strncmp(argv[1], "none", 4) == 0)) { (strncmp(argv[1], "none", 4) == 0)) {
ncfg->dhcp_enabled = 1; ncfg->dhcp_enabled = DYNAMIC_IP_CONFIG;
return CMD_DONE; return CMD_DONE;
} }
else if (argc != 4 ) { else if (argc != 4 ) {
printk("usage: ip <ip> <netmask> <gateway-ip>\n"); printk("usage: ipconfig <ip> <netmask> <gateway-ip>\n");
printk(" or : ip none (to enable DHCP)\n"); printk(" or : ipconfig none (to enable DHCP)\n");
return CMD_DONE; return CMD_DONE;
} }
/* IP address */ /* IP address */
lwip_addr = str2ip(argv[1]); lwip_addr = str2ip(argv[1]);
INFO_SPI("nif:%p lwip_addr=0x%x\n", nif, lwip_addr.addr);
netif_set_ipaddr(nif, &lwip_addr); netif_set_ipaddr(nif, &lwip_addr);
/* Netmask */ /* Netmask */
lwip_addr = str2ip(argv[2]); lwip_addr = str2ip(argv[2]);
@ -207,7 +210,7 @@ cmd_set_ip(int argc, char* argv[], void* ctx)
lwip_addr = str2ip(argv[3]); lwip_addr = str2ip(argv[3]);
netif_set_gw(nif, &lwip_addr); netif_set_gw(nif, &lwip_addr);
/* Disable DHCP */ /* Disable DHCP */
ncfg->dhcp_enabled = 0; ncfg->dhcp_enabled = STATIC_IP_CONFIG;
return CMD_DONE; return CMD_DONE;
} }
@ -455,11 +458,15 @@ cmd_status(int argc, char* argv[], void* ctx)
/* print ip address */ /* print ip address */
if (netif_is_up(netif_default)) if (netif_is_up(netif_default))
printk("ip addr: %s\n", ip2str(netif_default->ip_addr)); {
printk("ip addr: %s - ", ip2str(netif_default->ip_addr));
printk("netmask: %s - ", ip2str(netif_default->netmask));
printk("gateway: %s\n", ip2str(netif_default->gw));
}
else else
printk("ip interface is down\n"); printk("ip interface is down\n");
printk("dhcp : "); printk("dhcp : ");
if (ncfg->dhcp_enabled) { if (ncfg->dhcp_enabled == DYNAMIC_IP_CONFIG) {
printk("enabled\n"); printk("enabled\n");
} }
else { else {
@ -468,8 +475,8 @@ cmd_status(int argc, char* argv[], void* ctx)
struct ip_addr addr1 = dns_getserver(0); struct ip_addr addr1 = dns_getserver(0);
struct ip_addr addr2 = dns_getserver(1); struct ip_addr addr2 = dns_getserver(1);
printk("==> DNS1: %s\n", ip2str(addr1), addr1); printk("DNS: %s - ", ip2str(addr1));
printk("==> DNS2: %s\n", ip2str(addr2), addr2); printk("%s\n", ip2str(addr2));
showTTCPstatus(); showTTCPstatus();
return CMD_DONE; return CMD_DONE;

View File

@ -140,8 +140,13 @@ Y; \
#define WARN(msg, args...) IF_DEBUG(WARN,WARN_DEBUG(msg, ##args)) #define WARN(msg, args...) IF_DEBUG(WARN,WARN_DEBUG(msg, ##args))
#define WARN_VER(msg, args...) IF_DEBUG_VER(WARN,WARN_DEBUG(msg, ##args)) #define WARN_VER(msg, args...) IF_DEBUG_VER(WARN,WARN_DEBUG(msg, ##args))
#define WARN_POLL(msg, args...) IF_DEBUG_POLL(WARN,WARN_DEBUG(msg, ##args)) #define WARN_POLL(msg, args...) IF_DEBUG_POLL(WARN,WARN_DEBUG(msg, ##args))
#if 0 // disable to reduce the size of binary
#define INFO_INIT(msg, args...) IF_DEBUG(INIT,PRINT_DEBUG(msg, ##args)) #define INFO_INIT(msg, args...) IF_DEBUG(INIT,PRINT_DEBUG(msg, ##args))
#define INFO_INIT_VER(msg, args...) IF_DEBUG_VER(INIT,PRINT_DEBUG(msg, ##args)) #define INFO_INIT_VER(msg, args...) IF_DEBUG_VER(INIT,PRINT_DEBUG(msg, ##args))
#else
#define INFO_INIT(msg, args...)
#define INFO_INIT_VER(msg, args...)
#endif
#define INFO_TCP(msg, args...) IF_DEBUG(TCP,PRINT_DEBUG(msg, ##args)) #define INFO_TCP(msg, args...) IF_DEBUG(TCP,PRINT_DEBUG(msg, ##args))
#define INFO_TCP_VER(msg, args...) IF_DEBUG_VER(TCP,PRINT_DEBUG(msg, ##args)) #define INFO_TCP_VER(msg, args...) IF_DEBUG_VER(TCP,PRINT_DEBUG(msg, ##args))
#define INFO_TCP_DUMP(msg, args...) IF_DEBUG_DUMP(TCP,PRINT_DEBUG(msg, ##args)) #define INFO_TCP_DUMP(msg, args...) IF_DEBUG_DUMP(TCP,PRINT_DEBUG(msg, ##args))

View File

@ -1,12 +1,21 @@
#ifndef _LWIP_SETUP_H #ifndef _LWIP_SETUP_H
#define _LWIP_SETUP_H #define _LWIP_SETUP_H
#define INIT_IP_CONFIG 0xff
#define STATIC_IP_CONFIG 0
#define DYNAMIC_IP_CONFIG 1
struct net_cfg { struct net_cfg {
struct netif *netif; /* lwip network interface */ struct netif *netif; /* lwip network interface */
uint8_t dhcp_enabled; uint8_t dhcp_enabled;
uint8_t dhcp_running; uint8_t dhcp_running;
}; };
struct ctx_server {
struct net_cfg net_cfg;
uint8_t wl_init_complete;
};
/*! Start the IP stack. /*! Start the IP stack.
* If cfg->netif must have been allocated and lwip_init() * If cfg->netif must have been allocated and lwip_init()
* must have been called before this function is called * must have been called before this function is called

View File

@ -78,11 +78,6 @@ void fw_download_cb(void* ctx, uint8_t** buf, uint32_t* len)
#endif #endif
#endif #endif
struct ctx_server {
struct net_cfg net_cfg;
uint8_t wl_init_complete;
};
bool ifStatus = false; bool ifStatus = false;
bool scanNetCompleted = false; bool scanNetCompleted = false;
@ -114,7 +109,7 @@ wl_cm_conn_cb(struct wl_network_t* net, void* ctx)
INFO_INIT("Connection cb...\n"); INFO_INIT("Connection cb...\n");
printk("link up, connected to \"%s\"\n", ssid2str(&net->ssid)); printk("link up, connected to \"%s\"\n", ssid2str(&net->ssid));
if ( hs->net_cfg.dhcp_enabled ) { if ( hs->net_cfg.dhcp_enabled == DYNAMIC_IP_CONFIG ) {
INFO_INIT("Start DHCP...\n"); INFO_INIT("Start DHCP...\n");
printk("requesting dhcp ... "); printk("requesting dhcp ... ");
int8_t result = dhcp_start(hs->net_cfg.netif); int8_t result = dhcp_start(hs->net_cfg.netif);
@ -122,7 +117,7 @@ wl_cm_conn_cb(struct wl_network_t* net, void* ctx)
hs->net_cfg.dhcp_running = 1; hs->net_cfg.dhcp_running = 1;
} }
else { else {
netif_set_up(hs->net_cfg.netif); netif_set_up(hs->net_cfg.netif);
} }
INFO_INIT("Start DNS...\n"); INFO_INIT("Start DNS...\n");
@ -270,7 +265,7 @@ poll(struct ctx_server* hs)
#endif #endif
} }
void initShell() void initShell(void* ctx)
{ {
/* initialize shell */ /* initialize shell */
INFO_INIT("Shell init...\n"); INFO_INIT("Shell init...\n");
@ -278,11 +273,10 @@ void initShell()
console_add_cmd("scan", cmd_scan, NULL); console_add_cmd("scan", cmd_scan, NULL);
console_add_cmd("connect", cmd_connect, NULL); console_add_cmd("connect", cmd_connect, NULL);
console_add_cmd("setkey", cmd_setkey, NULL); console_add_cmd("setkey", cmd_setkey, NULL);
console_add_cmd("status", cmd_status, NULL); console_add_cmd("status", cmd_status, ctx);
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); console_add_cmd("ipconfig", cmd_set_ip, ctx);
#ifdef ADD_CMDS #ifdef ADD_CMDS
console_add_cmd("powersave", cmd_power, NULL); console_add_cmd("powersave", cmd_power, NULL);
console_add_cmd("psconf", cmd_psconf, NULL); console_add_cmd("psconf", cmd_psconf, NULL);
@ -319,12 +313,16 @@ wl_init_complete_cb(void* ctx)
struct ip_addr ipaddr, netmask, gw; struct ip_addr ipaddr, netmask, gw;
wl_err_t wl_status; wl_err_t wl_status;
IP4_ADDR(&gw, 0,0,0,0); if (hs->net_cfg.dhcp_enabled == INIT_IP_CONFIG)
IP4_ADDR(&ipaddr, 0,0,0,0); {
IP4_ADDR(&netmask, 0,0,0,0); IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 0,0,0,0);
IP4_ADDR(&netmask, 0,0,0,0);
/* default is dhcp enabled */
hs->net_cfg.dhcp_enabled = DYNAMIC_IP_CONFIG;
}
/* default is dhcp enabled */
hs->net_cfg.dhcp_enabled = 1;
start_ip_stack(&hs->net_cfg, start_ip_stack(&hs->net_cfg,
ipaddr, ipaddr,
netmask, netmask,
@ -339,7 +337,7 @@ wl_init_complete_cb(void* ctx)
wl_scan(); wl_scan();
if (initSpi()){ if (initSpi(hs)){
WARN("Spi not initialized\n"); WARN("Spi not initialized\n");
}else }else
{ {
@ -362,6 +360,8 @@ void startup_init(void)
DEB_PIN_UP(2); DEB_PIN_UP(2);
} }
const char timestamp[] = __TIMESTAMP__;
/** /**
* *
*/ */
@ -381,8 +381,6 @@ main(void)
tc_init(); tc_init();
initShell();
delay_init(FOSC0); delay_init(FOSC0);
#ifdef _TEST_SPI_ #ifdef _TEST_SPI_
@ -396,7 +394,7 @@ main(void)
} }
#else #else
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__); printk("Arduino Wifi Startup... [%s]\n", timestamp);
size_t size_ctx_server = sizeof(struct ctx_server); size_t size_ctx_server = sizeof(struct ctx_server);
hs = calloc(1, size_ctx_server); hs = calloc(1, size_ctx_server);
@ -405,10 +403,11 @@ main(void)
size_t size_netif = sizeof(struct netif); size_t size_netif = sizeof(struct netif);
hs->net_cfg.netif = calloc(1, size_netif); hs->net_cfg.netif = calloc(1, size_netif);
ASSERT(hs->net_cfg.netif, "out of memory"); ASSERT(hs->net_cfg.netif, "out of memory");
hs->net_cfg.dhcp_enabled = INIT_IP_CONFIG;
INFO_INIT("hs:%p size:0x%x netif:%p size:0x%x\n", hs, size_ctx_server, INFO_INIT("hs:%p size:0x%x netif:%p size:0x%x\n", hs, size_ctx_server,
hs->net_cfg.netif, size_netif); hs->net_cfg.netif, size_netif);
initShell(hs);
timer_init(NULL, NULL); timer_init(NULL, NULL);
lwip_init(); lwip_init();

View File

@ -32,6 +32,8 @@ enum {
SET_PASSPHRASE_CMD = 0x11, SET_PASSPHRASE_CMD = 0x11,
SET_KEY_CMD = 0x12, SET_KEY_CMD = 0x12,
TEST_CMD = 0x13, TEST_CMD = 0x13,
SET_IP_CONFIG_CMD = 0x14,
SET_DNS_CONFIG_CMD = 0x15,
GET_CONN_STATUS_CMD = 0x20, GET_CONN_STATUS_CMD = 0x20,
GET_IPADDR_CMD = 0x21, GET_IPADDR_CMD = 0x21,
@ -155,3 +157,4 @@ typedef struct __attribute__((__packed__))
}tByteParam; }tByteParam;
#endif #endif
uint8_t param;

View File

@ -41,13 +41,13 @@
</OverrideVtorValue> </OverrideVtorValue>
<Channel> <Channel>
<host>127.0.0.1</host> <host>127.0.0.1</host>
<port>51464</port> <port>51999</port>
<ssl>False</ssl> <ssl>False</ssl>
</Channel> </Channel>
<ToolOptions> <ToolOptions>
<InterfaceName>JTAG</InterfaceName> <InterfaceName>JTAG</InterfaceName>
<InterfaceProperties> <InterfaceProperties>
<JtagDbgClock>7500000</JtagDbgClock> <JtagDbgClock>250000</JtagDbgClock>
<JtagProgClock>1000000</JtagProgClock> <JtagProgClock>1000000</JtagProgClock>
<IspClock>150000</IspClock> <IspClock>150000</IspClock>
<JtagInChain>false</JtagInChain> <JtagInChain>false</JtagInChain>
@ -67,130 +67,128 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings> <ToolchainSettings>
<Avr32Gcc> <Avr32Gcc>
<avr32gcc.common.outputfiles.hex>True</avr32gcc.common.outputfiles.hex> <avr32gcc.common.outputfiles.hex>True</avr32gcc.common.outputfiles.hex>
<avr32gcc.common.outputfiles.lss>True</avr32gcc.common.outputfiles.lss> <avr32gcc.common.outputfiles.lss>True</avr32gcc.common.outputfiles.lss>
<avr32gcc.common.outputfiles.eep>True</avr32gcc.common.outputfiles.eep> <avr32gcc.common.outputfiles.eep>True</avr32gcc.common.outputfiles.eep>
<avr32gcc.common.outputfiles.srec>True</avr32gcc.common.outputfiles.srec> <avr32gcc.common.outputfiles.srec>True</avr32gcc.common.outputfiles.srec>
<avr32gcc.compiler.symbols.DefSymbols> <avr32gcc.compiler.symbols.DefSymbols>
<ListValues> <ListValues>
<Value>BOARD=ARDUINO</Value> <Value>BOARD=ARDUINO</Value>
<Value>_ASSERT_ENABLE_</Value> <Value>WITH_KEY</Value>
<Value>EXT_BOARD=SPB104</Value> <Value>WITH_WPA</Value>
<Value>WITH_KEY</Value> <Value>WITH_NO_DMA</Value>
<Value>WITH_WPA</Value> <Value>DATAFLASH=1</Value>
<Value>WITH_NO_DMA</Value> <Value>_INFO_DEBUG_=1</Value>
<Value>DATAFLASH=1</Value> </ListValues>
<Value>_INFO_DEBUG_=1</Value> </avr32gcc.compiler.symbols.DefSymbols>
</ListValues> <avr32gcc.compiler.directories.IncludePaths>
</avr32gcc.compiler.symbols.DefSymbols> <ListValues>
<avr32gcc.compiler.directories.IncludePaths> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA</Value>
<ListValues> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/TC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/TC</Value> <Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/FLASHC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EBI/SMC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/FLASHC</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/DEBUG</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EBI/SMC</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/DELAY</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/DEBUG</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/USART</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/DELAY</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/SPI</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/USART</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/RTC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/SPI</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PM</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/RTC</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/GPIO</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PM</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EIC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/GPIO</Value> <Value>../src/CONFIG</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EIC</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/CPU/CYCLE_COUNTER</Value>
<Value>../src/CONFIG</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS/INCLUDE</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/CPU/CYCLE_COUNTER</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/PREPROCESSOR</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS/INCLUDE</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/PREPROCESSOR</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/INTC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS</Value> <Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/INTC</Value> <Value>../src</Value>
<Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include</Value>
<Value>../src</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-port-1.3.2/HD/if/include</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/include/ipv4</Value> <Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-port-1.3.2/HD/if/include</Value> </ListValues>
<Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD</Value> </avr32gcc.compiler.directories.IncludePaths>
</ListValues> <avr32gcc.compiler.optimization.level>Optimize for size (-Os)</avr32gcc.compiler.optimization.level>
</avr32gcc.compiler.directories.IncludePaths> <avr32gcc.compiler.optimization.OtherFlags>-fdata-sections -ffunction-sections</avr32gcc.compiler.optimization.OtherFlags>
<avr32gcc.compiler.optimization.level>Optimize for size (-Os)</avr32gcc.compiler.optimization.level> <avr32gcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</avr32gcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<avr32gcc.compiler.optimization.OtherFlags>-fdata-sections</avr32gcc.compiler.optimization.OtherFlags> <avr32gcc.compiler.optimization.UseAssemblerForPseudoInstructions>True</avr32gcc.compiler.optimization.UseAssemblerForPseudoInstructions>
<avr32gcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</avr32gcc.compiler.optimization.PrepareFunctionsForGarbageCollection> <avr32gcc.compiler.optimization.ForceDoubleWordAlignment>True</avr32gcc.compiler.optimization.ForceDoubleWordAlignment>
<avr32gcc.compiler.optimization.UseAssemblerForPseudoInstructions>True</avr32gcc.compiler.optimization.UseAssemblerForPseudoInstructions> <avr32gcc.compiler.warnings.AllWarnings>True</avr32gcc.compiler.warnings.AllWarnings>
<avr32gcc.compiler.optimization.ForceDoubleWordAlignment>True</avr32gcc.compiler.optimization.ForceDoubleWordAlignment> <avr32gcc.compiler.miscellaneous.OtherFlags>-c -fmessage-length=0</avr32gcc.compiler.miscellaneous.OtherFlags>
<avr32gcc.compiler.warnings.AllWarnings>True</avr32gcc.compiler.warnings.AllWarnings> <avr32gcc.linker.general.DoNotUseStandardStartFiles>True</avr32gcc.linker.general.DoNotUseStandardStartFiles>
<avr32gcc.compiler.miscellaneous.OtherFlags>-c -fmessage-length=0</avr32gcc.compiler.miscellaneous.OtherFlags> <avr32gcc.linker.libraries.Libraries>
<avr32gcc.linker.general.DoNotUseStandardStartFiles>True</avr32gcc.linker.general.DoNotUseStandardStartFiles> <ListValues>
<avr32gcc.linker.libraries.Libraries> <Value>newlib_addons-at32ucr2-speed_opt</Value>
<ListValues> <Value>_ucr2_hd_spi_v2.7.0</Value>
<Value>newlib_addons-at32ucr2-speed_opt</Value> <Value>_ucr2_hd_wl_sta_intwpa_v2.7.0</Value>
<Value>_ucr2_hd_wl_sta_intwpa_v2.7.0</Value> </ListValues>
<Value>_ucr2_hd_spi_v2.7.0</Value> </avr32gcc.linker.libraries.Libraries>
</ListValues> <avr32gcc.linker.libraries.LibrarySearchPaths>
</avr32gcc.linker.libraries.Libraries> <ListValues>
<avr32gcc.linker.libraries.LibrarySearchPaths> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS</Value>
<ListValues> <Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS</Value> <Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR2/GCC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value> </ListValues>
<Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/v2.7.0/UCR2/GCC</Value> </avr32gcc.linker.libraries.LibrarySearchPaths>
</ListValues> <avr32gcc.linker.optimization.GarbageCollectUnusedSections>True</avr32gcc.linker.optimization.GarbageCollectUnusedSections>
</avr32gcc.linker.libraries.LibrarySearchPaths> <avr32gcc.linker.optimization.PutReadOnlyDataInWritableDataSection>True</avr32gcc.linker.optimization.PutReadOnlyDataInWritableDataSection>
<avr32gcc.linker.optimization.GarbageCollectUnusedSections>True</avr32gcc.linker.optimization.GarbageCollectUnusedSections> <avr32gcc.linker.optimization.AllowDirectReferencesToDataSection>True</avr32gcc.linker.optimization.AllowDirectReferencesToDataSection>
<avr32gcc.linker.optimization.PutReadOnlyDataInWritableDataSection>True</avr32gcc.linker.optimization.PutReadOnlyDataInWritableDataSection> <avr32gcc.linker.miscellaneous.LinkerFlags>-Wl,--gc-sections -Wl,-e,_trampoline -T../src/SOFTWARE_FRAMEWORK/UTILS/LINKER_SCRIPTS/AT32UC3A/1256/GCC/link_uc3a1256.lds</avr32gcc.linker.miscellaneous.LinkerFlags>
<avr32gcc.linker.optimization.AllowDirectReferencesToDataSection>True</avr32gcc.linker.optimization.AllowDirectReferencesToDataSection> <avr32gcc.assembler.general.IncludePaths>
<avr32gcc.linker.miscellaneous.LinkerFlags>-Wl,--gc-sections -Wl,-e,_trampoline -T../src/SOFTWARE_FRAMEWORK/UTILS/LINKER_SCRIPTS/AT32UC3A/1256/GCC/link_uc3a1256.lds</avr32gcc.linker.miscellaneous.LinkerFlags> <ListValues>
<avr32gcc.assembler.general.IncludePaths> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA</Value>
<ListValues> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/TC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/TC</Value> <Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/FLASHC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EBI/SMC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/FLASHC</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/DEBUG</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EBI/SMC</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/DELAY</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/DEBUG</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/USART</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/DELAY</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/SPI</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/USART</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/RTC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/SPI</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PM</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/RTC</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/GPIO</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PM</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EIC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/GPIO</Value> <Value>../src/CONFIG</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EIC</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/CPU/CYCLE_COUNTER</Value>
<Value>../src/CONFIG</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS/INCLUDE</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/CPU/CYCLE_COUNTER</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/PREPROCESSOR</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS/INCLUDE</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/PREPROCESSOR</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/INTC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS</Value> <Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/INTC</Value> </ListValues>
<Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value> </avr32gcc.assembler.general.IncludePaths>
</ListValues> <avr32gcc.preprocessingassembler.general.AssemblerFlags>-Wa,-g</avr32gcc.preprocessingassembler.general.AssemblerFlags>
</avr32gcc.assembler.general.IncludePaths> <avr32gcc.preprocessingassembler.general.IncludePaths>
<avr32gcc.preprocessingassembler.general.AssemblerFlags>-Wa,-g</avr32gcc.preprocessingassembler.general.AssemblerFlags> <ListValues>
<avr32gcc.preprocessingassembler.general.IncludePaths> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA</Value>
<ListValues> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/TC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/TC</Value> <Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/MEMORY/CTRL_ACCESS</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/FLASHC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/COMPONENTS/MEMORY/DATA_FLASH/AT45DBX</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EBI/SMC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/FLASHC</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/DEBUG</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EBI/SMC</Value> <Value>../src/SOFTWARE_FRAMEWORK/SERVICES/DELAY</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/DEBUG</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/USART</Value>
<Value>../src/SOFTWARE_FRAMEWORK/SERVICES/DELAY</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/SPI</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/USART</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/RTC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/SPI</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PM</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/RTC</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/GPIO</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/PM</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EIC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/GPIO</Value> <Value>../src/CONFIG</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/EIC</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/CPU/CYCLE_COUNTER</Value>
<Value>../src/CONFIG</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS/INCLUDE</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/CPU/CYCLE_COUNTER</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS/PREPROCESSOR</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/LIBS/NEWLIB_ADDONS/INCLUDE</Value> <Value>../src/SOFTWARE_FRAMEWORK/UTILS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS/PREPROCESSOR</Value> <Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/INTC</Value>
<Value>../src/SOFTWARE_FRAMEWORK/UTILS</Value> <Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value>
<Value>../src/SOFTWARE_FRAMEWORK/DRIVERS/INTC</Value> </ListValues>
<Value>../src/SOFTWARE_FRAMEWORK/BOARDS</Value> </avr32gcc.preprocessingassembler.general.IncludePaths>
</ListValues> </Avr32Gcc>
</avr32gcc.preprocessingassembler.general.IncludePaths>
</Avr32Gcc>
</ToolchainSettings> </ToolchainSettings>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@ -98,6 +98,31 @@ int WiFiClass::begin(char* ssid, const char *passphrase)
return status; return status;
} }
void WiFiClass::config(IPAddress local_ip)
{
WiFiDrv::config(1, (uint32_t)local_ip, 0, 0);
}
void WiFiClass::config(IPAddress local_ip, IPAddress gateway)
{
WiFiDrv::config(2, (uint32_t)local_ip, (uint32_t)gateway, 0);
}
void WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
{
WiFiDrv::config(3, (uint32_t)local_ip, (uint32_t)gateway, (uint32_t)subnet);
}
void WiFiClass::setDNS(IPAddress dns_server1)
{
WiFiDrv::setDNS(1, (uint32_t)dns_server1, 0);
}
void WiFiClass::setDNS(IPAddress dns_server1, IPAddress dns_server2)
{
WiFiDrv::setDNS(2, (uint32_t)dns_server1, (uint32_t)dns_server2);
}
int WiFiClass::disconnect() int WiFiClass::disconnect()
{ {
return WiFiDrv::disconnect(); return WiFiDrv::disconnect();

View File

@ -59,6 +59,41 @@ public:
*/ */
int begin(char* ssid, const char *passphrase); int begin(char* ssid, const char *passphrase);
/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
*/
void config(IPAddress local_ip);
/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param gateway : Static gateway configuration
*/
void config(IPAddress local_ip, IPAddress gateway);
/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param gateway: Static gateway configuration
* param subnet: Static Subnet mask
*/
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
/* Change DNS Ip configuration
*
* param dns_server1: ip configuration for DNS server 1
*/
void setDNS(IPAddress dns_server1);
/* Change DNS Ip configuration
*
* param dns_server1: ip configuration for DNS server 1
* param dns_server2: ip configuration for DNS server 2
*
*/
void setDNS(IPAddress dns_server1, IPAddress dns_server2);
/* /*
* Disconnect from the network * Disconnect from the network
* *

View File

@ -131,12 +131,11 @@ void WiFiClient::stop() {
ServerDrv::stopClient(_sock); ServerDrv::stopClient(_sock);
WiFiClass::_state[_sock] = NA_STATE; WiFiClass::_state[_sock] = NA_STATE;
unsigned long start = millis(); int count = 0;
// wait maximum 5 secs for the connection to close
while (status() != CLOSED && ++count < 50)
delay(100);
// wait a second for the connection to close
while (status() != CLOSED && millis() - start < 1000)
delay(1);
_sock = 255; _sock = 255;
} }
@ -150,7 +149,7 @@ uint8_t WiFiClient::connected() {
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 || return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
s == FIN_WAIT_2 || s == TIME_WAIT || s == FIN_WAIT_2 || s == TIME_WAIT ||
s == SYN_SENT || s== SYN_RCVD || s == SYN_SENT || s== SYN_RCVD ||
(s == CLOSE_WAIT && !available())); (s == CLOSE_WAIT));
} }
} }

View File

@ -152,6 +152,55 @@ int8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const
return _data; return _data;
} }
void WiFiDrv::config(uint8_t validParams, uint32_t local_ip, uint32_t gateway, uint32_t subnet)
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(SET_IP_CONFIG_CMD, PARAM_NUMS_4);
SpiDrv::sendParam((uint8_t*)&validParams, 1, NO_LAST_PARAM);
SpiDrv::sendParam((uint8_t*)&local_ip, 4, NO_LAST_PARAM);
SpiDrv::sendParam((uint8_t*)&gateway, 4, NO_LAST_PARAM);
SpiDrv::sendParam((uint8_t*)&subnet, 4, LAST_PARAM);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
if (!SpiDrv::waitResponseCmd(SET_IP_CONFIG_CMD, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse");
_data = WL_FAILURE;
}
SpiDrv::spiSlaveDeselect();
}
void WiFiDrv::setDNS(uint8_t validParams, uint32_t dns_server1, uint32_t dns_server2)
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(SET_DNS_CONFIG_CMD, PARAM_NUMS_3);
SpiDrv::sendParam((uint8_t*)&validParams, 1, NO_LAST_PARAM);
SpiDrv::sendParam((uint8_t*)&dns_server1, 4, NO_LAST_PARAM);
SpiDrv::sendParam((uint8_t*)&dns_server2, 4, LAST_PARAM);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
if (!SpiDrv::waitResponseCmd(SET_DNS_CONFIG_CMD, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse");
_data = WL_FAILURE;
}
SpiDrv::spiSlaveDeselect();
}
int8_t WiFiDrv::disconnect() int8_t WiFiDrv::disconnect()
{ {
WAIT_FOR_SLAVE_SELECT(); WAIT_FOR_SLAVE_SELECT();

View File

@ -90,6 +90,27 @@ public:
*/ */
static int8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len); static int8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
/* Set ip configuration disabling dhcp client
*
* param validParams: set the number of parameters that we want to change
* i.e. validParams = 1 means that we'll change only ip address
* validParams = 3 means that we'll change ip address, gateway and netmask
* param local_ip: Static ip configuration
* param gateway: Static gateway configuration
* param subnet: Static subnet mask configuration
*/
static void config(uint8_t validParams, uint32_t local_ip, uint32_t gateway, uint32_t subnet);
/* Set DNS ip configuration
*
* param validParams: set the number of parameters that we want to change
* i.e. validParams = 1 means that we'll change only dns_server1
* validParams = 2 means that we'll change dns_server1 and dns_server2
* param dns_server1: Static DNS server1 configuration
* param dns_server2: Static DNS server2 configuration
*/
static void setDNS(uint8_t validParams, uint32_t dns_server1, uint32_t dns_server2);
/* /*
* Disconnect from the network * Disconnect from the network
* *

View File

@ -27,6 +27,8 @@ enum {
SET_PASSPHRASE_CMD = 0x11, SET_PASSPHRASE_CMD = 0x11,
SET_KEY_CMD = 0x12, SET_KEY_CMD = 0x12,
TEST_CMD = 0x13, TEST_CMD = 0x13,
SET_IP_CONFIG_CMD = 0x14,
SET_DNS_CONFIG_CMD = 0x15,
GET_CONN_STATUS_CMD = 0x20, GET_CONN_STATUS_CMD = 0x20,
GET_IPADDR_CMD = 0x21, GET_IPADDR_CMD = 0x21,