wapi: skip associate if ssid is invalid

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2020-04-03 13:30:45 +08:00 committed by Abdelatif Guettouche
parent df1d0e73f8
commit 6ab29d4ffb
2 changed files with 37 additions and 29 deletions

View File

@ -411,17 +411,24 @@ static void netinit_net_bringup(void)
{
#ifdef CONFIG_NETINIT_DHCPC
uint8_t mac[IFHWADDRLEN];
struct dhcpc_state ds;
FAR void *handle;
#endif
/* Bring the network up. */
netlib_ifup(NET_DEVNAME);
if (netlib_ifup(NET_DEVNAME) < 0)
{
return;
}
#ifdef CONFIG_WIRELESS_WAPI
/* Associate the wlan with an access point. */
netinit_associate(NET_DEVNAME);
if (netinit_associate(NET_DEVNAME) < 0)
{
return;
}
#endif
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
@ -438,40 +445,37 @@ static void netinit_net_bringup(void)
/* Set up the DHCPC modules */
handle = dhcpc_open(NET_DEVNAME, &mac, IFHWADDRLEN);
if (handle == NULL)
{
return;
}
/* Get an IP address. Note that there is no logic for renewing the IP
* address in this example. The address should be renewed in
* ds.lease_time/2 seconds.
/* Get an IP address. Note that there is no logic for renewing the
* IP address in this example. The address should be renewed in
* (ds.lease_time / 2) seconds.
*/
if (handle != NULL)
if (dhcpc_request(handle, &ds) == OK)
{
struct dhcpc_state ds =
{
};
netlib_set_ipv4addr(NET_DEVNAME, &ds.ipaddr);
if (dhcpc_request(handle, &ds) == OK)
if (ds.netmask.s_addr != 0)
{
netlib_set_ipv4addr(NET_DEVNAME, &ds.ipaddr);
if (ds.netmask.s_addr != 0)
{
netlib_set_ipv4netmask(NET_DEVNAME, &ds.netmask);
}
if (ds.default_router.s_addr != 0)
{
netlib_set_dripv4addr(NET_DEVNAME, &ds.default_router);
}
if (ds.dnsaddr.s_addr != 0)
{
netlib_set_ipv4dnsaddr(&ds.dnsaddr);
}
netlib_set_ipv4netmask(NET_DEVNAME, &ds.netmask);
}
dhcpc_close(handle);
if (ds.default_router.s_addr != 0)
{
netlib_set_dripv4addr(NET_DEVNAME, &ds.default_router);
}
if (ds.dnsaddr.s_addr != 0)
{
netlib_set_ipv4dnsaddr(&ds.dnsaddr);
}
}
dhcpc_close(handle);
#endif
#ifdef CONFIG_NETUTILS_NTPCLIENT

View File

@ -41,6 +41,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <nuttx/wireless/wireless.h>
@ -60,7 +61,7 @@
int netinit_associate(FAR const char *ifname)
{
struct wpa_wconfig_s conf;
int ret;
int ret = -EINVAL;
FAR void *load;
load = wapi_load_config(ifname, NULL, &conf);
@ -77,7 +78,10 @@ int netinit_associate(FAR const char *ifname)
conf.phraselen = strlen(conf.passphrase);
}
ret = wpa_driver_wext_associate(&conf);
if (conf.ssidlen > 0)
{
ret = wpa_driver_wext_associate(&conf);
}
wapi_unload_config(load);