diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-21 19:58:50 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-21 19:58:50 -0600 |
commit | bc70ded6e8535f004b2c9f5f7a471fa548c33fab (patch) | |
tree | dbeef9f9a0856803885177d637c7cd9e41090303 /libdhcp/include | |
parent | a27d33b74d77ccb3d9dd9d68f4a9e2d5deed54e0 (diff) |
wip dhcp
Diffstat (limited to 'libdhcp/include')
-rw-r--r-- | libdhcp/include/libdhcp/dhcp.h | 88 |
1 files changed, 35 insertions, 53 deletions
diff --git a/libdhcp/include/libdhcp/dhcp.h b/libdhcp/include/libdhcp/dhcp.h index 7d1f61d..6970748 100644 --- a/libdhcp/include/libdhcp/dhcp.h +++ b/libdhcp/include/libdhcp/dhcp.h @@ -64,12 +64,30 @@ * SPDX-Licence-Identifier: MIT */ -#ifndef _DHCP_H_ -#define _DHCP_H_ +#ifndef _LIBDHCP_DHCP_H_ +#define _LIBDHCP_DHCP_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include <libmisc/net.h> + +typedef struct {} implements_net_udpsock; +ssize_t sendto(implements_net_udpsock *sock, void *buf, size_t len, struct net_ip4_addr addr, uint16_t port); +ssize_t recvfrom(implements_net_udpsock *sock, void *buf, size_t len, struct net_ip4_addr *ret_addr, uint16_t *ret_port); + +struct dhcp_lease { + struct net_ip4_addr addr; + struct net_ip4_addr subnet_mask; + struct net_ip4_addr gateway; + struct net_ip4_addr dns; + uint32_t lifetime; /* in seconds, except 0xffffffff is "infinity" */ +}; + +enum dhcp_event { + DHCP_ASSIGN, + DHCP_UPDATE, + DHCP_CONFLICT, +}; + +typedef void (*dhcp_callback_t)(enum dhcp_event, struct dhcp_lease); /* * @brief @@ -80,30 +98,26 @@ extern "C" { /* Retry to processing DHCP */ -#define MAX_DHCP_RETRY 2 ///< Maximum retry count -#define DHCP_WAIT_TIME 10 ///< Wait Time 10s +#define MAX_DHCP_RETRY 2 ///< Maximum retry count +#define DHCP_WAIT_TIME 10 ///< Wait Time 10s /* UDP port numbers for DHCP */ -#define DHCP_SERVER_PORT 67 ///< DHCP server port number +#define DHCP_SERVER_PORT 67 ///< DHCP server port number #define DHCP_CLIENT_PORT 68 ///< DHCP client port number - #define MAGIC_COOKIE 0x63825363 ///< You should not modify it number. -#define DCHP_HOST_NAME "WIZnet\0" - /* * @brief return value of @ref DHCP_run() */ -enum -{ - DHCP_FAILED = 0, ///< Processing Fail - DHCP_RUNNING, ///< Processing DHCP protocol - DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign) - DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update) - DHCP_IP_LEASED, ///< Stand by - DHCP_STOPPED ///< Stop processing DHCP protocol +enum { + DHCP_FAILED = 0, ///< Processing Fail + DHCP_RUNNING, ///< Processing DHCP protocol + DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign) + DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update) + DHCP_IP_LEASED, ///< Stand by + DHCP_STOPPED ///< Stop processing DHCP protocol }; /* @@ -139,7 +153,7 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co * * @note This function is always called by you main task. */ -uint8_t DHCP_run(void); +uint8_t DHCP_run(implements_net_udpsock *sock, dhcp_callback_t cb); /* * @brief Stop DHCP processing @@ -147,36 +161,4 @@ uint8_t DHCP_run(void); */ void DHCP_stop(void); -/* Get Network information assigned from DHCP server */ -/* - * @brief Get IP address - * @param ip - IP address to be returned - */ -void getIPfromDHCP(uint8_t* ip); -/* - * @brief Get Gateway address - * @param ip - Gateway address to be returned - */ -void getGWfromDHCP(uint8_t* ip); -/* - * @brief Get Subnet mask value - * @param ip - Subnet mask to be returned - */ -void getSNfromDHCP(uint8_t* ip); -/* - * @brief Get DNS address - * @param ip - DNS address to be returned - */ -void getDNSfromDHCP(uint8_t* ip); - -/* - * @brief Get the leased time by DHCP sever - * @return unit 1s - */ -uint32_t getDHCPLeasetime(void); - -#ifdef __cplusplus -} -#endif - -#endif /* _DHCP_H_ */ +#endif /* _LIBDHCP_DHCP_H_ */ |