0.01.00
dhcp6.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #ifndef DHCP6_HPP_
35 #define DHCP6_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include "common/message.hpp"
40 #include "net/udp6.hpp"
41 
42 using ot::Encoding::BigEndian::HostSwap16;
43 using ot::Encoding::BigEndian::HostSwap32;
44 
45 namespace ot {
46 namespace Dhcp6 {
47 
63 enum
64 {
65  kDhcpClientPort = 546,
66  kDhcpServerPort = 547,
67  kTransactionIdSize = 3,
68  kLinkLayerAddressLen = 8,
69  kHardwareTypeEui64 = 27,
70 };
71 
76 typedef enum Type
77 {
78  kTypeSolicit = 1,
79  kTypeAdvertise = 2,
80  kTypeRequest = 3,
81  kTypeConfirm = 4,
82  kTypeRenew = 5,
83  kTypeRebind = 6,
84  kTypeReply = 7,
85  kTypeRelease = 8,
86  kTypeDecline = 9,
87  kTypeReconfigure = 10,
88  kTypeInformationRequest = 11,
89  kTypeRelayForward = 12,
90  kTypeRelayReply = 13,
91  kTypeLeaseQuery = 14,
92  kTypeLeaseQueryReply = 15,
93 } Type;
94 
95 
102 {
103 public:
108  void Init(void) { mType = 0; mTransactionId[0] = 0; }
109 
116  Type GetType(void) const { return static_cast<Type>(mType); }
117 
124  void SetType(Type aType) { mType = static_cast<uint8_t>(aType); }
125 
132  uint8_t *GetTransactionId(void) { return mTransactionId; }
133 
140  void SetTransactionId(uint8_t *aBuf) { memcpy(mTransactionId, aBuf, kTransactionIdSize); }
141 
142 private:
143  uint8_t mType;
144  uint8_t mTransactionId[kTransactionIdSize];
146 
151 typedef enum Code
152 {
153  kOptionClientIdentifier = 1,
154  kOptionServerIdentifier = 2,
155  kOptionIaNa = 3,
156  kOptionIaTa = 4,
157  kOptionIaAddress = 5,
158  kOptionRequestOption = 6,
159  kOptionPreference = 7,
160  kOptionElapsedTime = 8,
161  kOptionRelayMessage = 9,
162  kOptionAuthentication = 11,
163  kOptionServerUnicast = 12,
164  kOptionStatusCode = 13,
165  kOptionRapidCommit = 14,
166  kOptionUserClass = 15,
167  kOptionVendorClass = 16,
168  kOptionVendorSpecificInformation = 17,
169  kOptionInterfaceId = 18,
170  kOptionReconfigureMessage = 19,
171  kOptionReconfigureAccept = 20,
172  kOptionLeaseQuery = 44,
173  kOptionClientData = 45,
174  kOptionClientLastTransactionTime = 46,
175 } Code;
176 
183 {
184 public:
189  void Init(void) { mCode = 0; mLength = 0; }
190 
197  Code GetCode(void) const { return static_cast<Code>(HostSwap16(mCode)); }
198 
205  void SetCode(Code aCode) { mCode = HostSwap16(static_cast<uint16_t>(aCode)); }
206 
213  uint16_t GetLength(void) const { return HostSwap16(mLength); }
214 
221  void SetLength(uint16_t aLength) { mLength = HostSwap16(aLength); }
222 
223 private:
224  uint16_t mCode;
225  uint16_t mLength;
227 
232 typedef enum DuidType
233 {
234  kDuidLLT = 1,
235  kDuidEN = 2,
236  kDuidLL = 3,
237 } DuidType;
238 
241 {
242 public:
247  void Init(void) { SetCode(kOptionClientIdentifier); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
248 
255  DuidType GetDuidType(void) const { return static_cast<DuidType>(HostSwap16(mDuidType)); }
256 
263  void SetDuidType(DuidType aDuidType) { mDuidType = HostSwap16(static_cast<uint16_t>(aDuidType)); }
264 
271  uint16_t GetDuidHardwareType(void) const { return HostSwap16(mDuidHardwareType); }
272 
279  void SetDuidHardwareType(uint16_t aDuidHardwareType) { mDuidHardwareType = HostSwap16(aDuidHardwareType); }
280 
287  uint8_t *GetDuidLinkLayerAddress(void) { return mDuidLinkLayerAddress; }
288 
295  void SetDuidLinkLayerAddress(const Mac::ExtAddress *aDuidLinkLayerAddress) { memcpy(mDuidLinkLayerAddress, aDuidLinkLayerAddress, sizeof(Mac::ExtAddress)); }
296 
297 private:
298  uint16_t mDuidType;
299  uint16_t mDuidHardwareType;
300  uint8_t mDuidLinkLayerAddress[kLinkLayerAddressLen];
302 
305 {
306 public:
311  void Init(void) { SetCode(kOptionServerIdentifier); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
312 
319  DuidType GetDuidType(void) const { return static_cast<DuidType>(HostSwap16(mDuidType)); }
320 
327  void SetDuidType(DuidType aDuidType) { mDuidType = HostSwap16(static_cast<uint16_t>(aDuidType)); }
328 
335  uint16_t GetDuidHardwareType(void) const { return HostSwap16(mDuidHardwareType); }
336 
343  void SetDuidHardwareType(uint16_t aDuidHardwareType) { mDuidHardwareType = HostSwap16(aDuidHardwareType); }
344 
351  uint8_t *GetDuidLinkLayerAddress(void) { return mDuidLinkLayerAddress; }
352 
359  void SetDuidLinkLayerAddress(const Mac::ExtAddress *aDuidLinkLayerAddress) { memcpy(mDuidLinkLayerAddress, aDuidLinkLayerAddress, sizeof(Mac::ExtAddress)); }
360 
361 private:
362  uint16_t mDuidType;
363  uint16_t mDuidHardwareType;
364  uint8_t mDuidLinkLayerAddress[kLinkLayerAddressLen];
366 
368 class IaNa: public Dhcp6Option
369 {
370 public:
375  void Init(void) { SetCode(kOptionIaNa); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
376 
383  uint32_t GetIaid(void) const { return HostSwap32(mIaid); }
384 
391  void SetIaid(uint32_t aIaid) { mIaid = HostSwap32(aIaid); }
392 
399  uint32_t GetT1(void) const { return HostSwap32(mT1); }
400 
407  void SetT1(uint32_t aT1) { mT1 = HostSwap32(aT1); }
408 
415  uint32_t GetT2(void) const { return HostSwap32(mT2); }
416 
423  void SetT2(uint32_t aT2) { mT2 = HostSwap32(aT2); }
424 
425 private:
426  uint32_t mIaid;
427  uint32_t mT1;
428  uint32_t mT2;
430 
432 class IaAddress: public Dhcp6Option
433 {
434 public:
439  void Init(void) { SetCode(kOptionIaAddress); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
440 
447  otIp6Address *GetAddress(void) { return &mAddress; }
448 
455  void SetAddress(otIp6Address &aAddress) { memcpy(mAddress.mFields.m8, aAddress.mFields.m8, sizeof(otIp6Address)); }
456 
463  uint32_t GetPreferredLifetime(void) const { return HostSwap32(mPreferredLifetime); }
464 
471  void SetPreferredLifetime(uint32_t aPreferredLifetime) { mPreferredLifetime = HostSwap32(aPreferredLifetime); }
472 
479  uint32_t GetValidLifetime(void) const { return HostSwap32(mValidLifetime); }
480 
487  void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = HostSwap32(aValidLifetime); }
488 
489 private:
490  otIp6Address mAddress;
491  uint32_t mPreferredLifetime;
492  uint32_t mValidLifetime;
494 
497 {
498 public:
503  void Init(void) { SetCode(kOptionElapsedTime); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
504 
511  uint16_t GetElapsedTime(void) const { return HostSwap16(mElapsedTime); }
512 
519  void SetElapsedTime(uint16_t aElapsedTime) { mElapsedTime = HostSwap16(aElapsedTime); }
520 
521 private:
522  uint16_t mElapsedTime;
524 
529 typedef enum Status
530 {
531  kStatusSuccess = 0,
532  kStatusUnspecFail = 1,
533  kStatusNoAddrsAvail = 2,
534  kStatusNoBinding = 3,
535  kStatusNotOnLink = 4,
536  kStatusUseMulticast = 5,
537  kUnknownQueryType = 7,
538  kMalformedQuery = 8,
539  kNotConfigured = 9,
540  kNotAllowed = 10,
541 } Status;
542 
544 class StatusCode: public Dhcp6Option
545 {
546 public:
551  void Init(void) { SetCode(kOptionStatusCode); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
552 
559  Status GetStatusCode(void) const { return static_cast<Status>(HostSwap16(mStatus)); }
560 
567  void SetStatusCode(Status aStatus) { mStatus = HostSwap16(static_cast<uint16_t>(aStatus)); }
568 
569 private:
570  uint16_t mStatus;
572 
575 {
576 public:
581  void Init(void) { SetCode(kOptionRapidCommit); SetLength(sizeof(*this) - sizeof(Dhcp6Option)); }
583 
584 } // namespace Dhcp6
585 } // namespace ot
586 
587 #endif // DHCP6_HPP_
Code
DHCPv6 Option Codes.
Definition: dhcp6.hpp:151
void SetT1(uint32_t aT1)
This method sets the value of T1.
Definition: dhcp6.hpp:407
This structure represents an IPv6 address.
Definition: types.h:417
void SetDuidType(DuidType aDuidType)
This method sets the server Duid Type.
Definition: dhcp6.hpp:327
union otIp6Address::OT_TOOL_PACKED_FIELD mFields
IPv6 accessor fields.
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:375
This class implements DHCPv6 header.
Definition: dhcp6.hpp:101
Definition: cli.cpp:90
void SetPreferredLifetime(uint32_t aPreferredLifetime)
This method sets the preferred lifetime of the IPv6 address.
Definition: dhcp6.hpp:471
void SetIaid(uint32_t aIaid)
This method sets the client IAID.
Definition: dhcp6.hpp:391
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:247
Type GetType(void) const
This method returns the DHCPv6 message type.
Definition: dhcp6.hpp:116
Type
DHCPv6 Message Types.
Definition: dhcp6.hpp:76
void SetElapsedTime(uint16_t aElapsedTime)
This method sets the elapsed time since solicit starts.
Definition: dhcp6.hpp:519
Definition: dhcp6.hpp:304
uint32_t GetValidLifetime(void) const
This method returns the valid lifetime of the IPv6 address.
Definition: dhcp6.hpp:479
void SetDuidHardwareType(uint16_t aDuidHardwareType)
This method sets the server Duid HardwareType.
Definition: dhcp6.hpp:343
uint32_t GetPreferredLifetime(void) const
This method returns the preferred lifetime of the IPv6 address.
Definition: dhcp6.hpp:463
void SetValidLifetime(uint32_t aValidLifetime)
This method sets the valid lifetime of the IPv6 address.
Definition: dhcp6.hpp:487
DuidType
Duid Type.
Definition: dhcp6.hpp:232
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:581
#define OT_TOOL_PACKED_BEGIN
Compiler-specific indication that a class or struct must be byte packed.
Definition: toolchain.h:170
uint32_t GetT1(void) const
This method returns T1.
Definition: dhcp6.hpp:399
Definition: dhcp6.hpp:240
uint32_t GetIaid(void) const
This method returns client IAID.
Definition: dhcp6.hpp:383
void Init(void)
This method initializes the DHCPv6 header to all zeros.
Definition: dhcp6.hpp:108
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:503
Status GetStatusCode(void) const
This method returns the status code.
Definition: dhcp6.hpp:559
DuidType GetDuidType(void) const
This method returns the client Duid Type.
Definition: dhcp6.hpp:255
This file includes definitions for UDP/IPv6 sockets.
This structure represents an IEEE 802.15.4 Extended Address.
Definition: mac_frame.hpp:84
uint16_t GetElapsedTime(void) const
This method returns the elapsed time since solicit starts.
Definition: dhcp6.hpp:511
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:439
Definition: dhcp6.hpp:544
enum ot::Dhcp6::Code Code
DHCPv6 Option Codes.
uint16_t GetDuidHardwareType(void) const
This method returns the server Duid HardwareType.
Definition: dhcp6.hpp:335
DuidType GetDuidType(void) const
This method returns the server Duid Type.
Definition: dhcp6.hpp:319
Code GetCode(void) const
This method returns the DHCPv6 option code.
Definition: dhcp6.hpp:197
void SetTransactionId(uint8_t *aBuf)
This method sets the DHCPv6 message transaction id.
Definition: dhcp6.hpp:140
void SetAddress(otIp6Address &aAddress)
This method sets the IPv6 address.
Definition: dhcp6.hpp:455
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:551
void SetDuidHardwareType(uint16_t aDuidHardwareType)
This method sets the client Duid HardwareType.
Definition: dhcp6.hpp:279
uint8_t m8[OT_IP6_ADDRESS_SIZE]
8-bit fields
Definition: types.h:421
This file includes definitions for the message buffer pool and message buffers.
void SetDuidType(DuidType aDuidType)
This method sets the client Duid Type.
Definition: dhcp6.hpp:263
uint8_t * GetDuidLinkLayerAddress(void)
This method returns the client LinkLayerAddress.
Definition: dhcp6.hpp:287
uint32_t GetT2(void) const
This method returns T2.
Definition: dhcp6.hpp:415
uint8_t * GetDuidLinkLayerAddress(void)
This method returns the server LinkLayerAddress.
Definition: dhcp6.hpp:351
void SetDuidLinkLayerAddress(const Mac::ExtAddress *aDuidLinkLayerAddress)
This method sets the server LinkLayerAddress.
Definition: dhcp6.hpp:359
#define OT_TOOL_PACKED_END
Compiler-specific indication at the end of a byte packed class or struct.
Definition: toolchain.h:172
void SetDuidLinkLayerAddress(const Mac::ExtAddress *aDuidLinkLayerAddress)
This method sets the client LinkLayerAddress.
Definition: dhcp6.hpp:295
void SetStatusCode(Status aStatus)
This method sets the status code.
Definition: dhcp6.hpp:567
Definition: dhcp6.hpp:368
enum ot::Dhcp6::DuidType DuidType
Duid Type.
uint16_t GetLength(void) const
This method returns the Length of DHCPv6 option.
Definition: dhcp6.hpp:213
otIp6Address * GetAddress(void)
This method returns the pointer to the IPv6 address.
Definition: dhcp6.hpp:447
Definition: dhcp6.hpp:432
void SetT2(uint32_t aT2)
This method sets the value of T2.
Definition: dhcp6.hpp:423
void Init(void)
This method initializes the DHCPv6 option to all zeros.
Definition: dhcp6.hpp:189
Definition: dhcp6.hpp:574
Definition: dhcp6.hpp:496
uint8_t * GetTransactionId(void)
This method returns the DHCPv6 message transaction id.
Definition: dhcp6.hpp:132
enum ot::Dhcp6::Status Status
Status Code.
void SetLength(uint16_t aLength)
This method sets the length of DHCPv6 option.
Definition: dhcp6.hpp:221
void SetType(Type aType)
This method sets the DHCPv6 message type.
Definition: dhcp6.hpp:124
uint16_t GetDuidHardwareType(void) const
This method returns the client Duid HardwareType.
Definition: dhcp6.hpp:271
void SetCode(Code aCode)
This method sets the DHCPv6 option code.
Definition: dhcp6.hpp:205
Status
Status Code.
Definition: dhcp6.hpp:529
enum ot::Dhcp6::Type Type
DHCPv6 Message Types.
This file includes compile-time configuration constants for OpenThread.
void Init(void)
This method initializes the DHCPv6 Option.
Definition: dhcp6.hpp:311
This class implements DHCPv6 option.
Definition: dhcp6.hpp:182