Skip to content

Conversation

@zandiarash
Copy link

@zandiarash zandiarash commented Nov 30, 2025

Description

  • Add implementation for NativeSetDeviceName().
  • Update declaration of System.Device.Wifi library.

Motivation and Context

I should mention that I am not familiar with C++ and after I changed nf-interpreter project I flashed my chip like this

nanoff --platform esp32 --target ESP32_REV3 --serialport COM6 --update  --clrfile "D:\Sources Electronic\Nanoframework - Copy\nf-interpreter\build\nanoCLR.bin"

How Has This Been Tested?

Screenshots

Before :
x
After :
x

Types of changes

  • Improvement (non-breaking change that improves a sample)
  • Bug fix (fixes an issue with a current sample)
  • New Sample (adds a new sample)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Documentation/comment (fixes and improvements documentation related)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Summary by CodeRabbit

  • New Features

    • Added ability to set the device hostname via the WifiAdapter API for easier identification on Wi‑Fi networks.
  • Platform Notes

    • Implemented on ESP32 targets (hostname applied to the network interface).
    • On some RTOS targets this API is a stub/not implemented or a no-op; behavior may vary by platform.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 30, 2025

Walkthrough

Adds a native Wi‑Fi adapter method to set the device hostname: header declaration, registration in the platform‑neutral native method table with an updated assembly CRC and an extra NULL slot, an ESP32 implementation that sets the STA netif hostname, and AzureRTOS stubs (NOTIMPL/no‑op).

Changes

Cohort / File(s) Summary
Native interface declaration
src/System.Device.Wifi/sys_dev_wifi_native.h
Added NativeSetDeviceName___VOID__STRING declaration to Library_sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.
Method registration & assembly identity
src/System.Device.Wifi/sys_dev_wifi_native.cpp
Inserted NativeSetDeviceName___VOID__STRING into method_lookup (after GetNativeScanReport___SZARRAY_U1), added an extra NULL slot earlier in the table, and updated g_CLR_AssemblyNative_System_Device_Wifi CRC from 0x00A058C6 to 0x030E2768.
ESP32 platform implementation
targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
Added #include <esp_netif.h> and implemented NativeSetDeviceName___VOID__STRING(CLR_RT_StackFrame&): read/validate hostname, resolve STA netif via esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), call esp_netif_set_hostname, and map errors to CLR return codes; guarded by SOC/WIRELESS config macros.
AzureRTOS/ST platform implementation
targets/AzureRTOS/ST/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
Added NativeSetDeviceName___VOID__STRING(CLR_RT_StackFrame&) returning CLR_E_NOTIMPL; added NativeInit___VOID no‑op; minor formatting/cleanup adjustments.

Sequence Diagram(s)

