|
9 | 9 |
|
10 | 10 | #include <stdint.h> |
11 | 11 |
|
| 12 | +// DHCP client state machine states (RFC 2131). |
12 | 13 | typedef enum dhcp_state : uint8_t { |
13 | | - DHCP_STATE_INIT = 0, |
14 | | - DHCP_STATE_SELECTING, |
15 | | - DHCP_STATE_REQUESTING, |
16 | | - DHCP_STATE_BOUND, |
17 | | - DHCP_STATE_RENEWING, |
18 | | - DHCP_STATE_REBINDING, |
| 14 | + DHCP_STATE_INIT = 0, // Initial state, no configuration. |
| 15 | + DHCP_STATE_SELECTING, // Waiting for DHCPOFFER messages. |
| 16 | + DHCP_STATE_REQUESTING, // Waiting for DHCPACK message. |
| 17 | + DHCP_STATE_BOUND, // Lease acquired and valid. |
| 18 | + DHCP_STATE_RENEWING, // Renewing lease with original server (T1 expired). |
| 19 | + DHCP_STATE_REBINDING, // Rebinding with any server (T2 expired). |
19 | 20 | } dhcp_state_t; |
20 | 21 |
|
| 22 | +// DHCP client status information for an interface. |
21 | 23 | struct gr_dhcp_status { |
22 | | - uint16_t iface_id; |
23 | | - dhcp_state_t state; |
24 | | - ip4_addr_t server_ip; |
25 | | - ip4_addr_t assigned_ip; |
26 | | - uint32_t lease_time; |
27 | | - uint32_t renewal_time; // T1 |
28 | | - uint32_t rebind_time; // T2 |
| 24 | + uint16_t iface_id; // Interface ID running DHCP client. |
| 25 | + dhcp_state_t state; // Current DHCP state. |
| 26 | + ip4_addr_t server_ip; // DHCP server IPv4 address. |
| 27 | + ip4_addr_t assigned_ip; // Assigned IPv4 address. |
| 28 | + uint32_t lease_time; // Lease duration in seconds. |
| 29 | + uint32_t renewal_time; // Renewal time (T1) in seconds. |
| 30 | + uint32_t rebind_time; // Rebinding time (T2) in seconds. |
29 | 31 | }; |
30 | 32 |
|
31 | 33 | #define GR_DHCP_MODULE 0xd4c9 |
32 | 34 |
|
33 | | -// list //////////////////////////////////////////////////////////////////////// |
34 | | - |
| 35 | +// List all active DHCP clients and their status. |
35 | 36 | #define GR_DHCP_LIST REQUEST_TYPE(GR_DHCP_MODULE, 0x01) |
36 | 37 |
|
37 | 38 | // struct gr_dhcp_list_req { }; |
38 | 39 |
|
39 | 40 | STREAM_RESP(struct gr_dhcp_status); |
40 | 41 |
|
41 | | -// start /////////////////////////////////////////////////////////////////////// |
42 | | - |
| 42 | +// Start DHCP client on an interface. |
| 43 | +// Initiates DHCP discovery to obtain IPv4 address configuration. |
43 | 44 | #define GR_DHCP_START REQUEST_TYPE(GR_DHCP_MODULE, 0x02) |
44 | 45 |
|
45 | 46 | struct gr_dhcp_start_req { |
46 | | - uint16_t iface_id; |
| 47 | + uint16_t iface_id; // Interface ID to start DHCP client on. |
47 | 48 | }; |
48 | 49 |
|
49 | 50 | // struct gr_dhcp_start_resp { }; |
50 | 51 |
|
51 | | -// stop //////////////////////////////////////////////////////////////////////// |
52 | | - |
| 52 | +// Stop DHCP client on an interface. |
| 53 | +// Releases the current lease and removes assigned address. |
53 | 54 | #define GR_DHCP_STOP REQUEST_TYPE(GR_DHCP_MODULE, 0x03) |
54 | 55 |
|
55 | 56 | struct gr_dhcp_stop_req { |
56 | | - uint16_t iface_id; |
| 57 | + uint16_t iface_id; // Interface ID to stop DHCP client on. |
57 | 58 | }; |
58 | 59 |
|
59 | 60 | // struct gr_dhcp_stop_resp { }; |
0 commit comments