Skip to content

Commit

Permalink
Add Pico-w AP channel configuration support
Browse files Browse the repository at this point in the history
Adds support to the rp2040 network driver for configuring the channel used in AP mode.

Signed-off-by: Winford <winford@object.stream>
  • Loading branch information
UncleGrumpy committed Jun 6, 2024
1 parent b5a2c62 commit cb6952f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- ESP32 support for setting the network channel used in AP mode.
- Pico-W support for setting the network channel used in AP mode.

### Fixed

Expand Down
9 changes: 9 additions & 0 deletions src/platforms/rp2040/src/lib/networkdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define PORT_REPLY_SIZE (TUPLE_SIZE(2) + REF_SIZE)

static const char *const ap_atom = ATOM_STR("\x2", "ap");
static const char *const ap_channel_atom = ATOM_STR("\xA", "ap_channel");
static const char *const ap_sta_connected_atom = ATOM_STR("\x10", "ap_sta_connected");
static const char *const ap_sta_disconnected_atom = ATOM_STR("\x13", "ap_sta_disconnected");
static const char *const ap_started_atom = ATOM_STR("\xA", "ap_started");
Expand Down Expand Up @@ -382,6 +383,7 @@ static term start_ap(term ap_config, GlobalContext *global)
{
term ssid_term = interop_kv_get_value(ap_config, ssid_atom, global);
term pass_term = interop_kv_get_value(ap_config, psk_atom, global);
term channel_term = interop_kv_get_value(ap_config, ap_channel_atom, global);

//
// Check parameters
Expand Down Expand Up @@ -409,9 +411,16 @@ static term start_ap(term ap_config, GlobalContext *global)
return BADARG_ATOM;
}
}
uint32_t channel = 0;
if (!term_is_invalid_term(channel_term)) {
channel = term_to_int32(channel_term);
}

uint32_t auth = (psk == NULL) ? CYW43_AUTH_OPEN : CYW43_AUTH_WPA2_AES_PSK;
cyw43_state.assoc_cb = network_driver_cyw43_assoc_cb;
if (channel != 0) {
cyw43_wifi_ap_set_channel(&cyw43_state, channel);
}
cyw43_arch_enable_ap_mode(ssid, psk, auth);
send_ap_started(global);
free(ssid);
Expand Down

0 comments on commit cb6952f

Please sign in to comment.