Skip to content

Commit 6aa2d6e

Browse files
committed
Wifi DeviceName added
1 parent 8f92554 commit 6aa2d6e

File tree

4 files changed

+101
-49
lines changed

4 files changed

+101
-49
lines changed

src/System.Device.Wifi/sys_dev_wifi_native.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ static const CLR_RT_MethodHandler method_lookup[] =
3333
NULL,
3434
NULL,
3535
NULL,
36+
NULL,
3637
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID,
3738
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeInit___VOID,
3839
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeConnect___SystemDeviceWifiWifiConnectionStatus__STRING__STRING__SystemDeviceWifiWifiReconnectionKind,
3940
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeDisconnect___VOID,
4041
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeScanAsync___VOID,
4142
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeScanReport___SZARRAY_U1,
43+
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING,
4244
NULL,
4345
Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeFindWirelessAdapters___STATIC__SZARRAY_U1,
4446
NULL,
@@ -81,7 +83,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
8183
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_Wifi =
8284
{
8385
"System.Device.Wifi",
84-
0x00A058C6,
86+
0x030E2768,
8587
method_lookup,
8688
{ 100, 0, 6, 4 }
8789
};

src/System.Device.Wifi/sys_dev_wifi_native.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter
6666
NANOCLR_NATIVE_DECLARE(NativeDisconnect___VOID);
6767
NANOCLR_NATIVE_DECLARE(NativeScanAsync___VOID);
6868
NANOCLR_NATIVE_DECLARE(GetNativeScanReport___SZARRAY_U1);
69+
NANOCLR_NATIVE_DECLARE(NativeSetDeviceName___VOID__STRING);
6970
NANOCLR_NATIVE_DECLARE(NativeFindWirelessAdapters___STATIC__SZARRAY_U1);
7071

7172
//--//

targets/AzureRTOS/ST/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <sys_dev_wifi_native.h>
88
#include <nf_rt_events_native.h>
9-
//#include <esp_wifi_types.h>
9+
// #include <esp_wifi_types.h>
1010

1111
///////////////////////////////////////////////////////////////////////////////////////
1212
// !!! KEEP IN SYNC WITH System.Device.WiFi (in managed code) !!! //
@@ -20,7 +20,6 @@ struct ScanRecord
2020
uint8_t cypherType;
2121
};
2222

23-
2423
// //
2524
// // Stores Ap records to target string.
2625
// // if pTarget == 0 then just calculates length of target
@@ -59,6 +58,16 @@ struct ScanRecord
5958
// return (recordCount * sizeof(ScanRecord) + sizeof(uint16_t));
6059
// }
6160

