Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Access Point static IPv4 on the raspberrypi port #7976

Merged
merged 4 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions ports/raspberrypi/common-hal/wifi/Radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "lwip/raw.h"
#include "lwip_src/ping.h"

#include "shared/netutils/dhcpserver.h"

#define MAC_ADDRESS_LENGTH 6

#define NETIF_STA (&cyw43_state.netif[CYW43_ITF_STA])
Expand Down Expand Up @@ -359,11 +361,14 @@ void common_hal_wifi_radio_stop_dhcp_client(wifi_radio_obj_t *self) {
}

void common_hal_wifi_radio_start_dhcp_server(wifi_radio_obj_t *self) {
mp_raise_NotImplementedError(NULL);
ip4_addr_t ipv4_addr, netmask_addr;
ipaddress_ipaddress_to_lwip(common_hal_wifi_radio_get_ipv4_address_ap(self), &ipv4_addr);
ipaddress_ipaddress_to_lwip(common_hal_wifi_radio_get_ipv4_subnet_ap(self), &netmask_addr);
dhcp_server_init(&cyw43_state.dhcp_server, &ipv4_addr, &netmask_addr);
}

void common_hal_wifi_radio_stop_dhcp_server(wifi_radio_obj_t *self) {
mp_raise_NotImplementedError(NULL);
dhcp_server_deinit(&cyw43_state.dhcp_server);
}

void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway, mp_obj_t ipv4_dns) {
Expand All @@ -380,7 +385,15 @@ void common_hal_wifi_radio_set_ipv4_address(wifi_radio_obj_t *self, mp_obj_t ipv
}

void common_hal_wifi_radio_set_ipv4_address_ap(wifi_radio_obj_t *self, mp_obj_t ipv4, mp_obj_t netmask, mp_obj_t gateway) {
mp_raise_NotImplementedError(NULL);
common_hal_wifi_radio_stop_dhcp_server(self);

ip4_addr_t ipv4_addr, netmask_addr, gateway_addr;
ipaddress_ipaddress_to_lwip(ipv4, &ipv4_addr);
ipaddress_ipaddress_to_lwip(netmask, &netmask_addr);
ipaddress_ipaddress_to_lwip(gateway, &gateway_addr);
netif_set_addr(NETIF_AP, &ipv4_addr, &netmask_addr, &gateway_addr);

common_hal_wifi_radio_start_dhcp_server(self);
}

volatile bool ping_received;
Expand Down