8000 drivers/cyw43: Allow configuring the netif/mDNS hostname. · micropython/micropython@b6c2196 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6c2196

Browse files
iabdalkaderdpgeorge
authored andcommitted
drivers/cyw43: Allow configuring the netif/mDNS hostname.
Allow boards to configure/override the default hostname used for netif and mDNS.
1 parent 1bf2fd0 commit b6c2196

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

drivers/cyw43/cyw43.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
#define CYW43_LINK_NONET (-2)
4848
#define CYW43_LINK_BADAUTH (-3)
4949

50+
#ifndef MICROPY_BOARD_HOSTNAME
51+
#define MICROPY_BOARD_HOSTNAME "PYBD"
52+
#endif
53+
54+
#ifndef MICROPY_BOARD_HOSTNAME_LENGTH
55+
#define MICROPY_BOARD_HOSTNAME_LENGTH 16
56+
#endif
57+
5058
typedef struct _cyw43_t {
5159
cyw43_ll_t cyw43_ll;
5260

@@ -76,6 +84,7 @@ typedef struct _cyw43_t {
7684
struct netif netif[2];
7785
struct dhcp dhcp_client;
7886
dhcp_server_t dhcp_server;
87+
char hostname[MICROPY_BOARD_HOSTNAME_LENGTH];
7988
} cyw43_t;
8089

8190
extern cyw43_t cyw43_state;

drivers/cyw43/cyw43_ctrl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ void cyw43_init(cyw43_t *self) {
101101
self->ap_channel = 3;
102102
self->ap_ssid 8000 _len = 0;
103103
self->ap_key_len = 0;
104+
strncpy(self->hostname, MICROPY_BOARD_HOSTNAME, MICROPY_BOARD_HOSTNAME_LENGTH);
105+
self->hostname[MICROPY_BOARD_HOSTNAME_LENGTH - 1] = 0;
104106

105107
cyw43_poll = NULL;
106108
}

drivers/cyw43/cyw43_lwip.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void cyw43_tcpip_init(cyw43_t *self, int itf) {
117117
#else
118118
netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, cyw43_netif_init, netif_input);
119119
#endif
120-
netif_set_hostname(n, "PYBD");
120+
netif_set_hostname(n, self->hostname);
121121
netif_set_default(n);
122122
netif_set_up(n);
123123

@@ -132,8 +132,9 @@ void cyw43_tcpip_init(cyw43_t *self, int itf) {
132132
#if LWIP_MDNS_RESPONDER
133133
// TODO better to call after IP address is set
134134
char mdns_hostname[9];
135-
memcpy(&mdns_hostname[0], "PYBD", 4);
136-
mp_hal_get_mac_ascii(MP_HAL_MAC_WLAN0, 8, 4, &mdns_hostname[4]);
135+
int len = MIN(strlen(self->hostname), 4);
136+
memcpy(&mdns_hostname[0], self->hostname, len);
137+
mp_hal_get_mac_ascii(MP_HAL_MAC_WLAN0, 4 + len, 8 - len, &mdns_hostname[len]);
137138
mdns_hostname[8] = '\0';
138139
mdns_resp_add_netif(n, mdns_hostname, 60);
139140
#endif

0 commit comments

Comments
 (0)
0