Skip to content

Commit

Permalink
feat(esp_netfi): add captive portal DHCPS option
Browse files Browse the repository at this point in the history
  • Loading branch information
jkingsman committed Apr 8, 2024
1 parent b3f7e2c commit d7d4456
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/esp_netif/include/esp_netif_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef enum{
ESP_NETIF_IP_REQUEST_RETRY_TIME = 52, /**< Request IP address retry counter */
ESP_NETIF_VENDOR_CLASS_IDENTIFIER = 60, /**< Vendor Class Identifier of a DHCP client */
ESP_NETIF_VENDOR_SPECIFIC_INFO = 43, /**< Vendor Specific Information of a DHCP server */
ESP_NETIF_CAPTIVEPORTAL_URI = 114, /**< Captive Portal Identification */
} esp_netif_dhcp_option_id_t;

/** IP event declarations */
Expand Down
8 changes: 7 additions & 1 deletion components/esp_netif/lwip/esp_netif_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,6 @@ esp_err_t esp_netif_dhcps_option_api(esp_netif_api_msg_t *msg)
if (dhcps_status == ESP_NETIF_DHCP_STARTED) {
return ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED;
}

switch (opt->id) {
case IP_ADDRESS_LEASE_TIME: {
if (*(uint32_t *)opt->val != 0) {
Expand Down Expand Up @@ -2335,6 +2334,13 @@ esp_err_t esp_netif_dhcps_option_api(esp_netif_api_msg_t *msg)
}
break;
}
case ESP_NETIF_CAPTIVEPORTAL_URI: {
/* unlike other flags/constant-sized IP addresses, we need to allocate for the URI */
char* captiveportal_uri = (char*) malloc((opt->len+1)*sizeof(char));
strcpy(captiveportal_uri, opt->val);
opt_info = captiveportal_uri;
break;
}

default:
break;
Expand Down
24 changes: 24 additions & 0 deletions components/lwip/apps/dhcpserver/dhcpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
#define DHCP_OPTION_BROADCAST_ADDRESS 28
#define DHCP_OPTION_REQ_LIST 55
#define DHCP_OPTION_CAPTIVEPORTAL_URI 114
#define DHCP_OPTION_END 255

//#define USE_CLASS_B_NET 1
Expand Down Expand Up @@ -135,6 +136,7 @@ struct dhcps_t {
dhcps_time_t dhcps_lease_time;
dhcps_offer_t dhcps_offer;
dhcps_offer_t dhcps_dns;
char *dhcps_captiveportal_uri;
dhcps_cb_t dhcps_cb;
void* dhcps_cb_arg;
struct udp_pcb *dhcps_pcb;
Expand Down Expand Up @@ -164,6 +166,7 @@ dhcps_t *dhcps_new(void)
dhcps->dhcps_lease_time = DHCPS_LEASE_TIME_DEF;
dhcps->dhcps_offer = 0xFF;
dhcps->dhcps_dns = 0x00;
dhcps->dhcps_captiveportal_uri = NULL;
dhcps->dhcps_pcb = NULL;
dhcps->state = DHCPS_HANDLE_CREATED;
return dhcps;
Expand Down Expand Up @@ -238,6 +241,10 @@ void *dhcps_option_info(dhcps_t *dhcps, u8_t op_id, u32_t opt_len)
option_arg = &dhcps->dhcps_mask;
}

break;
case CAPTIVEPORTAL_URI:
option_arg = &dhcps->dhcps_captiveportal_uri;

break;
default:
break;
Expand Down Expand Up @@ -292,6 +299,11 @@ err_t dhcps_set_option_info(dhcps_t *dhcps, u8_t op_id, void *opt_info, u32_t op
dhcps->dhcps_mask = *(ip4_addr_t *)opt_info;
}

break;

case CAPTIVEPORTAL_URI:
dhcps->dhcps_captiveportal_uri = (char *)opt_info;
break;

default:
break;
Expand Down Expand Up @@ -400,6 +412,7 @@ static u8_t *add_msg_type(u8_t *optptr, u8_t type)
*******************************************************************************/
static u8_t *add_offer_options(dhcps_t *dhcps, u8_t *optptr)
{
u32_t i;
ip4_addr_t ipadd;

ipadd.addr = *((u32_t *) &dhcps->server_address);
Expand Down Expand Up @@ -468,6 +481,17 @@ static u8_t *add_offer_options(dhcps_t *dhcps, u8_t *optptr)
*optptr++ = 0x05;
*optptr++ = 0xdc;

if (dhcps->dhcps_captiveportal_uri) {
size_t length = strlen(dhcps->dhcps_captiveportal_uri);

*optptr++ = DHCP_OPTION_CAPTIVEPORTAL_URI;
*optptr++ = length;
for (i = 0; i < length; i++)
{
*optptr++ = dhcps->dhcps_captiveportal_uri[i];
}
}

*optptr++ = DHCP_OPTION_PERFORM_ROUTER_DISCOVERY;
*optptr++ = 1;
*optptr++ = 0x00;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ typedef enum
CLIENT_LAST_TRANSACTION_TIME = 91,
ASSOCIATED_IP = 92,
USER_AUTHENTICATION_PROTOCOL = 98,
CAPTIVEPORTAL_URI = 114,
AUTO_CONFIGURE = 116,
NAME_SERVICE_SEARCH = 117,
SUBNET_SELECTION = 118,
Expand Down

0 comments on commit d7d4456

Please sign in to comment.