From: "Pali Rohár" <pali.rohar@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 06/10] a2dp-codecs: Define a2dp_vendor_codec_t struct in endian neutral way
Date: Sun, 23 Dec 2018 11:40:17 +0100 [thread overview]
Message-ID: <20181223104021.18620-7-pali.rohar@gmail.com> (raw)
In-Reply-To: <20181223104021.18620-1-pali.rohar@gmail.com>
And define new macros A2DP_GET_VENDOR_ID(), A2DP_GET_CODEC_ID() and
A2DP_SET_VENDOR_ID_CODEC_ID() for easily filling a2dp_vendor_codec_t
struct.
---
android/a2dp.c | 8 ++++----
android/avdtp.c | 6 ++++--
android/hal-audio-aptx.c | 18 ++++++------------
profiles/audio/a2dp-codecs.h | 24 ++++++++++++++++++++++--
profiles/audio/a2dp.c | 9 +++++----
tools/avinfo.c | 4 ++--
6 files changed, 43 insertions(+), 26 deletions(-)
diff --git a/android/a2dp.c b/android/a2dp.c
index f21904208..8bcdfd20f 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -417,8 +417,8 @@ static int check_capabilities(struct a2dp_preset *preset,
preset->len);
case A2DP_CODEC_VENDOR:
vndcodec = (void *) codec->data;
- if (btohl(vndcodec->vendor_id) == APTX_VENDOR_ID &&
- btohs(vndcodec->codec_id) == APTX_CODEC_ID)
+ if (A2DP_GET_VENDOR_ID(*vndcodec) == APTX_VENDOR_ID &&
+ A2DP_GET_CODEC_ID(*vndcodec) == APTX_CODEC_ID)
return aptx_check_config(codec->data, codec_len,
preset->data, preset->len);
return -EINVAL;
@@ -1344,8 +1344,8 @@ static uint8_t register_endpoint(const uint8_t *uuid, uint8_t codec,
a2dp_vendor_codec_t *vndcodec = (void *) endpoint->caps->data;
avdtp_sep_set_vendor_codec(endpoint->sep,
- btohl(vndcodec->vendor_id),
- btohs(vndcodec->codec_id));
+ A2DP_GET_VENDOR_ID(*vndcodec),
+ A2DP_GET_CODEC_ID(*vndcodec));
}
endpoints = g_slist_append(endpoints, endpoint);
diff --git a/android/avdtp.c b/android/avdtp.c
index 34caf3db5..7fb8cb731 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -1103,10 +1103,12 @@ struct avdtp_remote_sep *avdtp_find_remote_sep(struct avdtp *session,
a2dp_vendor_codec_t *vndcodec =
(void *) codec_data->data;
- if (btohl(vndcodec->vendor_id) != lsep->vndcodec_vendor)
+ if (A2DP_GET_VENDOR_ID(*vndcodec) !=
+ lsep->vndcodec_vendor)
continue;
- if (btohs(vndcodec->codec_id) != lsep->vndcodec_codec)
+ if (A2DP_GET_CODEC_ID(*vndcodec) !=
+ lsep->vndcodec_codec)
continue;
}
diff --git a/android/hal-audio-aptx.c b/android/hal-audio-aptx.c
index bff2331a9..4e364fc65 100644
--- a/android/hal-audio-aptx.c
+++ b/android/hal-audio-aptx.c
@@ -37,27 +37,21 @@ struct aptx_data {
static const a2dp_aptx_t aptx_presets[] = {
{
- .info = {
- .vendor_id = APTX_VENDOR_ID,
- .codec_id = APTX_CODEC_ID,
- },
+ .info =
+ A2DP_SET_VENDOR_ID_CODEC_ID(APTX_VENDOR_ID, APTX_CODEC_ID),
.frequency = APTX_SAMPLING_FREQ_44100 |
APTX_SAMPLING_FREQ_48000,
.channel_mode = APTX_CHANNEL_MODE_STEREO,
},
{
- .info = {
- .vendor_id = APTX_VENDOR_ID,
- .codec_id = APTX_CODEC_ID,
- },
+ .info =
+ A2DP_SET_VENDOR_ID_CODEC_ID(APTX_VENDOR_ID, APTX_CODEC_ID),
.frequency = APTX_SAMPLING_FREQ_48000,
.channel_mode = APTX_CHANNEL_MODE_STEREO,
},
{
- .info = {
- .vendor_id = APTX_VENDOR_ID,
- .codec_id = APTX_CODEC_ID,
- },
+ .info =
+ A2DP_SET_VENDOR_ID_CODEC_ID(APTX_VENDOR_ID, APTX_CODEC_ID),
.frequency = APTX_SAMPLING_FREQ_44100,
.channel_mode = APTX_CHANNEL_MODE_STEREO,
},
diff --git a/profiles/audio/a2dp-codecs.h b/profiles/audio/a2dp-codecs.h
index 47030bcc1..a310efe49 100644
--- a/profiles/audio/a2dp-codecs.h
+++ b/profiles/audio/a2dp-codecs.h
@@ -198,10 +198,30 @@
#define LDAC_CODEC_ID 0x00aa
typedef struct {
- uint32_t vendor_id;
- uint16_t codec_id;
+ uint8_t vendor_id4;
+ uint8_t vendor_id3;
+ uint8_t vendor_id2;
+ uint8_t vendor_id1;
+ uint8_t codec_id2;
+ uint8_t codec_id1;
} __attribute__ ((packed)) a2dp_vendor_codec_t;
+#define A2DP_GET_VENDOR_ID(a) ( \
+ (((uint32_t)(a).vendor_id4) << 0) | \
+ (((uint32_t)(a).vendor_id3) << 8) | \
+ (((uint32_t)(a).vendor_id2) << 16) | \
+ (((uint32_t)(a).vendor_id1) << 24) \
+ )
+#define A2DP_GET_CODEC_ID(a) ((a).codec_id2 | (((uint16_t)(a).codec_id1) << 8))
+#define A2DP_SET_VENDOR_ID_CODEC_ID(v, c) ((a2dp_vendor_codec_t){ \
+ .vendor_id4 = (((v) >> 0) & 0xff), \
+ .vendor_id3 = (((v) >> 8) & 0xff), \
+ .vendor_id2 = (((v) >> 16) & 0xff), \
+ .vendor_id1 = (((v) >> 24) & 0xff), \
+ .codec_id2 = (((c) >> 0) & 0xff), \
+ .codec_id1 = (((c) >> 8) & 0xff), \
+ })
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
typedef struct {
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index fc98bb264..344459332 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -523,14 +523,15 @@ static gboolean endpoint_match_codec_ind(struct avdtp *session,
local_codec = (a2dp_vendor_codec_t *) capabilities;
remote_codec = (a2dp_vendor_codec_t *) codec->data;
- if (remote_codec->vendor_id != local_codec->vendor_id)
+ if (A2DP_GET_VENDOR_ID(*remote_codec) !=
+ A2DP_GET_VENDOR_ID(*local_codec))
return FALSE;
- if (remote_codec->codec_id != local_codec->codec_id)
+ if (A2DP_GET_CODEC_ID(*remote_codec) != A2DP_GET_CODEC_ID(*local_codec))
return FALSE;
- DBG("vendor 0x%08x codec 0x%04x", btohl(remote_codec->vendor_id),
- btohs(remote_codec->codec_id));
+ DBG("vendor 0x%08x codec 0x%04x", A2DP_GET_VENDOR_ID(*remote_codec),
+ A2DP_GET_CODEC_ID(*remote_codec));
return TRUE;
}
diff --git a/tools/avinfo.c b/tools/avinfo.c
index bb80cf583..9a07e675d 100644
--- a/tools/avinfo.c
+++ b/tools/avinfo.c
@@ -221,8 +221,8 @@ static void print_vendor(a2dp_vendor_codec_t *vendor, uint8_t size)
return;
}
- vendor_id = btohl(vendor->vendor_id);
- codec_id = btohs(vendor->codec_id);
+ vendor_id = A2DP_GET_VENDOR_ID(*vendor);
+ codec_id = A2DP_GET_CODEC_ID(*vendor);
printf("\tMedia Codec: Vendor Specific A2DP Codec");
--
2.11.0
next prev parent reply other threads:[~2018-12-23 10:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-19 16:50 [PATCH 00/10] A2DP: Fix endianity and define new A2DP codecs Pali Rohár
2018-12-19 16:51 ` [PATCH 01/10] avinfo: Fix buffer overflow when parsing broken/malicious data Pali Rohár
2018-12-19 16:51 ` [PATCH 02/10] avinfo: Show Vendor Specific Data Pali Rohár
2018-12-19 16:51 ` [PATCH 03/10] a2dp-codecs: Add SBC prefix for MIN/MAX_BITPOOL constants Pali Rohár
2018-12-19 16:51 ` [PATCH 04/10] a2dp-codecs: Fix codec id for ATRAC Pali Rohár
2018-12-19 16:51 ` [PATCH 05/10] a2dp-codecs & avinfo: Fix parsing MPEG bit rate values Pali Rohár
2018-12-19 16:51 ` [PATCH 06/10] a2dp-codecs: Define a2dp_vendor_codec_t struct in endian neutral way Pali Rohár
2018-12-19 16:51 ` [PATCH 07/10] a2dp-codecs: Add needed includes and properly check for endian macros Pali Rohár
2018-12-19 16:51 ` [PATCH 08/10] a2dp-codecs: Properly define macros and struct for LDAC codec Pali Rohár
2018-12-19 16:51 ` [PATCH 09/10] a2dp-codecs: Add macros and structures for FastStream, aptX Low Latency and aptX HD codecs Pali Rohár
2018-12-19 16:51 ` [PATCH 10/10] avinfo: Parse information about A2DP codecs: FastStream, aptX Low Latency, aptX HD and LDAC Pali Rohár
2018-12-22 22:54 ` [PATCH 00/10] A2DP: Fix endianity and define new A2DP codecs Luiz Augusto von Dentz
2018-12-23 9:30 ` Pali Rohár
2018-12-23 10:40 ` [PATCH v2 " Pali Rohár
2018-12-23 10:40 ` [PATCH v2 01/10] avinfo: Fix buffer overflow when parsing broken/malicious data Pali Rohár
2018-12-23 10:40 ` [PATCH v2 02/10] avinfo: Show Vendor Specific Data Pali Rohár
2018-12-23 10:40 ` [PATCH v2 03/10] a2dp-codecs: Add SBC prefix for MIN/MAX_BITPOOL constants Pali Rohár
2018-12-23 10:40 ` [PATCH v2 04/10] a2dp-codecs: Fix codec id for ATRAC Pali Rohár
2018-12-23 10:40 ` [PATCH v2 05/10] a2dp-codecs & avinfo: Fix parsing MPEG bit rate values Pali Rohár
2018-12-23 10:40 ` Pali Rohár [this message]
2018-12-23 10:40 ` [PATCH v2 07/10] a2dp-codecs: Add needed includes and properly check for endian macros Pali Rohár
2018-12-23 10:40 ` [PATCH v2 08/10] a2dp-codecs: Properly define macros and struct for LDAC codec Pali Rohár
2018-12-23 10:40 ` [PATCH v2 09/10] a2dp-codecs: Add macros and structures for new codecs Pali Rohár
2018-12-23 10:40 ` [PATCH v2 10/10] avinfo: Parse new A2DP codecs Pali Rohár
2018-12-28 18:23 ` [PATCH v2 00/10] A2DP: Fix endianity and define " Luiz Augusto von Dentz
2018-12-28 18:59 ` 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=20181223104021.18620-7-pali.rohar@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).