From e43ed7d47d9b2c37ccff6dc75d6bfe4c8a55ac86 Mon Sep 17 00:00:00 2001 From: Mimmo La Fauci Date: Thu, 21 Mar 2013 09:24:07 +0100 Subject: Added API to set static IP and DNS server --- firmwares/wifishield/wifiHD/src/ard_spi.c | 126 ++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 6 deletions(-) (limited to 'firmwares/wifishield/wifiHD/src/ard_spi.c') diff --git a/firmwares/wifishield/wifiHD/src/ard_spi.c b/firmwares/wifishield/wifiHD/src/ard_spi.c index 66b3ba5..55c51cc 100644 --- a/firmwares/wifishield/wifiHD/src/ard_spi.c +++ b/firmwares/wifishield/wifiHD/src/ard_spi.c @@ -26,6 +26,7 @@ #include #include "util.h" #include "lwip/udp.h" +#include "lwip_setup.h" 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 static volatile Bool startRecvCmdSignal = FALSE; -#define MAX_CMD_NUM 34 +#define MAX_CMD_NUM 36 typedef struct sCmd_spi_list{ cmd_spi_cb_t cb; char cmd_id; @@ -535,6 +536,117 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) { RETURN_ERR(err) } +int set_ip_config_cmd_cb(int numParam, char* buf, void* ctx) { + struct ip_addr lwip_addr; + uint32_t _ip_addr = 0; + 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; + const uint8_t DNS_SERVER_IDX_CHANG = 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_IP_CONFIG_PARAMS) + { + int i=0; + for (; iparamLen == 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 = 0; + }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; + const uint8_t DNS_SERVER_IDX_CHANG = 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 (; iparamLen == 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 = 0; + }else + RETURN_ERR(WL_FAILURE) + + RETURN_ERR(err) +} + + + void set_result(wl_status_t _status) { result = _status; @@ -1402,12 +1514,12 @@ int call_reply_cb(char* recv, char* reply) { { tSpiMsg* spiMsg = (tSpiMsg*) recv; _result = cmd_spi_list[i].cb(spiMsg->nParam, - (char*) &(spiMsg->params[0]), NULL); + (char*) &(spiMsg->params[0]), cmd_spi_list[i].ctx); }else { tSpiMsgData* spiMsg = (tSpiMsgData*) recv; _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) @@ -1452,10 +1564,12 @@ int call_reply_cb(char* recv, char* reply) { 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_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_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_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); @@ -1786,7 +1900,7 @@ void initExtInt() Enable_global_interrupt(); } -int initSpi() +int initSpi(void* ctx) { volatile avr32_spi_t *spi = &AVR32_SPI0; gpio_map_t spi_piomap = { \ @@ -1838,7 +1952,7 @@ int initSpi() #ifdef _SPI_STATS_ initStatSpi(); #endif - init_spi_cmds(); + init_spi_cmds(ctx); memset(_receiveBuffer, 0, sizeof(_receiveBuffer)); memset(buf, 0, sizeof(buf)); -- cgit v1.2.3-18-g5258 From 41d49e97f0d93853659f37fe5e4d4e0a19c20b41 Mon Sep 17 00:00:00 2001 From: Mimmo La Fauci Date: Fri, 22 Mar 2013 13:42:12 +0100 Subject: Fix issue with multiple clients on WebServer --- firmwares/wifishield/wifiHD/src/ard_spi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'firmwares/wifishield/wifiHD/src/ard_spi.c') diff --git a/firmwares/wifishield/wifiHD/src/ard_spi.c b/firmwares/wifishield/wifiHD/src/ard_spi.c index 55c51cc..b79c1fc 100644 --- a/firmwares/wifishield/wifiHD/src/ard_spi.c +++ b/firmwares/wifishield/wifiHD/src/ard_spi.c @@ -538,13 +538,11 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) { int set_ip_config_cmd_cb(int numParam, char* buf, void* ctx) { struct ip_addr lwip_addr; - uint32_t _ip_addr = 0; 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; - const uint8_t DNS_SERVER_IDX_CHANG = 2; wl_err_t err = WL_SUCCESS; tParam* params = (tParam*) buf; @@ -607,7 +605,6 @@ int set_dns_config_cmd_cb(int numParam, char* buf, void* ctx) { struct netif *nif = ncfg->netif; uint8_t parmsToChange=0; const uint8_t MAX_DNS_CONFIG_PARAMS = 2; - const uint8_t DNS_SERVER_IDX_CHANG = 2; wl_err_t err = WL_SUCCESS; tParam* params = (tParam*) buf; @@ -1787,7 +1784,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi) { int8_t numParams = 0; 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) { numParams = _receiveBuffer[PARAM_LEN_POS]; @@ -1804,6 +1801,10 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi) } if (!endOfFrame){ 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); -- cgit v1.2.3-18-g5258 From 6265d401817934c4b2d9ee3bf8dab44de1bb08cb Mon Sep 17 00:00:00 2001 From: Mimmo La Fauci Date: Tue, 26 Mar 2013 19:49:19 +0100 Subject: Fix issue on client side --- firmwares/wifishield/wifiHD/src/ard_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'firmwares/wifishield/wifiHD/src/ard_spi.c') diff --git a/firmwares/wifishield/wifiHD/src/ard_spi.c b/firmwares/wifishield/wifiHD/src/ard_spi.c index b79c1fc..8bd288b 100644 --- a/firmwares/wifishield/wifiHD/src/ard_spi.c +++ b/firmwares/wifishield/wifiHD/src/ard_spi.c @@ -591,7 +591,7 @@ int set_ip_config_cmd_cb(int numParam, char* buf, void* ctx) { } /* Disable DHCP */ - ncfg->dhcp_enabled = 0; + ncfg->dhcp_enabled = STATIC_IP_CONFIG; }else RETURN_ERR(WL_FAILURE) @@ -635,7 +635,7 @@ int set_dns_config_cmd_cb(int numParam, char* buf, void* ctx) { } } /* Disable DHCP */ - ncfg->dhcp_enabled = 0; + ncfg->dhcp_enabled = STATIC_IP_CONFIG; }else RETURN_ERR(WL_FAILURE) -- cgit v1.2.3-18-g5258