Skip to content

Commit 83dbd39

Browse files
committed
Merge remote-tracking branch 'mlafauci/wifishield-bugfix' into HEAD
2 parents 1b0bff6 + 3c1fb4c commit 83dbd39

File tree

19 files changed

+16321
-16000
lines changed

19 files changed

+16321
-16000
lines changed
Binary file not shown.

hardware/arduino/firmwares/wifishield/wifiHD/Release/wifiHD.hex

+15,744-15,665
Large diffs are not rendered by default.

hardware/arduino/firmwares/wifishield/wifiHD/src/ard_spi.c

+122-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <board_init.h>
2727
#include "util.h"
2828
#include "lwip/udp.h"
29+
#include "lwip_setup.h"
2930

3031
extern const char* fwVersion;
3132

@@ -94,7 +95,7 @@ bool end_write = false; //TODO only for debug
9495
// Signal indicating a new command is coming from SPI interface
9596
static volatile Bool startRecvCmdSignal = FALSE;
9697

97-
#define MAX_CMD_NUM 34
98+
#define MAX_CMD_NUM 36
9899
typedef struct sCmd_spi_list{
99100
cmd_spi_cb_t cb;
100101
char cmd_id;
@@ -535,6 +536,114 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
535536
RETURN_ERR(err)
536537
}
537538

539+
int set_ip_config_cmd_cb(int numParam, char* buf, void* ctx) {
540+
struct ip_addr lwip_addr;
541+
struct ctx_server *hs = ctx;
542+
struct net_cfg *ncfg = &(hs->net_cfg);
543+
struct netif *nif = ncfg->netif;
544+
uint8_t parmsToChange=0;
545+
const uint8_t MAX_IP_CONFIG_PARAMS = 3;
546+
547+
wl_err_t err = WL_SUCCESS;
548+
tParam* params = (tParam*) buf;
549+
550+
if (params->paramLen == 1)
551+
{
552+
GET_PARAM_NEXT(BYTE, params, _parmsToChange);
553+
parmsToChange = _parmsToChange;
554+
}
555+
else
556+
RETURN_ERR(WL_FAILURE)
557+
558+
INFO_SPI("%p numParam=%d parmsToChange=%d\n", ctx, numParam, parmsToChange);
559+
560+
if (parmsToChange <= MAX_IP_CONFIG_PARAMS)
561+
{
562+
int i=0;
563+
for (; i<parmsToChange; ++i)
564+
{
565+
if (params->paramLen == 4)
566+
{
567+
GET_PARAM_NEXT(LONG, params, _ip_addr);
568+
lwip_addr.addr = _ip_addr;
569+
INFO_SPI("%d] nif:%p lwip_addr=0x%x\n", i, nif, lwip_addr.addr);
570+
switch (i)
571+
{
572+
case 0: // local_ip
573+
{
574+
netif_set_ipaddr(nif, &lwip_addr);
575+
break;
576+
}
577+
case 1: // gateway
578+
{
579+
netif_set_gw(nif, &lwip_addr);
580+
break;
581+
}
582+
case 2: // subnet
583+
{
584+
netif_set_netmask(nif, &lwip_addr);
585+
break;
586+
}
587+
}
588+
}else{
589+
RETURN_ERR(WL_FAILURE)
590+
}
591+
592+
}
593+
/* Disable DHCP */
594+
ncfg->dhcp_enabled = STATIC_IP_CONFIG;
595+
}else
596+
RETURN_ERR(WL_FAILURE)
597+
598+
RETURN_ERR(err)
599+
}
600+
601+
int set_dns_config_cmd_cb(int numParam, char* buf, void* ctx) {
602+
struct ip_addr lwip_addr;
603+
struct ctx_server *hs = ctx;
604+
struct net_cfg *ncfg = &(hs->net_cfg);
605+
struct netif *nif = ncfg->netif;
606+
uint8_t parmsToChange=0;
607+
const uint8_t MAX_DNS_CONFIG_PARAMS = 2;
608+
609+
wl_err_t err = WL_SUCCESS;
610+
tParam* params = (tParam*) buf;
611+
612+
if (params->paramLen == 1)
613+
{
614+
GET_PARAM_NEXT(BYTE, params, _parmsToChange);
615+
parmsToChange = _parmsToChange;
616+
}
617+
else
618+
RETURN_ERR(WL_FAILURE)
619+
620+
INFO_SPI("%p numParam=%d parmsToChange=%d\n", ctx, numParam, parmsToChange);
621+
622+
if (parmsToChange <= MAX_DNS_CONFIG_PARAMS)
623+
{
624+
int i=0;
625+
for (; i<parmsToChange; ++i)
626+
{
627+
if (params->paramLen == 4)
628+
{
629+
GET_PARAM_NEXT(LONG, params, _ip_addr);
630+
lwip_addr.addr = _ip_addr;
631+
INFO_SPI("%d] nif:%p lwip_addr=0x%x\n", i, nif, lwip_addr.addr);
632+
dns_setserver(i, &lwip_addr);
633+
}else{
634+
RETURN_ERR(WL_FAILURE)
635+
}
636+
}
637+
/* Disable DHCP */
638+
ncfg->dhcp_enabled = STATIC_IP_CONFIG;
639+
}else
640+
RETURN_ERR(WL_FAILURE)
641+
642+
RETURN_ERR(err)
643+
}
644+
645+
646+
538647
void set_result(wl_status_t _status)
539648
{
540649
result = _status;
@@ -1402,12 +1511,12 @@ int call_reply_cb(char* recv, char* reply) {
14021511
{
14031512
tSpiMsg* spiMsg = (tSpiMsg*) recv;
14041513
_result = cmd_spi_list[i].cb(spiMsg->nParam,
1405-
(char*) &(spiMsg->params[0]), NULL);
1514+
(char*) &(spiMsg->params[0]), cmd_spi_list[i].ctx);
14061515
}else
14071516
{
14081517
tSpiMsgData* spiMsg = (tSpiMsgData*) recv;
14091518
_result = cmd_spi_list[i].cb(spiMsg->nParam,
1410-
(char*) &(spiMsg->params[0]), NULL);
1519+
(char*) &(spiMsg->params[0]), cmd_spi_list[i].ctx);
14111520
}
14121521

