×
Namespaces

Variants
Actions

WISE Discover Device

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: ebra (17 Jun 2008)
Last edited: hamishwillee (30 May 2013)

Maemo Platform

int search_servers(wise_connection_manager* manager)
{
inquiry_info *inquiry=NULL;
int max_rsp,num_rsp,device_id,socket,len,flags,index;
 
/* Get local device ID */
device_id = hci_get_route(NULL);
if ( device_id < 0 ) return WISE_CONNECTION_ERROR;
 
/* Open socket */
socket = hci_open_dev( device_id );
if ( socket < 0 ) return WISE_CONNECTION_ERROR;
 
len = 8;
max_rsp = 255;
 
/* Flush existing Bluetooth devices */
flags = IREQ_CACHE_FLUSH;
 
/* Search Bluetooth devices */
inquiry = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
if ( inquiry==NULL ) return WISE_CONNECTION_ERROR;
num_rsp = hci_inquiry(device_id,len,max_rsp,NULL,&inquiry,flags);
 
for ( index=0; index < num_rsp; index++ )
{
wise_device* device = malloc(sizeof(wise_device));
if ( device!=NULL )
{
ba2str(&(inquiry+index)->bdaddr,device->BT_address);
if ( search_service(manager,device,logger)!=WISE_OK ) free(device);
else add_server(manager,device);
}
}
free(inquiry);
close(socket);
return WISE_OK;
}

S60 Platform

struct TDeviceData
{
THostName iDeviceName;
TBTDevAddr iDeviceAddr;
TUint iDeviceServicePort;
};
 
typedef RPointerArray<TDeviceData> TDeviceDataList;
TDeviceDataList iFoundDevices;
void CWISEConnectionManager::SearchServersL()
{
RHostResolver resolver;
TInquirySockAddr addr;
TNameEntry entry;
 
// reset search arrays
iFoundDevices.ResetAndDestroy();
 
// load protocol for discovery
TProtocolDesc pdesc;
User::LeaveIfError(iSocketServ.FindProtocol(KBTLinkManagerTxt(), pdesc));
 
// initialize host resolver
User::LeaveIfError(resolver.Open(iSocketServ, pdesc.iAddrFamily, pdesc.iProtocol));
 
// start device discovery by invoking remote address lookup
addr.SetIAC(KGIAC);
addr.SetAction(KHostResInquiry|KHostResName|KHostResIgnoreCache);
TInt error = resolver.GetByAddress(addr, entry);
while ( error==KErrNone )
{
TDeviceData *devData = new (ELeave) TDeviceData();
devData->iDeviceName = entry().iName;
devData->iDeviceAddr =
static_cast<TBTSockAddr>(entry().iAddr).BTAddr();
 
devData->iDeviceServicePort = 0;
iFoundDevices.Append(devData);
error = resolver.Next(entry);
}
resolver.Close();
}

Links

This page was last modified on 30 May 2013, at 06:39.
46 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.

×