Skip to content

Commit 5ffc4b2

Browse files
committed
Tick more boxes on the TODO list
* v6 on by default * dhcp can start v4 & v6 separately * self documenting property for v4 & v6 support * v4 support is always on .. for now
1 parent bc2e6b4 commit 5ffc4b2

File tree

7 files changed

+70
-13
lines changed

7 files changed

+70
-13
lines changed

docs/shared_bindings_matrix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"sys": "CIRCUITPY_SYS",
8686
"terminalio": "CIRCUITPY_DISPLAYIO",
8787
"usb": "CIRCUITPY_PYUSB",
88+
"wifi.supports_ipv6": "CIRCUITPY_SOCKETPOOL_IPV6",
8889
}
8990

9091
MODULES_NOT_IN_BINDINGS = ["binascii", "errno", "json", "re", "ulab"]

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,19 @@ void common_hal_wifi_radio_set_ipv4_dns(wifi_radio_obj_t *self, mp_obj_t ipv4_dn
532532
esp_netif_set_dns_info(self->netif, ESP_NETIF_DNS_MAIN, &dns_addr);
533533
}
534534

535-
void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self) {
536-
esp_netif_dhcpc_start(self->netif);
535+
void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self, bool ipv4, bool ipv6) {
536+
if (ipv4) {
537+
esp_netif_dhcpc_start(self->netif);
538+
} else {
539+
esp_netif_dhcpc_stop(self->netif);
540+
}
537541
#if LWIP_IPV6_DHCP6
538-
esp_netif_create_ip6_linklocal(self->netif);
539-
dhcp6_enable_stateless(esp_netif_get_netif_impl(self->netif));
542+
if (ipv6) {
543+
esp_netif_create_ip6_linklocal(self->netif);
544+
dhcp6_enable_stateless(esp_netif_get_netif_impl(self->netif));
545+
} else {
546+
dhcp6_disable(esp_netif_get_netif_impl(self->netif));
547+
}
540548
#endif
541549
}
542550

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ void common_hal_wifi_init(bool user_initiated) {
136136
if (wifi_inited) {
137137
if (user_initiated && !wifi_user_initiated) {
138138
common_hal_wifi_radio_set_enabled(self, true);
139+
// explicitly start dhcp
140+
common_hal_wifi_radio_start_dhcp_client(self, true, true);
139141
}
140142
return;
141143
}
@@ -201,6 +203,8 @@ void common_hal_wifi_init(bool user_initiated) {
201203
common_hal_wifi_radio_start_station(self);
202204
// start wifi
203205
common_hal_wifi_radio_set_enabled(self, true);
206+
// explicitly start dhcp
207+
common_hal_wifi_radio_start_dhcp_client(self, true, true);
204208
}
205209

206210
void wifi_user_reset(void) {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ void common_hal_wifi_radio_set_ipv4_dns(wifi_radio_obj_t *self, mp_obj_t ipv4_dn
406406
dns_setserver(0, &addr);
407407
}
408408

409-
void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self) {
410-
dhcp_start(NETIF_STA);
409+
void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self, bool ipv4, bool ipv6) {
410+
if (ipv4) {
411+
dhcp_start(NETIF_STA);
412+
} else {
413+
dhcp_stop(NETIF_STA);
414+
}
411415
}
412416

413417
void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self) {

shared-bindings/wifi/Radio.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,27 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_stations_ap_obj, wifi_radio_get_station
700700
MP_PROPERTY_GETTER(wifi_radio_stations_ap_obj,
701701
(mp_obj_t)&wifi_radio_get_stations_ap_obj);
702702

703-
//| def start_dhcp(self) -> None:
704-
//| """Starts the station DHCP client."""
703+
//| def start_dhcp(self, *, ipv4: bool = supports_ipv4, ipv6: bool = supports_ipv6) -> None:
704+
//| """Starts the station DHCP client.
705+
//|
706+
//| If specified
707+
//| """
705708
//| ...
706-
static mp_obj_t wifi_radio_start_dhcp_client(mp_obj_t self) {
707-
common_hal_wifi_radio_start_dhcp_client(self);
709+
static mp_obj_t wifi_radio_start_dhcp_client(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
710+
enum { ARG_ipv4, ARG_ipv6 };
711+
static const mp_arg_t allowed_args[] = {
712+
{ MP_QSTR_ipv4, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = MP_ROM_TRUE } },
713+
{ MP_QSTR_ipv6, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = CIRCUITPY_SOCKETPOOL_IPV6 ? MP_ROM_TRUE : MP_ROM_FALSE } },
714+
};
715+
716+
wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
717+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
718+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
719+
720+
common_hal_wifi_radio_start_dhcp_client(self, args[ARG_ipv4].u_bool, args[ARG_ipv6].u_bool);
708721
return mp_const_none;
709722
}
710-
MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_dhcp_client_obj, wifi_radio_start_dhcp_client);
723+
static MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_dhcp_client_obj, 1, wifi_radio_start_dhcp_client);
711724

712725
//| def stop_dhcp(self) -> None:
713726
//| """Stops the station DHCP client. Needed to assign a static IP address."""

shared-bindings/wifi/Radio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self);
8686
extern bool common_hal_wifi_radio_get_ap_active(wifi_radio_obj_t *self);
8787
extern mp_obj_t common_hal_wifi_radio_get_stations_ap(wifi_radio_obj_t *self);
8888

89-
extern void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self);
89+
extern void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self, bool ipv4, bool ipv6);
9090
extern void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self);
9191
extern void common_hal_wifi_radio_start_dhcp_server(wifi_radio_obj_t *self);
9292
extern void common_hal_wifi_radio_stop_dhcp_server(wifi_radio_obj_t *self);

shared-bindings/wifi/__init__.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,32 @@
1313

1414
//| """
1515
//| The `wifi` module provides necessary low-level functionality for managing
16-
//| wifi connections. Use `socketpool` for communicating over the network."""
16+
//| wifi connections. Use `socketpool` for communicating over the network.
1717
//|
18+
//| .. jinja
19+
//| """
20+
21+
//| supports_ipv6: bool
22+
//| """``True`` when ipv6 is supported. Read-only
23+
//|
24+
//| .. raw:: html
25+
//|
26+
//| <p>
27+
//| <details>
28+
//| <summary>True on these boards</summary>
29+
//| <ul>
30+
//| {% for board in support_matrix_reverse["wifi.supports_ipv6"] %}
31+
//| <li> {{ board }}
32+
//| {% endfor %}
33+
//| </ul>
34+
//| </details>
35+
//| </p>
36+
//|
37+
//| """
38+
39+
//| supports_ipv4: bool
40+
//| """``True`` when ipv4 is supported. Read-only"""
41+
1842
//| radio: Radio
1943
//| """Wifi radio used to manage both station and AP modes.
2044
//| This object is the sole instance of `wifi.Radio`."""
@@ -43,6 +67,9 @@ static const mp_rom_map_elem_t wifi_module_globals_table[] = {
4367

4468
// Properties
4569
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) },
70+
71+
{ MP_ROM_QSTR(MP_QSTR_supports_ipv6), MP_ROM_PTR(CIRCUITPY_SOCKETPOOL_IPV6 ? MP_ROM_TRUE : MP_ROM_FALSE) },
72+
{ MP_ROM_QSTR(MP_QSTR_supports_ipv4), MP_ROM_TRUE },
4673
};
4774
static MP_DEFINE_CONST_DICT(wifi_module_globals, wifi_module_globals_table);
4875

0 commit comments

Comments
 (0)