esp-hosted icon indicating copy to clipboard operation
esp-hosted copied to clipboard

lwip DHCP Server running on esp-hosted/master as SOFTAP

Open claydonkey opened this issue 9 months ago • 7 comments

  1. A DHCP Server on esp-hosted is setup to lease IPS from the SOFTAP.
  2. The PC connects to the SOFTAP over WIFI successfully on Channel 1.
  3. The PC gets an IP in the range of 192.168.2.2-254.
Wireless LAN adapter WiFi:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Wireless-AC 9560 160MHz
   Physical Address. . . . . . . . . : 18-1D-EA-81-60-3C
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.2.2(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : 14 November 2023 21:17:44
   Lease Expires . . . . . . . . . . : 14 November 2023 23:30:14
   Default Gateway . . . . . . . . . : 0.0.0.0
   DHCP Server . . . . . . . . . . . : 192.168.2.1
   DNS Servers . . . . . . . . . . . : 192.168.2.1
   NetBIOS over Tcpip. . . . . . . . : Disabled`

That side of things seems taken card of.

  1. Host receives no packets from the pc after this.

The code seems pretty trivial:


dhcps_t *dhcps;

void lwip_init(uint8_t mac_address[6]) {
	/* Initialize the LwIP stack with RTOS */
	ip4_addr_t lwip_ip, lwip_netmask, lwip_gw;
	/* set MAC hardware address length */
	gnetif.hwaddr_len = ETHARP_HWADDR_LEN;

	/* set MAC hardware address */
	memcpy(gnetif.hwaddr, mac_address, NETIF_MAX_HWADDR_LEN);
	IP4_ADDR(&lwip_ip, 192, 168, 2, 1);
	IP4_ADDR(&lwip_netmask, 255, 255, 255, 0);
	IP4_ADDR(&lwip_gw, 0, 0, 0, 0);

	/* add the network interface (IPv4/IPv6) with RTOS */
	netif_add(&gnetif, &lwip_ip, &lwip_netmask, &lwip_gw, NULL, ethernetif_init_low, tcpip_input);
	gnetif.linkoutput = myif_link_output;
	gnetif.output = etharp_output;
	gnetif.hwaddr_len = 6;
	gnetif.mtu = 1500;
	gnetif.name[0] = 's';
	gnetif.name[1] = 't';
	gnetif.flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;

	/* Registers the default network interface */
	netif_set_default(&gnetif);

	if (netif_is_link_up(&gnetif)) {
		/* When the netif is fully configured this function must be called */
		netif_set_up(&gnetif);
	} else {
		/* When the netif link is down this function must be called */
		netif_set_down(&gnetif);
	}

	/* Start DHCP negotiation to a network interface (IPv4) */

		dhcps = dhcps_new();
		dhcps_set_new_lease_cb(dhcps, dhcps_callback, &gnetif); // callback just sets 
		dhcps_set_option_info(dhcps, SUBNET_MASK, (void*) &lwip_netmask, sizeof(lwip_netmask));
		dhcps_start(dhcps, &gnetif, lwip_ip);
		netif_set_addr(&gnetif, &lwip_ip, &lwip_netmask, &lwip_gw);
	}
}

claydonkey avatar Nov 14 '23 22:11 claydonkey