2005-11-08 09:31:17

by Arpit Rai

[permalink] [raw]
Subject: [Bluez-devel] C Program for Getting Link Quality

Hi

I've written a C program to help me get the link quality between two
bluetooth dongles. But, on compilation there are problems with the
definition:

cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
hci_conn_info)); (Error: 'hci_conn_info_req' undeclared)

This the program I'm running:

//Program for finding LQ
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>

int main(int argc, char **argv)
{
int dev_id = -1;
uint16_t *handle;
struct hci_conn_info_req *cr;
struct hci_request rq;
read_link_quality_rp rp;
bdaddr_t bdaddr;
int dd;
char addr[18] = "00:10:60:B3:2C:F8";

//connecting
int ptype;
uint8_t role;

role = 0;
ptype = HCI_DM1 | HCI_DM3 | HCI_DM5 | HCI_DH1 | HCI_DH3 | HCI_DH5;
str2ba(addr, &bdaddr);


if(dev_id < 0)
{
dev_id = hci_get_route(&bdaddr);
if(dev_id < 0)
{
printf("Cannot connect\n");
return 0;
}
}

if(hci_create_connection(dd, &bdaddr, htobs(ptype), 0, role, handle,4000) <
0)
{
//printf("Cannot create connection\n");
//return 0;
}


//get connection links
dd = hci_open_dev(dev_id);
if (dd < 0)
{
printf("HCI device open failed\n");
return 0;
}

cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
hci_conn_info));
if (!cr)
return 0;

bacpy(&cr->bdaddr, &bdaddr);
cr->type = ACL_LINK;
if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0)
{
printf("Get connection info failed\n");
return 0;
}

memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_STATUS_PARAM;
rq.ocf = OCF_READ_LINK_QUALITY;
rq.cparam = &cr->conn_info->handle;
rq.clen = 2;
rq.rparam = &rp;
rq.rlen = READ_LINK_QUALITY_RP_SIZE;

if (hci_send_req(dd, &rq, 100) < 0)
{
printf("HCI get_link_quality request failed\n");
return 0;
}

if (rp.status)
{
printf("HCI get_link_quality cmd failed\n", rp.status);
return 0;
}

int link_quality = rp.link_quality;
printf("Link quality for %s: %d", addr, link_quality);

close(dd);
free(cr);

//return link_quality;
}

On compilation, I get the following errors:

In file included from getlq.c:6:
/usr/include/bluetooth/hci.h:1113: error: syntax error before 'sa_family_t'
/usr/include/bluetooth/hci.h:1115: error: syntax error before '}' token
getlq.c: In function 'main':
getlq.c:53: error: 'hci_conn_info_req' undeclared (first use in this
function)
getlq.c:53: error: (Each undeclared identifier is reported only once
getlq.c:53: error: for each function it appears in.)
getlq.c:53: error: syntax error before ')' token
getlq.c:59: error: syntax error before 'int'
getlq.c: At top level:
getlq.c:65: error: syntax error before '&' token
getlq.c:85: error: 'rp' undeclared here (not in a function)
getlq.c:86: error: syntax error before string constant
getlq.c:86: error: conflicting types for 'printf'
getlq.c:86: note: a parameter list with an ellipsis can't match an empty
parameter name list declaration
getlq.c:86: warning: data definition has no type or storage class
getlq.c:88: warning: parameter names (without types) in function declaration
getlq.c:88: warning: data definition has no type or storage class
getlq.c:89: warning: parameter names (without types) in function declaration
getlq.c:89: error: conflicting types for 'free'
/usr/include/stdlib.h:601: error: previous declaration of 'free' was here
getlq.c:89: warning: data definition has no type or storage class
getlq.c:92: error: syntax error before '}' token

Any idea why I'm getting the compilation error?

Regards
Arpit


Attachments:
(No filename) (3.36 kB)
(No filename) (7.58 kB)
Download all attachments

2005-11-09 14:02:32

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] C Program for Getting Link Quality

Hi Arpit,

