#ifndef DHCP6_HPP_
#define DHCP6_HPP_
#include "openthread-core-config.h"
#include "common/message.hpp"
#include "net/udp6.hpp"
namespace ot {
namespace Dhcp6 {
using ot::Encoding::BigEndian::HostSwap16;
using ot::Encoding::BigEndian::HostSwap32;
enum
{
kDhcpClientPort = 546,
kDhcpServerPort = 547,
kTransactionIdSize = 3,
kLinkLayerAddressLen = 8,
kHardwareTypeEui64 = 27,
kHardwareTypeEthernet = 1,
kLinkLayerAddressPlusLen = 6,
};
typedef enum Type
{
kTypeSolicit = 1,
kTypeAdvertise = 2,
kTypeRequest = 3,
kTypeConfirm = 4,
kTypeRenew = 5,
kTypeRebind = 6,
kTypeReply = 7,
kTypeRelease = 8,
kTypeDecline = 9,
kTypeReconfigure = 10,
kTypeInformationRequest = 11,
kTypeRelayForward = 12,
kTypeRelayReply = 13,
kTypeLeaseQuery = 14,
kTypeLeaseQueryReply = 15,
} Type;
OT_TOOL_PACKED_BEGIN
class Dhcp6Header
{
public:
void Init(void)
{
mType = 0;
mTransactionId[0] = 0;
}
Type GetType(void) const { return static_cast<Type>(mType); }
void SetType(Type aType) { mType = static_cast<uint8_t>(aType); }
uint8_t *GetTransactionId(void) { return mTransactionId; }
void SetTransactionId(uint8_t *aBuf) { memcpy(mTransactionId, aBuf, kTransactionIdSize); }
private:
uint8_t mType; uint8_t mTransactionId[kTransactionIdSize]; } OT_TOOL_PACKED_END;
typedef enum Code
{
kOptionClientIdentifier = 1,
kOptionServerIdentifier = 2,
kOptionIaNa = 3,
kOptionIaTa = 4,
kOptionIaAddress = 5,
kOptionRequestOption = 6,
kOptionPreference = 7,
kOptionElapsedTime = 8,
kOptionRelayMessage = 9,
kOptionAuthentication = 11,
kOptionServerUnicast = 12,
kOptionStatusCode = 13,
kOptionRapidCommit = 14,
kOptionUserClass = 15,
kOptionVendorClass = 16,
kOptionVendorSpecificInformation = 17,
kOptionInterfaceId = 18,
kOptionReconfigureMessage = 19,
kOptionReconfigureAccept = 20,
kOptionLeaseQuery = 44,
kOptionClientData = 45,
kOptionClientLastTransactionTime = 46,
} Code;
OT_TOOL_PACKED_BEGIN
class Dhcp6Option
{
public:
void Init(void)
{
mCode = 0;
mLength = 0;
}
Code GetCode(void) const { return static_cast<Code>(HostSwap16(mCode)); }
void SetCode(Code aCode) { mCode = HostSwap16(static_cast<uint16_t>(aCode)); }
uint16_t GetLength(void) const { return HostSwap16(mLength); }
void SetLength(uint16_t aLength) { mLength = HostSwap16(aLength); }
private:
uint16_t mCode; uint16_t mLength; } OT_TOOL_PACKED_END;
typedef enum DuidType
{
kDuidLLT = 1,
kDuidEN = 2,
kDuidLL = 3,
} DuidType;
OT_TOOL_PACKED_BEGIN
class ClientIdentifier : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionClientIdentifier);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
DuidType GetDuidType(void) const { return static_cast<DuidType>(HostSwap16(mDuidType)); }
void SetDuidType(DuidType aDuidType) { mDuidType = HostSwap16(static_cast<uint16_t>(aDuidType)); }
uint16_t GetDuidHardwareType(void) const { return HostSwap16(mDuidHardwareType); }
void SetDuidHardwareType(uint16_t aDuidHardwareType) { mDuidHardwareType = HostSwap16(aDuidHardwareType); }
uint8_t *GetDuidLinkLayerAddress(void) { return mDuidLinkLayerAddress; }
void SetDuidLinkLayerAddress(const Mac::ExtAddress &aDuidLinkLayerAddress)
{
memcpy(mDuidLinkLayerAddress, &aDuidLinkLayerAddress, sizeof(Mac::ExtAddress));
}
private:
uint16_t mDuidType; uint16_t mDuidHardwareType; uint8_t mDuidLinkLayerAddress[kLinkLayerAddressLen]; } OT_TOOL_PACKED_END;
OT_TOOL_PACKED_BEGIN
class ServerIdentifier : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionServerIdentifier);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
DuidType GetDuidType(void) const { return static_cast<DuidType>(HostSwap16(mDuidType)); }
void SetDuidType(DuidType aDuidType) { mDuidType = HostSwap16(static_cast<uint16_t>(aDuidType)); }
uint16_t GetDuidHardwareType(void) const { return HostSwap16(mDuidHardwareType); }
void SetDuidHardwareType(uint16_t aDuidHardwareType) { mDuidHardwareType = HostSwap16(aDuidHardwareType); }
uint8_t *GetDuidLinkLayerAddress(void) { return mDuidLinkLayerAddress; }
void SetDuidLinkLayerAddress(const Mac::ExtAddress &aDuidLinkLayerAddress)
{
memcpy(mDuidLinkLayerAddress, &aDuidLinkLayerAddress, sizeof(Mac::ExtAddress));
}
private:
uint16_t mDuidType; uint16_t mDuidHardwareType; uint8_t mDuidLinkLayerAddress[kLinkLayerAddressLen]; } OT_TOOL_PACKED_END;
OT_TOOL_PACKED_BEGIN
class IaNa : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionIaNa);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
uint32_t GetIaid(void) const { return HostSwap32(mIaid); }
void SetIaid(uint32_t aIaid) { mIaid = HostSwap32(aIaid); }
uint32_t GetT1(void) const { return HostSwap32(mT1); }
void SetT1(uint32_t aT1) { mT1 = HostSwap32(aT1); }
uint32_t GetT2(void) const { return HostSwap32(mT2); }
void SetT2(uint32_t aT2) { mT2 = HostSwap32(aT2); }
private:
uint32_t mIaid; uint32_t mT1; uint32_t mT2; } OT_TOOL_PACKED_END;
OT_TOOL_PACKED_BEGIN
class IaAddress : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionIaAddress);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
Ip6::Address &GetAddress(void) { return mAddress; }
void SetAddress(otIp6Address &aAddress) { memcpy(mAddress.mFields.m8, aAddress.mFields.m8, sizeof(otIp6Address)); }
uint32_t GetPreferredLifetime(void) const { return HostSwap32(mPreferredLifetime); }
void SetPreferredLifetime(uint32_t aPreferredLifetime) { mPreferredLifetime = HostSwap32(aPreferredLifetime); }
uint32_t GetValidLifetime(void) const { return HostSwap32(mValidLifetime); }
void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = HostSwap32(aValidLifetime); }
private:
Ip6::Address mAddress; uint32_t mPreferredLifetime; uint32_t mValidLifetime; } OT_TOOL_PACKED_END;
OT_TOOL_PACKED_BEGIN
class ElapsedTime : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionElapsedTime);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
uint16_t GetElapsedTime(void) const { return HostSwap16(mElapsedTime); }
void SetElapsedTime(uint16_t aElapsedTime) { mElapsedTime = HostSwap16(aElapsedTime); }
private:
uint16_t mElapsedTime; } OT_TOOL_PACKED_END;
typedef enum Status
{
kStatusSuccess = 0,
kStatusUnspecFail = 1,
kStatusNoAddrsAvail = 2,
kStatusNoBinding = 3,
kStatusNotOnLink = 4,
kStatusUseMulticast = 5,
kUnknownQueryType = 7,
kMalformedQuery = 8,
kNotConfigured = 9,
kNotAllowed = 10,
} Status;
OT_TOOL_PACKED_BEGIN
class StatusCode : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionStatusCode);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
Status GetStatusCode(void) const { return static_cast<Status>(HostSwap16(mStatus)); }
void SetStatusCode(Status aStatus) { mStatus = HostSwap16(static_cast<uint16_t>(aStatus)); }
private:
uint16_t mStatus; } OT_TOOL_PACKED_END;
OT_TOOL_PACKED_BEGIN
class RapidCommit : public Dhcp6Option
{
public:
void Init(void)
{
SetCode(kOptionRapidCommit);
SetLength(sizeof(*this) - sizeof(Dhcp6Option));
}
} OT_TOOL_PACKED_END;
} }
#endif