Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/System.Device.Wifi/sys_dev_wifi_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
NULL,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeInit___VOID,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeConnect___SystemDeviceWifiWifiConnectionStatus__STRING__STRING__SystemDeviceWifiWifiReconnectionKind,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeDisconnect___VOID,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeScanAsync___VOID,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeScanReport___SZARRAY_U1,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING,
NULL,
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeFindWirelessAdapters___STATIC__SZARRAY_U1,
NULL,
Expand Down Expand Up @@ -81,7 +83,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_Wifi =
{
"System.Device.Wifi",
0x00A058C6,
0x030E2768,
method_lookup,
{ 100, 0, 6, 4 }
};
Expand Down
1 change: 1 addition & 0 deletions src/System.Device.Wifi/sys_dev_wifi_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter
NANOCLR_NATIVE_DECLARE(NativeDisconnect___VOID);
NANOCLR_NATIVE_DECLARE(NativeScanAsync___VOID);
NANOCLR_NATIVE_DECLARE(GetNativeScanReport___SZARRAY_U1);
NANOCLR_NATIVE_DECLARE(NativeSetDeviceName___VOID__STRING);
NANOCLR_NATIVE_DECLARE(NativeFindWirelessAdapters___STATIC__SZARRAY_U1);

//--//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <sys_dev_wifi_native.h>
#include <nf_rt_events_native.h>
//#include <esp_wifi_types.h>

///////////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH System.Device.WiFi (in managed code) !!! //
Expand All @@ -20,7 +19,6 @@ struct ScanRecord
uint8_t cypherType;
};


// //
// // Stores Ap records to target string.
// // if pTarget == 0 then just calculates length of target
Expand Down Expand Up @@ -59,6 +57,16 @@ struct ScanRecord
// return (recordCount * sizeof(ScanRecord) + sizeof(uint16_t));
// }

HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING(
CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
{
NANOCLR_SET_AND_LEAVE(CLR_E_NOTIMPL);
}
NANOCLR_NOCLEANUP();
}

HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID(CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
Expand Down Expand Up @@ -113,7 +121,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::
int reconnectionKind;
int netIndex;
CLR_RT_HeapBlock hbTimeout;
//CLR_INT64 *timeout;
// CLR_INT64 *timeout;
bool eventResult = true;
WifiConnectionStatus Status = WifiConnectionStatus_UnspecifiedFailure;

Expand Down Expand Up @@ -147,49 +155,50 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::
// Wait for connect to finish
while (eventResult)
{
// int connectResult = Network_Interface_Connect_Result(netIndex);
// if (connectResult >= 0)
// {
// // Map ESP32 wifi reason code to WifiConnectionStatus
// switch (connectResult)
// {
// case 0:
// Status = WifiConnectionStatus_Success;
// break;

// case WIFI_REASON_NO_AP_FOUND:
// Status = WifiConnectionStatus_NetworkNotAvailable;
// break;

// case WIFI_REASON_AUTH_EXPIRE:
// case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
// case WIFI_REASON_BEACON_TIMEOUT:
// case WIFI_REASON_AUTH_FAIL:
// case WIFI_REASON_ASSOC_FAIL:
// case WIFI_REASON_HANDSHAKE_TIMEOUT:
// Status = WifiConnectionStatus_InvalidCredential;
// break;

// default:
// Status = WifiConnectionStatus_UnspecifiedFailure;
// break;
// }
// break;
// }

// // Get timeout
// NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout));

// // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete
// NANOCLR_CHECK_HRESULT(
// g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Wifi_Station, eventResult));

// if (!eventResult)
// {
// // Timeout
// Status = WifiConnectionStatus_Timeout;
// break;
// }
// int connectResult = Network_Interface_Connect_Result(netIndex);
// if (connectResult >= 0)
// {
// // Map ESP32 wifi reason code to WifiConnectionStatus
// switch (connectResult)
// {
// case 0:
// Status = WifiConnectionStatus_Success;
// break;

// case WIFI_REASON_NO_AP_FOUND:
// Status = WifiConnectionStatus_NetworkNotAvailable;
// break;

// case WIFI_REASON_AUTH_EXPIRE:
// case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
// case WIFI_REASON_BEACON_TIMEOUT:
// case WIFI_REASON_AUTH_FAIL:
// case WIFI_REASON_ASSOC_FAIL:
// case WIFI_REASON_HANDSHAKE_TIMEOUT:
// Status = WifiConnectionStatus_InvalidCredential;
// break;

// default:
// Status = WifiConnectionStatus_UnspecifiedFailure;
// break;
// }
// break;
// }

// // Get timeout
// NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout));

// // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete
// NANOCLR_CHECK_HRESULT(
// g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Wifi_Station,
// eventResult));

// if (!eventResult)
// {
// // Timeout
// Status = WifiConnectionStatus_Timeout;
// break;
// }
}

// Return value to the managed application
Expand Down Expand Up @@ -241,7 +250,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeSca
// // Temporary ap record storage
// wifi_ap_record_t *ap_records = 0;
// {
//CLR_RT_HeapBlock &top = stack.PushValueAndClear();
// CLR_RT_HeapBlock &top = stack.PushValueAndClear();
// CLR_RT_HeapBlock_Array *array;
// CLR_UINT8 *buf;
// uint16_t number = 0;
Expand Down Expand Up @@ -288,7 +297,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeSca
// platform_free(ap_records);
// }

//NANOCLR_CLEANUP_END();
// NANOCLR_CLEANUP_END();

NANOCLR_NOCLEANUP_NOLABEL();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <nf_rt_events_native.h>
#include <esp_wifi_types.h>
#include <NF_ESP32_Network.h>
#include <esp_netif.h>

////////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH System.Device.Wifi (in managed code) !!! //
Expand All @@ -21,6 +22,44 @@ struct ScanRecord
uint8_t cypherType;
};

HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING(
CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
{
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SOC_WIRELESS_HOST_SUPPORTED)
{
// Get deviceName from args
const char *hostname = stack.Arg1().RecoverString();
FAULT_ON_NULL(hostname);

// Get adapter index to check it's valid.
int netIndex;
NANOCLR_CHECK_HRESULT(GetNetInterfaceIndex(stack, &netIndex));

// Get the default Wi-Fi STA esp_netif
// This is the default key used by ESP-IDF for the station interface
esp_netif_t *sta_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
if (sta_netif == nullptr)
{
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
}

esp_err_t err = esp_netif_set_hostname(sta_netif, hostname);
if (err != ESP_OK)
{
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION);
}
}
#else
{
NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
}
#endif
}
NANOCLR_NOCLEANUP();
}

HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID(CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
Expand Down