Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/PAL/Include/nanoPAL_Sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ bool Network_Interface_Close(int index);
int Network_Interface_Disconnect(int index);
int Network_Interface_Start_Connect(int index, const char *ssid, const char *passphase, int options);
int Network_Interface_Connect_Result(int configIndex);
bool Network_Interface_Start_Scan(int index);
int Network_Interface_Start_Scan(int index);

// Wireless AP methods
void Network_Interface_Add_Station(uint16_t index, uint8_t *macAddress);
Expand Down
17 changes: 10 additions & 7 deletions targets/AzureRTOS/_common/target_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool Network_Interface_Close(int index)
return false;
}

bool Network_Interface_Start_Scan(int index)
int Network_Interface_Start_Scan(int index)
{
HAL_Configuration_NetworkInterface networkConfiguration;

Expand All @@ -121,18 +121,21 @@ bool Network_Interface_Start_Scan(int index)
DeviceConfigurationOption_Network,
index))
{
// failed to load configuration
// FIXME output error?
return SOCK_SOCKET_ERROR;
// failed to get configuration
// TODO include error code enum
return 7777; // StartScanOutcome_FailedToGetConfiguration;
}

// can only do this is this is STA
if (networkConfiguration.InterfaceType == NetworkInterfaceType_Wireless80211)
if (networkConfiguration.InterfaceType != NetworkInterfaceType_Wireless80211)
{
// return (NF_ESP32_Wireless_Scan() == 0);
// TODO include error code enum
return 8888; // StartScanOutcome_WrongInterfaceType;
}

return false;
// TODO return NF_ESP32_Wireless_Scan();
// TODO include error code enum
return 9999;
}

bool GetWirelessConfig(int index, HAL_Configuration_Wireless80211 **wirelessConfig)
Expand Down
4 changes: 1 addition & 3 deletions targets/ESP32/_Network/NF_ESP32_Wireless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,7 @@ int NF_ESP32_Wireless_Scan()

// Start a Wi-Fi scan
// When complete a Scan Complete event will be fired
esp_err_t res = esp_wifi_scan_start(&config, false);

return (int)res;
return esp_wifi_scan_start(&config, false);
}

wifi_auth_mode_t MapAuthentication(AuthenticationType type)
Expand Down
13 changes: 6 additions & 7 deletions targets/ESP32/_common/Target_Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool Network_Interface_Close(int index)
return false;
}

bool Network_Interface_Start_Scan(int index)
int Network_Interface_Start_Scan(int index)
{
HAL_Configuration_NetworkInterface networkConfiguration;

Expand All @@ -107,18 +107,17 @@ bool Network_Interface_Start_Scan(int index)
DeviceConfigurationOption_Network,
index))
{
// failed to load configuration
// FIXME output error?
return SOCK_SOCKET_ERROR;
// failed to get configuration
return StartScanOutcome_FailedToGetConfiguration;
}

// can only do this is this is STA
if (networkConfiguration.InterfaceType == NetworkInterfaceType_Wireless80211)
if (networkConfiguration.InterfaceType != NetworkInterfaceType_Wireless80211)
{
return (NF_ESP32_Wireless_Scan() == 0);
return StartScanOutcome_WrongInterfaceType;
}

return false;
return NF_ESP32_Wireless_Scan();
}

bool GetWirelessConfig(int index, HAL_Configuration_Wireless80211 **wirelessConfig)
Expand Down
20 changes: 16 additions & 4 deletions targets/ESP32/_include/NF_ESP32_Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@
#define NF_ESP32_NETWORK_H

#include <nanoHAL.h>
#include <lwIP_Sockets.h>
#include <esp32_idf.h>

// ESP IDF 4.0 it's using an abstraction layer (esp_netif) that hides the netif index
// we need that for our interface with lwIP, so we have to clone those here
// not very elegant but will have to work for now
#define IDF_WIFI_STA_DEF 0
#define IDF_WIFI_AP_DEF 1
#define IDF_ETH_DEF 2
#define IDF_WIFI_STA_DEF 0
#define IDF_WIFI_AP_DEF 1
#define IDF_ETH_DEF 2

typedef enum __nfpack StartScanOutcome
{
StartScanOutcome_Success = 0,
StartScanOutcome_FailedToGetConfiguration = 10,
StartScanOutcome_WrongInterfaceType = 20,
// these are the same as the IDF error codes
StartScanOutcome_Esp32WifiNotInit = ESP_ERR_WIFI_NOT_INIT,
StartScanOutcome_Esp32WifiNotStarted = ESP_ERR_WIFI_NOT_STARTED,
StartScanOutcome_Esp32WifiTimeout = ESP_ERR_WIFI_TIMEOUT,
StartScanOutcome_Esp32WifiState = ESP_ERR_WIFI_STATE,

} StartScanOutcome;

extern bool NF_ESP32_ConnectInProgress;
extern int NF_ESP32_ConnectResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include <sys_dev_wifi_native.h>
#include <nf_rt_events_native.h>
#include <esp_wifi_types.h>
#include <NF_ESP32_Network.h>

///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH System.Device.Wifi (in managed code) !!! //
///////////////////////////////////////////////////////////////////////////////////////
struct ScanRecord
Expand Down Expand Up @@ -180,17 +181,38 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeDiscon
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeScanAsync___VOID(CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
{
int netIndex;

NANOCLR_CHECK_HRESULT(GetNetInterfaceIndex(stack, &netIndex));
int netIndex;
int startScanResult;

// Start scan
if (Network_Interface_Start_Scan(netIndex) == false)
{
NANOCLR_CHECK_HRESULT(GetNetInterfaceIndex(stack, &netIndex));

// Start scan
startScanResult = Network_Interface_Start_Scan(netIndex);

switch (startScanResult)
{

case StartScanOutcome_WrongInterfaceType:
case StartScanOutcome_Esp32WifiNotInit:
case StartScanOutcome_Esp32WifiNotStarted:
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION);
}
break;

case StartScanOutcome_Esp32WifiState:
NANOCLR_SET_AND_LEAVE(CLR_E_BUSY);
break;

case StartScanOutcome_Esp32WifiTimeout:
NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT);
break;

case StartScanOutcome_FailedToGetConfiguration:
default:
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
break;
}

NANOCLR_NOCLEANUP();
}

Expand Down