Revision as of 12:22, 2 May 2008 by Forum Nokia KB (Talk | contribs)

Advertising Bluetooth services using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

ID Creation date April 25, 2008
Platform S60 3rd Edition, MR Tested on devices Nokia N95
Category Symbian C++ Subcategory Bluetooth

Keywords (APIs, classes, methods, functions): RSdp, RSdpDatabase, TSdpServRecordHandle, RSdpDatabase::CreateServiceRecordL(), RSdpDatabase::UpdateAttributeL()


RSdp provides a session to the Service Discovery Database. Used to create subsessions to database functionality. A clients must create and connect a session, before using a RSdpDatabase subsession to access the database.

RSdpDatabase is subsession to the SDP through which service records and their attributes can be added, deleted, and updated.

Following example show how to advertise own (KBT_serviceID 0x10ff) bluetooth service. Discovering this particular service can be found from CSdpAgent.

Listening of the bluetooth connection is explained in Bluetooth_connection. Channel number parameter in CMyServiceAdvertiser::StartAdvertiserL(TInt aChannel) method comes there.

MMP file

The following capabilities and libraries are required:

CAPABILITY      LocalServices
LIBRARY sdpagent.lib
LIBRARY sdpdatabase.lib

Header file

#include <btsdp.h>
#include <bt_sock.h>
// The service id that identifies our service. This id will be
// used when advertising the service and discovering the service.
#define KBT_serviceID 0x10ff
// Service name and description for our service
_LIT(KBTServiceName, "BTpmp");
_LIT(KBTServiceDesc, "BTpmp");
// Service discovery protocol session
RSdp iSdp;
// Service discovery database (sdp)
RSdpDatabase iSdpDB;
// Service record
TSdpServRecordHandle iRecord;
// Service record state
TInt iRecordState;

Source file

Start service advertiser on given channel. Entry to service discovery database will be entered describing our advertised service.

void CMyServiceAdvertiser::StartAdvertiserL(TInt aChannel)
// Open sdp session
// Open sdp database session
// Create a record of the correct service class
TUUID serviceUUID(KBT_serviceID);
iSdpDB.CreateServiceRecordL(serviceUUID, iRecord);
// Add a protocol to the record
CSdpAttrValueDES* protocolDescriptorList = CSdpAttrValueDES::NewDESL(NULL);
TBuf8<1> channel;
// Create protocol list for our service
->StartListL() // list of protocols required for this method
// Set protocol list to the record
iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdProtocolDescriptorList,
// Add a name to the record
KSdpAttrIdBasePrimaryLanguage +
// Add a description to the record
KSdpAttrIdBasePrimaryLanguage +
// Set service available

Set availability of our advertised service. Service record on the service discovery database will be updated accordingly.

void CMyServiceAdvertiser::UpdateAvailabilityL(TBool aAvailable)
TInt state = aAvailable ? 0xFF : 0x00;
// Set availability
iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdServiceAvailability, state);
// Mark record changed
iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdServiceRecordState,

Stop advertising service

void CMyServiceAdvertiser::StopAdvertiserL()
if ( iRecord!=NULL )
// Delete out record from service discovery database
// Close sdp and sdp db sessions


Own bluetooth service is advertised and can be discovered according to CSdpAgent.

See also

RHostResolver Bluetooth device discovering
Bluetooth_connection Bluetooth connection listening
CSdpAgent Bluetooth service discovery
RSdp Bluetooth service advertising

134 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.