* [Bluez-users] Odd inquiry scan result
@ 2005-06-29 16:38 Olivier Randriamanana
2005-06-29 17:28 ` Steven Singer
0 siblings, 1 reply; 3+ messages in thread
From: Olivier Randriamanana @ 2005-06-29 16:38 UTC (permalink / raw)
To: bluez-users
Hi,
I'm trying to understand how to send HCI commands (my
final goal is to put my device in periodic
inquiry...). For the moment, using hcitool.c as an
example, I issue a HCI_Read_Inquiry_Scan_Activity
command to the device.
I zero the read_inq_activity_rp structure, and send
the command. No error it seems, as the Command
Complete event is received, and here is the hex dump
of received data:
> HCI Event: 0x0e plen 8
01 1D 0C 12 00 00 00 00
However my read_inq_activity_rp structure is not
changed. I would have expected it to have the default
values (as read from the spec).
I can't figure out what I'm getting wrong, could
someone please provide a hint???
Regards,
Olivier
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
void hex_dump(char *pref, int width, unsigned char
*buf, int len);
void send_cmd(int dev_id, uint16_t ocf,uint8_t ogf /*,
int argc, char **argv*/);
int main(int argc, char* argv[])
{
printf("%s:\n",argv[0]);
send_cmd(0,OCF_PERIODIC_INQUIRY,OGF_HOST_CTL);
return 0;
}
void send_cmd(int dev_id, uint16_t uocf,uint8_t uogf
/*, int argc, char **argv*/)
{
char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
struct hci_filter flt;
hci_event_hdr *hdr;
int i, opt, len, dd;
read_inq_activity_rp rp;
read_inq_activity_rp* prp;
uint16_t ocf = OCF_READ_INQ_ACTIVITY;
uint8_t ogf = OGF_HOST_CTL;
printf("%s: OGF %d OCF %d dev_id
%d\n",__FUNCTION__,ogf,ocf,dev_id);
dd = hci_open_dev(dev_id);
if (dd < 0) {
perror("Device open failed");
exit(EXIT_FAILURE);
}
/* Setup filter */
hci_filter_clear(&flt);
hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
hci_filter_all_events(&flt);
if (setsockopt(dd, SOL_HCI, HCI_FILTER, &flt,
sizeof(flt)) < 0) {
perror("HCI filter setup failed");
exit(EXIT_FAILURE);
}
prp = &rp;
prp->status = 0;
prp->interval = 0;
prp->window = 0;
len = READ_INQ_ACTIVITY_RP_SIZE;
ptr = &rp;
printf("< HCI Command: ogf 0x%02x, ocf 0x%04x, plen
%d (sizeof %d)\n", ogf, ocf, len,sizeof(rp));
if (hci_send_cmd(dd, ogf, ocf, len, ptr /*buf*/) <
0) {
perror("Send failed");
exit(EXIT_FAILURE);
}
printf("rp.status %d, interval %d, window %d\n",
prp->status,
prp->interval,
prp->window);
len = read(dd, buf, sizeof(buf));
if (len < 0) {
perror("Read failed");
exit(EXIT_FAILURE);
}
hdr = (void *)(buf + 1);
ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
len -= (1 + HCI_EVENT_HDR_SIZE);
printf("> HCI Event: 0x%02x plen %d\n", hdr->evt,
hdr->plen);
hex_dump(" ", 20, ptr, len); fflush(stdout);
printf("rp.status %d, interval %d, window %d\n",
prp->status,
prp->interval,
prp->window);
prp = ptr;
printf("rp.status %d, interval %d, window %d\n",
prp->status,
prp->interval,
prp->window);
hci_close_dev(dd);
}
void hex_dump(char *pref, int width, unsigned char
*buf, int len)
{
register int i,n;
for (i = 0, n = 1; i < len; i++, n++) {
if (n == 1)
printf("%s", pref);
printf("%2.2X ", buf[i]);
if (n == width) {
printf("\n");
n = 0;
}
}
if (i && n!=1)
printf("\n");
}
--
Olivier
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Bluez-users] Odd inquiry scan result
2005-06-29 16:38 [Bluez-users] Odd inquiry scan result Olivier Randriamanana
@ 2005-06-29 17:28 ` Steven Singer
2005-06-29 17:55 ` Marcel Holtmann
0 siblings, 1 reply; 3+ messages in thread
From: Steven Singer @ 2005-06-29 17:28 UTC (permalink / raw)
To: bluez-users
Olivier Randriamanana wrote:
>> HCI Event: 0x0e plen 8
> 01 1D 0C 12 00 00 00 00
Event 0e: Command Complete
01: num_hci_command_packets = 1
1D 0C: Opcode 0x0c1d = Read Inquiry Scan Activity
12: Status = Invalid HCI command parameters !
00 00 00 00: Parameters = not valid as there was an error !
See the 10 commandments of C by Henry Spencer at:
http://www.lysator.liu.se/c/ten-commandments.html
Commandment 6:
If a function be advertised to return an error code in the event of
difficulties, thou shalt check for that code, yea, even though the
checks triple the size of thy code and produce aches in thy typing
fingers, for if thou thinkest ``it cannot happen to me'', the gods
shall surely punish thee for thy arrogance.
In this case for "function ... return" read "event ... contain".
[...]
> len = READ_INQ_ACTIVITY_RP_SIZE;
[...]
> if (hci_send_cmd(dd, ogf, ocf, len, ptr /*buf*/) < 0) {
Would I be right in thinking that READ_INQ_ACTIVITY_RP_SIZE is the
size of the response and not the size of the command?
You should be passing the size of the command parameters (0) here.
Confirm that the command that was sent was correct by looking at an
hcidump log.
- Steven
--
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Bluez-users] Odd inquiry scan result
2005-06-29 17:28 ` Steven Singer
@ 2005-06-29 17:55 ` Marcel Holtmann
0 siblings, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2005-06-29 17:55 UTC (permalink / raw)
To: bluez-users
Hi Steven,
> >> HCI Event: 0x0e plen 8
> > 01 1D 0C 12 00 00 00 00
>
> Event 0e: Command Complete
> 01: num_hci_command_packets = 1
> 1D 0C: Opcode 0x0c1d = Read Inquiry Scan Activity
> 12: Status = Invalid HCI command parameters !
> 00 00 00 00: Parameters = not valid as there was an error !
thanks for the decoding work, but using "hcidump -X -V" would have also
done the work ;)
> See the 10 commandments of C by Henry Spencer at:
>
> http://www.lysator.liu.se/c/ten-commandments.html
These are really good ones. I like them.
Regards
Marcel
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-06-29 17:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-29 16:38 [Bluez-users] Odd inquiry scan result Olivier Randriamanana
2005-06-29 17:28 ` Steven Singer
2005-06-29 17:55 ` Marcel Holtmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.