[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bluetooth-dev] SDP Client in 20010108 stack



Matthias Fuchs wrote:

> Hi Marcus,
> 
> Marcus Smith wrote:
> 
>> Hello,
>> 
>> I've recently completed code modifications to support SDP client
>> inquiry/response
>> in the 20010108.  Through the ioctl() layer, you can: 1) establish an
>> sdp connection
>> 2) send a request...collect the response and 3) close the sdp connection.
>> How far is Axis (or anyone else) in providing this
>> functionality?  Is there any interest in obtaining this code?
> 
> That sounds good. From where do you actually send the sdp request ? Did
> you add some new functionality to the btd ?
> btd is growing and growing :-) 
> 
> I am also interessted in your sdp code. Can you send it to me (since I
> do not know when the sourceforge site is working :-) ?
> 
> Matthias
> 
Here is a snapshot of some code which I've used to test the SDP client 
functionality.  It
will at least give an indication of how I built the client code.  The 
code is done.  I'll work on a patch
and publish it when ready.

Marcus





/*------------------------------------------------------------------*/
/* inq.c - This is a sample program that was written to test the    */
/* Axis 20010108 stack opening ttyBTC multiple times.  It is to be  */
/* run with 'btd' running in a separate process.  This will attempt */
/* to open the ttyBTC control tty and attempt an inquiry.           */
/*                                                                  */
/* Author: Marcus Smith                                             */
/* Date: 1/25/2001                                                  */
/* Copyright (C) 2001 RidgeRun Inc.                                 */
/*------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <linux/bluetooth/btcommon.h>
#include <linux/bluetooth/sdp.h>
#include <linux/bluetooth/l2cap.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>    /* For tcflush() & TCIOFLUSH */
#include <sys/ioctl.h>  /* For ioctl. */

#define BT_CONTROL_TTY "/dev/ttyBTC"
#define UUID_PUBLIC_BROWSE_GROUP 0x1002
#define SDP_SERVICESEARCH_REQ 2

int main(int argc, char **argv)
{
   int i;
   inquiry_results *inq_res;
   int bt_cfd = -1;
   struct bt_connection conn;
   unsigned char tmp_bd[8];
   int sdpConnectionID = -1;
   int index;
   unsigned int conID;

   /*-----------------------------------------------------------*/
   /* Issue the prompt for the user to input the BD address.    */
   /*-----------------------------------------------------------*/
   printf("Enter the remote BD address (xx:xx:xx:xx:xx:xx <line> \n=> ");

   if ( scanf("%x:%x:%x:%x:%x:%x %d", &tmp_bd[0], &tmp_bd[1], &tmp_bd[2], &tmp_bd[3], &tmp_bd[4], &tmp_bd[5], &tmp_bd[6]) < 6)
   {
      fprintf(stderr, "Error:  Invalid format - try again\n");
      exit(-1);
   }

   /*-----------------------------------------------------------*/
   /* Fill in the bt_connection structure before the ioctl.     */
   /*-----------------------------------------------------------*/
   memcpy(conn.bd, tmp_bd, 6);
   conn.id = CREATE_SDP_ID(tmp_bd[6] /* BT line */, 0 /* This is a no-op on the connection construction */);
   printf("Connection ID: 0x%X\n", conn.id);

   /*-----------------------------------------------------*/
   /* Open the bluetooth control tty.                     */
   /*-----------------------------------------------------*/
   fprintf(stderr, "Opening the connection for iteration # %d\n", index);
   if ((bt_cfd = open(BT_CONTROL_TTY, O_RDWR)) < 0 )
   { 
      perror("open_device");
      exit(1);
   }

   /*-----------------------------------------------------------*/
   /* Flush this file descriptor.                               */
   /*-----------------------------------------------------------*/
   tcflush(bt_cfd, TCIOFLUSH);

   /*-----------------------------------------------------------*/
   /* Issue the ioctl to setup the connection.                  */
   /*-----------------------------------------------------------*/
   sleep(5);
   if ( (sdpConnectionID = ioctl(bt_cfd, BTCONNECT, &conn)) < 0 )
   {
      perror("SDP connection error");
      close(bt_cfd);
      exit(-1);
   }
   
   fprintf(stderr, "Connection a success!\n");
   if ( sdpConnectionID >= 0 )
   {
      bt_sdp_request sdpRequestData;

      /*------------------------------------------------------------------*/
      /* Fill in the command buffer.                                      */
      /*------------------------------------------------------------------*/
      memset(&sdpRequestData, 0x00, sizeof(bt_sdp_request));
      fprintf(stderr, "Getting ready for the SDP Request transaction - Connection ID = %d\n", sdpConnectionID);

      /*------------------------------------------------------------------------------------*/
      /* Write out the Data Element Sequence Header, which is 0x35.                         */
      /*------------------------------------------------------------------------------------*/
      sdpRequestData.pduPayload[0] = 0x35;
    
      /*------------------------------------------------------------------------------------*/
      /* Write out the number of bytes to follow.  Since there is one UUID16_HDR and a 16   */
      /* byte UUID, there are 3 bytes following.                                            */
      /*------------------------------------------------------------------------------------*/
      sdpRequestData.pduPayload[1] = 0x03;
    
      /*------------------------------------------------------------------------------------*/
      /* Apply the UUID16_HDR and the PublicBrowseGroup.                                    */
      /*------------------------------------------------------------------------------------*/
      sdpRequestData.pduPayload[2] = 0x19;
      sdpRequestData.pduPayload[3] = (UUID_PUBLIC_BROWSE_GROUP >> 8) & 0xff;
      sdpRequestData.pduPayload[4] = UUID_PUBLIC_BROWSE_GROUP & 0xff;
       
      /*------------------------------------------------------------------*/
      /* Issue the sdp request.                                           */
      /*------------------------------------------------------------------*/
      sdpRequestData.pduLength = 5;
      sdpRequestData.sdpCommand = SDP_SERVICESEARCH_REQ;
      
      /*---------------------------------------------------------------------------*/
      /* Fill in the bt_sdp_request data structure.                                */
      /*---------------------------------------------------------------------------*/
      sdpRequestData.conID = CREATE_SDP_ID(tmp_bd[6] /* BT line */, sdpConnectionID /* No longer a no-op */);
   
      /* Issue the ioctl. */
      if ( ioctl(bt_cfd, BT_SDP_REQUEST, &sdpRequestData) < 0 )
      {
         perror("SDP request error");
         exit(-1);
      }
      else
      {
         fprintf(stderr, "Successful in sdp request\n");
      }
   
      /*------------------------------------------------------------------------*/
      /* Close the SDP connection.                                              */
      /*------------------------------------------------------------------------*/
      conID = CREATE_SDP_ID(tmp_bd[6] /* BT line */, sdpConnectionID /* No longer a no-op */);
      ioctl(bt_cfd, BTDISCONNECT, &conID);
      close(bt_cfd);

   }

   return 0;

}  /* End of test2 program */