DHCP Allows selecting the DHCP server's network interface
This changes the parameters of dhcpserver_start. Besides that, dhcpserver_start should only be called after user_init has finished, else the call sdk_system_get_netif(SOFTAP_IF) will return NULL.
This commit is contained in:
parent
9523e872f8
commit
be7cabd94d
4 changed files with 19 additions and 12 deletions
|
|
@ -48,10 +48,6 @@ void user_init(void)
|
||||||
};
|
};
|
||||||
sdk_wifi_softap_set_config(&ap_config);
|
sdk_wifi_softap_set_config(&ap_config);
|
||||||
|
|
||||||
ip_addr_t first_client_ip;
|
|
||||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
|
||||||
dhcpserver_start(&first_client_ip, 4);
|
|
||||||
|
|
||||||
xTaskCreate(telnetTask, "telnetTask", 512, NULL, 2, NULL);
|
xTaskCreate(telnetTask, "telnetTask", 512, NULL, 2, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,6 +56,10 @@ void user_init(void)
|
||||||
*/
|
*/
|
||||||
static void telnetTask(void *pvParameters)
|
static void telnetTask(void *pvParameters)
|
||||||
{
|
{
|
||||||
|
ip_addr_t first_client_ip;
|
||||||
|
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||||
|
dhcpserver_start(sdk_system_get_netif(SOFTAP_IF), &first_client_ip, 4);
|
||||||
|
|
||||||
struct netconn *nc = netconn_new (NETCONN_TCP);
|
struct netconn *nc = netconn_new (NETCONN_TCP);
|
||||||
if(!nc) {
|
if(!nc) {
|
||||||
printf("Status monitor: Failed to allocate socket.\r\n");
|
printf("Status monitor: Failed to allocate socket.\r\n");
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,12 @@ inline static void sprintf_ipaddr(const ip_addr_t *addr, char *dest)
|
||||||
ip4_addr2(addr), ip4_addr3(addr), ip4_addr4(addr));
|
ip4_addr2(addr), ip4_addr3(addr), ip4_addr4(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases)
|
void dhcpserver_start(struct netif *server_if, const ip_addr_t *first_client_addr, uint8_t max_leases)
|
||||||
{
|
{
|
||||||
|
if(!server_if){
|
||||||
|
printf("DHCP Server Error: server_if is NULL.\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* Stop any existing running dhcpserver */
|
/* Stop any existing running dhcpserver */
|
||||||
if(dhcpserver_task_handle)
|
if(dhcpserver_task_handle)
|
||||||
dhcpserver_stop();
|
dhcpserver_stop();
|
||||||
|
|
@ -89,7 +93,7 @@ void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases)
|
||||||
// state->server_if is assigned once the task is running - see comment in dhcpserver_task()
|
// state->server_if is assigned once the task is running - see comment in dhcpserver_task()
|
||||||
ip_addr_copy(state->first_client_addr, *first_client_addr);
|
ip_addr_copy(state->first_client_addr, *first_client_addr);
|
||||||
|
|
||||||
xTaskCreate(dhcpserver_task, "DHCPServer", 768, NULL, 8, &dhcpserver_task_handle);
|
xTaskCreate(dhcpserver_task, "DHCPServer", 768, server_if, 8, &dhcpserver_task_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dhcpserver_stop(void)
|
void dhcpserver_stop(void)
|
||||||
|
|
@ -104,7 +108,7 @@ void dhcpserver_stop(void)
|
||||||
static void dhcpserver_task(void *pxParameter)
|
static void dhcpserver_task(void *pxParameter)
|
||||||
{
|
{
|
||||||
/* netif_list isn't assigned until after user_init completes, which is why we do it inside the task */
|
/* netif_list isn't assigned until after user_init completes, which is why we do it inside the task */
|
||||||
state->server_if = netif_list; /* TODO: Make this configurable */
|
state->server_if = pxParameter;
|
||||||
|
|
||||||
state->nc = netconn_new (NETCONN_UDP);
|
state->nc = netconn_new (NETCONN_UDP);
|
||||||
if(!state->nc) {
|
if(!state->nc) {
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,10 @@ extern "C" {
|
||||||
first_client_addr is the IP address of the first lease to be handed
|
first_client_addr is the IP address of the first lease to be handed
|
||||||
to a client. Subsequent lease addresses are calculated by
|
to a client. Subsequent lease addresses are calculated by
|
||||||
incrementing the final octet of the IPv4 address, up to max_leases.
|
incrementing the final octet of the IPv4 address, up to max_leases.
|
||||||
|
|
||||||
|
The server will wait for requests on server_if interface.
|
||||||
*/
|
*/
|
||||||
void dhcpserver_start(const ip_addr_t *first_client_addr, uint8_t max_leases);
|
void dhcpserver_start(struct netif *server_if, const ip_addr_t *first_client_addr, uint8_t max_leases);
|
||||||
|
|
||||||
void dhcpserver_get_lease(const ip_addr_t *first_client_addr, uint8_t max_leases);
|
void dhcpserver_get_lease(const ip_addr_t *first_client_addr, uint8_t max_leases);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,11 @@ DEFINE_TESTCASE(04_wifi_basic, DUAL)
|
||||||
|
|
||||||
static void server_task(void *pvParameters)
|
static void server_task(void *pvParameters)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ip_addr_t first_client_ip;
|
||||||
|
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
||||||
|
dhcpserver_start(sdk_system_get_netif(SOFTAP_IF), &first_client_ip, 4);
|
||||||
|
|
||||||
char buf[BUF_SIZE];
|
char buf[BUF_SIZE];
|
||||||
struct netconn *nc = netconn_new(NETCONN_TCP);
|
struct netconn *nc = netconn_new(NETCONN_TCP);
|
||||||
TEST_ASSERT_TRUE_MESSAGE(nc != 0, "Failed to allocate socket");
|
TEST_ASSERT_TRUE_MESSAGE(nc != 0, "Failed to allocate socket");
|
||||||
|
|
@ -103,10 +108,6 @@ static void a_04_wifi_basic(void)
|
||||||
};
|
};
|
||||||
sdk_wifi_softap_set_config(&ap_config);
|
sdk_wifi_softap_set_config(&ap_config);
|
||||||
|
|
||||||
ip_addr_t first_client_ip;
|
|
||||||
IP4_ADDR(&first_client_ip, 172, 16, 0, 2);
|
|
||||||
dhcpserver_start(&first_client_ip, 4);
|
|
||||||
|
|
||||||
xTaskCreate(server_task, "setver_task", 1024, NULL, 2, NULL);
|
xTaskCreate(server_task, "setver_task", 1024, NULL, 2, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue