26
26
#include <board_init.h>
27
27
#include "util.h"
28
28
#include "lwip/udp.h"
29
+ #include "lwip_setup.h"
29
30
30
31
extern const char * fwVersion ;
31
32
@@ -94,7 +95,7 @@ bool end_write = false; //TODO only for debug
94
95
// Signal indicating a new command is coming from SPI interface
95
96
static volatile Bool startRecvCmdSignal = FALSE;
96
97
97
- #define MAX_CMD_NUM 34
98
+ #define MAX_CMD_NUM 36
98
99
typedef struct sCmd_spi_list {
99
100
cmd_spi_cb_t cb ;
100
101
char cmd_id ;
@@ -535,6 +536,114 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
535
536
RETURN_ERR (err )
536
537
}
537
538
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
+
538
647
void set_result (wl_status_t _status )
539
648
{
540
649
result = _status ;
@@ -1402,12 +1511,12 @@ int call_reply_cb(char* recv, char* reply) {
1402
1511
{
1403
1512
tSpiMsg * spiMsg = (tSpiMsg * ) recv ;
1404
1513
_result = cmd_spi_list [i ].cb (spiMsg -> nParam ,
1405
- (char * ) & (spiMsg -> params [0 ]), NULL );
1514
+ (char * ) & (spiMsg -> params [0 ]), cmd_spi_list [ i ]. ctx );
1406
1515
}else
1407
1516
{
1408
1517
tSpiMsgData * spiMsg = (tSpiMsgData * ) recv ;
1409
1518
_result = cmd_spi_list [i ].cb (spiMsg -> nParam ,
1410
- (char * ) & (spiMsg -> params [0 ]), NULL );
1519
+ (char * ) & (spiMsg -> params [0 ]), cmd_spi_list [ i ]. ctx );
1411
1520
}
1412
1521
1413
1522
if (_result != WIFI_SPI_ACK )
@@ -1452,10 +1561,12 @@ int call_reply_cb(char* recv, char* reply) {
1452
1561
return REPLY_NO_ERR ;
1453
1562
}
1454
1563
1455
- void init_spi_cmds () {
1564
+ void init_spi_cmds (void * ctx ) {
1456
1565
spi_add_cmd (SET_NET_CMD , set_net_cmd_cb , ack_reply_cb , NULL , CMD_SET_FLAG );
1457
1566
spi_add_cmd (SET_PASSPHRASE_CMD , set_passphrase_cmd_cb , ack_reply_cb , NULL , CMD_SET_FLAG );
1458
1567
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 );
1459
1570
spi_add_cmd (GET_CONN_STATUS_CMD , get_result_cmd_cb , get_reply_cb , NULL , CMD_GET_FLAG );
1460
1571
spi_add_cmd (GET_IPADDR_CMD , ack_cmd_cb , get_reply_ipaddr_cb , NULL , CMD_GET_FLAG );
1461
1572
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)
1673
1784
{
1674
1785
int8_t numParams = 0 ;
1675
1786
int idx = PARAM_LEN_POS + 1 ;
1676
- bool islen16bit = _receiveBuffer [CMD_POS ] & DATA_FLAG ;
1787
+ bool islen16bit = (( _receiveBuffer [CMD_POS ] & DATA_FLAG ) == DATA_FLAG ) ;
1677
1788
if (index >= idx )
1678
1789
{
1679
1790
numParams = _receiveBuffer [PARAM_LEN_POS ];
@@ -1690,6 +1801,10 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
1690
1801
}
1691
1802
if (!endOfFrame ){
1692
1803
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
1693
1808
}
1694
1809
}
1695
1810
} while (!endOfFrame );
@@ -1786,7 +1901,7 @@ void initExtInt()
1786
1901
Enable_global_interrupt ();
1787
1902
}
1788
1903
1789
- int initSpi ()
1904
+ int initSpi (void * ctx )
1790
1905
{
1791
1906
volatile avr32_spi_t * spi = & AVR32_SPI0 ;
1792
1907
gpio_map_t spi_piomap = { \
@@ -1838,7 +1953,7 @@ int initSpi()
1838
1953
#ifdef _SPI_STATS_
1839
1954
initStatSpi ();
1840
1955
#endif
1841
- init_spi_cmds ();
1956
+ init_spi_cmds (ctx );
1842
1957
1843
1958
memset (_receiveBuffer , 0 , sizeof (_receiveBuffer ));
1844
1959
memset (buf , 0 , sizeof (buf ));
0 commit comments