Skip to content

Commit 38cdefa

Browse files
committed
Wifi DeviceName added
1 parent 8f92554 commit 38cdefa

File tree

4 files changed

+100
-49
lines changed

4 files changed

+100
-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: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

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

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

23-
2422
// //
2523
// // Stores Ap records to target string.
2624
// // if pTarget == 0 then just calculates length of target
@@ -59,6 +57,16 @@ struct ScanRecord
5957
// return (recordCount * sizeof(ScanRecord) + sizeof(uint16_t));
6058
// }
6159

60+
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::NativeSetDeviceName___VOID__STRING(
61+
CLR_RT_StackFrame &stack)
62+
{
63+
NANOCLR_HEADER();
64+
{
65+
NANOCLR_SET_AND_LEAVE(CLR_E_NOTIMPL);
66+
}
67+
NANOCLR_NOCLEANUP();
68+
}
69+
6270
HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::DisposeNative___VOID(CLR_RT_StackFrame &stack)
6371
{
6472
NANOCLR_HEADER();
@@ -113,7 +121,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::
113121
int reconnectionKind;
114122
int netIndex;
115123
CLR_RT_HeapBlock hbTimeout;
116-
//CLR_INT64 *timeout;
124+
// CLR_INT64 *timeout;
117125
bool eventResult = true;
118126
WifiConnectionStatus Status = WifiConnectionStatus_UnspecifiedFailure;
119127

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

195204
// Return value to the managed application
@@ -241,7 +250,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeSca
241250
// // Temporary ap record storage
242251
// wifi_ap_record_t *ap_records = 0;
243252
// {
244-
//CLR_RT_HeapBlock &top = stack.PushValueAndClear();
253+
// CLR_RT_HeapBlock &top = stack.PushValueAndClear();
245254
// CLR_RT_HeapBlock_Array *array;
246255
// CLR_UINT8 *buf;
247256
// uint16_t number = 0;
@@ -288,7 +297,7 @@ HRESULT Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter::GetNativeSca
288297
// platform_free(ap_records);
289298
// }
290299

291-
//NANOCLR_CLEANUP_END();
300+
// NANOCLR_CLEANUP_END();
292301

293302
NANOCLR_NOCLEANUP_NOLABEL();
294303
}

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)