Skip to content

Conversation

@julianuziemblo
Copy link
Contributor

Description

This PR adds STA mode to Wi-Fi manager. For easier Wi-Fi management, the /dev/wifi device had to be split into three devices:

  • /dev/wifi/ctrl: Wi-Fi state management: on/off. Putting Wi-Fi "on" initializes the WHD interfaces: STA as primary and AP as secondary. It also creates the latter 2 devices for managing STA and AP modes.
  • /dev/wifi/sta: STA mode management: set connection timeout, set SSID and key of the network you want to connect to, connect/disconnect.
  • /dev/wifi/ap: AP mode management: set idle timeout, set SSID and key of the access point, start/stop (interface unchanged)

Motivation and Context

STA mode (client mode) needed on some platforms (especially imxrt).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change):
    • /dev/wifi device split into three devices (described in "Description" section above)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: armv7m7-imxrt117x-evk, NILEE.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

@gemini-code-assist
Copy link

Summary of Changes

Hello @julianuziemblo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive support for Wi-Fi Station (client) mode, significantly enhancing the Wi-Fi manager's capabilities. To accommodate both STA and Access Point (AP) modes more effectively, the existing /dev/wifi device has been refactored and split into three distinct devices: /dev/wifi/ctrl for overall Wi-Fi state, /dev/wifi/sta for client-specific operations, and /dev/wifi/ap for access point management. This change provides a more granular and robust control mechanism for Wi-Fi functionalities, particularly important for platforms requiring client mode connectivity.

Highlights

  • New Feature: STA (Station) Mode Support: The Wi-Fi manager now fully supports STA (client) mode, allowing devices to connect to existing Wi-Fi networks. This is crucial for platforms like imxrt that require client functionality.
  • Breaking Change: Wi-Fi Device API Split: The monolithic /dev/wifi device has been refactored and split into three distinct devices for more granular control: /dev/wifi/ctrl for overall Wi-Fi state management, /dev/wifi/sta for STA-specific operations (connect, disconnect, set SSID/key), and /dev/wifi/ap for AP-specific operations (start, stop, set SSID/key, idle timeout).
  • Refactored Internal Structure: The internal wifi_common structure has been redesigned to manage separate configurations and states for STA and AP interfaces, utilizing device-specific locks and condition variables for improved concurrency and clarity.
  • Centralized Interface Management: New utility functions wifi_add_interface and wifi_remove_interface have been introduced to streamline the process of bringing Wi-Fi network interfaces up and down.
  • Asynchronous Cleanup: An asynchronous cleanup mechanism (wifi_do_cleaup) has been added to remove device files when the Wi-Fi manager is turned off, preventing resource leaks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Wi-Fi Station (STA) mode and refactors the existing Wi-Fi manager. The single /dev/wifi device is split into three distinct devices: /dev/wifi/ctrl for overall control, /dev/wifi/sta for station mode, and /dev/wifi/ap for access point mode. This is a significant and well-structured change that improves modularity. My review has identified a few issues, including a critical bug in the usage of the Wi-Fi scanning API that could lead to undefined behavior, a high-severity buffer over-read in a string trimming function, and incorrect command parsing. I have also included some medium-severity suggestions to improve code clarity and maintainability.

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1166 branch from 9daa85e to 784ddcb Compare December 10, 2025 14:34
@julianuziemblo
Copy link
Contributor Author

/gemini review

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1166 branch from 784ddcb to 83a2483 Compare December 10, 2025 14:36
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-216 branch from f3bc2e2 to 9d95cb0 Compare December 10, 2025 14:36
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Wi-Fi Station (STA) mode and refactors the existing Wi-Fi manager to handle multiple interfaces: STA, AP, and a control device. The code is well-structured, separating concerns for each mode. However, I have identified several critical issues related to error handling and resource management. These include potential resource leaks during initialization, incorrect state management on failure, and unhandled error return codes from key functions. Addressing these points will improve the robustness and stability of the Wi-Fi manager.

@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1166 branch from 83a2483 to 31c06f8 Compare December 10, 2025 14:44
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-216 branch from 9d95cb0 to 6c57a6d Compare December 10, 2025 14:48
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1166 branch 4 times, most recently from a05dec7 to 60be5a8 Compare December 12, 2025 10:33
kmk142789
kmk142789 previously approved these changes Dec 12, 2025
JIRA: RTOS-1166
cmd-line utilities may pass extra space or newline as opposed to NULL
byte at the end of the string, making them hold wrong values.

JIRA: RTOS-1166
This change required some reorganising of the code.
3 new devices were added in /dev/wifi/:
- /dev/wifi/ctrl: control (Wi-Fi on/off)
- /dev/wifi/ap:   AP mode ctrl (set credentials, start/stop)
- /dev/wifi/sta:  STA mode ctrl (set credsentials, connect/disconnect)

Migration for AP:
- turn on Wi-Fi by writing "on" to /dev/wifi/ctrl
- set credentials, timeout and start/stop like before, writing
  to /dev/wifi/ap instead of /dev/wifi

Using STA:
- turn on Wi-Fi by writing "on" to /dev/wifi/ctrl
- set credentials and timeout the same as in AP mode, writing
  them to /dev/wifi/sta
- write "connect"/"disconnect" to /dev/wifi/sta to manage connection
  to an access point

JIRA: RTOS-1166
@julianuziemblo julianuziemblo force-pushed the julianuziemblo/RTOS-1166 branch from 60be5a8 to 064df9b Compare December 15, 2025 11:06
@nalajcie
Copy link
Member

I've blocked the spammer.

image

if (timeout < 0) {
errno = 0;
timeout = strtol(buf, &endp, 0);
if (errno != 0 || endp == buf || timeout == LONG_MAX) {
Copy link
Contributor

Choose a reason for hiding this comment

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

timeout == LONG_MAX should be already handled by errno != 0 (ERANGE).

return -1;
}

ssid = trim(ssid, &len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Move it before SSID size check.

return -1;
}

key = trim(key, &len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Move it before PSK size checks.


static int wifi_dev_write(const char *data, size_t size)
{
data = trim(data, &size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that strncmp is not aware of trimmed size. For example if data is timeout it will call wifi_ap_set_idle_timeout(data + 8, 7 - 8).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it will as before strncmp there is size >= 8 check which will not be passed, hence not calling wifi_ap_set_idle_timeout

struct {
bool busy;
char buf[128];
char buf[16];
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use move it to stack since it's very small.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants