diff -r 000000000000 -r 29b1cd4cb562 bluetooth/btstack/HCIShared/src/hcishared.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetooth/btstack/HCIShared/src/hcishared.cpp Fri Jan 15 08:13:17 2010 +0200 @@ -0,0 +1,499 @@ +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +/** + @file + @publishedPartner +*/ + +#include +#include "btfeatures.h" + + +enum TBTFeaturesPanic + { + ERangeTooLarge, + }; + +void FeaturesPanic(TBTFeaturesPanic aPanic) + { + _LIT(KPanicText, "BTFeatures"); + User::Panic(KPanicText, aPanic); + } + +void Panic(THCISharePanic aPanic) +// Panic due to stack bug. + { + User::Panic(KHCISharedPanicName, aPanic); + } + +/** +Constructor +Start with no requests to update the required configuration. +*/ + +EXPORT_C TBTFeatures::TBTFeatures() + { + Init(0); + } + +/** +Constructor +Start with request to update the required configuration + +@param aFeatures the required bluetooth features +*/ + +EXPORT_C TBTFeatures::TBTFeatures(TUint64 aFeatures) + { + Init(aFeatures); + } + + +void TBTFeatures::Init(TUint64 aFeatures) + { + const TInt KMaxBit = 7; + iFeatures.SetMax(); + for (TInt pos = 0; pos < iFeatures.MaxSize(); pos++) + { + TUint8 byte = (pos <= KMaxBit) ? (aFeatures >> (pos * 8)) & 0xff : 0; + iFeatures[pos] = byte; + } + } + +TUint32 TBTFeatures::Extract32BitsOffset(TInt aStart, TInt aEnd, TInt aOffset) const + { + return Extract32Bits(aStart, aEnd) << aOffset; + } + +TUint32 TBTFeatures::Extract32Bits(TInt aStart, TInt aEnd) const + { + __ASSERT_DEBUG(aEnd - aStart <= 32, FeaturesPanic(ERangeTooLarge)); + TUint32 result =0; + TInt outOffset = 0; + for (TInt bit = aStart; bit <= aEnd; bit++) + { + result |= (operator[](bit) ? 1<(iSwitchAllowed + (iLowPowerModePolicy << 1)); + } + + +/** +Constructor +Start with default configuration +*/ +EXPORT_C TBTBasebandLinkState::TBTBasebandLinkState() + : iLinkState(ELinkDown), + iAuthenticated(EFalse), + iEncrypted(EFalse), + iMode(EActiveMode), + iRole(ERoleUnknown), + iPacketTypes(EAnyPacket), + iMaxSlots(5) + { + } + +/** +Set the link state + +@param aState link state values +*/ +EXPORT_C void TBTBasebandLinkState::SetLinkState(TLinkState aState) + { + iLinkState = aState; + } + +/** +Set the authentication state + +@param aAuthenticated TBool value indicates whether authentication is allowed or not +*/ +EXPORT_C void TBTBasebandLinkState::SetAuthenticated(TBool aAuthenticated) + { + iAuthenticated = aAuthenticated; + } + +/** +Set the encryption state + +@param aEncrypted TBool value indicates whether encryption is allowed or not +*/ +EXPORT_C void TBTBasebandLinkState::SetEncrypted(TBool aEncrypted) + { + iEncrypted = aEncrypted; + } + +/** +Set the link mode + +@param aMode TBool value indicates the BT link mode +*/ +EXPORT_C void TBTBasebandLinkState::SetLinkMode(TBTLinkMode aMode) + { + iMode = aMode; + } + +/** +Set the link role + +@param aRole Bluetooth SIG specified values for specification of (piconet) role +*/ +EXPORT_C void TBTBasebandLinkState::SetLinkRole(TBTBasebandRole aRole) + { + iRole = aRole; + } + +/** +Set the packet types + +@param aPacketTypes Bluetooth SIG specified packet types +*/ +EXPORT_C void TBTBasebandLinkState::SetPacketTypes(TUint16 aPacketTypes) + { + iPacketTypes = aPacketTypes; + } + +/** +Set the maximum types + +@param aMaxSlots LMP maximum slot +*/ +EXPORT_C void TBTBasebandLinkState::SetMaxSlots(TUint8 aMaxSlots) + { + iMaxSlots = aMaxSlots; + } + +/** +Return current baseband link state + +@return current baseband link state +*/ +EXPORT_C TBTBasebandLinkState::TLinkState TBTBasebandLinkState::LinkState() const + { + return iLinkState; + } + +/** +Return current authentication status + +@return current authentication status +*/ +EXPORT_C TBool TBTBasebandLinkState::Authenticated() const + { + return iAuthenticated; + } + +/** +Return current encryption status + +@return current encryption status +*/ +EXPORT_C TBool TBTBasebandLinkState::Encrypted() const + { + return iEncrypted; + } + +/** +Return current baseband link state + +@return current baseband link state +*/ +EXPORT_C TBTLinkMode TBTBasebandLinkState::LinkMode() const + { + return iMode; + } + +/** +Return current baseband link role + +@return current baseband link role +*/ +EXPORT_C TBTBasebandRole TBTBasebandLinkState::LinkRole() const + { + return iRole; + } + +/** +Return current baseband packet types + +@return current baseband packet types +*/ +EXPORT_C TUint16 TBTBasebandLinkState::PacketTypes() const + { + return iPacketTypes; + } + +/** +Return current baseband max slots + +@return current baseband max slots +*/ +EXPORT_C TUint8 TBTBasebandLinkState::MaxSlots() const + { + return iMaxSlots; + }