williamr@2: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // eui_addr.h - modified EUI-xx for IPv6 interface identifiers williamr@2: // Modified EUI-xx address structure for IPv6 interface identifiers williamr@2: // williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file eui_addr.h williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: williamr@2: #ifndef __EUI_ADDR_H__ williamr@2: #define __EUI_ADDR_H__ williamr@2: williamr@2: #include // TUint* williamr@2: #include "es_sock.h" // TSockAddr williamr@2: williamr@2: /** Address family ID */ williamr@4: const TUint KAfEui64 = 0x0F64; //< TODO williamr@2: williamr@2: /** Panic codes. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: enum TEuiPanic williamr@2: { williamr@2: EEuiPanicFamilyMismatch, williamr@2: EEuiPanicBitIsNotBit, williamr@2: EEuiPanicSourceTooLong williamr@2: }; williamr@2: williamr@2: williamr@2: // williamr@2: // Lots of these functions should be inlined -tom williamr@2: // williamr@2: williamr@2: /** williamr@2: * The raw 64 bits of Modified EUI-64 address stored in network byte order. williamr@2: * @publishedAll williamr@2: * @released williamr@2: */ williamr@2: class TE64Addr williamr@2: { williamr@2: public: williamr@4: IMPORT_C TE64Addr(); //< Constructs an address with zero value williamr@4: IMPORT_C TE64Addr(const TE64Addr& aAddr); //< Constructs an address with given value williamr@4: IMPORT_C TE64Addr(const TInt64& aAddr); //< Constructs an address with given value williamr@4: IMPORT_C TE64Addr(const TUint8* aPtr, TUint aLength); //< Constructs an address with given value williamr@2: williamr@4: IMPORT_C void SetAddr(const TE64Addr& aAddr); //< Sets the address value williamr@4: IMPORT_C void SetAddr(const TInt64& aAddr); //< Sets the address value williamr@4: IMPORT_C void SetAddr(const TUint8* aPtr, TUint aLength); //< Sets the address value williamr@2: williamr@2: williamr@4: IMPORT_C void SetAddrZero(); //< Creates a zero address williamr@2: williamr@2: /** williamr@2: * Creates a random address. williamr@2: * The Group bit is set to 0. williamr@2: * The Universal bit is set to 0. williamr@2: */ williamr@2: IMPORT_C void SetAddrRandom(); williamr@2: williamr@2: /** williamr@2: * Creates a random non-zero address. williamr@2: * The Group bit is set to 0. williamr@2: * The Universal bit is set to 0. williamr@2: */ williamr@2: IMPORT_C void SetAddrRandomNZ(); williamr@2: williamr@2: /** williamr@2: * Creates a random non-zero address that does not match the parameter address. williamr@2: * The Group bit is set to 0. williamr@2: * The Universal bit is set to 0. williamr@2: */ williamr@2: IMPORT_C void SetAddrRandomNZButNot(const TE64Addr& aAddr); williamr@2: williamr@2: // Really should define TE48Addr for this... -tom williamr@4: IMPORT_C void SetAddrFromEUI48(const TUint8* aPtr); //< Reads and converts a value from EUI-48 (6 bytes) williamr@2: williamr@4: IMPORT_C void SetGroupBit(TBool aBit = 1); //< Sets the Group bit to 1 by default williamr@4: IMPORT_C void SetUniversalBit(TBool aBit = 1); //< Sets the Universal bit to 1 by default williamr@2: williamr@4: IMPORT_C TBool Match(const TE64Addr& aAddr) const; //< TRUE if the address matches given address williamr@4: IMPORT_C TBool IsZero() const; //< TRUE if the address is a zero address williamr@4: IMPORT_C TBool IsGroup() const; //< TRUE if the Group bit is set in the address williamr@4: IMPORT_C TBool IsUniversal() const; //< TRUE if the Universal bit is set in the address williamr@2: williamr@4: // IMPORT_C TInt Input(const TDesC& aBuf); //< Reads a value for the address from a string williamr@4: IMPORT_C void Output(TDes& aBuf) const; //< Writes the address into a string williamr@2: williamr@4: IMPORT_C static TUint AddrLen(); //< Returns the size of raw KAfEui64 content format williamr@4: IMPORT_C TUint8* AddrPtr(); //< Returns a pointer to raw KAfEui64 content format williamr@4: IMPORT_C const TUint8* AddrPtrC() const; //< Returns a const pointer to raw KAfEui64 content format williamr@2: williamr@2: private: williamr@2: union williamr@2: { williamr@2: TUint8 iAddr8[64 / 8]; williamr@2: TUint16 iAddr16[64 / 16]; williamr@2: TUint32 iAddr32[64 / 32]; williamr@2: } u; williamr@2: }; williamr@2: williamr@2: struct SE64Addr { williamr@4: TE64Addr iAddr; //< 8 bytes of Modified EUI-64 address (64 bits) williamr@2: }; williamr@2: williamr@2: /** williamr@2: * This class specializes the generic socket server address class williamr@2: * TSockAddr for the IPv6 Interface Identifier; the Modified EUI-64 williamr@2: * address. Value KAfEui64 is used for the protocol family field williamr@2: * of the TSockAddr base class. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: */ williamr@2: class TEui64Addr : public TSockAddr williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Constructs a basic IPv6 Interface Identifier. williamr@2: * The family is initialized to KafEui64. williamr@2: * The port (unused) is initialized to 0. williamr@2: * The address is set to zero address. williamr@2: */ williamr@2: IMPORT_C TEui64Addr(); williamr@2: williamr@2: /** williamr@2: * Constructs an IPv6 Interface Identifier from TSockAddr. williamr@2: * The family of the parameter must be KAfEui64 or 0. williamr@2: * The family of the resulting address is KAfEui64. williamr@2: * The port (unused) is initialized to 0. williamr@2: * The address bytes are copied from the parameter. williamr@2: * williamr@2: * @param anAddr TSockAddr to be used as initial content. williamr@2: */ williamr@2: IMPORT_C TEui64Addr(const TSockAddr& aAddr); williamr@2: williamr@2: /** williamr@2: * Constructs an IPv6 Interface Identifier from TE64Addr. williamr@2: * The family is initialized to KAfEui64. williamr@2: * The port (unused) is initialized to 0. williamr@2: * The address bytes are copied from the parameter. williamr@2: * williamr@2: * @param aAddr TE64Addr to be used as initial content. williamr@2: */ williamr@2: inline TEui64Addr(const TE64Addr& aAddr); williamr@2: williamr@2: /** williamr@2: * Initializes the TSockAddr parts of an IPv6 Interface Identifier. williamr@2: * The family is set to KAfEui64. williamr@2: * The port (unused) is initialized to 0. williamr@2: * The address bytes are not touched. williamr@2: */ williamr@2: IMPORT_C void Init(); williamr@2: williamr@2: /** williamr@2: * Sets the address bytes to given value. williamr@2: * The other TSockAddr fields are not touched. williamr@2: */ williamr@2: IMPORT_C void SetAddress(const TE64Addr& aAddr); williamr@4: IMPORT_C TE64Addr& Address() const; //< Accesses the address bytes williamr@2: williamr@4: IMPORT_C TBool Match(const TEui64Addr& aAddr) const; //< TRUE if the address bytes match the parameter's williamr@4: IMPORT_C TBool IsZero() const; //< TRUE if the address bytes are all zeros williamr@2: williamr@4: IMPORT_C static TEui64Addr& Cast(const TSockAddr& aAddr); //< Unsafely casts a TSockAddr to TEui64Addr williamr@4: IMPORT_C static TEui64Addr& Cast(const TSockAddr* aAddr); //< Unsafely casts a TSockAddr to TEui64Addr williamr@2: williamr@2: protected: williamr@4: IMPORT_C SE64Addr* AddrPtr() const; //< Returns a pointer to KAfEui64 content format williamr@4: IMPORT_C static TUint AddrLen(); //< Returns the size of the KAfEui64 content format williamr@2: }; williamr@2: williamr@2: inline TEui64Addr::TEui64Addr(const TE64Addr& aAddr) : TSockAddr() williamr@2: { williamr@2: Init(); williamr@2: SetAddress(aAddr); williamr@2: }; williamr@2: williamr@2: #endif