remotecontrol/avrcp/remconbeareravrcp/src/avrcpsdputils.cpp
changeset 51 20ac952a623c
equal deleted inserted replaced
48:22de2e391156 51:20ac952a623c
       
     1 // Copyright (c) 2008-2010 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 #include <bt_sock.h>
       
    17 
       
    18 #include "avrcpsdputils.h"
       
    19 
       
    20 static void AddCommonServiceRecordAttributesL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle aRecHandle)
       
    21 	{
       
    22 	// Provider Name
       
    23 	aSdpDatabase.UpdateAttributeL(aRecHandle,
       
    24 		KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetProviderName,
       
    25 		AvrcpSdp::KAvrcpProviderName
       
    26 		);
       
    27 	
       
    28 	// Service Description
       
    29 	aSdpDatabase.UpdateAttributeL(aRecHandle,
       
    30 		KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceDescription,
       
    31 		AvrcpSdp::KAvrcpServiceDescription
       
    32 		);	
       
    33 	
       
    34 	// Add to public browse group
       
    35 	CSdpAttrValueDES *attrValDES = CSdpAttrValueDES::NewDESL(0);
       
    36 	CleanupStack::PushL(attrValDES);
       
    37 	attrValDES->StartListL()
       
    38 		->BuildUUIDL(TUUID(TUint16(KPublicBrowseGroupUUID)))
       
    39 	->EndListL();
       
    40 	aSdpDatabase.UpdateAttributeL(aRecHandle, KSdpAttrIdBrowseGroupList, *attrValDES);
       
    41 	CleanupStack::PopAndDestroy(attrValDES);
       
    42 	}
       
    43 
       
    44 static CSdpAttrValueDES* GenerateControllerServiceClassListLC(TUint16 aProfileVersion)
       
    45 	{
       
    46 	// New service record with service class attribute containing
       
    47 	// 0x110e (for A/V Remote Control) and potentially also 0x110f
       
    48 	CSdpAttrValueDES* serviceClassUuids = CSdpAttrValueDES::NewDESL(NULL);
       
    49 	CleanupStack::PushL(serviceClassUuids);
       
    50 	
       
    51 	// Unfortunately in earlier releases of the specification the controller service class UUID
       
    52 	// was the same as the the profile UUID - meaning that searching for records with this UUID
       
    53 	// would return both controller and target records (since they both belong to the same profile).
       
    54 	// This was corrected by adding a specific service class UUID for the controller role - both
       
    55 	// the specific UUID and the old "profile" UUID are provided in the list of service classes (for
       
    56 	// backwards compatibility).
       
    57 	//
       
    58 	// This new SDP record structure was introduced in AVRCP 1.4 and so if we conform to AVRCP 1.4 we 
       
    59 	// can use the new SDP record structure - if we are presenting ourselves as an earlier version 
       
    60 	// we must restrain ourselves and use the previously specified structure.
       
    61 	if(aProfileVersion == AvrcpSdp::KAvrcpProfileVersion13)
       
    62 		{
       
    63 		serviceClassUuids->StartListL()
       
    64 				->BuildUUIDL(TUUID(TUint16(KAVRemoteControlUUID)))
       
    65 		->EndListL();
       
    66 		}
       
    67 	else
       
    68 		{
       
    69 		serviceClassUuids->StartListL()
       
    70 				->BuildUUIDL(TUUID(TUint16(KAVRemoteControlUUID)))
       
    71 				->BuildUUIDL(TUUID(TUint16(KAVRemoteControlControllerUUID)))
       
    72 		->EndListL();
       
    73 		}
       
    74 	
       
    75 	return serviceClassUuids;
       
    76 	}
       
    77 
       
    78 void AvrcpSdpUtils::CreateTargetServiceRecordL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle)
       
    79 	{
       
    80 	// New service record with service class attribute containing
       
    81 	// 0x110c (for A/V Remote Control Target) 
       
    82 	aSdpDatabase.CreateServiceRecordL(KAVRemoteControlTargetUUID, aRecHandle);
       
    83 	
       
    84 	aSdpDatabase.UpdateAttributeL(aRecHandle,
       
    85 		KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
       
    86 		AvrcpSdp::KAvrcpTargetServiceName
       
    87 		);
       
    88 	
       
    89 	AddCommonServiceRecordAttributesL(aSdpDatabase, aRecHandle);
       
    90 	}
       
    91 
       
    92 void AvrcpSdpUtils::CreateControllerServiceRecordL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle, TUint16 aProfileVersion)
       
    93 	{
       
    94 	// New service record with service class attribute containing
       
    95 	// 0x110e (for A/V Remote Control) 
       
    96 	CSdpAttrValueDES* serviceClassUuids = GenerateControllerServiceClassListLC(aProfileVersion);
       
    97 	
       
    98 	aSdpDatabase.CreateServiceRecordL(*serviceClassUuids, aRecHandle);
       
    99 	CleanupStack::PopAndDestroy(serviceClassUuids);
       
   100 	
       
   101 	aSdpDatabase.UpdateAttributeL(aRecHandle,
       
   102 		KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName,
       
   103 		AvrcpSdp::KAvrcpControllerServiceName
       
   104 		);
       
   105 	
       
   106 	AddCommonServiceRecordAttributesL(aSdpDatabase, aRecHandle);
       
   107 	}
       
   108 
       
   109 void AvrcpSdpUtils::UpdateControllerServiceClassListL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle, TUint16 aProfileVersion)
       
   110 	{
       
   111 	CSdpAttrValueDES* serviceClassUuids = GenerateControllerServiceClassListLC(aProfileVersion);
       
   112 	
       
   113 	aSdpDatabase.UpdateAttributeL(aRecHandle, KSdpAttrIdServiceClassIDList, *serviceClassUuids);
       
   114 	CleanupStack::PopAndDestroy(serviceClassUuids);
       
   115 	}
       
   116 
       
   117 void AvrcpSdpUtils::UpdateProtocolDescriptorListL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle, TUint16 aProtocolVersion)
       
   118 	{
       
   119 	CSdpAttrValueDES *attrValDES = CSdpAttrValueDES::NewDESL(0);
       
   120 	CleanupStack::PushL(attrValDES);
       
   121 	attrValDES->StartListL()
       
   122 		->BuildDESL()->StartListL()
       
   123 			->BuildUUIDL(TUUID(TUint16(KL2CAP)))					// L2CAP
       
   124 			->BuildUintL(TSdpIntBuf<TUint16>(KAVCTP))				// PSM = AVCTP
       
   125 		->EndListL()
       
   126 		->BuildDESL()->StartListL()
       
   127 			->BuildUUIDL(TUUID(TUint16(KAVCTP)))					// AVCTP
       
   128 			->BuildUintL(TSdpIntBuf<TUint16>(aProtocolVersion))
       
   129 		->EndListL()
       
   130 	->EndListL();
       
   131 	aSdpDatabase.UpdateAttributeL(aRecHandle, KSdpAttrIdProtocolDescriptorList, *attrValDES);
       
   132 	CleanupStack::PopAndDestroy(attrValDES);
       
   133 	}
       
   134 
       
   135 void AvrcpSdpUtils::UpdateAdditionalProtocolDescriptorListL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle)
       
   136 	{
       
   137 	CSdpAttrValueDES *attrValDES = CSdpAttrValueDES::NewDESL(0);
       
   138 	CleanupStack::PushL(attrValDES);
       
   139 	attrValDES->StartListL()
       
   140 		->BuildDESL()->StartListL()
       
   141 			->BuildUUIDL(TUUID(TUint16(KL2CAP)))				// L2CAP
       
   142 			->BuildUintL(TSdpIntBuf<TUint16>(0x1b))				// PSM = AVCTP_browse
       
   143 		->EndListL()
       
   144 		->BuildDESL()->StartListL()
       
   145 			->BuildUUIDL(TUUID(TUint16(KAVCTP)))					// AVCTP
       
   146 			->BuildUintL(TSdpIntBuf<TUint16>(AvrcpSdp::KAvctpProtocolVersion13))// 0x0103
       
   147 		->EndListL()
       
   148 	->EndListL();
       
   149 	aSdpDatabase.UpdateAttributeL(aRecHandle, KSdpAttrIdAdditionalProtocolDescriptorList, *attrValDES);
       
   150 	CleanupStack::PopAndDestroy(attrValDES);
       
   151 	}
       
   152 
       
   153 void AvrcpSdpUtils::UpdateProfileDescriptorListL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle, TUint16 aProfileVersion)
       
   154 	{
       
   155 	CSdpAttrValueDES *attrValDES = CSdpAttrValueDES::NewDESL(0);
       
   156 	CleanupStack::PushL(attrValDES);
       
   157 	attrValDES->StartListL()
       
   158 		->BuildDESL()->StartListL()
       
   159 			//In the profile descriptor list the Control UUID is used 
       
   160 			//for BOTH controller and target
       
   161 			->BuildUUIDL(KAVRemoteControlUUID) 
       
   162 			->BuildUintL(TSdpIntBuf<TUint16>(aProfileVersion))
       
   163 		->EndListL()
       
   164 	->EndListL();
       
   165 	aSdpDatabase.UpdateAttributeL(aRecHandle, KSdpAttrIdBluetoothProfileDescriptorList, *attrValDES);
       
   166 	CleanupStack::PopAndDestroy(attrValDES);
       
   167 	}
       
   168 
       
   169 void AvrcpSdpUtils::UpdateSupportedFeaturesL(RSdpDatabase& aSdpDatabase, TSdpServRecordHandle& aRecHandle, AvrcpSdp::TRecordType aType, TUint16 aFeatures)
       
   170 	{
       
   171 	// Supported Features
       
   172 	// For both target and controller roles if we support that role then
       
   173 	// indicate support for all categories that are available within that
       
   174 	// role.
       
   175 	CSdpAttrValue* attrVal = NULL;
       
   176 	TSdpIntBuf<TUint16> featureBuf = (aType==AvrcpSdp::ERemoteControl) ? AvrcpSdp::KAvrcpBaseCtFeatures | aFeatures : AvrcpSdp::KAvrcpBaseTgFeatures | aFeatures;
       
   177 	attrVal = CSdpAttrValueUint::NewUintL(featureBuf); 
       
   178 	CleanupStack::PushL(attrVal);
       
   179 	aSdpDatabase.UpdateAttributeL(aRecHandle, KSdpAttrIdSupportedFeatures, *attrVal);
       
   180 	CleanupStack::PopAndDestroy(attrVal);
       
   181 	}