> Yes, I forgot to include the icotl.h as well.Anyway, for I changed the
> definition of: cr = (hci_conn_info_req *)malloc(sizeof(*cr) +
> sizeof(struct hci_conn_info)); to this: cr = (struct
> hci_conn_info_req*) malloc(sizeof(struct hci_conn_info_req) +
> sizeof(struct hci_conn_info)); . This doesn't give me the error any
> more.
>
> However, running the compiled program results in: Get connection info
> failed

why don't you make your program GPL and copy the code from hcitool for
getting the link quality. And use a decent coding style and not HTML
mail, because this give me a headache.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2005-11-09 12:52:50

by Arpit Rai

[permalink] [raw]
Subject: Re: [Bluez-devel] C Program for Getting Link Quality

Hi Marcel

Yes, I forgot to include the icotl.h as well.Anyway, for I changed the
definition of: cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
hci_conn_info)); to this: cr = (struct hci_conn_info_req*)
malloc(sizeof(struct hci_conn_info_req) + sizeof(struct hci_conn_info)); .
This doesn't give me the error any more.

However, running the compiled program results in: Get connection info failed

//Program for finding LQ
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

int main(int argc, char **argv)
{
int dev_id;
uint16_t *handle;
struct hci_conn_info_req *cr=0;
struct hci_request rq;
read_link_quality_rp rp;
bdaddr_t bdaddr;
int dd;
int err=0;
char addr[18] = "00:10:60:B3:2C:F3";


printf("Link quality for %s: ", addr);

//connecting
int ptype;
uint8_t role;

role = 0;
ptype = HCI_DM1 | HCI_DM3 | HCI_DM5 | HCI_DH1 | HCI_DH3 | HCI_DH5;
str2ba(addr, &bdaddr);


if(dev_id < 0)
{
dev_id = hci_get_route(&bdaddr);
if(dev_id < 0)
{
printf("Cannot connect\n");
return 0;
}
}

if(hci_create_connection(dd, &bdaddr, htobs(ptype), 0, role, handle,4000) <
0)
{
//printf("Cannot create connection\n");
//return 0;
}


//get connection links
dd = hci_open_dev(dev_id);
if (dd < 0) {
printf("HCI device open failed\n");
return 0;
}

//cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
hci_conn_info));
cr = (struct hci_conn_info_req*) malloc(sizeof(struct hci_conn_info_req) +
sizeof(struct hci_conn_info));
if (!cr)
{
return 0;
}

bacpy(&cr->bdaddr, &bdaddr);
cr->type = ACL_LINK;
if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0)
{
printf("Get connection info failed\n");
return 0;
}


memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_STATUS_PARAM;
rq.ocf = OCF_READ_LINK_QUALITY;
rq.cparam = &cr->conn_info->handle;
rq.clen = 2;
rq.rparam = &rp;
rq.rlen = READ_LINK_QUALITY_RP_SIZE;

if (hci_send_req(dd, &rq, 100) < 0)
{
printf("HCI get_link_quality request failed\n");
return 0;
}

if (rp.status)
{
printf("HCI get_link_quality cmd failed\n", rp.status);
return 0;
}

int link_quality = rp.link_quality;
printf("Link quality for %s: %d", addr, link_quality);

close(dd);
free(cr);


//return link_quality;
}

Any idea what might be wrong?

Regards
Arpit


On 11/9/05, Marcel Holtmann <[email protected]> wrote:
>
> Hi Arpit,
>
> > I did a yum update bluez*.
> >
> > The verion I'm using is:
> >
> > [root@174-15 bluetooth]# ls -l
> > total 116
> > -rw-r--r-- 1 root root 3607 Mar 2 2005 bluetooth.h
> >
> > On including sys/socket.h..the error is the same:
>
> maybe <sys/ioctl.h> is also missing.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server.
> Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Bluez-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


Attachments:
(No filename) (3.34 kB)
(No filename) (14.63 kB)
Download all attachments

2005-11-08 18:17:17

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] C Program for Getting Link Quality

Hi Arpit,

> I did a yum update bluez*.
>
> The verion I'm using is:
>
> [root@174-15 bluetooth]# ls -l
> total 116
> -rw-r--r-- 1 root root 3607 Mar 2 2005 bluetooth.h
>
> On including sys/socket.h..the error is the same:

