1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /** @file
8  *  @brief DHCPv6 client
9  */
10 
11 #ifndef ZEPHYR_INCLUDE_NET_DHCPV6_H_
12 #define ZEPHYR_INCLUDE_NET_DHCPV6_H_
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /**
19  * @brief DHCPv6
20  * @defgroup dhcpv6 DHCPv6
21  * @since 3.5
22  * @version 0.8.0
23  * @ingroup networking
24  * @{
25  */
26 
27 /** @cond INTERNAL_HIDDEN */
28 
29 /** Current state of DHCPv6 client address/prefix negotiation. */
30 enum net_dhcpv6_state {
31 	NET_DHCPV6_DISABLED,
32 	NET_DHCPV6_INIT,
33 	NET_DHCPV6_SOLICITING,
34 	NET_DHCPV6_REQUESTING,
35 	NET_DHCPV6_CONFIRMING,
36 	NET_DHCPV6_RENEWING,
37 	NET_DHCPV6_REBINDING,
38 	NET_DHCPV6_INFO_REQUESTING,
39 	NET_DHCPV6_BOUND,
40 } __packed;
41 
42 #define DHCPV6_TID_SIZE 3
43 
44 #ifndef CONFIG_NET_DHCPV6_DUID_MAX_LEN
45 #define CONFIG_NET_DHCPV6_DUID_MAX_LEN 22
46 #endif
47 
48 struct net_dhcpv6_duid_raw {
49 	uint16_t type;
50 	uint8_t buf[CONFIG_NET_DHCPV6_DUID_MAX_LEN];
51 } __packed;
52 
53 struct net_dhcpv6_duid_storage {
54 	struct net_dhcpv6_duid_raw duid;
55 	uint8_t length;
56 };
57 
58 struct net_if;
59 
60 /** @endcond */
61 
62 /** @brief DHCPv6 client configuration parameters. */
63 struct net_dhcpv6_params {
64 	bool request_addr : 1; /**< Request IPv6 address. */
65 	bool request_prefix : 1; /**< Request IPv6 prefix. */
66 };
67 
68 /**
69  *  @brief Start DHCPv6 client on an iface
70  *
71  *  @details Start DHCPv6 client on a given interface. DHCPv6 client will start
72  *  negotiation for IPv6 address and/or prefix, depending on the configuration.
73  *  Once the negotiation is complete, IPv6 address/prefix details will be added
74  *  to the interface.
75  *
76  *  @param iface A valid pointer to a network interface
77  *  @param params DHCPv6 client configuration parameters.
78  */
79 void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params);
80 
81 /**
82  *  @brief Stop DHCPv6 client on an iface
83  *
84  *  @details Stop DHCPv6 client on a given interface. DHCPv6 client
85  *  will remove all configuration obtained from a DHCP server from the
86  *  interface and stop any further negotiation with the server.
87  *
88  *  @param iface A valid pointer to a network interface
89  */
90 void net_dhcpv6_stop(struct net_if *iface);
91 
92 /**
93  *  @brief Restart DHCPv6 client on an iface
94  *
95  *  @details Restart DHCPv6 client on a given interface. DHCPv6 client
96  *  will restart the state machine without any of the initial delays.
97  *
98  *  @param iface A valid pointer to a network interface
99  */
100 void net_dhcpv6_restart(struct net_if *iface);
101 
102 /** @cond INTERNAL_HIDDEN */
103 
104 /**
105  *  @brief DHCPv6 state name
106  *
107  *  @internal
108  */
109 const char *net_dhcpv6_state_name(enum net_dhcpv6_state state);
110 
111 /** @endcond */
112 
113 /**
114  * @}
115  */
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif /* ZEPHYR_INCLUDE_NET_DHCPV6_H_ */
122