1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Portions of this software have been released under the following terms: 31 * 32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC. 33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY 34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION 35 * 36 * To anyone who acknowledges that this file is provided "AS IS" 37 * without any express or implied warranty: 38 * permission to use, copy, modify, and distribute this file for any 39 * purpose is hereby granted without fee, provided that the above 40 * copyright notices and this notice appears in all source code copies, 41 * and that none of the names of Open Software Foundation, Inc., Hewlett- 42 * Packard Company or Digital Equipment Corporation be used 43 * in advertising or publicity pertaining to distribution of the software 44 * without specific, written prior permission. Neither Open Software 45 * Foundation, Inc., Hewlett-Packard Company nor Digital 46 * Equipment Corporation makes any representations about the suitability 47 * of this software for any purpose. 48 * 49 * Copyright (c) 2007, Novell, Inc. All rights reserved. 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in the 58 * documentation and/or other materials provided with the distribution. 59 * 3. Neither the name of Novell Inc. nor the names of its contributors 60 * may be used to endorse or promote products derived from this 61 * this software without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY 67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 * 74 * @APPLE_LICENSE_HEADER_END@ 75 */ 76 77/* 78** 79** NAME: 80** 81** uuidp.h 82** 83** FACILITY: 84** 85** UUID 86** 87** ABSTRACT: 88** 89** Interface Definitions for UUID subroutines used by 90** the uuid module 91** 92** 93*/ 94 95#ifndef _UUIDP_H 96#define _UUIDP_H 1 97 98/* 99 * Max size of a uuid string: tttttttt-tttt-cccc-cccc-nnnnnnnnnnnn 100 * Note: this includes the implied '\0' 101 */ 102#define UUID_C_UUID_STRING_MAX 37 103 104/* 105 * defines for time calculations 106 */ 107#ifndef UUID_C_100NS_PER_SEC 108#define UUID_C_100NS_PER_SEC 10000000 109#endif 110 111#ifndef UUID_C_100NS_PER_USEC 112#define UUID_C_100NS_PER_USEC 10 113#endif 114 115 116 117/* 118 * UADD_UVLW_2_UVLW - macro to add two unsigned 64-bit long integers 119 * (ie. add two unsigned 'very' long words) 120 * 121 * Important note: It is important that this macro accommodate (and it does) 122 * invocations where one of the addends is also the sum. 123 * 124 * This macro was snarfed from the DTSS group and was originally: 125 * 126 * UTCadd - macro to add two UTC times 127 * 128 * add lo and high order longword separately, using sign bits of the low-order 129 * longwords to determine carry. sign bits are tested before addition in two 130 * cases - where sign bits match. when the addend sign bits differ the sign of 131 * the result is also tested: 132 * 133 * sign sign 134 * addend 1 addend 2 carry? 135 * 136 * 1 1 TRUE 137 * 1 0 TRUE if sign of sum clear 138 * 0 1 TRUE if sign of sum clear 139 * 0 0 FALSE 140 */ 141#define UADD_UVLW_2_UVLW(add1, add2, sum) \ 142 if (!(((add1)->lo&0x80000000UL) ^ ((add2)->lo&0x80000000UL))) \ 143 { \ 144 if (((add1)->lo&0x80000000UL)) \ 145 { \ 146 (sum)->lo = (add1)->lo + (add2)->lo ; \ 147 (sum)->hi = (add1)->hi + (add2)->hi+1 ; \ 148 } \ 149 else \ 150 { \ 151 (sum)->lo = (add1)->lo + (add2)->lo ; \ 152 (sum)->hi = (add1)->hi + (add2)->hi ; \ 153 } \ 154 } \ 155 else \ 156 { \ 157 (sum)->lo = (add1)->lo + (add2)->lo ; \ 158 (sum)->hi = (add1)->hi + (add2)->hi ; \ 159 if (!((sum)->lo&0x80000000UL)) \ 160 (sum)->hi++ ; \ 161 } 162 163 164/* 165 * UADD_ULW_2_UVLW - macro to add a 32-bit unsigned integer to 166 * a 64-bit unsigned integer 167 * 168 * Note: see the UADD_UVLW_2_UVLW() macro 169 * 170 */ 171#define UADD_ULW_2_UVLW(add1, add2, sum) \ 172{ \ 173 (sum)->hi = (add2)->hi; \ 174 if ((*add1) & (add2)->lo & 0x80000000UL) \ 175 { \ 176 (sum)->lo = (*add1) + (add2)->lo; \ 177 (sum)->hi++; \ 178 } \ 179 else \ 180 { \ 181 (sum)->lo = (*add1) + (add2)->lo; \ 182 if (!((sum)->lo & 0x80000000UL)) \ 183 { \ 184 (sum)->hi++; \ 185 } \ 186 } \ 187} 188 189/* 190 * UADD_UW_2_UVLW - macro to add a 16-bit unsigned integer to 191 * a 64-bit unsigned integer 192 * 193 * Note: see the UADD_UVLW_2_UVLW() macro 194 * 195 */ 196#define UADD_UW_2_UVLW(add1, add2, sum) \ 197{ \ 198 (sum)->hi = (add2)->hi; \ 199 if ((add2)->lo & 0x80000000UL) \ 200 { \ 201 (sum)->lo = (*add1) + (add2)->lo; \ 202 if (!((sum)->lo & 0x80000000UL)) \ 203 { \ 204 (sum)->hi++; \ 205 } \ 206 } \ 207 else \ 208 { \ 209 (sum)->lo = (*add1) + (add2)->lo; \ 210 } \ 211} 212 213 214 215/* 216 * a macro to set *status uuid_s_coding_error 217 */ 218#ifdef CODING_ERROR 219#undef CODING_ERROR 220#endif 221 222#ifdef DEBUG 223#define CODING_ERROR(status) *(status) = uuid_s_coding_error 224#else 225#define CODING_ERROR(status) 226#endif 227 228typedef struct 229{ 230 char eaddr[6]; /* 6 bytes of ethernet hardware address */ 231} uuid_address_t, *uuid_address_p_t; 232 233typedef struct 234{ 235 unsigned32 lo; 236 unsigned32 hi; 237} uuid_time_t, *uuid_time_p_t; 238 239typedef struct 240{ 241 unsigned32 lo; 242 unsigned32 hi; 243} unsigned64_t, *unsigned64_p_t; 244 245/* 246 * U U I D _ _ U E M U L 247 * 248 * 32-bit unsigned * 32-bit unsigned multiply -> 64-bit result 249 */ 250 void uuid__uemul ( 251 unsigned32 /*u*/, 252 unsigned32 /*v*/, 253 unsigned64_t * /*prodPtr*/ 254 ); 255 256/* 257 * U U I D _ _ R E A D _ C L O C K 258 */ 259 unsigned16 uuid__read_clock ( void ); 260 261/* 262 * U U I D _ _ W R I T E _ C L O C K 263 */ 264 void uuid__write_clock ( unsigned16 /*time*/ ); 265 266/* 267 * U U I D _ _ G E T _ O S _ P I D 268 * 269 * Get the process id 270 */ 271 unsigned32 uuid__get_os_pid ( void ); 272 273/* 274 * U U I D _ _ G E T _ O S _ T I M E 275 * 276 * Get OS time 277 */ 278 void uuid__get_os_time ( uuid_time_t * /*uuid_time*/); 279 280/* 281 * U U I D _ _ G E T _ O S _ A D D R E S S 282 * 283 * Get ethernet hardware address from the OS 284 */ 285 void uuid__get_os_address ( 286 uuid_address_t * /*address*/, 287 unsigned32 * /*st*/ 288 ); 289 290#endif /* _UUIDP_H */ 291