Skip to content

system/wifibridge: keep the configuration across resets - #3893

Open
daniel-p-carvalho wants to merge 1 commit into
apache:masterfrom
daniel-p-carvalho:feat/wifibridge-persist
Open

daniel-p-carvalho wants to merge 1 commit into
apache:masterfrom
daniel-p-carvalho:feat/wifibridge-persist

Conversation

@daniel-p-carvalho

Copy link
Copy Markdown
Contributor

Summary

Let the wifibridge command keep its configuration across resets. This is the follow-up to #3876, which left saving the SSID and the passphrase out.

wifibridge save [-s <ssid>] [-p <passphrase>] [-c <channel>] [-3] [-a <ipaddr>] [-d|-D]
wifibridge clear
  • save writes the SSID, the passphrase, the channel, the security, the bridge address and the DHCP server option. start then uses them instead of the Kconfig defaults, and the options given to start win for that run only. clear forgets them.
  • New -D option: do not run the DHCP server. With -d it lets one run override a saved choice either way, the last one on the command line wins.
  • The configuration is one record (magic number, version, CRC-32) at the start of CONFIG_NETUTILS_WIFIBRIDGE_STORAGE: a file of a file system mounted at boot, or a block device such as the MTD of a few pages of flash. A missing or damaged record is ignored and the defaults are used. The passphrase is stored as is.
  • wifibridge_save(), wifibridge_load() and wifibridge_clear() in netutils/wifibridge, behind CONFIG_NETUTILS_WIFIBRIDGE_PERSIST (default n). The SoftAP parameters are now checked in one place, also by start before anything is changed.

The library is generic. On the EV49N51A the storage is the program flash exposed as an MTD by apache/nuttx#20788, which this PR needs on that board. Other boards only need a file system or a block device.

Impact

New, optional, default n. Without CONFIG_NETUTILS_WIFIBRIDGE_PERSIST nothing changes, except that start and save accept -D and the parameter checks moved to one function.

Testing

Host: Ubuntu Linux, XC32 v6.00. Target: EV49N51A (PIC32MZ-W1), PIC32MZ_PROGMEM with FTL and BCH as /dev/mtdblock1 (apache/nuttx#20788), CONFIG_NETUTILS_WIFIBRIDGE_DHCPD=y, flashed with a PICkit 3.

  • No saved record: start uses the defaults (NuttX-BR, no DHCP server).
  • save -s TestD -p abcd1234 -d, then start: the AP is TestD and dhcpd br0 runs; the same after a reset. stop ends the DHCP server too.
  • start -D over a saved -d: no DHCP server. After save -D and a reset, start: none; start -d over it: the DHCP server runs.
  • start -d -D runs without the DHCP server and start -D -d with it.
  • save with a short passphrase fails with EINVAL and keeps the previous record.
  • clear and a reset: the defaults are back.
  • Earlier run with -c 11 -a 10.0.0.7: the record kept the SSID, channel and address across resets, and the options of start overrode them for one run.
  • checkpatch passes.

Not tested: WPA3 (-3) saved in the record, which needs the BA414E engine.

Comment thread include/netutils/wifibridge.h Outdated
Comment thread include/netutils/wifibridge.h Outdated
Comment thread netutils/wifibridge/wifibridge.c Outdated
*
* Description:
* Read what wifibridge_save() kept and set the matching fields of the
* configuration. The SSID and the passphrase are copied to the buffers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we change to array

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, ssid and passphrase are now arrays with the sizes in the prototype.

Comment thread netutils/wifibridge/wifibridge.c Outdated
int fd;

fd = open(CONFIG_NETUTILS_WIFIBRIDGE_STORAGE,
write ? O_RDWR | O_CREAT : O_RDONLY, 0600);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we add O_TRUCT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, the write opens with O_WRONLY | O_CREAT | O_TRUNC. Tested on the simulator: a 400-byte file is left with the 116 bytes of the record.

Comment thread netutils/wifibridge/wifibridge.c Outdated

if (write)
{
nbytes = pwrite(fd, record, sizeof(*record), 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

write

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, it is a plain write() now (the offset was always 0). I renamed the bool argument of wifibridge_record_io() to store, since it hid write().

Comment thread netutils/wifibridge/wifibridge.c Outdated
}
else
{
nbytes = pread(fd, record, sizeof(*record), 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

read

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, a plain read() now.

Add the save and clear commands, and the wifibridge_save(),
wifibridge_load() and wifibridge_clear() functions behind them, enabled by
NETUTILS_WIFIBRIDGE_PERSIST.  save keeps the SSID, the passphrase, the
channel, the security, the address and the DHCP server option; start then
uses them instead of the defaults of the configuration, and the options of
start win for that run only.  clear forgets them.

The configuration is a record with a magic number, a version and a CRC-32,
written at the start of NETUTILS_WIFIBRIDGE_STORAGE: a file of a file
system mounted at boot, or a block device such as the MTD of a few pages
of flash.  A record that is missing or damaged is ignored and the
defaults are used.  The passphrase is stored as is.

The parameters of the SoftAP are now checked in one place, also by start
before anything is changed.

Tested on an EV49N51A with the MTD of two pages of the program flash
(PIC32MZ_PROGMEM, FTL and BCH, as /dev/mtdblock1): start with an empty
storage uses the defaults; after save -s Persist -p persist1234 -c 11
-a 10.0.0.7 -d, start comes up with that SSID, channel, address and the
DHCP server, also after a reset; the options of start override it for one
run; clear brings the defaults back; save refuses a short passphrase.

Assisted-by: Claude Code:claude-sonnet-5-5
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants