Return-Path: Message-ID: From: "Albert Huang" To: bluez-devel@lists.sourceforge.net Subject: Re: [Bluez-devel] cannot " hci_create_connection " In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_45383_2168228.1148074768426" References: Sender: bluez-devel-admin@lists.sourceforge.net Errors-To: bluez-devel-admin@lists.sourceforge.net Reply-To: bluez-devel@lists.sourceforge.net List-Unsubscribe: , List-Id: BlueZ development List-Post: List-Help: List-Subscribe: , List-Archive: Date: Fri, 19 May 2006 17:39:28 -0400 ------=_Part_45383_2168228.1148074768426 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline use hcidump -X -V and pay attention to the output to see what happens. -albert On 5/19/06, ozkan gumus wrote: > > hi mr holtmann, > > i have problem with hci_create_connection function at line 120. > here's the code , when program comes to the line of > hci_create_connection function > it always says : > > #./simplescan > scanning ... > 00:0E:6D:3F:E0:73 ozkan > Cannot create connection > > > simplescan.c > > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > > #include > #include > #include > > int main(int argc, char **argv) > { > inquiry_info *ii =3D NULL; > int max_rsp, num_rsp; > int dev_id, sock, len, flags; > int i; > char addr[19] =3D { 0 }; > char name[248] =3D { 0 }; > int measure ; > > dev_id =3D hci_get_route(NULL); > sock =3D hci_open_dev( dev_id ); > if (dev_id < 0 || sock < 0) { > perror("opening socket"); > exit(1); > } > > len =3D 8; > max_rsp =3D 255; > flags =3D IREQ_CACHE_FLUSH; > ii =3D (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info)); > printf("scanning ...\n"); > num_rsp =3D hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); > if( num_rsp < 0 ) perror("hci_inquiry"); > > for (i =3D 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); > measure =3D read_rssi(&(ii+i)->bdaddr); > printf("the RSSI measure for %s is %d",name,measure); > } > > free( ii ); > close( sock ); > return 0; > } > > > static int find_conn(int s, int dev_id, long arg) > { > struct hci_conn_list_req *cl; > struct hci_conn_info *ci; > int i; > > if (!(cl =3D malloc(10 * sizeof(*ci) + sizeof(*cl)))) { > perror("Can't allocate memory"); > exit(1); > } > cl->dev_id =3D dev_id; > cl->conn_num =3D 10; > ci =3D cl->conn_info; > > if (ioctl(s, HCIGETCONNLIST, (void*)cl)) { > perror("Can't get connection list"); > exit(1); > } > > for (i=3D0; i < cl->conn_num; i++, ci++) > if (!bacmp((bdaddr_t *)arg, &ci->bdaddr)) > return 1; > return 0; > } > > > int read_rssi(char* address) { > int cc =3D 0; > int dd; > int dev_id; > uint16_t handle; > struct hci_conn_info_req *cr; > struct hci_request rq; > read_rssi_rp rp; > bdaddr_t bdaddr; > > str2ba(address, &bdaddr); > > dev_id =3D hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); > if (dev_id < 0) { > dev_id =3D hci_get_route(&bdaddr); > cc =3D 1; > } > if (dev_id < 0) { > printf("Device not available\n"); > exit(1); > } > > dd =3D hci_open_dev(dev_id); > if (dd < 0) { > printf("Cannot open device\n"); > exit(1); > } > // *************************** PROBLEM HERE ************************* > if (cc) { > if (hci_create_connection(dd, &bdaddr, 0x0008 | 0x0010, 0, 0, &handle= , > 25000) < 0) { > printf("Cannot create connection\n"); > close(dd); > exit(1); > } > } > // ***************************** > ***************************************** > cr =3D malloc(sizeof(*cr) + sizeof(struct hci_conn_info)); > if (!cr) { > printf("Could not allocate memory\n"); > exit(1); > } > > bacpy(&cr->bdaddr, &bdaddr); > cr->type =3D ACL_LINK; > if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) { > printf("Get connection info failed\n"); > exit(1); > } > > memset(&rq, 0, sizeof(rq)); > rq.ogf =3D OGF_STATUS_PARAM; > rq.ocf =3D OCF_READ_RSSI; > rq.cparam =3D &cr->conn_info->handle; > rq.clen =3D 2; > rq.rparam =3D &rp; > rq.rlen =3D READ_RSSI_RP_SIZE; > > if (hci_send_req(dd, &rq, 100) < 0) { > printf("Read RSSI failed\n"); > exit(1); > } > > if (rp.status) { > printf("Read RSSI returned (error) status 0x%2.2X\n", rp.status); > exit(1); > } > > if (cc) { > hci_disconnect(dd, handle, 0x13, 10000); > } > > close(dd); > free(cr); > printf("My RSSI is : %d",rp.rssi); > return rp.rssi ; > } > > can you give me some advise to resolve this problem, ? do you think my > ptype or clkoffset are false ? > > i will be very grateful for a little help.. > > thanks, > > > > > > ------------------------------ > Find just what you're after with the new, more precise MSN Search - try i= t > now! ------------------------= ------------------------------- 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 I= BM > WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642_______________________________________________ Bluez-devel mailin= g list > Bluez-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/bluez-devel > ------=_Part_45383_2168228.1148074768426 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline use hcidump -X -V and pay attention to the output to see what happens.

