bluetoothcommsprofiles/btpan/bnep/RBnepSetupConnectionRequestControl.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 <e32std.h>
       
    23 #include "RBnepSetupConnectionRequestControl.h"
       
    24 
       
    25 #ifdef __FLOG_ACTIVE
       
    26 _LIT8(KLogComponent, LOG_COMPONENT_PAN_BNEP);
       
    27 #endif
       
    28 
       
    29 const TInt KRoleUnknown = 0xffff;
       
    30 
       
    31 /**
       
    32    Extract a role UUID.
       
    33    @param aRole a TUUID object to update.
       
    34    @param aOffset The role extracted is the aOffset the role in the packet.
       
    35    valid values are zero and one.
       
    36    @return KErrCorrupt Invalid UUID size.
       
    37    @internalComponent
       
    38 */
       
    39 TInt RBnepSetupConnectionRequestControl::GetRole (TUUID& aRole, TInt aOffset)
       
    40     {
       
    41     LOG_FUNC
       
    42     aRole = TUUID(KRoleUnknown);
       
    43     TBuf8<KSdpUUIDMaxLength> buf;
       
    44     buf.SetLength(KUUIDSizeLength);
       
    45 	if(Length() < KUUIDSizeOffset + KUUIDSizeLength)
       
    46 		{
       
    47 		return KErrCorrupt;
       
    48 		}
       
    49     CopyOut(buf, KUUIDSizeOffset);
       
    50     TInt uuidSize = buf[0];
       
    51     LOG1(_L8("uuidSize = %d"),uuidSize);                                                          	
       
    52 	TInt offset;
       
    53     switch (uuidSize)
       
    54         {
       
    55         case 2:
       
    56         case 4:
       
    57         case 16:
       
    58             // If the UUID length is valid, extract its value.
       
    59             buf.SetLength(uuidSize);
       
    60  			//Check the offset is within our buffer boundary
       
    61 		 	offset = KUUIDOffset + aOffset * uuidSize;
       
    62 		 	if(Length() < offset + uuidSize)
       
    63 		 		{
       
    64 		 		return KErrCorrupt;
       
    65 		 		}
       
    66             CopyOut(buf, offset);
       
    67 		
       
    68             TRAPD(err, aRole.SetL(buf));
       
    69             return err;
       
    70         default:
       
    71             return KErrCorrupt;
       
    72         } 
       
    73     }
       
    74 
       
    75 /**
       
    76    Allocate the memory required for a connection setup request.
       
    77    @internalComponent
       
    78 */
       
    79 void RBnepSetupConnectionRequestControl::InitL ()
       
    80     {
       
    81     LOG_FUNC
       
    82     AllocL(KMaxSizeOfSetupRequest); 
       
    83     }
       
    84 
       
    85 /**
       
    86    Initialise the role UUIDs.
       
    87    @internalComponent
       
    88 */
       
    89 void RBnepSetupConnectionRequestControl::SetRolesL (TUUID& aLocalRole, TUUID& aRemoteRole)
       
    90     {
       
    91     LOG_FUNC
       
    92     TInt uuidSize = Max(aLocalRole.MinimumSize(), aRemoteRole.MinimumSize());
       
    93     TBuf8<2*sizeof(TUint8)> header;
       
    94     header.SetMax();
       
    95     header[KControlTypeOffset] = EBnepSetupConnectionRequestMessage;
       
    96     header[KUUIDSizeOffset] = static_cast<TUint8>(uuidSize);
       
    97     CopyIn(header);
       
    98     TPtrC8 uuid;
       
    99     uuid.Set(aRemoteRole.SpecifiedLengthL(uuidSize));
       
   100     CopyIn(uuid, KUUIDOffset);
       
   101     uuid.Set(aLocalRole.SpecifiedLengthL(uuidSize));
       
   102     CopyIn(uuid, KUUIDOffset + uuidSize);
       
   103     TrimEnd(KUUIDOffset + (2 * uuidSize));
       
   104     DUMPFRAME(_L8("RBnepSetupConnectionRequestControl"));
       
   105     }
       
   106 
       
   107 
       
   108