Wiesner András e4d27454cd - add tag to CBD
- DHCP state separated
- link change handler added
- timer mutex added
2023-10-15 12:17:37 +02:00

76 lines
1.9 KiB
C

#ifndef ETHERLIB_DHCP_H
#define ETHERLIB_DHCP_H
#include <stdint.h>
//#include "../../eth_interface.h"
#include "etherlib/cbd_table.h"
#include "etherlib_options.h"
typedef struct {
uint8_t op; ///< Operations
uint8_t htype; ///< Hardware type
uint8_t hlen; ///< Hardware address length
uint8_t hops; ///< Number of network hops
uint32_t xid; ///< Transaction ID
uint16_t secs; ///< Seconds elapsed since client started trying to boot
uint16_t flags; ///< Flags
uint32_t ciaddr; ///< Client IP address (filled in DHCPREQUEST)
uint32_t yiaddr; ///< 'Your' client IP address
uint32_t siaddr; ///< DHCP server IP address
uint32_t giaddr; ///< Relay agent IP address
uint8_t chaddr[16]; ///< Client hardware address
char * sname; ///< Optional server host name
char * file; ///< Boot file name
} DhcpProps;
/**
* DHCP state.
*/
typedef enum {
DHCP_INIT_REBOOT,
DHCP_REBOOTING,
DHCP_INIT,
DHCP_REQUESTING,
DHCP_SELECTING,
DHCP_REBINDING,
DHCP_BOUND,
DHCP_RENEWING
} DhcpFSMState;
/**
* DHCP id codes.
*/
typedef enum {
DHCP_BOOTREQUEST = 1,
DHCP_BOOTREPLY = 0
} DhcpOpCode;
#define DHCP_MIN_PACKET_SIZE (312)
#define DHCP_CLIENT_PORT (68)
#define DHCP_SERVER_PORT (67)
struct EthInterface_;
typedef struct {
DhcpFSMState state; ///< DHCP state machine state
void *buf; ///< Pointer to packet an allocated packet buffer
cbd desc; ///< UDP connection block descriptor
uint32_t tranId; ///< Transaction ID
struct EthInterface_ *intf; ///< Pointer to corresponding Ethernet interface
ETHLIB_OS_MTX_TYPE procMtx; ///< Mutex protecting the state machine
} DhcpState;
/**
* Initiate DHCP on interface
* @param intf interface
*/
void dhcp_initiate(struct EthInterface_ * intf);
/**
* Start DHCP operation.
* @param s pointer to DhcpState structure
*/
void dhcp_start(DhcpState * s);
#endif //ETHERLIB_DHCP_H