1.1.13 Client - DHCP Server APIs
This interface supports configuring the DHCP server functionality within the WINCS02.
To use the DHCP server its pool of addresses must be configured by calling WDRV_WINC_DHCPSPoolAddressSet
. The pool must lie within the network address space of the network interface selected.
An optional default gateway address can be supplied to DHCP clients by configuring an address using the function WDRV_WINC_DHCPSGatewaySet
.
Before use the DHCP server must be bound to a network interface using WDRV_WINC_DHCPSNetIfBind
and enabled using WDRV_WINC_DHCPSEnableSet
.
By default the DHCP server configurations are bound to WDRV_WINC_NETIF_IDX_DEFAULT
, so unless a non-default network interface is used the application should not need to call WDRV_WINC_DHCPSNetIfBind
.
Events of type WDRV_WINC_DHCPS_EVENT_TYPE
are received by the callback of type WDRV_WINC_DHCPS_EVENT_HANDLER
.
static void apDHCPSEventCallback(DRV_HANDLE handle, WDRV_WINC_DHCPS_EVENT_TYPE eventType, void *pEventInfo) { switch (eventType) { case WDRV_WINC_DHCPS_EVENT_LEASE_ASSIGNED: { char s[20] = {0}; WDRV_WINC_UtilsIPAddressToString((WDRV_WINC_IPV4_ADDR*)pEventInfo, s, sizeof(s)); printf("STA IP Address \"%s\"\r\n", s); break; } default: { break; } } } ... WDRV_WINC_IP_MULTI_ADDRESS apIPv4Addr; WDRV_WINC_IPV4_ADDR dhcpsIPv4PoolAddr; /* Convert network address from string to WDRV_WINC_IPV4_ADDR form. */ WDRV_WINC_UtilsStringToIPAddress("192.168.0.1", &apIPv4Addr.v4); /* Convert DHCP server pool start address from string to WDRV_WINC_IPV4_ADDR form. */ WDRV_WINC_UtilsStringToIPAddress("192.168.0.2", &dhcpsIPv4PoolAddr); /* Configure the network interface IP address to 192.168.0.1/24. */ WDRV_WINC_NetIfIPAddrSet(wdrvHandle, WDRV_WINC_NETIF_IDX_0, WDRV_WINC_IP_ADDRESS_TYPE_IPV4, &apIPv4Addr, 24); /* Configure the DHCP server pool start address. */ WDRV_WINC_DHCPSPoolAddressSet(wdrvHandle, WDRV_WINC_DHCPS_IDX_0, &dhcpsIPv4PoolAddr); /* Enable DHCP server configuration. */ WDRV_WINC_DHCPSEnableSet(wdrvHandle, WDRV_WINC_DHCPS_IDX_0, true, apDHCPSEventCallback);