2012-11-23 13:59:27

by Michael Knudsen

[permalink] [raw]
Subject: [PATCH v2 0/3] mgmt: read supported codecs

This implements the user space side of the read codecs command.

Whitespace issue pointed out by Kim Schulz should be fixed.

Michael Knudsen (3):
Bluetooth: Add HCI Coding Format definitions
Bluetooth: Support the read codecs operation
Doco: List the read codecs operation

doc/mgmt-api.txt | 20 +++++++++++++++
lib/hci.h | 9 +++++++
lib/mgmt.h | 8 ++++++
tools/btmgmt.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 111 insertions(+)

--
1.7.9.5



2012-11-26 11:56:46

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] mgmt: read supported codecs

Hi Michael,

On Fri, Nov 23, 2012, Michael Knudsen wrote:
> Bluetooth: Add HCI Coding Format definitions
> Bluetooth: Support the read codecs operation

Since these are user space patches they should not be prefixed with
"Bluetooth". Also please just use one space after the colon. The
appropriate prefix for the first patch would be "lib" and for the second
one "mgmt".

> Doco: List the read codecs operation

The prefix should be "doc". And please remove the double spaces here as
well.

Johan

2012-11-23 13:59:30

by Michael Knudsen

[permalink] [raw]
Subject: [PATCH v2 3/3] Doco: List the read codecs operation

---
doc/mgmt-api.txt | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 202c055..42af2d6 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -847,6 +847,26 @@ Set Device ID Command
a Command Status event on failure.


+Read Codecs Command
+====================
+
+ Command Code: 0x0029
+ Controller Index: <controller id>
+ Command Parameters:
+ Return Parameters:
+ Num_Of_Codecs (1 Octet)
+ Codec1 (1 Octet)
+ Codec2 (1 Octet)
+ ...
+
+ This command is used to read out the list of codecs that are
+ supported by the given controller.
+
+ This command generates a Command Complete event on success
+ or failure.
+
+
+
Command Complete Event
======================

--
1.7.9.5


2012-11-23 13:59:29

by Michael Knudsen

[permalink] [raw]
Subject: [PATCH v2 2/3] Bluetooth: Support the read codecs operation

---
lib/mgmt.h | 8 ++++++
tools/btmgmt.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 6c7e44a..f1950b2 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -318,6 +318,13 @@ struct mgmt_cp_set_device_id {
uint16_t version;
} __packed;

+#define MGMT_OP_READ_CODECS 0x0029
+struct mgmt_rp_read_codecs {
+ uint8_t count;
+ uint8_t codec[0];
+} __packed;
+
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
uint16_t opcode;
@@ -496,6 +503,7 @@ static const char *mgmt_op[] = {
"Block Device",
"Unblock Device",
"Set Device ID",
+ "Read Codecs",
};

static const char *mgmt_ev[] = {
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index ff6a46a..857c3a8 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -993,6 +993,79 @@ static void cmd_info(int mgmt_sk, uint16_t index, int argc, char **argv)
}
}

+struct codecs_map {
+ int codec;
+ char *name;
+} codecs_map[] = {
+ { HCI_FORMAT_ULAW, "uLAW" },
+ { HCI_FORMAT_ALAW, "aLAW" },
+ { HCI_FORMAT_CVSD, "CVSD" },
+ { HCI_FORMAT_TRANSPARENT, "transparent" },
+ { HCI_FORMAT_PCM, "PCM" },
+ { HCI_FORMAT_MSBC, "mSBC" },
+ { HCI_FORMAT_VENDOR, "vendor" },
+ { -1 },
+};
+
+static void codecs_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
+ void *rsp, uint16_t len, void *user_data)
+{
+ struct mgmt_rp_read_codecs *rp = rsp;
+ char addr[18];
+ int i, count;
+
+ if (status != 0) {
+ fprintf(stderr,
+ "Reading hci%u info failed with status 0x%02x (%s)\n",
+ id, status, mgmt_errstr(status));
+ exit(EXIT_FAILURE);
+ }
+
+ if (len < sizeof(*rp)) {
+ fprintf(stderr, "Too small codecs reply (%u bytes)\n", len);
+ exit(EXIT_FAILURE);
+ }
+
+ count = rp->count;
+
+ printf("hci%u:\tnumber of codecs: %u\n", id, count);
+
+ for (i = 0; i < count; i++) {
+ int entry;
+ struct codecs_map *p;
+
+ entry = rp->codec[i];
+
+ p = codecs_map;
+
+ while (p->codec != -1) {
+ if (entry == p->codec)
+ break;
+ else
+ p++;
+ }
+
+ if (p->codec != -1)
+ printf("\t%s (0x%x)\n", p->name, p->codec);
+ else
+ printf("\tunknown (0x%x)\n", p->codec);
+ }
+
+ exit(EXIT_SUCCESS);
+}
+
+static void cmd_codecs(int mgmt_sk, uint16_t index, int argc, char **argv)
+{
+ if (index == MGMT_INDEX_NONE)
+ index = 0;
+
+ if (mgmt_send_cmd(mgmt_sk, MGMT_OP_READ_CODECS, index, NULL,
+ 0, codecs_rsp, NULL) < 0) {
+ fprintf(stderr, "Unable to send read_info cmd\n");
+ exit(EXIT_FAILURE);
+ }
+}
+
static void setting_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
void *rsp, uint16_t len, void *user_data)
{
@@ -1824,6 +1897,7 @@ static struct {
{ "version", cmd_version, "Get the MGMT Version" },
{ "commands", cmd_commands, "List supported commands" },
{ "info", cmd_info, "Show controller info" },
+ { "codecs", cmd_codecs, "List supported codecs" },
{ "power", cmd_power, "Toggle powered state" },
{ "discov", cmd_discov, "Toggle discoverable state" },
{ "connectable",cmd_connectable,"Toggle connectable state" },
--
1.7.9.5


2012-11-23 13:59:28

by Michael Knudsen

[permalink] [raw]
Subject: [PATCH v2 1/3] Bluetooth: Add HCI Coding Format definitions

---
lib/hci.h | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/lib/hci.h b/lib/hci.h
index 2f18ec8..5e5f6b5 100644
--- a/lib/hci.h
+++ b/lib/hci.h
@@ -295,6 +295,15 @@ enum {
#define HCI_LM_RELIABLE 0x0010
#define HCI_LM_SECURE 0x0020

+/* Coding Format */
+#define HCI_FORMAT_ULAW 0x00
+#define HCI_FORMAT_ALAW 0x01
+#define HCI_FORMAT_CVSD 0x02
+#define HCI_FORMAT_TRANSPARENT 0x03
+#define HCI_FORMAT_PCM 0x04
+#define HCI_FORMAT_MSBC 0x05
+#define HCI_FORMAT_VENDOR 0xff
+
/* Link Key types */
#define HCI_LK_COMBINATION 0x00
#define HCI_LK_LOCAL_UNIT 0x01
--
1.7.9.5