sequenceDiagram
    participant Managed as Managed (C#)
    participant CLR as nanoCLR native entry
    participant ESP as esp_netif / ESP-IDF

    Managed->>CLR: Invoke NativeSetDeviceName(string hostname)
    CLR->>CLR: Read & validate hostname
    CLR->>CLR: Validate network interface index (if applicable)
    CLR->>ESP: esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")
    ESP-->>CLR: netif handle or NULL
    alt netif found
        CLR->>ESP: esp_netif_set_hostname(netif, hostname)
        ESP-->>CLR: esp_err_t (ESP_OK / error)
        CLR-->>Managed: return or mapped CLR error
    else netif not found
        CLR-->>Managed: return CLR_E_INVALID_OPERATION (or mapped error)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect ESP32 hostname validation (length/allowed characters) and error mapping from esp_err_t to CLR errors.
  • Verify config-guard macros (CONFIG_SOC_WIFI_SUPPORTED / CONFIG_SOC_WIRELESS_HOST_SUPPORTED) and build integration.
  • Confirm method_lookup ordering and the additional NULL slot consistency with other native tables and updated CRC propagation.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding implementation for NativeSetDeviceName, which is the primary purpose of the changeset across multiple files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6aa2d6e and 38cdefa.

📒 Files selected for processing (4)
  • src/System.Device.Wifi/sys_dev_wifi_native.cpp (2 hunks)
  • src/System.Device.Wifi/sys_dev_wifi_native.h (1 hunks)
  • targets/AzureRTOS/ST/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (5 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • targets/AzureRTOS/ST/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3243
File: targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp:31-50
Timestamp: 2025-12-02T09:32:22.287Z
Learning: In the nanoFramework WiFi implementation, hostname length validation for NativeSetDeviceName___VOID__STRING in targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp is performed at the caller level (managed code), not in the native implementation.
📚 Learning: 2025-12-02T09:32:22.287Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3243
File: targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp:31-50
Timestamp: 2025-12-02T09:32:22.287Z
Learning: In the nanoFramework WiFi implementation, hostname length validation for NativeSetDeviceName___VOID__STRING in targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp is performed at the caller level (managed code), not in the native implementation.

Applied to files:

  • src/System.Device.Wifi/sys_dev_wifi_native.cpp
  • src/System.Device.Wifi/sys_dev_wifi_native.h
  • targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
📚 Learning: 2024-09-25T11:28:38.536Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-09-25T11:28:38.536Z
Learning: When working with `nanoCLR_GetNativeAssemblyInformation`, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.

Applied to files:

  • src/System.Device.Wifi/sys_dev_wifi_native.cpp
  • src/System.Device.Wifi/sys_dev_wifi_native.h
📚 Learning: 2024-10-08T15:52:09.445Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In `nanoCLR_GetNativeAssemblyInformation`, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.

Applied to files:

  • src/System.Device.Wifi/sys_dev_wifi_native.h
📚 Learning: 2025-01-22T03:38:57.394Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3074
File: src/CLR/Core/GarbageCollector_Info.cpp:107-167
Timestamp: 2025-01-22T03:38:57.394Z
Learning: In CLR_RT_GarbageCollector::ValidateCluster, DataSize() validation is already handled by ValidateBlock() and other caller code, making additional size checks redundant.

Applied to files:

  • targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
📚 Learning: 2024-10-08T15:52:09.445Z
Learnt from: frobijn
Repo: nanoframework/nf-interpreter PR: 3023
File: targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs:0-0
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In the context of `NativeAssemblyDetails.Get()`, exceptions from `Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation` are very unlikely, and additional exception handling may not be necessary.

Applied to files:

  • targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
📚 Learning: 2025-01-22T03:38:57.394Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3074
File: src/CLR/Core/GarbageCollector_Info.cpp:107-167
Timestamp: 2025-01-22T03:38:57.394Z
Learning: In nanoFramework's memory management code, DataSize() validation is comprehensively handled through CLR_RT_HeapCluster::ValidateBlock() and other caller code. Additional size checks in ValidateCluster() are redundant as the validation is already performed at multiple levels.

Applied to files:

  • targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp
🧬 Code graph analysis (2)
src/System.Device.Wifi/sys_dev_wifi_native.cpp (2)
targets/AzureRTOS/ST/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (12)
  • DisposeNative___VOID (70-76)
  • DisposeNative___VOID (70-70)
  • NativeInit___VOID (78-84)
  • NativeInit___VOID (78-78)
  • NativeConnect___SystemDeviceWifiWifiConnectionStatus__STRING__STRING__SystemDeviceWifiWifiReconnectionKind (113-208)
  • NativeConnect___SystemDeviceWifiWifiConnectionStatus__STRING__STRING__SystemDeviceWifiWifiReconnectionKind (113-115)
  • NativeDisconnect___VOID (213-224)
  • NativeDisconnect___VOID (213-213)
  • NativeScanAsync___VOID (226-241)
  • NativeScanAsync___VOID (226-226)
  • NativeSetDeviceName___VOID__STRING (60-68)
  • NativeSetDeviceName___VOID__STRING (60-61)
targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (12)
  • DisposeNative___VOID (63-69)
  • DisposeNative___VOID (63-63)
  • NativeInit___VOID (71-77)
  • NativeInit___VOID (71-71)
  • NativeConnect___SystemDeviceWifiWifiConnectionStatus__STRING__STRING__SystemDeviceWifiWifiReconnectionKind (106-202)
  • NativeConnect___SystemDeviceWifiWifiConnectionStatus__STRING__STRING__SystemDeviceWifiWifiReconnectionKind (106-108)
  • NativeDisconnect___VOID (207-218)
  • NativeDisconnect___VOID (207-207)
  • NativeScanAsync___VOID (220-259)
  • NativeScanAsync___VOID (220-220)
  • NativeSetDeviceName___VOID__STRING (25-61)
  • NativeSetDeviceName___VOID__STRING (25-26)
targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (1)
targets/AzureRTOS/ST/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (4)
  • NativeSetDeviceName___VOID__STRING (60-68)
  • NativeSetDeviceName___VOID__STRING (60-61)
  • GetNetInterfaceIndex (89-108)
  • GetNetInterfaceIndex (89-91)
🔇 Additional comments (3)
src/System.Device.Wifi/sys_dev_wifi_native.h (1)

62-74: New NativeSetDeviceName declaration is consistent with native implementations.

The NativeSetDeviceName___VOID__STRING declaration is correctly added in WifiAdapter, with naming and placement aligned with the method table and target implementations; no issues found.

targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (1)

11-61: ESP32 hostname setter implementation and guards look correct.

Including esp_netif.h, validating the instance via GetNetInterfaceIndex, resolving WIFI_STA_DEF, and mapping failures to CLR_E_FAIL / CLR_E_INVALID_OPERATION with CLR_E_NOT_SUPPORTED on non‑WiFi SoCs follows existing patterns and matches the managed validation model; no changes needed.

src/System.Device.Wifi/sys_dev_wifi_native.cpp (1)

36-88: Method table wiring and CRC update for NativeSetDeviceName look consistent; please confirm tooling sync.

The additional NULL slot, new NativeSetDeviceName___VOID__STRING entry in method_lookup, and updated CRC value are structurally consistent with the new WifiAdapter method and header declarations; nothing problematic stands out. Please just confirm these entries/CRC were regenerated using the standard nanoFramework tooling and that the managed System.Device.Wifi assembly was updated accordingly so the IDs and checksum stay in sync.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f92554 and b7a2467.

📒 Files selected for processing (3)
  • src/System.Device.Wifi/sys_dev_wifi_native.cpp (2 hunks)
  • src/System.Device.Wifi/sys_dev_wifi_native.h (1 hunks)
  • targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-10-12T19:00:39.000Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-12T19:00:39.000Z
Learning: When working with `nanoCLR_GetNativeAssemblyInformation`, fixed-size assembly names are required, so code that deals with variable-length names cannot be used.

Applied to files:

  • src/System.Device.Wifi/sys_dev_wifi_native.h
  • src/System.Device.Wifi/sys_dev_wifi_native.cpp
📚 Learning: 2024-10-08T15:52:09.445Z
Learnt from: josesimoes
Repo: nanoframework/nf-interpreter PR: 3023
File: targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp:191-225
Timestamp: 2024-10-08T15:52:09.445Z
Learning: In `nanoCLR_GetNativeAssemblyInformation`, there is no need to return the number of bytes written, as the memory buffer is zeroed, making the string buffer terminated.

Applied to files:

  • src/System.Device.Wifi/sys_dev_wifi_native.h
🔇 Additional comments (3)
src/System.Device.Wifi/sys_dev_wifi_native.h (1)

69-69: LGTM! Method declaration follows the correct pattern.

The native method declaration is properly formatted and consistently placed with other WifiAdapter methods.

src/System.Device.Wifi/sys_dev_wifi_native.cpp (1)

36-43: LGTM! Method lookup table correctly updated.

The new method has been properly wired into the method lookup table. The CRC update at line 86 correctly reflects the assembly changes.

targets/ESP32/_nanoCLR/System.Device.Wifi/sys_dev_wifi_native_System_Device_Wifi_WifiAdapter.cpp (1)

11-11: LGTM! Required include for ESP-NETIF APIs.

The esp_netif.h include is necessary for the hostname configuration functionality.

@Ellerbach
Copy link
Member

@zandiarash please also use the proper PR template.

@Ellerbach
Copy link
Member

Also, please adjust all the native devices. It's find to throw an exception but the build of other devices than ESP32 will break.

@Ellerbach
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@zandiarash
Copy link
Author

@zandiarash please also use the proper PR template.

Thank you for the guidance.
I’ve updated the pull request to use the proper template.

@nfbot nfbot added the Type: dependencies Pull requests that update a dependency file(s) or version label Dec 2, 2025
@josesimoes josesimoes added the Platform: ESP32 Everything related specifically with ESP32 platform label Dec 2, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@zandiarash
Copy link
Author

\azp run
To maintain a clean and linear commit history, should I make all commits as a single commit ?

@josesimoes josesimoes changed the title Wifi DeviceName has been added Add implementation for NativeSetDeviceName Dec 2, 2025
@josesimoes
Copy link
Member

\azp run
To maintain a clean and linear commit history, should I make all commits as a single commit ?

If you can do it, that's preferable.

@zandiarash
Copy link
Author

\azp run
To maintain a clean and linear commit history, should I make all commits as a single commit ?

If you can do it, that's preferable.

@josesimoes I’ve already made everything into a single commit (your review messages and bot suggestions).👍

@josesimoes
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@josesimoes
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Platform: ESP32 Everything related specifically with ESP32 platform Type: dependencies Pull requests that update a dependency file(s) or version Type: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants