Skip to content

Commit 6296a73

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents a51bfdf + 3b7d2f1 commit 6296a73

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

locale/circuitpython.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ msgid "Stack size must be at least 256"
21432143
msgstr ""
21442144

21452145
#: ports/espressif/common-hal/wifi/Radio.c
2146-
msgid "Station must be started"
2146+
msgid "Interface must be started"
21472147
msgstr ""
21482148

21492149
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c

ports/espressif/common-hal/wifi/Radio.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self) {
112112

113113
void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname) {
114114
esp_netif_set_hostname(self->netif, hostname);
115+
esp_netif_set_hostname(self->ap_netif, hostname);
115116
}
116117

117118
mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
@@ -122,7 +123,7 @@ mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) {
122123

123124
void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t *mac) {
124125
if (!self->sta_mode) {
125-
mp_raise_RuntimeError(translate("Station must be started"));
126+
mp_raise_RuntimeError(translate("Interface must be started"));
126127
}
127128
if ((mac[0] & 0b1) == 0b1) {
128129
mp_raise_RuntimeError(translate("Invalid multicast MAC address"));
@@ -136,6 +137,16 @@ mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) {
136137
return mp_obj_new_bytes(mac, MAC_ADDRESS_LENGTH);
137138
}
138139

140+
void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint8_t *mac) {
141+
if (!self->ap_mode) {
142+
mp_raise_RuntimeError(translate("Interface must be started"));
143+
}
144+
if ((mac[0] & 0b1) == 0b1) {
145+
mp_raise_RuntimeError(translate("Invalid multicast MAC address"));
146+
}
147+
esp_wifi_set_mac(ESP_IF_WIFI_AP, mac);
148+
}
149+
139150
mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) {
140151
if (self->current_scan != NULL) {
141152
mp_raise_RuntimeError(translate("Already scanning for wifi networks"));

shared-bindings/wifi/Radio.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,38 @@ const mp_obj_property_t wifi_radio_mac_address_obj = {
149149
MP_ROM_NONE },
150150
};
151151

152-
//| mac_address_ap: bytes
153-
//| """MAC address of the wifi radio access point. (read-only)"""
152+
//| mac_address_ap: ReadableBuffer
153+
//| """MAC address for the AP. When the address is altered after interface is started
154+
//| the changes would only be reflected once the interface restarts."""
154155
//|
155-
STATIC mp_obj_t wifi_radio_get_mac_address_ap(mp_obj_t self) {
156+
STATIC mp_obj_t wifi_radio_get_mac_address_ap(mp_obj_t self_in) {
157+
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
156158
return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address_ap(self));
157-
158159
}
159160
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_ap_obj, wifi_radio_get_mac_address_ap);
160161

162+
STATIC mp_obj_t wifi_radio_set_mac_address_ap(mp_obj_t self_in, mp_obj_t mac_address_in) {
163+
mp_buffer_info_t mac_address;
164+
mp_get_buffer_raise(mac_address_in, &mac_address, MP_BUFFER_READ);
165+
166+
if (mac_address.len != MAC_ADDRESS_LENGTH) {
167+
mp_raise_ValueError(translate("Invalid MAC address"));
168+
}
169+
170+
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in);
171+
common_hal_wifi_radio_set_mac_address_ap(self, mac_address.buf);
172+
173+
return mp_const_none;
174+
}
175+
MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_mac_address_ap_obj, wifi_radio_set_mac_address_ap);
176+
161177
const mp_obj_property_t wifi_radio_mac_address_ap_obj = {
162178
.base.type = &mp_type_property,
163179
.proxy = { (mp_obj_t)&wifi_radio_get_mac_address_ap_obj,
164-
MP_ROM_NONE,
180+
(mp_obj_t)&wifi_radio_set_mac_address_ap_obj,
165181
MP_ROM_NONE },
166182
};
167183

168-
169184
//| def start_scanning_networks(self, *, start_channel: int = 1, stop_channel: int = 11) -> Iterable[Network]:
170185
//| """Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country."""
171186
//| ...

shared-bindings/wifi/Radio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ extern void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const cha
8080
extern mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self);
8181
extern void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t *mac);
8282
extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self);
83+
extern void common_hal_wifi_radio_set_mac_address_ap(wifi_radio_obj_t *self, const uint8_t *mac);
8384

8485
extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self);
8586
extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self);

0 commit comments

Comments
 (0)