Skip to content

Commit eafc084

Browse files
committed
api: document gr_dhcp.h
Add comments for DHCP client state machine states, status structure and API endpoints. Replace informal // STREAM() comment with STREAM_RESP() macro for compile-time type checking. Signed-off-by: Robin Jarry <[email protected]>
1 parent 0ca0c4c commit eafc084

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

modules/dhcp/api/gr_dhcp.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,52 @@
99

1010
#include <stdint.h>
1111

12+
// DHCP client state machine states (RFC 2131).
1213
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).
1920
} dhcp_state_t;
2021

22+
// DHCP client status information for an interface.
2123
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.
2931
};
3032

3133
#define GR_DHCP_MODULE 0xd4c9
3234

33-
// list ////////////////////////////////////////////////////////////////////////
34-
35+
// List all active DHCP clients and their status.
3536
#define GR_DHCP_LIST REQUEST_TYPE(GR_DHCP_MODULE, 0x01)
3637

3738
// struct gr_dhcp_list_req { };
3839

3940
STREAM_RESP(struct gr_dhcp_status);
4041

41-
// start ///////////////////////////////////////////////////////////////////////
42-
42+
// Start DHCP client on an interface.
43+
// Initiates DHCP discovery to obtain IPv4 address configuration.
4344
#define GR_DHCP_START REQUEST_TYPE(GR_DHCP_MODULE, 0x02)
4445

4546
struct gr_dhcp_start_req {
46-
uint16_t iface_id;
47+
uint16_t iface_id; // Interface ID to start DHCP client on.
4748
};
4849

4950
// struct gr_dhcp_start_resp { };
5051

51-
// stop ////////////////////////////////////////////////////////////////////////
52-
52+
// Stop DHCP client on an interface.
53+
// Releases the current lease and removes assigned address.
5354
#define GR_DHCP_STOP REQUEST_TYPE(GR_DHCP_MODULE, 0x03)
5455

5556
struct gr_dhcp_stop_req {
56-
uint16_t iface_id;
57+
uint16_t iface_id; // Interface ID to stop DHCP client on.
5758
};
5859

5960
// struct gr_dhcp_stop_resp { };

0 commit comments

Comments
 (0)