-albert

On 5/19/06, ozkan gumus <ozkan_gumus@hotmail.com> wrote:

hi mr holtmann,

i have problem with hci_create_connection function at line 120.
here= 's the code ,  when program comes to the line  of hci_create_conn= ection function
it always says :

 #./simplescan
scanning ...
00:0E:6D:3F:E0:73  ozkan
= Cannot create connection


simplescan.c

#include <stdio.h>
#include <errno.h>
#include <cty= pe.h>
#include <fcntl.h>
#include <unistd.h>
#inclu= de <stdlib.h>
#include <string.h>
#include <getopt.h >
#include <sys/param.h>
#include <sys/ioctl.h>
#in= clude <sys/socket.h>
#include <signal.h>
#include <ter= mios.h>
#include <fcntl.h>
#include <getopt.h>
#include <asm/types.h>
#include <netinet/in.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h&g= t;
#include <bluetooth/hci_lib.h>

int main(int argc, char **argv)
{
    inquiry_info = *ii =3D NULL;
    int max_rsp, num_rsp;
  &n= bsp; int dev_id, sock, len, flags;
    int i;
 &n= bsp;  char addr[19] =3D { 0 };
    char name[248] = =3D { 0 };
 int measure ;

    dev_id =3D hci_get_route(NULL);
   = sock =3D hci_open_dev( dev_id );
    if (dev_id < 0 |= | sock < 0) {
        perror("= ;opening socket");
        exit(= 1);
    }

    len  =3D 8;
    max_rsp =3D 25= 5;
    flags =3D IREQ_CACHE_FLUSH;
    = ii =3D (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
 &nbs= p;  printf("scanning ...\n");
    num_rsp = =3D hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
    if( num_rsp < 0 ) perror("hci_inquiry")= ;

    for (i =3D 0; i < num_rsp; i++) {
  &= nbsp;     ba2str(&(ii+i)->bdaddr, addr);
&nbs= p;       memset(name, 0, sizeof(name));
&n= bsp;       if (hci_read_remote_name(sock, &am= p;(ii+i)->bdaddr, sizeof(name),
      =       name, 0) < 0)
        strcpy(name, "[unknown]= ");
        printf("%s = ; %s\n", addr, name);
  measure =3D read_rssi(&(ii+i)= ->bdaddr);
  printf("the RSSI measure for %s is %d&quo= t;,name,measure);
    }

    free( ii );
    close( sock );
&= nbsp;   return 0;
}


static int find_conn(int s, int dev_id, long arg)
{
 stru= ct hci_conn_list_req *cl;
 struct hci_conn_info *ci;
 int i= ;

 if (!(cl =3D malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
 &= nbsp;perror("Can't allocate memory");
  exit(1);
=  }
 cl->dev_id =3D dev_id;
 cl->conn_num =3D 10;=
 ci =3D cl->conn_info;

 if (ioctl(s, HCIGETCONNLIST, (void*)cl)) {
  perror(&= quot;Can't get connection list");
  exit(1);
 }

 for (i=3D0; i < cl->conn_num; i++, ci++)
  if (= !bacmp((bdaddr_t *)arg, &ci->bdaddr))
   return 1;=
 return 0;
}


int read_rssi(char* address) {
  int cc =3D 0;
  int= dd;
  int dev_id;
  uint16_t handle;
  struct hci_= conn_info_req *cr;
  struct hci_request rq;
  read_rssi_rp = rp;
  bdaddr_t bdaddr;
 
  str2ba(address, &bdaddr);
 
  dev_id =3D hci_fo= r_each_dev(HCI_UP, find_conn, (long) &bdaddr);
  if (dev_id <= ; 0) {
    dev_id =3D hci_get_route(&bdaddr);
&nbs= p;   cc =3D 1;
  }
  if (dev_id < 0) {
    printf("Device not available\n");
 = ;   exit(1);
  }
 
  dd =3D hci_open_dev= (dev_id);
  if (dd < 0) {
    printf("Can= not open device\n");
    exit(1);
  }
// = ***************************   PROBLEM HERE=20 *************************
  if (cc) {
    if (hc= i_create_connection(dd, &bdaddr, 0x0008 | 0x0010, 0, 0, &handle, 25= 000) < 0) {
      printf("Cannot create= connection\n");
      close(dd);
      exit(1);
    }
&nbs= p; }
 // ***************************** ****************************= *************
  cr =3D malloc(sizeof(*cr) + sizeof(struct hci_conn_= info));
  if (!cr) {
    printf("Could not a= llocate memory\n");
    exit(1);
  }
   
 = ; bacpy(&cr->bdaddr, &bdaddr);
  cr->type =3D ACL_LIN= K;
  if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) {    printf("Get connection info failed\n");
   =20 exit(1);
  }
 
  memset(&rq, 0, sizeof(rq));  rq.ogf    =3D OGF_STATUS_PARAM;
  rq.ocf&nb= sp;   =3D OCF_READ_RSSI;
  rq.cparam =3D &cr->conn= _info->handle;
  rq.clen   =3D 2;
  rq.rparam = =3D &rp;
  rq.rlen   =3D READ_RSSI_RP_SIZE;
 
  = if (hci_send_req(dd, &rq, 100) < 0) {
    printf(&= quot;Read RSSI failed\n");
    exit(1);
  }<= br> 
  if (rp.status) {
    printf("Re= ad RSSI returned (error) status 0x%2.2X\n",=20 rp.status);
    exit(1);
  }
 
 = if (cc) {
    hci_disconnect(dd, handle, 0x13, 10000);  }
 
  close(dd);
  free(cr);
  pr= intf("My RSSI is  : %d",rp.rssi);
  return rp.rssi ;=
}

can you give me some advise to resolve this problem, ? do you think my p= type or clkoffset are false ?

i will be very grateful for a little help..

thanks,

 

 



Find = just what you're after with the new, more precise MSN Search - try it now! =20 ------------------------------------------------------- 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 easi= er Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=3Dlnk&= ;kid=3D120709&bid=3D263057&dat=3D121642 _______________________________________________ Bluez-devel mailing list Bluez-devel@lists.sour= ceforge.net https:= //lists.sourceforge.net/lists/listinfo/bluez-devel

------=_Part_45383_2168228.1148074768426-- ------------------------------------------------------- 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