public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-users] hci_inquiry problem
@ 2007-08-29 14:17 giulio fedel
  2007-08-30 10:43 ` giulio fedel
  0 siblings, 1 reply; 2+ messages in thread
From: giulio fedel @ 2007-08-29 14:17 UTC (permalink / raw)
  To: bluez-users

Hi,
I'm working on an arm embedded system. It turn out that hci_inquiry in 
hci.c (libs) calls

--> buf = malloc(sizeof(*ir) + (sizeof(inquiry_info) * (nrsp)))
...
--> ioctl(dd, HCIINQUIRY, (unsigned long) buf)
...

My problem is that sizeof(struct hci_inquiry_req) is not the same in 
kernel space and in user space (nothing strange), so when in the kernel 
driver in hci_core.c we do:

--> hci_inquiry_req * ir;
...
--> ptr += sizeof(ir);
--> copy_to_user(ptr, buf, sizeof(struct inquiry_info) * ir.num_rsp)

and in the library code (hci_inquiry)

--> hci_inquiry_req * ir;
...
--> memcpy((void *) *ii, buf + sizeof(*ir), size);

the things do not work as aspected.
I solved my problem with __attribute__ ((packed)) in hci.h
in the kernel tree (include/net/bluetooth/) and in the library
(include/hci.h).

Regards.

     Giulio Fedel


patches on hci(s).h

Kernel side:


--- linux-2.6.22.1/include/net/bluetooth/hci.h.orig     2007-08-29 
15:14:49.000000000 +0200
+++ linux-2.6.22.1/include/net/bluetooth/hci.h  2007-08-29 
15:14:35.000000000 +0200
@@ -845,7 +845,7 @@
         __u8  lap[3];
         __u8  length;
         __u8  num_rsp;
-};
+} __attribute__ ((packed));
  #define IREQ_CACHE_FLUSH 0x0001

  #endif /* __HCI_H */


library:

--- bluez-libs-3.16/include/hci.h.orig  2007-08-29 15:18:25.000000000 +0200
+++ bluez-libs-3.16/include/hci.h       2007-08-29 15:18:58.000000000 +0200
@@ -1815,7 +1815,7 @@
         uint8_t  lap[3];
         uint8_t  length;
         uint8_t  num_rsp;
-};
+} __attribute__ ((packed)) ;
  #define IREQ_CACHE_FLUSH 0x0001

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Bluez-users] hci_inquiry problem
  2007-08-29 14:17 [Bluez-users] hci_inquiry problem giulio fedel
@ 2007-08-30 10:43 ` giulio fedel
  0 siblings, 0 replies; 2+ messages in thread
From: giulio fedel @ 2007-08-30 10:43 UTC (permalink / raw)
  To: BlueZ users

Thinking a bit more, I found the difference in the structure sizes due 
to a mismatch with arm abi/eabi interfaces (gcc mabi apcs-gnu/aapcs 
option). Probably only a my compiler version specific issue.

     Giulio Fedel

giulio fedel wrote:
> Hi,
> I'm working on an arm embedded system. It turn out that hci_inquiry in 
> hci.c (libs) calls
> 
> --> buf = malloc(sizeof(*ir) + (sizeof(inquiry_info) * (nrsp)))
> ...
> --> ioctl(dd, HCIINQUIRY, (unsigned long) buf)
> ...
> 
> My problem is that sizeof(struct hci_inquiry_req) is not the same in 
> kernel space and in user space (nothing strange), so when in the kernel 
> driver in hci_core.c we do:
> 
> --> hci_inquiry_req * ir;
> ...
> --> ptr += sizeof(ir);
> --> copy_to_user(ptr, buf, sizeof(struct inquiry_info) * ir.num_rsp)
> 
> and in the library code (hci_inquiry)
> 
> --> hci_inquiry_req * ir;
> ...
> --> memcpy((void *) *ii, buf + sizeof(*ir), size);
> 
> the things do not work as aspected.
> I solved my problem with __attribute__ ((packed)) in hci.h
> in the kernel tree (include/net/bluetooth/) and in the library
> (include/hci.h).
> 
> Regards.
> 
>      Giulio Fedel
> 
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Bluez-users mailing list
Bluez-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-users

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-30 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-29 14:17 [Bluez-users] hci_inquiry problem giulio fedel
2007-08-30 10:43 ` giulio fedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox