bluetoothcommsprofiles/btpan/bnep/RBnepFilterMultiAddrSetRequestControl.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include <bluetooth/logger.h>
       
    22 #include <es_sock.h>
       
    23 #include "BnepTypes.h"
       
    24 #include "RBnepFilterMultiAddrSetRequestControl.h"
       
    25 
       
    26 #include "TBnepBTDevAddr.h"
       
    27 
       
    28 #ifdef __FLOG_ACTIVE
       
    29 _LIT8(KLogComponent, LOG_COMPONENT_PAN_BNEP);
       
    30 #endif
       
    31 
       
    32 /**
       
    33    Retrieve one value pair from a multicast address filter control
       
    34    @note This method should be called repeatedly until all the values are read out (ie. return value from the last pair is KErrEof)
       
    35    @param aStartValue The start value for the multicast address range
       
    36    @param aEndValue The end value of the multicast address range
       
    37    @param aIndex The index of the multicast address filter pairs, starting from zero.
       
    38    @return KErrNone if there any more addresses in the list, or KErrEof when there are no more addresses left
       
    39    @internalComponent
       
    40 */
       
    41 TInt RBnepFilterMultiAddrSetRequestControl::MultiAddrRange (TBnepBTDevAddr& aStartAddr, TBnepBTDevAddr& aEndAddr, TUint aIndex)
       
    42     {
       
    43     LOG_FUNC
       
    44     LOG2(_L8("RBnepFilterMultiAddrSet[%x]: Getting multicast address pair, index %d..."), this, aIndex);
       
    45     // since this might be (probably is) from another device, check their quoted size against the size of the packet we've got
       
    46     TInt length = Length();
       
    47     TInt multiAddrLength = static_cast<TInt>(MulticastAddressListLength());
       
    48     TInt preamble = static_cast<TInt>(KSizeOfBnepControlType + KSizeOfMultiAddrFilterListLength);
       
    49 
       
    50     if(multiAddrLength <= 0)
       
    51         {
       
    52         return KErrNotFound;
       
    53         }
       
    54 
       
    55     if(length < multiAddrLength + preamble)
       
    56         {
       
    57         LOG3(_L8("RBnepFilterMultiAddrSet[%x]: Multicast address list length is invalid - our mbuf chain length (minus control type and length headers) %d, claimed length %d"), this, (Length() - (KSizeOfBnepControlType + KSizeOfMultiAddrFilterListLength)), MulticastAddressListLength());
       
    58         return KErrArgument;
       
    59         }
       
    60 
       
    61     TUint currentPair = (aIndex*(2*KSizeOfMultiAddr) + KMultiAddrListFirstPairFieldOffset);
       
    62 	TInt rerr = aStartAddr.SetAddress(*this, currentPair);
       
    63 	if(rerr == KErrNone)
       
    64 		{
       
    65 		rerr = aEndAddr.SetAddress(*this, currentPair + KSizeOfMultiAddr);
       
    66 		}
       
    67 	
       
    68     if(rerr != KErrNone || MulticastAddressListLength() <= (currentPair + (2*KSizeOfMultiAddr))) // check if this is the last pair
       
    69         {
       
    70         LOG1(_L8("RBnepFilterMultiAddrSet[%x]: ...last item in list - returning KErrEof"), this);
       
    71         return KErrEof;
       
    72         }
       
    73     else
       
    74         {
       
    75         LOG1(_L8("RBnepFilterMultiAddrSet[%x]: ...more items in list - returning KErrNone"), this);
       
    76         return KErrNone;
       
    77         }
       
    78     }
       
    79 
       
    80 /**
       
    81    Return the length of the multicast address list
       
    82    @internalComponent
       
    83 */
       
    84 TUint16 RBnepFilterMultiAddrSetRequestControl::MulticastAddressListLength ()
       
    85     {
       
    86     LOG_FUNC
       
    87     TUint16 length;
       
    88     length = BigEndian::Get16((First()->Ptr() + KMultiAddrListLengthFieldOffset));
       
    89     LOG1(_L8("...multicast address list length %d..."), length);
       
    90     return length;
       
    91     }