From: "Pali Rohár" <pali.rohar@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: Bluez has fully broken profiles/audio/a2dp-codecs.h file for big endian
Date: Tue, 18 Dec 2018 15:50:33 +0100 [thread overview]
Message-ID: <20181218145033.itlwcfraxsusafb3@pali> (raw)
[-- Attachment #1: Type: text/plain, Size: 2016 bytes --]
Hello,
I spotted that bluez has file profiles/audio/a2dp-codecs.h in its git
repository with some #if __BYTE_ORDER == checks, including #ifdef for
big endian systems.
But this file is fully broken for big endian systems. For example, there
is following structure which is same for both little and big endian
systems:
typedef struct {
uint32_t vendor_id;
uint16_t codec_id;
} __attribute__ ((packed)) a2dp_vendor_codec_t;
Which is valid only for little endian systems, as those definitions are
bound to little endian ordering -- not to host ordering.
Next there is a2dp_mpeg_t. It has different definition for little endian
and big endian systems.
little endian:
typedef struct {
uint8_t channel_mode:4;
uint8_t crc:1;
uint8_t layer:3;
uint8_t frequency:6;
uint8_t mpf:1;
uint8_t rfa:1;
uint16_t bitrate;
} __attribute__ ((packed)) a2dp_mpeg_t;
big endian:
typedef struct {
uint8_t layer:3;
uint8_t crc:1;
uint8_t channel_mode:4;
uint8_t rfa:1;
uint8_t mpf:1;
uint8_t frequency:6;
uint16_t bitrate;
} __attribute__ ((packed)) a2dp_mpeg_t;
But as you can see, bitrate on big endian definition is incorrect. It
is still in little endian. Proper way would be to define bitrate as
"uint8_t bitrate[2];" or as "uint8_t bitrate_lo; uint8_t bitrate_hi".
So basically this file a2dp-codecs.h is not compatible with big endian
systems, even there are "#elif __BYTE_ORDER == __BIG_ENDIAN" branches.
If you are not going to support big endian systems, I suggest you to
drop all those "#elif __BYTE_ORDER == __BIG_ENDIAN" parts as people
think that existence of these macros means that code is supported on big
endian systems.
It is better throw an error that big endian is broken as trying to
produce non-working binaries.
Moreover, some people started copying this a2dp-codecs.h file to other
projects which just leads to copy+paste of broken code.
--
Pali Rohár
pali.rohar@gmail.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next reply other threads:[~2018-12-18 14:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-18 14:50 Pali Rohár [this message]
[not found] ` <CABBYNZKu-1s=GcyWYOqbjNZGknyPFHk4LEVVP7+w85oauEpDBA@mail.gmail.com>
2018-12-18 21:06 ` Bluez has fully broken profiles/audio/a2dp-codecs.h file for big endian Pali Rohár
2018-12-19 13:20 ` Luiz Augusto von Dentz
2018-12-19 16:46 ` Pali Rohár
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181218145033.itlwcfraxsusafb3@pali \
--to=pali.rohar@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox