From: "Rupesh Gujare" <rupesh_gujare@rediffmail.com>
To: "BlueZ development" <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] Need Help In SDP Programming......
Date: 2 Nov 2006 04:39:06 -0000 [thread overview]
Message-ID: <20061102043906.3875.qmail@webmail31.rediffmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 4299 bytes --]
Hello all,
I am a newbie to bluez programming. and i am currently writing a code that will discover all nearby bluetooth devices and make a SDP enquiry to know on which channel "OBEX Object Push" service is running.
For this purpose i have gone through a quiet a few documentation and sample code. And i am ready with some code.
Now my question is why it is required to give a "sleep(1)" call before sdp_connect() call? If i dont give it, sdp connection simply fails. And how should i reduce over all time of making discovery of devices and connecting to their respective SDP servers.
I am using USB dongle as a local bluetooth device.
Can someone help me on this issues? And how can i write better and efficient code?
Any reviews and suggestions for improvement r welcomed.
Any help will be greatly appreciated.
Thanks in advance
Rupesh..
My code :----
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
int port_search(bdaddr_t *target);
int main(int argc, char **argv)
{
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };
dev_id = hci_get_route(NULL);
sock = hci_open_dev( dev_id );
if (dev_id < 0 || sock < 0) {
perror("opening socket");
exit(1);
}
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
printf("%d Blue devices found\n",num_rsp);
if( num_rsp < 0 ) perror("hci_inquiry");
for (i = 0; i < num_rsp; i++) {
ba2str(&(ii+i)->bdaddr, addr);
memset(name, 0, sizeof(name));
if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
name, 0) < 0)
strcpy(name, "[unknown]");
printf("%s %s\n", addr, name);
port_search(&(ii+i)->bdaddr);
}
free( ii );
close( sock );
return 0;
}
int port_search(bdaddr_t *target)
{
uint16_t svc_uuid_int = 0x1105;
int status;
char addr[18];
bdaddr_t local_addr;
uuid_t svc_uuid;
sdp_list_t *response_list, *search_list, *attrid_list;
sdp_session_t *session = 0;
uint32_t range = 0x0000ffff;
uint8_t port = 0;
ba2str(target,addr);
printf("Target blue addr is %s\n",addr);
//str2ba( addr, &target );
// connect to the SDP server running on the remote machine
ba2str(&local_addr, addr);
printf("Local address is %s\n",addr);
sleep(1);
session = sdp_connect( BDADDR_ANY, target,SDP_RETRY_IF_BUSY);
if (session==NULL)
{
printf("Can not connect to SDP server\n");
return -1;
}
sdp_uuid16_create( &svc_uuid, svc_uuid_int );
search_list = sdp_list_append( 0, &svc_uuid );
attrid_list = sdp_list_append( 0, &range );
// get a list of service records that have UUID 0xabcd
response_list = NULL;
status = sdp_service_search_attr_req( session, search_list, SDP_ATTR_REQ_RANGE, attrid_list, &response_list);
if( status == 0 ) {
if(response_list==NULL)
{
printf("Object Push Service not found\n");
return -1;
}
sdp_list_t *proto_list;
sdp_list_t *r = response_list;
// go through each of the service records
for (; r; r = r->next ) {
sdp_record_t *rec = (sdp_record_t*) r->data;
// get a list of the protocol sequences
if( sdp_get_access_protos( rec, &proto_list ) == 0 )
// if(sdp_get_profile_descs(rec,&proto_list)==0)
{
// get the RFCOMM port number
port = sdp_get_proto_port( proto_list, RFCOMM_UUID );
sdp_list_free( proto_list, 0 );
}
sdp_record_free( rec );
}
}
sdp_list_free( response_list, 0 );
sdp_list_free( search_list, 0 );
sdp_list_free( attrid_list, 0 );
sdp_close( session );
if( port != 0 ) {
printf("found service running on RFCOMM port %d\n", port);
}
return 0;
}
[-- Attachment #1.2: Type: text/html, Size: 7049 bytes --]
[-- Attachment #2: Type: text/plain, Size: 373 bytes --]
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
[-- Attachment #3: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2006-11-02 4:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-02 4:39 Rupesh Gujare [this message]
2006-11-02 6:28 ` [Bluez-devel] Need Help In SDP Programming Mingfan.Lu
2006-11-02 9:58 ` Peter Wippich
-- strict thread matches above, loose matches on Subject: below --
2006-11-02 12:28 Rupesh Gujare
2006-11-02 13:05 ` Peter Wippich
2006-11-02 13:08 Rupesh Gujare
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061102043906.3875.qmail@webmail31.rediffmail.com \
--to=rupesh_gujare@rediffmail.com \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox