2006-05-19 07:38:27

by Özkan Gümüs

[permalink] [raw]
Subject: [Bluez-devel] cannot " hci_create_connection "


2006-05-19 21:39:28

by Albert Huang

[permalink] [raw]
Subject: Re: [Bluez-devel] cannot " hci_create_connection "

use hcidump -X -V and pay attention to the output to see what happens.

-albert

On 5/19/06, ozkan gumus <[email protected]> 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 <stdio.h>
> #include <errno.h>
> #include <ctype.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <stdlib.h>
> #include <string.h>
> #include <getopt.h>
> #include <sys/param.h>
> #include <sys/ioctl.h>
> #include <sys/socket.h>
> #include <signal.h>
> #include <termios.h>
> #include <fcntl.h>
> #include <getopt.h>
> #include <asm/types.h>
> #include <netinet/in.h>
>
> #include <bluetooth/bluetooth.h>
> #include <bluetooth/hci.h>
> #include <bluetooth/hci_lib.h>
>
> 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 };
> int measure ;
>
> 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));
> printf("scanning ...\n");
> num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
> 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);
> measure = 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 = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
> perror("Can't allocate memory");
> exit(1);
> }
> cl->dev_id = dev_id;
> cl->conn_num = 10;
> ci = cl->conn_info;
>
> if (ioctl(s, HCIGETCONNLIST, (void*)cl)) {
> perror("Can't get connection list");
> exit(1);
> }
>
> for (i=0; i < cl->conn_num; i++, ci++)
> if (!bacmp((bdaddr_t *)arg, &ci->bdaddr))
> return 1;
> return 0;
> }
>
>
> int read_rssi(char* address) {
> int cc = 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 = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
> if (dev_id < 0) {
> dev_id = hci_get_route(&bdaddr);
> cc = 1;
> }
> if (dev_id < 0) {
> printf("Device not available\n");
> exit(1);
> }
>
> dd = 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 = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));
> if (!cr) {
> printf("Could not allocate memory\n");
> exit(1);
> }
>
> bacpy(&cr->bdaddr, &bdaddr);
> cr->type = 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 = OGF_STATUS_PARAM;
> rq.ocf = OCF_READ_RSSI;
> rq.cparam = &cr->conn_info->handle;
> rq.clen = 2;
> rq.rparam = &rp;
> rq.rlen = 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 it
> now! <http://g.msn.com/8HMAENUS/2731??PS=47575>------------------------------------------------------- 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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


Attachments:
(No filename) (5.23 kB)
(No filename) (8.24 kB)
Download all attachments