61+
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING(
62+
CLR_RT_StackFrame &stack)
63+
{
64+
NANOCLR_HEADER();
65+
{
66+
NANOCLR_SET_AND_LEAVE(CLR_E_NOTIMPL);
67+
}
68+
NANOCLR_NOCLEANUP();
69+
}
70+
6271
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID(CLR_RT_StackFrame &stack)
6372
{
6473
NANOCLR_HEADER();
@@ -113,7 +122,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::
113122
int reconnectionKind;
114123
int netIndex;
115124
CLR_RT_HeapBlock hbTimeout;
116-
//CLR_INT64 *timeout;
125+
// CLR_INT64 *timeout;
117126
bool eventResult = true;
118127
WifiConnectionStatus Status = WifiConnectionStatus_UnspecifiedFailure;
119128

@@ -147,49 +156,50 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::
147156
// Wait for connect to finish
148157
while (eventResult)
149158
{
150-
// int connectResult = Network_Interface_Connect_Result(netIndex);
151-
// if (connectResult >= 0)
152-
// {
153-
// // Map ESP32 wifi reason code to WifiConnectionStatus
154-
// switch (connectResult)
155-
// {
156-
// case 0:
157-
// Status = WifiConnectionStatus_Success;
158-
// break;
159-
160-
// case WIFI_REASON_NO_AP_FOUND:
161-
// Status = WifiConnectionStatus_NetworkNotAvailable;
162-
// break;
163-
164-
// case WIFI_REASON_AUTH_EXPIRE:
165-
// case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
166-
// case WIFI_REASON_BEACON_TIMEOUT:
167-
// case WIFI_REASON_AUTH_FAIL:
168-
// case WIFI_REASON_ASSOC_FAIL:
169-
// case WIFI_REASON_HANDSHAKE_TIMEOUT:
170-
// Status = WifiConnectionStatus_InvalidCredential;
171-
// break;
172-
173-
// default:
174-
// Status = WifiConnectionStatus_UnspecifiedFailure;
175-
// break;
176-
// }
177-
// break;
178-
// }
179-
180-
// // Get timeout
181-
// NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout));
182-
183-
// // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete
184-
// NANOCLR_CHECK_HRESULT(
185-
// g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Wifi_Station, eventResult));
186-
187-
// if (!eventResult)
188-
// {
189-
// // Timeout
190-
// Status = WifiConnectionStatus_Timeout;
191-
// break;
192-
// }
159+
// int connectResult = Network_Interface_Connect_Result(netIndex);
160+
// if (connectResult >= 0)
161+
// {
162+
// // Map ESP32 wifi reason code to WifiConnectionStatus
163+
// switch (connectResult)
164+
// {
165+
// case 0:
166+
// Status = WifiConnectionStatus_Success;
167+
// break;
168+
169+
// case WIFI_REASON_NO_AP_FOUND:
170+
// Status = WifiConnectionStatus_NetworkNotAvailable;
171+
// break;
172+
173+
// case WIFI_REASON_AUTH_EXPIRE:
174+
// case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
175+
// case WIFI_REASON_BEACON_TIMEOUT:
176+
// case WIFI_REASON_AUTH_FAIL:
177+
// case WIFI_REASON_ASSOC_FAIL:
178+
// case WIFI_REASON_HANDSHAKE_TIMEOUT:
179+
// Status = WifiConnectionStatus_InvalidCredential;
180+
// break;
181+
182+
// default:
183+
// Status = WifiConnectionStatus_UnspecifiedFailure;
184+
// break;
185+
// }
186+
// break;
187+
// }
188+
189+
// // Get timeout
190+
// NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout));
191+
192+
// // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete
193+
// NANOCLR_CHECK_HRESULT(
194+
// g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Wifi_Station,
195+
// eventResult));
196+
197+
// if (!eventResult)
198+
// {
199+
// // Timeout
200+
// Status = WifiConnectionStatus_Timeout;
201+
// break;
202+
// }
193203
}
194204

195205
// Return value to the managed application
@@ -241,7 +251,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeSca
241251
// // Temporary ap record storage
242252
// wifi_ap_record_t *ap_records = 0;
243253
// {
244-
//CLR_RT_HeapBlock &top = stack.PushValueAndClear();
254+
// CLR_RT_HeapBlock &top = stack.PushValueAndClear();
245255
// CLR_RT_HeapBlock_Array *array;
246256
// CLR_UINT8 *buf;
247257
// uint16_t number = 0;
@@ -288,7 +298,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeSca
288298
// platform_free(ap_records);
289299
// }
290300

291-
//NANOCLR_CLEANUP_END();
301+
// NANOCLR_CLEANUP_END();
292302

293303
NANOCLR_NOCLEANUP_NOLABEL();
294304
}

targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <nf_rt_events_native.h>
99
#include <esp_wifi_types.h>
1010
#include <NF_ESP32_Network.h>
11+
#include <esp_netif.h>
1112

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

25+
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING(
26+
CLR_RT_StackFrame &stack)
27+
{
28+
NANOCLR_HEADER();
29+
{
30+
#if defined(CONFIG_SOC_WIFI_SUPPORTED) || defined(CONFIG_SOC_WIRELESS_HOST_SUPPORTED)
31+
{
32+
// Get deviceName from args
33+
const char *hostname = stack.Arg1().RecoverString();
34+
FAULT_ON_NULL(hostname);
35+
36+
// Get adapter index to check it's valid.
37+
int netIndex;
38+
NANOCLR_CHECK_HRESULT(GetNetInterfaceIndex(stack, &netIndex));
39+
40+
// Get the default Wi-Fi STA esp_netif
41+
// This is the default key used by ESP-IDF for the station interface
42+
esp_netif_t *sta_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
43+
if (sta_netif == nullptr)
44+
{
45+
NANOCLR_SET_AND_LEAVE(CLR_E_FAIL);
46+
}
47+
48+
esp_err_t err = esp_netif_set_hostname(sta_netif, hostname);
49+
if (err != ESP_OK)
50+
{
51+
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION);
52+
}
53+
}
54+
#else
55+
{
56+
NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
57+
}
58+
#endif
59+
}
60+
NANOCLR_NOCLEANUP();
61+
}
62+
2463
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID(CLR_RT_StackFrame &stack)
2564
{
2665
NANOCLR_HEADER();

0 commit comments

Comments
 (0)