- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello,
I am currently working on bluetooth project which require scanning of bluetooth/BLE devices and RSSI calculation for distance measurement. I am using Eclipse IDE to write code in C.
When I tried to run the following code, always end up with ioctl error:Get connection info failed: No such file or directory.
Following line in the code always returns -1" if (ioctl(sock, HCIGETCONNINFO, (unsigned long) cr) < 0)" .
Your inputs will be highly valued.
Sample Code:bluetooth.c
# include
# include
# include
# include
# include
# include
# include
# include
# include
void connectusingRF(int *sock,char *addr);
int main(int argc, char **argv)
{
inquiry_info *ii = NULL;
struct hci_conn_info_req *cr;
bdaddr_t bdaddr;
int8_t rssi;
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);
printf("device Id %x \n", dev_id);
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));
cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
if( num_rsp < 0 ) perror("hci_inquiry");
printf("we are here %d \n",num_rsp);
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);
}
str2ba(addr,&bdaddr);
bacpy(&cr->bdaddr, &bdaddr);
cr->type = ACL_LINK;
if (ioctl(sock, HCIGETCONNINFO, (unsigned long) cr) < 0) {
perror("Get connection info failed");
exit(1);
}
if (hc...
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi,
I've never seen that error before, so I looked for some information about ioctl. Look at http://linux.die.net/man/2/ioctl http://linux.die.net/man/2/ioctl at the Return Values section:
Usually, on success zero is returned. A few ioctl() requests use the return value as an output parameter and return a nonnegative value on success. On error, -1 is returned, and errno is set appropriately.
And then the errors are listed. What specific error are you getting? Is that a custom code or a sample code? I saw a few sample codes with similar structure and functions where the lines on the ioctl function contain some differences.
Also, what OS do you have on your computer, what Eclipse version are you using? What image version are you using?
Sergio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi HC,
Do you still need help with this thread, were you able to compile your code successfully?
Sergio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi Sergio,
I am able to compile my code now. The problem was with the code. I was not making any connection to the server before calling the ioctl. Now, code compiles well. Thanks for your help.
Regards,
HC

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page