Skip to contentSkip to conversation

endianess question

Bluez-devel Martin Röhricht 2 participants 2 messages Apr 7, 2006 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hello together,

whenever I take data out of a socket buffer using the get_unaligned() function like this:

	u16 control = get_unaligned((u16 *) skb->data);

do I have to worry about endianess correctness if I need to do some bit fiddling stuff?
For example:
The specification states that all packet formats shall use little-endian byte order, so an iframe is denoted like the following:

| 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 06 05 04 03 02 01
|---SAR---|------------ReqSeq-----------|-R--| ...

if I need to pull the ReqSeq value out of the 16 Bits, do I need to make use of a function like __btoh(control):

	u16 reqseq = (__btoh16(control) & 0x3F00) >> 8;
or is it enough to say:
	u16 reqseq = (control & 0x3F00) >> 8;

when I took the get_unaligned() function?

Martin

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#1 lore raw

Hi Martin,

Quoted 11 lines

whenever I take data out of a socket buffer using the get_unaligned() function like this:

	u16 control = get_unaligned((u16 *) skb->data);

do I have to worry about endianess correctness if I need to do some bit fiddling stuff?
For example:
The specification states that all packet formats shall use little-endian byte order, so an iframe is denoted like the following:

| 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 06 05 04 03 02 01
|---SAR---|------------ReqSeq-----------|-R--| ...
Quoted 6 lines

if I need to pull the ReqSeq value out of the 16 Bits, do I need to make use of a function like __btoh(control):

	u16 reqseq = (__btoh16(control) & 0x3F00) >> 8;
or is it enough to say:
	u16 reqseq = (control & 0x3F00) >> 8;

when I took the get_unaligned() function?

the get_unaligned() macro has nothing to do with the endian thing. So you still need to convert from little endian into machine byte order.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel