Return-Path: Message-ID: <3f5a9ba20611012228m6290f6ech41d3e7cb77fddf6d@mail.gmail.com> Date: Thu, 2 Nov 2006 14:28:12 +0800 From: "Mingfan.Lu" To: "Rupesh Gujare" , "BlueZ development" In-Reply-To: <20061102043906.3875.qmail@webmail31.rediffmail.com> MIME-Version: 1.0 References: <20061102043906.3875.qmail@webmail31.rediffmail.com> Subject: Re: [Bluez-devel] Need Help In SDP Programming...... Reply-To: BlueZ development List-Id: BlueZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============1921688207==" Sender: bluez-devel-bounces@lists.sourceforge.net Errors-To: bluez-devel-bounces@lists.sourceforge.net --===============1921688207== Content-Type: multipart/alternative; boundary="----=_Part_458_10826475.1162448892669" ------=_Part_458_10826475.1162448892669 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, What is your kernel version and Have you patch the latest bluez-patch ?. I think it is the problem of currency connections. There are many discussions about it in the maillist. From patch-linux-2.6.18-mh4 The problem seems to be solved. 2 Nov 2006 04:39:06 -0000, Rupesh Gujare : > > 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 > #include > #include > #include > #include > #include > #include > #include > #include > > 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; > } > > > > > ------------------------------------------------------------------------- > 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 > > _______________________________________________ > Bluez-devel mailing list > Bluez-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/bluez-devel > > > -- With respects, Mingfan.Lu ------=_Part_458_10826475.1162448892669 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi,
  What is your kernel version and Have you patch the latest bluez-patch ?.
  I think it is the problem of currency connections. There are many discussions about it in the maillist. From patch-linux-2.6.18-mh4
  The problem seems to be solved.

 
2 Nov 2006 04:39:06 -0000, Rupesh Gujare <rupesh_gujare@rediffmail.com>:

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;
}




-------------------------------------------------------------------------
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

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel





--
With respects,
   Mingfan.Lu ------=_Part_458_10826475.1162448892669-- --===============1921688207== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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 --===============1921688207== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Bluez-devel mailing list Bluez-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-devel --===============1921688207==--