14131522
if (_result != WIFI_SPI_ACK)
@@ -1452,10 +1561,12 @@ int call_reply_cb(char* recv, char* reply) {
14521561
return REPLY_NO_ERR;
14531562
}
14541563

1455-
void init_spi_cmds() {
1564+
void init_spi_cmds(void* ctx) {
14561565
spi_add_cmd(SET_NET_CMD, set_net_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
14571566
spi_add_cmd(SET_PASSPHRASE_CMD, set_passphrase_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
14581567
spi_add_cmd(SET_KEY_CMD, set_key_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
1568+
spi_add_cmd(SET_IP_CONFIG_CMD, set_ip_config_cmd_cb, ack_reply_cb, ctx, CMD_SET_FLAG);
1569+
spi_add_cmd(SET_DNS_CONFIG_CMD, set_dns_config_cmd_cb, ack_reply_cb, ctx, CMD_SET_FLAG);
14591570
spi_add_cmd(GET_CONN_STATUS_CMD, get_result_cmd_cb, get_reply_cb, NULL, CMD_GET_FLAG);
14601571
spi_add_cmd(GET_IPADDR_CMD, ack_cmd_cb, get_reply_ipaddr_cb, NULL, CMD_GET_FLAG);
14611572
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)
16731784
{
16741785
int8_t numParams = 0;
16751786
int idx = PARAM_LEN_POS+1;
1676-
bool islen16bit = _receiveBuffer[CMD_POS] & DATA_FLAG;
1787+
bool islen16bit = ((_receiveBuffer[CMD_POS] & DATA_FLAG) == DATA_FLAG);
16771788
if (index >= idx)
16781789
{
16791790
numParams = _receiveBuffer[PARAM_LEN_POS];
@@ -1690,6 +1801,10 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
16901801
}
16911802
if (!endOfFrame){
16921803
WARN("Wrong termination index:%d nParam:%d idx:%d 16bit:%d\n", index, numParams, idx, islen16bit);
1804+
#ifdef _DEBUG_
1805+
dump((char*)_receiveBuffer, receivedChars);
1806+
while(0);
1807+
#endif
16931808
}
16941809
}
16951810
} while (!endOfFrame);
@@ -1786,7 +1901,7 @@ void initExtInt()
17861901
Enable_global_interrupt();
17871902
}
17881903

1789-
int initSpi()
1904+
int initSpi(void* ctx)
17901905
{
17911906
volatile avr32_spi_t *spi = &AVR32_SPI0;
17921907
gpio_map_t spi_piomap = { \
@@ -1838,7 +1953,7 @@ int initSpi()
18381953
#ifdef _SPI_STATS_
18391954
initStatSpi();
18401955
#endif
1841-
init_spi_cmds();
1956+
init_spi_cmds(ctx);
18421957

18431958
memset(_receiveBuffer, 0, sizeof(_receiveBuffer));
18441959
memset(buf, 0, sizeof(buf));

hardware/arduino/firmwares/wifishield/wifiHD/src/ard_spi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void set_result_cmd(int err) ;
5757

5858
void set_result(wl_status_t _status);
5959

60-
int initSpi(void);
60+
int initSpi(void* ctx);
6161

6262
void initExtInt();
6363

0 commit comments

Comments
 (0)