Retro Rocket Kernel
BASIC-Powered Operating System
dhcp.h File Reference
#include "kernel.h"

Data Structures

struct  dhcp_packet_t
 Definition of a DHCP packet. More...
 

Macros

#define DHCP_TRANSACTION_IDENTIFIER   0x55AA55AA
 Hard coded transaction identifier. More...
 

Enumerations

enum  dhcp_request_type_t { DHCP_REQUEST = 1 , DHCP_REPLY = 2 }
 Direction of DHCP packet, outbound are REQUES and inbound (from the server to client) are REPLY. More...
 
enum  dhcp_udp_ports_t { DHCP_DST_PORT = 68 , DHCP_SRC_PORT = 67 }
 source and destination UDP port numbers More...
 
enum  dhcp_packet_type_t {
  DHCPDISCOVER = 1 , DHCPOFFER = 2 , DHCPREQUEST = 3 , DHCPDECLINE = 4 ,
  DHCPACK = 5 , DHCPNAK = 6 , DHCPRELEASE = 7 , DHCPINFORM = 8
}
 Packet types inside the options, type 53. More...
 
enum  dhcp_option_type_t {
  OPT_SUBNET = 1 , OPT_GATEWAY = 3 , OPT_DNS = 6 , OPT_HOSTNAME = 12 ,
  OPT_DOMAIN = 15 , OPT_NBNS = 44 , OPT_NBDD = 45 , OPT_NETBIOS_NODE_TYPE = 46 ,
  OPT_REQUESTED_IP = 50 , OPT_LEASE_TIME = 51 , OPT_TYPE = 53 , OPT_SERVER_IP = 54 ,
  OPT_PARAMETER_REQUEST_LIST = 55 , OPT_MAX_DHCP_SIZE = 57 , OPT_CLIENT_MAC = 61 , OPT_END = 255
}
 Types of options in the options fields. More...
 

Functions

struct dhcp_packet_t __attribute__ ((packed)) dhcp_packet_t
 Definition of a DHCP packet. More...
 
void dhcp_discover ()
 Initiate DHCP discovery Non-blocking, establishes IP address in the background. Network and IP stack card must be initialised first. More...
 
void dhcp_request (uint8_t *request_ip, uint32_t xid, uint32_t server_ip)
 send DHCPREQUEST packet. We send one on dhcp_discover() as DHCPDISCOVER then a second one as DHCPREQUEST once we are offered an IP address. More...
 
void * get_dhcp_options (dhcp_packet_t *packet, uint8_t type)
 Get an option from a DHCP packet. More...
 
uint16_t make_dhcp_packet (dhcp_packet_t *packet, uint8_t msg_type, uint8_t *request_ip, uint32_t xid, uint32_t server_ip)
 Build a DHCP packet. The contents of the options are built dynamically. More...
 

Variables

uint8_t op
 
uint8_t hardware_type
 
uint8_t hardware_addr_len
 
uint8_t hops
 
uint32_t xid
 
uint16_t seconds
 
uint16_t flags
 
uint32_t client_ip
 
uint32_t your_ip
 
uint32_t server_ip
 
uint32_t relay_agent_ip
 
uint8_t client_hardware_addr [16]
 
uint8_t server_name [64]
 
uint8_t boot_file [128]
 
uint8_t options [128]
 

Detailed Description

Author
Craig Edwards (craig.nosp@m.edwa.nosp@m.rds@b.nosp@m.rain.nosp@m.box.c.nosp@m.c)

Macro Definition Documentation

◆ DHCP_TRANSACTION_IDENTIFIER

#define DHCP_TRANSACTION_IDENTIFIER   0x55AA55AA

Hard coded transaction identifier.

Enumeration Type Documentation

◆ dhcp_option_type_t

Types of options in the options fields.

Enumerator
OPT_SUBNET 
OPT_GATEWAY 
OPT_DNS 
OPT_HOSTNAME 
OPT_DOMAIN 
OPT_NBNS 
OPT_NBDD 
OPT_NETBIOS_NODE_TYPE 
OPT_REQUESTED_IP 
OPT_LEASE_TIME 
OPT_TYPE 
OPT_SERVER_IP 
OPT_PARAMETER_REQUEST_LIST 
OPT_MAX_DHCP_SIZE 
OPT_CLIENT_MAC 
OPT_END 

◆ dhcp_packet_type_t

Packet types inside the options, type 53.

Enumerator
DHCPDISCOVER 
DHCPOFFER 
DHCPREQUEST 
DHCPDECLINE 
DHCPACK 
DHCPNAK 
DHCPRELEASE 
DHCPINFORM 

◆ dhcp_request_type_t

Direction of DHCP packet, outbound are REQUES and inbound (from the server to client) are REPLY.

Enumerator
DHCP_REQUEST 
DHCP_REPLY 

◆ dhcp_udp_ports_t

source and destination UDP port numbers

Enumerator
DHCP_DST_PORT 
DHCP_SRC_PORT 

Function Documentation

◆ __attribute__()

struct dhcp_packet_t __attribute__ ( (packed)  )

Definition of a DHCP packet.

◆ dhcp_discover()

void dhcp_discover ( )

Initiate DHCP discovery Non-blocking, establishes IP address in the background. Network and IP stack card must be initialised first.

◆ dhcp_request()

void dhcp_request ( uint8_t *  request_ip,
uint32_t  xid,
uint32_t  server_ip 
)

send DHCPREQUEST packet. We send one on dhcp_discover() as DHCPDISCOVER then a second one as DHCPREQUEST once we are offered an IP address.

Parameters
request_ipIP address we have been offered, if we have been offered an IP yet.
xidrequest ID as set by us when we did DHCPDISCOVER
server_ipserver IP that sent the offer to us

◆ get_dhcp_options()

void* get_dhcp_options ( dhcp_packet_t packet,
uint8_t  type 
)

Get an option from a DHCP packet.

Parameters
packetraw packet
typetype to search for
Returns
void* raw option, size must be known to the caller!

◆ make_dhcp_packet()

uint16_t make_dhcp_packet ( dhcp_packet_t packet,
uint8_t  msg_type,
uint8_t *  request_ip,
uint32_t  xid,
uint32_t  server_ip 
)

Build a DHCP packet. The contents of the options are built dynamically.

Parameters
packetPacket structure to fill
msg_typeMessage type to build
request_ipIP address we were offered
xidOur request identifier
server_ipIP of server that offered the configuration
Returns
packet size of constructed packet including options

Variable Documentation

◆ boot_file

uint8_t boot_file[128]

◆ client_hardware_addr

uint8_t client_hardware_addr[16]

◆ client_ip

uint32_t client_ip

◆ flags

uint16_t flags

◆ hardware_addr_len

uint8_t hardware_addr_len

◆ hardware_type

uint8_t hardware_type

◆ hops

uint8_t hops

◆ op

uint8_t op

◆ options

uint8_t options[128]

◆ relay_agent_ip

uint32_t relay_agent_ip

◆ seconds

uint16_t seconds

◆ server_ip

uint32_t server_ip

◆ server_name

uint8_t server_name[64]

◆ xid

uint32_t xid

◆ your_ip

uint32_t your_ip