Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dhcpv4.h
Go to the documentation of this file.
1
4
5/*
6 * Copyright (c) 2016 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11#ifndef ZEPHYR_INCLUDE_NET_DHCPV4_H_
12#define ZEPHYR_INCLUDE_NET_DHCPV4_H_
13
14#include <zephyr/sys/slist.h>
15#include <zephyr/types.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
29
31
37enum net_dhcpv4_state {
38 NET_DHCPV4_DISABLED,
39 NET_DHCPV4_INIT,
40 NET_DHCPV4_INIT_REBOOT,
41 NET_DHCPV4_SELECTING,
42 NET_DHCPV4_REQUESTING,
43 NET_DHCPV4_RENEWING,
44 NET_DHCPV4_REBINDING,
45 NET_DHCPV4_BOUND,
46 NET_DHCPV4_DECLINE,
47} __packed;
48
50
70
71struct net_dhcpv4_option_callback;
72struct net_in_addr;
73
89typedef void (*net_dhcpv4_option_callback_handler_t)(struct net_dhcpv4_option_callback *cb,
90 size_t length,
91 enum net_dhcpv4_msg_type msg_type,
92 struct net_if *iface);
93
95
106struct net_dhcpv4_option_callback {
110 sys_snode_t node;
111
114
116 uint8_t option;
117
119 size_t max_length;
120
124 void *data;
125};
126
128
137static inline void net_dhcpv4_init_option_callback(struct net_dhcpv4_option_callback *callback,
139 uint8_t option,
140 void *data,
141 size_t max_length)
142{
143 __ASSERT(callback, "Callback pointer should not be NULL");
144 __ASSERT(handler, "Callback handler pointer should not be NULL");
145 __ASSERT(data, "Data pointer should not be NULL");
146
147 callback->handler = handler;
148 callback->option = option;
149 callback->data = data;
150 callback->max_length = max_length;
151}
152
158int net_dhcpv4_add_option_callback(struct net_dhcpv4_option_callback *cb);
159
165int net_dhcpv4_remove_option_callback(struct net_dhcpv4_option_callback *cb);
166
176static inline void
177net_dhcpv4_init_option_vendor_callback(struct net_dhcpv4_option_callback *callback,
179 void *data, size_t max_length)
180{
181 __ASSERT(callback, "Callback pointer should not be NULL");
182 __ASSERT(handler, "Callback handler pointer should not be NULL");
183 __ASSERT(data, "Data pointer should not be NULL");
184
185 callback->handler = handler;
186 callback->option = option;
187 callback->data = data;
188 callback->max_length = max_length;
189}
190
196int net_dhcpv4_add_option_vendor_callback(struct net_dhcpv4_option_callback *cb);
197
203int net_dhcpv4_remove_option_vendor_callback(struct net_dhcpv4_option_callback *cb);
204
214void net_dhcpv4_start(struct net_if *iface);
215
225void net_dhcpv4_stop(struct net_if *iface);
226
236void net_dhcpv4_restart(struct net_if *iface);
237
258 const struct net_in_addr *requested_ip);
259
261
267const char *net_dhcpv4_state_name(enum net_dhcpv4_state state);
268
270
278
282
283#ifdef __cplusplus
284}
285#endif
286
287#endif /* ZEPHYR_INCLUDE_NET_DHCPV4_H_ */
int net_dhcpv4_set_reboot_hint(struct net_if *iface, const struct net_in_addr *requested_ip)
Set the address requested in INIT-REBOOT.
int net_dhcpv4_remove_option_vendor_callback(struct net_dhcpv4_option_callback *cb)
Remove an application callback for encapsulated vendor-specific options.
const char * net_dhcpv4_msg_type_name(enum net_dhcpv4_msg_type msg_type)
Return a text representation of the msg_type.
void net_dhcpv4_restart(struct net_if *iface)
Restart DHCPv4 client on an iface.
void(* net_dhcpv4_option_callback_handler_t)(struct net_dhcpv4_option_callback *cb, size_t length, enum net_dhcpv4_msg_type msg_type, struct net_if *iface)
Define the application callback handler function signature.
Definition dhcpv4.h:89
static void net_dhcpv4_init_option_callback(struct net_dhcpv4_option_callback *callback, net_dhcpv4_option_callback_handler_t handler, uint8_t option, void *data, size_t max_length)
Helper to initialize a struct net_dhcpv4_option_callback properly.
Definition dhcpv4.h:137
void net_dhcpv4_stop(struct net_if *iface)
Stop DHCPv4 client on an iface.
int net_dhcpv4_remove_option_callback(struct net_dhcpv4_option_callback *cb)
Remove an application callback.
int net_dhcpv4_add_option_vendor_callback(struct net_dhcpv4_option_callback *cb)
Add an application callback for encapsulated vendor-specific options.
net_dhcpv4_msg_type
DHCPv4 message types.
Definition dhcpv4.h:60
static void net_dhcpv4_init_option_vendor_callback(struct net_dhcpv4_option_callback *callback, net_dhcpv4_option_callback_handler_t handler, uint8_t option, void *data, size_t max_length)
Helper to initialize a struct net_dhcpv4_option_callback for encapsulated vendor-specific options pro...
Definition dhcpv4.h:177
int net_dhcpv4_add_option_callback(struct net_dhcpv4_option_callback *cb)
Add an application callback.
void net_dhcpv4_start(struct net_if *iface)
Start DHCPv4 client on an iface.
@ NET_DHCPV4_MSG_TYPE_REQUEST
Request message.
Definition dhcpv4.h:63
@ NET_DHCPV4_MSG_TYPE_ACK
Acknowledge message.
Definition dhcpv4.h:65
@ NET_DHCPV4_MSG_TYPE_OFFER
Offer message.
Definition dhcpv4.h:62
@ NET_DHCPV4_MSG_TYPE_RELEASE
Release message.
Definition dhcpv4.h:67
@ NET_DHCPV4_MSG_TYPE_NAK
Negative acknowledge message.
Definition dhcpv4.h:66
@ NET_DHCPV4_MSG_TYPE_DISCOVER
Discover message.
Definition dhcpv4.h:61
@ NET_DHCPV4_MSG_TYPE_INFORM
Inform message.
Definition dhcpv4.h:68
@ NET_DHCPV4_MSG_TYPE_DECLINE
Decline message.
Definition dhcpv4.h:64
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:42
state
Definition parser_state.h:29
Header file for the single-linked list API.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Network Interface structure.
Definition net_if.h:744
IPv4 address struct.
Definition net_ip.h:156