Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dhcpv4.h
Go to the documentation of this file.
1
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
35enum net_dhcpv4_state {
36 NET_DHCPV4_DISABLED,
37 NET_DHCPV4_INIT,
38 NET_DHCPV4_SELECTING,
39 NET_DHCPV4_REQUESTING,
40 NET_DHCPV4_RENEWING,
41 NET_DHCPV4_REBINDING,
42 NET_DHCPV4_BOUND,
43 NET_DHCPV4_DECLINE,
44} __packed;
45
67
68struct net_dhcpv4_option_callback;
69
85typedef void (*net_dhcpv4_option_callback_handler_t)(struct net_dhcpv4_option_callback *cb,
86 size_t length,
87 enum net_dhcpv4_msg_type msg_type,
88 struct net_if *iface);
89
102struct net_dhcpv4_option_callback {
106 sys_snode_t node;
107
110
112 uint8_t option;
113
115 size_t max_length;
116
120 void *data;
121};
122
133static inline void net_dhcpv4_init_option_callback(struct net_dhcpv4_option_callback *callback,
135 uint8_t option,
136 void *data,
137 size_t max_length)
138{
139 __ASSERT(callback, "Callback pointer should not be NULL");
140 __ASSERT(handler, "Callback handler pointer should not be NULL");
141 __ASSERT(data, "Data pointer should not be NULL");
142
143 callback->handler = handler;
144 callback->option = option;
145 callback->data = data;
146 callback->max_length = max_length;
147}
148
154int net_dhcpv4_add_option_callback(struct net_dhcpv4_option_callback *cb);
155
161int net_dhcpv4_remove_option_callback(struct net_dhcpv4_option_callback *cb);
162
172static inline void
173net_dhcpv4_init_option_vendor_callback(struct net_dhcpv4_option_callback *callback,
175 void *data, size_t max_length)
176{
177 __ASSERT(callback, "Callback pointer should not be NULL");
178 __ASSERT(handler, "Callback handler pointer should not be NULL");
179 __ASSERT(data, "Data pointer should not be NULL");
180
181 callback->handler = handler;
182 callback->option = option;
183 callback->data = data;
184 callback->max_length = max_length;
185}
186
192int net_dhcpv4_add_option_vendor_callback(struct net_dhcpv4_option_callback *cb);
193
199int net_dhcpv4_remove_option_vendor_callback(struct net_dhcpv4_option_callback *cb);
200
210void net_dhcpv4_start(struct net_if *iface);
211
221void net_dhcpv4_stop(struct net_if *iface);
222
232void net_dhcpv4_restart(struct net_if *iface);
233
241const char *net_dhcpv4_state_name(enum net_dhcpv4_state state);
242
252
257#ifdef __cplusplus
258}
259#endif
260
261#endif /* ZEPHYR_INCLUDE_NET_DHCPV4_H_ */
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.
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:133
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:57
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:85
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:173
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:60
@ NET_DHCPV4_MSG_TYPE_ACK
Acknowledge message.
Definition dhcpv4.h:62
@ NET_DHCPV4_MSG_TYPE_OFFER
Offer message.
Definition dhcpv4.h:59
@ NET_DHCPV4_MSG_TYPE_RELEASE
Release message.
Definition dhcpv4.h:64
@ NET_DHCPV4_MSG_TYPE_NAK
Negative acknowledge message.
Definition dhcpv4.h:63
@ NET_DHCPV4_MSG_TYPE_DISCOVER
Discover message.
Definition dhcpv4.h:58
@ NET_DHCPV4_MSG_TYPE_INFORM
Inform message.
Definition dhcpv4.h:65
@ NET_DHCPV4_MSG_TYPE_DECLINE
Decline message.
Definition dhcpv4.h:61
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
state
Definition parser_state.h:29
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Network Interface structure.
Definition net_if.h:678
static fdata_t data[2]
Definition test_fifo_contexts.c:15
static void handler(struct k_timer *timer)
Definition main.c:19