Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wifi connect timeout #898

Merged
merged 2 commits into from
Mar 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions hal/src/photon/wlan_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "wwd_sdpcm.h"
#include "delay_hal.h"
#include "dct_hal.h"
#include "concurrent_hal.h"

// dns.h includes a class member, which doesn't compile in C++
#define class clazz
Expand Down Expand Up @@ -149,19 +150,27 @@ int wlan_connect_init()

bool to_wiced_ip_address(wiced_ip_address_t& wiced, const dct_ip_address_v4_t& dct)
{
if (dct!=0) {
wiced.ip.v4 = dct;
wiced.version = WICED_IPV4;
}
if (dct!=0) {
wiced.ip.v4 = dct;
wiced.version = WICED_IPV4;
}
return (dct!=0);
}

void wlan_connect_timeout(os_timer_t t)
{
wlan_connect_cancel(false);
}

/**
* Do what is needed to finalize the connection.
* @return
*/
wlan_result_t wlan_connect_finalize()
{
os_timer_t cancel_timer = 0;
os_timer_create(&cancel_timer, 60000, &wlan_connect_timeout, nullptr, false /* oneshot */, nullptr);

// enable connection from stored profiles
wlan_result_t result = wiced_interface_up(WICED_STA_INTERFACE);
if (!result) {
Expand Down Expand Up @@ -194,6 +203,10 @@ wlan_result_t wlan_connect_finalize()
// DHCP happens synchronously
HAL_NET_notify_dhcp(!result);
wiced_network_up_cancel = 0;

if (cancel_timer) {
os_timer_destroy(cancel_timer, nullptr);
}
return result;
}

Expand Down Expand Up @@ -405,7 +418,7 @@ wiced_security_t toSecurity(const char* ssid, unsigned ssid_len, WLanSecurityTyp

bool equals_ssid(const char* ssid, wiced_ssid_t& current)
{
return (strlen(ssid)==current.length) && !memcmp(ssid, current.value, current.length);
return (strlen(ssid)==current.length) && !memcmp(ssid, current.value, current.length);
}

static bool wifi_creds_changed;
Expand All @@ -422,18 +435,18 @@ wiced_result_t add_wiced_wifi_credentials(const char *ssid, uint16_t ssidLen, co

// find a slot with the same ssid
for (unsigned i=0; i<CONFIG_AP_LIST_SIZE; i++) {
if (equals_ssid(ssid, wifi_config->stored_ap_list[i].details.SSID)) {
replace = i;
break;
}
if (equals_ssid(ssid, wifi_config->stored_ap_list[i].details.SSID)) {
replace = i;
break;
}
}

if (replace < 0)
{
// shuffle all slots along
memmove(wifi_config->stored_ap_list+1, wifi_config->stored_ap_list, sizeof(wiced_config_ap_entry_t)*(CONFIG_AP_LIST_SIZE-1));
replace = 0;
}
{
// shuffle all slots along
memmove(wifi_config->stored_ap_list+1, wifi_config->stored_ap_list, sizeof(wiced_config_ap_entry_t)*(CONFIG_AP_LIST_SIZE-1));
replace = 0;
}
wiced_config_ap_entry_t& entry = wifi_config->stored_ap_list[replace];
memset(&entry, 0, sizeof(entry));
passwordLen = std::min(passwordLen, uint16_t(64));
Expand Down Expand Up @@ -563,7 +576,7 @@ void wlan_fetch_ipconfig(WLanConfig* config)
config->uaSSID[len] = 0;

if (config->size>=WLanConfig_Size_V2) {
memcpy(config->BSSID, ap_info.BSSID.octet, sizeof(config->BSSID));
memcpy(config->BSSID, ap_info.BSSID.octet, sizeof(config->BSSID));
}
}
// todo DNS and DHCP servers
Expand Down