1.1 --- a/epoc32/include/eui_addr.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/eui_addr.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,196 @@
1.4 -eui_addr.h
1.5 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +// eui_addr.h - modified EUI-xx for IPv6 interface identifiers
1.19 +// Modified EUI-xx address structure for IPv6 interface identifiers
1.20 +//
1.21 +
1.22 +
1.23 +
1.24 +/**
1.25 + @file eui_addr.h
1.26 + @publishedAll
1.27 + @released
1.28 +*/
1.29 +
1.30 +#ifndef __EUI_ADDR_H__
1.31 +#define __EUI_ADDR_H__
1.32 +
1.33 +#include <e32def.h> // TUint*
1.34 +#include "es_sock.h" // TSockAddr
1.35 +
1.36 +/** Address family ID */
1.37 +const TUint KAfEui64 = 0x0F64; ///< TODO
1.38 +
1.39 +/** Panic codes.
1.40 +@publishedAll
1.41 +@released
1.42 +*/
1.43 +enum TEuiPanic
1.44 +{
1.45 + EEuiPanicFamilyMismatch,
1.46 + EEuiPanicBitIsNotBit,
1.47 + EEuiPanicSourceTooLong
1.48 +};
1.49 +
1.50 +
1.51 +//
1.52 +// Lots of these functions should be inlined -tom
1.53 +//
1.54 +
1.55 +/**
1.56 + * The raw 64 bits of Modified EUI-64 address stored in network byte order.
1.57 + * @publishedAll
1.58 + * @released
1.59 + */
1.60 +class TE64Addr
1.61 +{
1.62 + public:
1.63 + IMPORT_C TE64Addr(); ///< Constructs an address with zero value
1.64 + IMPORT_C TE64Addr(const TE64Addr& aAddr); ///< Constructs an address with given value
1.65 + IMPORT_C TE64Addr(const TInt64& aAddr); ///< Constructs an address with given value
1.66 + IMPORT_C TE64Addr(const TUint8* aPtr, TUint aLength); ///< Constructs an address with given value
1.67 +
1.68 + IMPORT_C void SetAddr(const TE64Addr& aAddr); ///< Sets the address value
1.69 + IMPORT_C void SetAddr(const TInt64& aAddr); ///< Sets the address value
1.70 + IMPORT_C void SetAddr(const TUint8* aPtr, TUint aLength); ///< Sets the address value
1.71 +
1.72 +
1.73 + IMPORT_C void SetAddrZero(); ///< Creates a zero address
1.74 +
1.75 + /**
1.76 + * Creates a random address.
1.77 + * The Group bit is set to 0.
1.78 + * The Universal bit is set to 0.
1.79 + */
1.80 + IMPORT_C void SetAddrRandom();
1.81 +
1.82 + /**
1.83 + * Creates a random non-zero address.
1.84 + * The Group bit is set to 0.
1.85 + * The Universal bit is set to 0.
1.86 + */
1.87 + IMPORT_C void SetAddrRandomNZ();
1.88 +
1.89 + /**
1.90 + * Creates a random non-zero address that does not match the parameter address.
1.91 + * The Group bit is set to 0.
1.92 + * The Universal bit is set to 0.
1.93 + */
1.94 + IMPORT_C void SetAddrRandomNZButNot(const TE64Addr& aAddr);
1.95 +
1.96 + // Really should define TE48Addr for this... -tom
1.97 + IMPORT_C void SetAddrFromEUI48(const TUint8* aPtr); ///< Reads and converts a value from EUI-48 (6 bytes)
1.98 +
1.99 + IMPORT_C void SetGroupBit(TBool aBit = 1); ///< Sets the Group bit to 1 by default
1.100 + IMPORT_C void SetUniversalBit(TBool aBit = 1); ///< Sets the Universal bit to 1 by default
1.101 +
1.102 + IMPORT_C TBool Match(const TE64Addr& aAddr) const; ///< TRUE if the address matches given address
1.103 + IMPORT_C TBool IsZero() const; ///< TRUE if the address is a zero address
1.104 + IMPORT_C TBool IsGroup() const; ///< TRUE if the Group bit is set in the address
1.105 + IMPORT_C TBool IsUniversal() const; ///< TRUE if the Universal bit is set in the address
1.106 +
1.107 +// IMPORT_C TInt Input(const TDesC& aBuf); ///< Reads a value for the address from a string
1.108 + IMPORT_C void Output(TDes& aBuf) const; ///< Writes the address into a string
1.109 +
1.110 + IMPORT_C static TUint AddrLen(); ///< Returns the size of raw KAfEui64 content format
1.111 + IMPORT_C TUint8* AddrPtr(); ///< Returns a pointer to raw KAfEui64 content format
1.112 + IMPORT_C const TUint8* AddrPtrC() const; ///< Returns a const pointer to raw KAfEui64 content format
1.113 +
1.114 + private:
1.115 + union
1.116 + {
1.117 + TUint8 iAddr8[64 / 8];
1.118 + TUint16 iAddr16[64 / 16];
1.119 + TUint32 iAddr32[64 / 32];
1.120 + } u;
1.121 +};
1.122 +
1.123 +struct SE64Addr {
1.124 + TE64Addr iAddr; ///< 8 bytes of Modified EUI-64 address (64 bits)
1.125 +};
1.126 +
1.127 +/**
1.128 + * This class specializes the generic socket server address class
1.129 + * TSockAddr for the IPv6 Interface Identifier; the Modified EUI-64
1.130 + * address. Value KAfEui64 is used for the protocol family field
1.131 + * of the TSockAddr base class.
1.132 + *
1.133 + * @publishedAll
1.134 + * @released
1.135 + */
1.136 +class TEui64Addr : public TSockAddr
1.137 +{
1.138 + public:
1.139 + /**
1.140 + * Constructs a basic IPv6 Interface Identifier.
1.141 + * The family is initialized to KafEui64.
1.142 + * The port (unused) is initialized to 0.
1.143 + * The address is set to zero address.
1.144 + */
1.145 + IMPORT_C TEui64Addr();
1.146 +
1.147 + /**
1.148 + * Constructs an IPv6 Interface Identifier from TSockAddr.
1.149 + * The family of the parameter must be KAfEui64 or 0.
1.150 + * The family of the resulting address is KAfEui64.
1.151 + * The port (unused) is initialized to 0.
1.152 + * The address bytes are copied from the parameter.
1.153 + *
1.154 + * @param anAddr TSockAddr to be used as initial content.
1.155 + */
1.156 + IMPORT_C TEui64Addr(const TSockAddr& aAddr);
1.157 +
1.158 + /**
1.159 + * Constructs an IPv6 Interface Identifier from TE64Addr.
1.160 + * The family is initialized to KAfEui64.
1.161 + * The port (unused) is initialized to 0.
1.162 + * The address bytes are copied from the parameter.
1.163 + *
1.164 + * @param aAddr TE64Addr to be used as initial content.
1.165 + */
1.166 + inline TEui64Addr(const TE64Addr& aAddr);
1.167 +
1.168 + /**
1.169 + * Initializes the TSockAddr parts of an IPv6 Interface Identifier.
1.170 + * The family is set to KAfEui64.
1.171 + * The port (unused) is initialized to 0.
1.172 + * The address bytes are not touched.
1.173 + */
1.174 + IMPORT_C void Init();
1.175 +
1.176 + /**
1.177 + * Sets the address bytes to given value.
1.178 + * The other TSockAddr fields are not touched.
1.179 + */
1.180 + IMPORT_C void SetAddress(const TE64Addr& aAddr);
1.181 + IMPORT_C TE64Addr& Address() const; ///< Accesses the address bytes
1.182 +
1.183 + IMPORT_C TBool Match(const TEui64Addr& aAddr) const; ///< TRUE if the address bytes match the parameter's
1.184 + IMPORT_C TBool IsZero() const; ///< TRUE if the address bytes are all zeros
1.185 +
1.186 + IMPORT_C static TEui64Addr& Cast(const TSockAddr& aAddr); ///< Unsafely casts a TSockAddr to TEui64Addr
1.187 + IMPORT_C static TEui64Addr& Cast(const TSockAddr* aAddr); ///< Unsafely casts a TSockAddr to TEui64Addr
1.188 +
1.189 + protected:
1.190 + IMPORT_C SE64Addr* AddrPtr() const; ///< Returns a pointer to KAfEui64 content format
1.191 + IMPORT_C static TUint AddrLen(); ///< Returns the size of the KAfEui64 content format
1.192 +};
1.193 +
1.194 +inline TEui64Addr::TEui64Addr(const TE64Addr& aAddr) : TSockAddr()
1.195 +{
1.196 + Init();
1.197 + SetAddress(aAddr);
1.198 +};
1.199 +
1.200 +#endif