Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: WiFi configuration issues via USB (HTTP/WPS provisioning sometimes unreliable) #2059

Merged
merged 21 commits into from
Mar 4, 2025

Conversation

sidprice
Copy link
Contributor

This PR adds Wi-Fi management for ctxLink using GDB and a new monitor command.

With the original releases of ctxLink some users had issues using the HTTP and WPS provisioning features of ctxLink.

Also, after provisioning some users found it hard to discover the IP address of ctxLink, this is required to connect to the probe.

The new monitor command is "wifi".

To inspect the current Wi-Fi status the following command is used:

mon wifi

This will display either "Not Connected," or the SSID, Signal Strength (RSSI), and IP address of the connected Access Point.

To connect to a Wi-Fi Access Point the following command is used, substituting the SSID and PassPhrase settings of the AP:

mon wifi SSID,Passphrase

Spaces are accepted for these two parameters, however, there should be no space before or after the ",".

Your checklist for this pull request

Closing issues

None.

@sidprice sidprice force-pushed the ctxlink_wifi_options branch 3 times, most recently from 758729a to 4e6ea5c Compare January 19, 2025 22:26
@dragonmux dragonmux added this to the v2.1 release milestone Jan 20, 2025
@dragonmux dragonmux added Enhancement General project improvement Foreign Host Board Non Native hardware to runing Black Magic firmware on labels Jan 20, 2025
@sidprice sidprice force-pushed the ctxlink_wifi_options branch from 4e6ea5c to 791891e Compare January 20, 2025 15:49
@sidprice sidprice force-pushed the ctxlink_wifi_options branch 3 times, most recently from 447e76d to eabddff Compare February 8, 2025 17:40
@Misaka0x2730
Copy link
Contributor

Hi!
First off, apologies if I’m stepping on your toes—I don’t mean to meddle in something that might be out of my scope.
I just wanted to suggest that there might be another way to achieve what you’re aiming for without modifying command.c.
Please, check the platform's custom command feature (PLATFORM_HAS_CUSTOM_COMMANDS), and you can find an example in my project here: https://github.com/Misaka0x2730/MioLink/blob/main/firmware/source/bmp/platform_commands.c#L38C17-L38C34
It could help keep the core code untouched while still delivering the same functionality.

@sidprice
Copy link
Contributor Author

@Misaka0x2730 Hello!

This was previously suggested by @ALTracer, and is a good idea. Since this PR is a feature update it is awaiting review and merging until after the next release. Hopefully, during this period I can adopt the suggestion.

@sidprice
Copy link
Contributor Author

I am not sure this is such a good idea since it prevents grouping the custom commands logically in the command list. Plus, there are quite a few other custom commands already in the command list, e.g. TraceSWO & RTT.

I think unless the maintainers (@dragonmux ) feel it is required I am going to leave the added command for this PR as it is.

@Misaka0x2730
Copy link
Contributor

I agree that @dragonmux is the one who’ll ultimately decide here.
However, I want to clarify my thoughts on “custom” commands. For instance, TraceSWO and RTT are supported by many (if not most) platforms—so they’re hardly “custom” in the sense of belonging to just one.
By contrast, Wi-Fi is specific to your platform, which I believe aligns more with the idea of platform-specific commands.

@perigoso
Copy link
Contributor

I agree that these should be platform commands at least for now, though not having control over the grouping is unfortunate.
I have some ideas to rework to the command system but until then we are limited with what we can do. Do note that this only affects the print on the help command and doesn't affect functionality

@sidprice
Copy link
Contributor Author

@perigoso Thanks for your input. I would be happy to review the platform commands should the command table/architecture change in the future.

@sidprice sidprice force-pushed the ctxlink_wifi_options branch from eabddff to 11b0093 Compare February 13, 2025 18:53
@dragonmux dragonmux changed the title Ctxlink_wifi_options Fix: WiFi configuration issues via USB (HTTP/WPS provisioning sometimes unreliable) Feb 24, 2025
@dragonmux
Copy link
Member

Having had a conversation with Sid on Discord, we are switching this to being a fix PR rather than a feature, and promoting it into the v2.0 track for after rc2's release.

@dragonmux dragonmux added the Bug Confirmed bug label Feb 24, 2025
@dragonmux dragonmux modified the milestones: v2.1 release, v2.0 release Feb 24, 2025
Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

Apologies getting to review this took so long. Most of the items are types related (signed-unsigned conversions mostly) and should all be pretty simple fixes. With them taken care of we'll get this merged so this issue can be fixed for the full v2.0 release.

Comment on lines 70 to +75
#ifdef PLATFORM_HAS_BATTERY
static bool cmd_target_battery(target_s *t, int argc, const char **argv);
#endif
#ifdef PLATFORM_HAS_WIFI
static bool cmd_wifi(target_s *t, int argc, const char **argv);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but for a future one: These should probably both become platform commands. That way you don't need to export as much platform state into the rest of the code base, and they get grouped under the platform commands heading in the mon help output. We can look at improving this in v2.1 though so this is fine as is for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed as previously discussed.

@@ -531,6 +536,12 @@ static void app_wifi_callback(uint8_t msg_type, void *msg)
break;
}

case M2M_WIFI_CONN_INFO_RESPONSE_EVENT: {
tstrM2MConnInfo *connection_info = (tstrM2MConnInfo *)msg;
memcpy(&conn_info, connection_info, sizeof(tstrM2MConnInfo));
Copy link
Member

Choose a reason for hiding this comment

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

For what it's worth, memcpy() takes a void pointer for the pointer parameters so you could simplify this to memcpy(&conn_info, msg, sizeof(tstrM2MConnInfo)); and forgo the pointer conversion and local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, however the local aids with debugging, that is why it was added.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm.. ah, by allowing you to view the pre-and-post-image of the memcpy() before running it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, the parameter "msg" is a void pointer from the WINC1500 stack and it may point to one of several different structures depending upon the message type (msg_type). I use an intermediate local of the expected type to allow easier examination of the structure with the debugger. I think originally, the debugger didn't handle type casting too well, hence this approach.

@@ -558,10 +569,14 @@ static void app_wifi_callback(uint8_t msg_type, void *msg)
}

case M2M_WIFI_IP_ADDRESS_ASSIGNED_EVENT: {
t_wifiEventData *wifi_event_data = (t_wifiEventData *)msg;
if (wifi_event_data != NULL)
tstrM2MIPConfig *ip_config = (tstrM2MIPConfig *)msg;
Copy link
Member

Choose a reason for hiding this comment

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

Beyond checking the pointer is non-NULL, is this local used for anything here? If not then the if should probably become if (msg != NULL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like the above comment, the local is a useful debugging addition.

@sidprice sidprice force-pushed the ctxlink_wifi_options branch from 11b0093 to af71d57 Compare March 3, 2025 22:10
Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

This is looking much better - good work! Spotted a couple of small things in the rewritten wifi_connect() logic, but with them taken care of we're happy to merge this.

Previous version of the parser did not handle multiple spaces.
@sidprice sidprice force-pushed the ctxlink_wifi_options branch from af71d57 to bf9529a Compare March 4, 2025 16:45
Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

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

LGTM, merging - nice work cleaning things up so quickly. Thank you for the contribution!

@dragonmux dragonmux merged commit bf9529a into blackmagic-debug:main Mar 4, 2025
36 checks passed
@sidprice sidprice deleted the ctxlink_wifi_options branch March 4, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bug Enhancement General project improvement Foreign Host Board Non Native hardware to runing Black Magic firmware on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants