87 lines
2.2 KiB
C
87 lines
2.2 KiB
C
#ifndef ETHERLIB_DHCP_H
|
|
#define ETHERLIB_DHCP_H
|
|
|
|
#include <stdint.h>
|
|
//#include "../../eth_interface.h"
|
|
#include "../../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,
|
|
DHCP_STOPPED,
|
|
} 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
|
|
uint32_t renewAlarmId; ///< IP renew alarm ID (valid if nonzero)
|
|
uint32_t retryAlarmId; ///< DISCOVER retry alarm ID (valid if nonzero)
|
|
} DhcpState;
|
|
|
|
#define DHCP_RETRY_TIMEOUT_S (3)
|
|
|
|
/**
|
|
* 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);
|
|
|
|
/**
|
|
* Stop DHCP operation.
|
|
* @param s pointer to DhcpState structure
|
|
*/
|
|
void dhcp_stop(DhcpState * s);
|
|
|
|
#endif //ETHERLIB_DHCP_H
|