1/* 2 * Copyright (c) 2009-2013 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * DHCPDUID.h 26 * - definition of DHCP DUID 27 */ 28 29/* 30 * Modification History 31 * 32 * September 30, 2009 Dieter Siegmund (dieter@apple.com) 33 * - created 34 */ 35 36#ifndef _S_DHCPDUID_H 37#define _S_DHCPDUID_H 38 39#include <stdio.h> 40#include <stdint.h> 41#include <stdbool.h> 42#include <arpa/inet.h> 43#include <CoreFoundation/CFString.h> 44#include "nbo.h" 45#include "symbol_scope.h" 46 47enum { 48 kDHCPDUIDTypeNone = 0, 49 kDHCPDUIDTypeLLT = 1, 50 kDHCPDUIDTypeEN = 2, 51 kDHCPDUIDTypeLL = 3 52}; 53 54typedef int DHCPDUIDType; 55 56typedef struct { 57 uint8_t duid_type[2]; /* 1 */ 58 uint8_t hardware_type[2]; 59 uint8_t time[4]; /* seconds since midnight UTC 2000/01/01 */ 60 uint8_t linklayer_address[1]; /* variable length */ 61} DHCPDUID_LLT, * DHCPDUID_LLTRef; 62 63typedef struct { 64 uint8_t duid_type[2]; /* 2 */ 65 uint8_t enterprise_number[4]; 66 uint8_t identifier[1]; /* variable length */ 67} DHCPDUID_EN, * DHCPDUID_ENRef; 68 69typedef struct { 70 uint8_t duid_type[2]; /* 3 */ 71 uint8_t hardware_type[2]; 72 uint8_t linklayer_address[1]; /* variable length */ 73} DHCPDUID_LL, * DHCPDUID_LLRef; 74 75typedef union { 76 DHCPDUID_LLT llt; 77 DHCPDUID_EN en; 78 DHCPDUID_LL ll; 79} DHCPDUID, * DHCPDUIDRef; 80 81 82INLINE uint16_t 83DHCPDUIDGetType(const DHCPDUIDRef duid) 84{ 85 return (net_uint16_get(duid->llt.duid_type)); 86} 87 88INLINE void 89DHCPDUIDSetType(DHCPDUIDRef duid, uint16_t duid_type) 90{ 91 net_uint16_set(duid->llt.duid_type, duid_type); 92 return; 93} 94 95void 96DHCPDUIDPrintToString(CFMutableStringRef str, 97 const DHCPDUIDRef duid, int duid_len); 98 99INLINE uint16_t 100DHCPDUID_LLTGetHardwareType(const DHCPDUID_LLTRef llt) 101{ 102 return (net_uint16_get(llt->hardware_type)); 103 104} 105 106INLINE void 107DHCPDUID_LLTSetHardwareType(DHCPDUID_LLTRef llt, uint16_t hardware_type) 108{ 109 net_uint16_set(llt->hardware_type, hardware_type); 110 return; 111} 112 113INLINE uint32_t 114DHCPDUID_LLTGetTime(const DHCPDUID_LLTRef llt) 115{ 116 return (net_uint32_get(llt->time)); 117 118} 119 120INLINE void 121DHCPDUID_LLTSetTime(DHCPDUID_LLTRef llt, uint32_t time) 122{ 123 net_uint32_set(llt->time, time); 124 return; 125} 126 127INLINE uint16_t 128DHCPDUID_ENGetEnterpriseNumber(const DHCPDUID_ENRef en) 129{ 130 return (net_uint32_get(en->enterprise_number)); 131 132} 133 134INLINE void 135DHCPDUID_ENSetEnterpriseNumber(DHCPDUID_ENRef en, uint32_t ent_num) 136{ 137 net_uint32_set(en->enterprise_number, ent_num); 138 return; 139} 140 141INLINE uint16_t 142DHCPDUID_LLGetHardwareType(const DHCPDUID_LLRef ll) 143{ 144 return (net_uint16_get(ll->hardware_type)); 145 146} 147 148INLINE void 149DHCPDUID_LLSetHardwareType(DHCPDUID_LLRef ll, uint16_t hardware_type) 150{ 151 net_uint16_set(ll->hardware_type, hardware_type); 152 return; 153} 154 155bool 156DHCPDUIDIsValid(const DHCPDUIDRef duid, int duid_len); 157 158char * 159DHCPDUIDToString(const DHCPDUIDRef duid, int duid_len); 160 161#endif /* _S_DHCPDUID_H */ 162