Skip to content

Commit 0b9f28b

Browse files
committed
Make DHCP name size configurable
1 parent 1dff394 commit 0b9f28b

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

mongoose.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,10 @@ struct timeval {
10611061
#define MG_SET_MAC_ADDRESS(mac)
10621062
#endif
10631063

1064+
#ifndef MG_TCPIP_DHCPNAME_SIZE
1065+
#define MG_TCPIP_DHCPNAME_SIZE 18 // struct mg_tcpip_if :: dhcp_name size
1066+
#endif
1067+
10641068
#ifndef MG_SET_WIFI_CONFIG
10651069
#define MG_SET_WIFI_CONFIG(data)
10661070
#endif
@@ -3082,19 +3086,20 @@ typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev,
30823086
void *ev_data);
30833087

30843088
enum {
3085-
MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state)
3086-
MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr
3087-
MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr
3088-
MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str *
3089-
MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL
3090-
MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct mg_wifi_scan_bss_data *
3091-
MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL
3092-
MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and chip specific
3093-
MG_TCPIP_EV_DRIVER, // Driver event driver specific
3094-
MG_TCPIP_EV_USER // Starting ID for user events
3089+
MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state)
3090+
MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr
3091+
MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr
3092+
MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str *
3093+
MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL
3094+
MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct
3095+
// mg_wifi_scan_bss_data *
3096+
MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL
3097+
MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and
3098+
// chip specific
3099+
MG_TCPIP_EV_DRIVER, // Driver event driver specific
3100+
MG_TCPIP_EV_USER // Starting ID for user events
30953101
};
30963102

3097-
30983103
// Network interface
30993104
struct mg_tcpip_if {
31003105
uint8_t mac[6]; // MAC address. Must be set to a valid MAC
@@ -3114,8 +3119,8 @@ struct mg_tcpip_if {
31143119
mg_tcpip_event_handler_t fn; // User-specified event handler function
31153120
struct mg_mgr *mgr; // Mongoose event manager
31163121
struct mg_queue recv_queue; // Receive queue
3117-
char dhcp_name[12]; // Name reported to DHCP, "mip" if unset
3118-
uint16_t mtu; // Interface MTU
3122+
char dhcp_name[MG_TCPIP_DHCPNAME_SIZE]; // Name for DHCP, "mip" if unset
3123+
uint16_t mtu; // Interface MTU
31193124
#define MG_TCPIP_MTU_DEFAULT 1500
31203125

31213126
// Internal state, user can use it but should not change it
@@ -3168,7 +3173,6 @@ struct mg_tcpip_spi {
31683173
uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
31693174
};
31703175

3171-
31723176
#endif
31733177

31743178

src/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@
179179
#define MG_SET_MAC_ADDRESS(mac)
180180
#endif
181181

182+
#ifndef MG_TCPIP_DHCPNAME_SIZE
183+
#define MG_TCPIP_DHCPNAME_SIZE 18 // struct mg_tcpip_if :: dhcp_name size
184+
#endif
185+
182186
#ifndef MG_SET_WIFI_CONFIG
183187
#define MG_SET_WIFI_CONFIG(data)
184188
#endif

src/net_builtin.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev,
2020
void *ev_data);
2121

2222
enum {
23-
MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state)
24-
MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr
25-
MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr
26-
MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str *
27-
MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL
28-
MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct mg_wifi_scan_bss_data *
29-
MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL
30-
MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and chip specific
31-
MG_TCPIP_EV_DRIVER, // Driver event driver specific
32-
MG_TCPIP_EV_USER // Starting ID for user events
23+
MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state)
24+
MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr
25+
MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr
26+
MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str *
27+
MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL
28+
MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct
29+
// mg_wifi_scan_bss_data *
30+
MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL
31+
MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and
32+
// chip specific
33+
MG_TCPIP_EV_DRIVER, // Driver event driver specific
34+
MG_TCPIP_EV_USER // Starting ID for user events
3335
};
3436

35-
3637
// Network interface
3738
struct mg_tcpip_if {
3839
uint8_t mac[6]; // MAC address. Must be set to a valid MAC
@@ -52,8 +53,8 @@ struct mg_tcpip_if {
5253
mg_tcpip_event_handler_t fn; // User-specified event handler function
5354
struct mg_mgr *mgr; // Mongoose event manager
5455
struct mg_queue recv_queue; // Receive queue
55-
char dhcp_name[12]; // Name reported to DHCP, "mip" if unset
56-
uint16_t mtu; // Interface MTU
56+
char dhcp_name[MG_TCPIP_DHCPNAME_SIZE]; // Name for DHCP, "mip" if unset
57+
uint16_t mtu; // Interface MTU
5758
#define MG_TCPIP_MTU_DEFAULT 1500
5859

5960
// Internal state, user can use it but should not change it
@@ -106,5 +107,4 @@ struct mg_tcpip_spi {
106107
uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
107108
};
108109

109-
110110
#endif

0 commit comments

Comments
 (0)