maybe <sys/ioctl.h> is also missing.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2005-11-08 17:58:10

by Arpit Rai

[permalink] [raw]
Subject: Re: [Bluez-devel] C Program for Getting Link Quality

Hi Marcel

I did a yum update bluez*.

The verion I'm using is:

[root@174-15 bluetooth]# ls -l
total 116
-rw-r--r-- 1 root root 3607 Mar 2 2005 bluetooth.h

On including sys/socket.h..the error is the same:

[root@174-15 cprog]# gcc -o getlq getlq.c -lbluetooth
getlq.c: In function 'main':
getlq.c:54: error: 'hci_conn_info_req' undeclared (first use in this
function)
getlq.c:54: error: (Each undeclared identifier is reported only once
getlq.c:54: error: for each function it appears in.)
getlq.c:54: error: syntax error before ')' token
getlq.c:60: error: syntax error before 'int'
getlq.c: At top level:
getlq.c:66: error: syntax error before '&' token
getlq.c:86: error: 'rp' undeclared here (not in a function)
getlq.c:87: error: syntax error before string constant
getlq.c:87: error: conflicting types for 'printf'
getlq.c:87: note: a parameter list with an ellipsis can't match an empty
parameter name list declaration
getlq.c:87: warning: data definition has no type or storage class
getlq.c:89: warning: parameter names (without types) in function declaration
getlq.c:89: warning: data definition has no type or storage class
getlq.c:90: warning: parameter names (without types) in function declaration
getlq.c:90: error: conflicting types for 'free'
/usr/include/stdlib.h:601: error: previous declaration of 'free' was here
getlq.c:90: warning: data definition has no type or storage class
getlq.c:93: error: syntax error before '}' token

Any idea why its saying hci_conn_info_req undeclared?

Regards
Arpit

On 11/8/05, Marcel Holtmann <[email protected]> wrote:
>
> Hi Arpit,
>
> > I've written a C program to help me get the link quality between two
> > bluetooth dongles. But, on compilation there are problems with the
> > definition:
> >
> > cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
> > hci_conn_info)); (Error: 'hci_conn_info_req' undeclared)
> >
> > This the program I'm running:
> >
> > //Program for finding LQ
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <unistd.h>
> > #include <bluetooth/bluetooth.h>
> > #include <bluetooth/hci.h>
> > #include <bluetooth/hci_lib.h>
>
> don't forget to include <sys/socket.h> before <bluetooth/bluetooth.h> or
> use a newer version of the Bluetooth library.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server.
> Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Bluez-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


Attachments:
(No filename) (2.71 kB)
(No filename) (5.17 kB)
Download all attachments

2005-11-08 12:49:55

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] C Program for Getting Link Quality

Hi Arpit,

> I've written a C program to help me get the link quality between two
> bluetooth dongles. But, on compilation there are problems with the
> definition:
>
> cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
> hci_conn_info)); (Error: 'hci_conn_info_req' undeclared)
>
> This the program I'm running:
>
> //Program for finding LQ
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <bluetooth/bluetooth.h>
> #include <bluetooth/hci.h>
> #include <bluetooth/hci_lib.h>

don't forget to include <sys/socket.h> before <bluetooth/bluetooth.h> or
use a newer version of the Bluetooth library.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2005-11-08 09:46:51

by Collin R. Mulliner

[permalink] [raw]
Subject: Re: [Bluez-devel] C Program for Getting Link Quality

I thought the link quality is useless because each manufacturer has
different "quality" values and therefore the returned value is mostly
useless ... or did that change?


curious ... Collin

On Tue, 2005-11-08 at 17:31 +0800, Arpit Rai wrote:
> Hi
>
> I've written a C program to help me get the link quality between two
> bluetooth dongles. But, on compilation there are problems with the
> definition:
>
> cr = (hci_conn_info_req *)malloc(sizeof(*cr) + sizeof(struct
> hci_conn_info)); (Error: 'hci_conn_info_req' undeclared)

--
Collin R. Mulliner <[email protected]>
BETAVERSiON Systems [http://www.betaversion.net]
info/pgp: finger [email protected]
Ever used Mosaic?



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel