|
33 | 33 | #include "py/runtime.h"
|
34 | 34 | #include "py/objproperty.h"
|
35 | 35 |
|
| 36 | +#define MAC_ADDRESS_LENGTH 6 |
| 37 | + |
36 | 38 | //| class Radio:
|
37 | 39 | //| """Native wifi radio.
|
38 | 40 | //|
|
@@ -115,23 +117,38 @@ const mp_obj_property_t wifi_radio_hostname_obj = {
|
115 | 117 | MP_ROM_NONE},
|
116 | 118 | };
|
117 | 119 |
|
118 |
| -//| mac_address: bytes |
119 |
| -//| """MAC address of the wifi radio station. (read-only)""" |
| 120 | +//| mac_address: ReadableBuffer |
| 121 | +//| """MAC address for the station. When the address is altered after interface is connected |
| 122 | +//| the changes would only be reflected once the interface reconnects.""" |
120 | 123 | //|
|
121 |
| -STATIC mp_obj_t wifi_radio_get_mac_address(mp_obj_t self) { |
| 124 | +STATIC mp_obj_t wifi_radio_get_mac_address(mp_obj_t self_in) { |
| 125 | + wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in); |
122 | 126 | return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address(self));
|
123 |
| - |
124 | 127 | }
|
125 | 128 | MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_obj, wifi_radio_get_mac_address);
|
126 | 129 |
|
| 130 | +STATIC mp_obj_t wifi_radio_set_mac_address(mp_obj_t self_in, mp_obj_t mac_address_in) { |
| 131 | + mp_buffer_info_t mac_address; |
| 132 | + mp_get_buffer_raise(mac_address_in, &mac_address, MP_BUFFER_READ); |
| 133 | + |
| 134 | + if (mac_address.len != MAC_ADDRESS_LENGTH) { |
| 135 | + mp_raise_ValueError(translate("Invalid MAC address")); |
| 136 | + } |
| 137 | + |
| 138 | + wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 139 | + common_hal_wifi_radio_set_mac_address(self, mac_address.buf); |
| 140 | + |
| 141 | + return mp_const_none; |
| 142 | +} |
| 143 | +MP_DEFINE_CONST_FUN_OBJ_2(wifi_radio_set_mac_address_obj, wifi_radio_set_mac_address); |
| 144 | + |
127 | 145 | const mp_obj_property_t wifi_radio_mac_address_obj = {
|
128 | 146 | .base.type = &mp_type_property,
|
129 | 147 | .proxy = { (mp_obj_t)&wifi_radio_get_mac_address_obj,
|
130 |
| - MP_ROM_NONE, |
| 148 | + (mp_obj_t)&wifi_radio_set_mac_address_obj, |
131 | 149 | MP_ROM_NONE },
|
132 | 150 | };
|
133 | 151 |
|
134 |
| - |
135 | 152 | //| mac_address_ap: bytes
|
136 | 153 | //| """MAC address of the wifi radio access point. (read-only)"""
|
137 | 154 | //|
|
@@ -307,7 +324,11 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
|
307 | 324 | }
|
308 | 325 |
|
309 | 326 | mp_buffer_info_t ssid;
|
| 327 | + ssid.len = 0; |
310 | 328 | mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
| 329 | + if (ssid.len > 32) { |
| 330 | + mp_raise_ValueError(translate("ssid can't be more than 32 bytes")); |
| 331 | + } |
311 | 332 |
|
312 | 333 | mp_buffer_info_t password;
|
313 | 334 | password.len = 0;
|
|
0 commit comments