OSDN Git Service

Read local supported codecs as part of boot sequence
authorSrinu Jella <sjella@codeaurora.org>
Wed, 22 Jul 2015 12:00:32 +0000 (17:30 +0530)
committerAndre Eisenbach <eisenbach@google.com>
Fri, 4 Mar 2016 18:29:18 +0000 (10:29 -0800)
Add support to read local supported codecs as part of
controller module initialization.

Also added an API from controller interface to get the
local supported codecs.

Change-Id: I37a4ab9e6a20ed057ca794dbdd4f99c2a8c65a6e

device/include/controller.h
device/src/controller.c
hci/include/hci_packet_factory.h
hci/include/hci_packet_parser.h
hci/src/hci_packet_factory.c
hci/src/hci_packet_parser.c

index 3e181b9..291c33d 100644 (file)
@@ -75,6 +75,7 @@ typedef struct controller_t {
 
   uint8_t (*get_ble_resolving_list_max_size)(void);
   void (*set_ble_resolving_list_max_size)(int resolving_list_max_size);
+  uint8_t *(*get_local_supported_codecs)(uint8_t *number_of_codecs);
 } controller_t;
 
 const controller_t *controller_get_interface();
index e8ca35f..afec7da 100644 (file)
@@ -45,6 +45,7 @@ const uint8_t SCO_HOST_BUFFER_SIZE = 0xff;
 #define MAX_FEATURES_CLASSIC_PAGE_COUNT 3
 #define BLE_SUPPORTED_STATES_SIZE         8
 #define BLE_SUPPORTED_FEATURES_SIZE       8
+#define MAX_LOCAL_SUPPORTED_CODECS_SIZE   8
 
 static const hci_t *hci;
 static const hci_packet_factory_t *packet_factory;
@@ -67,6 +68,8 @@ static uint8_t ble_resolving_list_max_size;
 static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE];
 static bt_device_features_t features_ble;
 static uint16_t ble_suggested_default_data_length;
+static uint8_t local_supported_codecs[MAX_LOCAL_SUPPORTED_CODECS_SIZE];
+static uint8_t number_of_local_supported_codecs = 0;
 
 static bool readable;
 static bool ble_supported;
@@ -241,6 +244,14 @@ static future_t *start_up(void) {
     packet_parser->parse_generic_command_complete(response);
   }
 
+  // read local supported codecs
+  if(HCI_READ_LOCAL_CODECS_SUPPORTED(supported_commands)) {
+    response = AWAIT_COMMAND(packet_factory->make_read_local_supported_codecs());
+    packet_parser->parse_read_local_supported_codecs_response(
+        response,
+        &number_of_local_supported_codecs, local_supported_codecs);
+  }
+
   readable = true;
   return future_new_immediate(FUTURE_SUCCESS);
 }
@@ -290,6 +301,15 @@ static uint8_t get_last_features_classic_index(void) {
   return last_features_classic_page_index;
 }
 
+static uint8_t *get_local_supported_codecs(uint8_t *number_of_codecs) {
+  assert(readable);
+  if(number_of_local_supported_codecs) {
+    *number_of_codecs = number_of_local_supported_codecs;
+    return local_supported_codecs;
+  }
+  return NULL;
+}
+
 static const bt_device_features_t *get_features_ble(void) {
   assert(readable);
   assert(ble_supported);
@@ -460,7 +480,8 @@ static const controller_t interface = {
   get_ble_white_list_size,
 
   get_ble_resolving_list_max_size,
-  set_ble_resolving_list_max_size
+  set_ble_resolving_list_max_size,
+  get_local_supported_codecs
 };
 
 const controller_t *controller_get_interface() {
index 79110e1..ac6f12a 100644 (file)
@@ -40,6 +40,7 @@ typedef struct {
   BT_HDR *(*make_ble_read_resolving_list_size)(void);
   BT_HDR *(*make_ble_read_suggested_default_data_length)(void);
   BT_HDR *(*make_ble_set_event_mask)(const bt_event_mask_t *event_mask);
+  BT_HDR *(*make_read_local_supported_codecs)(void);
 } hci_packet_factory_t;
 
 const hci_packet_factory_t *hci_packet_factory_get_interface();
index 14b38ab..ba3b193 100644 (file)
@@ -91,6 +91,11 @@ typedef struct {
     BT_HDR *response,
     uint16_t *ble_default_packet_length_ptr
   );
+
+  void (*parse_read_local_supported_codecs_response)(
+    BT_HDR *response,
+    uint8_t *number_of_local_supported_codecs, uint8_t *local_supported_codecs);
+
 } hci_packet_parser_t;
 
 const hci_packet_parser_t *hci_packet_parser_get_interface();
index bc8fca5..96f578a 100644 (file)
@@ -137,6 +137,10 @@ static BT_HDR *make_ble_read_suggested_default_data_length(void) {
     return make_command_no_params(HCI_BLE_READ_DEFAULT_DATA_LENGTH);
 }
 
+static BT_HDR *make_read_local_supported_codecs(void) {
+    return make_command_no_params(HCI_READ_LOCAL_SUPPORTED_CODECS);
+}
+
 static BT_HDR *make_ble_set_event_mask(const bt_event_mask_t *event_mask) {
   uint8_t *stream;
   uint8_t parameter_size = sizeof(bt_event_mask_t);
@@ -193,7 +197,8 @@ static const hci_packet_factory_t interface = {
   make_ble_read_local_supported_features,
   make_ble_read_resolving_list_size,
   make_ble_read_suggested_default_data_length,
-  make_ble_set_event_mask
+  make_ble_set_event_mask,
+  make_read_local_supported_codecs
 };
 
 const hci_packet_factory_t *hci_packet_factory_get_interface() {
index 8470c3f..d5ee034 100644 (file)
@@ -71,6 +71,23 @@ static void parse_read_local_version_info_response(
   buffer_allocator->free(response);
 }
 
+static void parse_read_local_supported_codecs_response(
+    BT_HDR *response,
+    uint8_t *number_of_local_supported_codecs, uint8_t *local_supported_codecs) {
+
+  uint8_t *stream = read_command_complete_header(response, HCI_READ_LOCAL_SUPPORTED_CODECS, 0 /* bytes after */);
+  if(stream) {
+    STREAM_TO_UINT8(*number_of_local_supported_codecs, stream);
+    for ( uint8_t i = 0; i < *number_of_local_supported_codecs; i++)
+    {
+      STREAM_TO_UINT8(*local_supported_codecs, stream);
+      local_supported_codecs++;
+    }
+  }
+
+  buffer_allocator->free(response);
+}
+
 static void parse_read_bd_addr_response(
     BT_HDR *response,
     bt_bdaddr_t *address_ptr) {
@@ -218,8 +235,10 @@ static uint8_t *read_command_complete_header(
   // Assume the next field is the status field
   STREAM_TO_UINT8(status, stream);
 
-  if (status != HCI_SUCCESS)
+  if (status != HCI_SUCCESS){
+    LOG_ERROR("%s: return status - 0x%x", __func__, status);
     return NULL;
+  }
 
   return stream;
 }
@@ -236,7 +255,8 @@ static const hci_packet_parser_t interface = {
   parse_ble_read_supported_states_response,
   parse_ble_read_local_supported_features_response,
   parse_ble_read_resolving_list_size_response,
-  parse_ble_read_suggested_default_data_length_response
+  parse_ble_read_suggested_default_data_length_response,
+  parse_read_local_supported_codecs_response
 };
 
 const hci_packet_parser_t *hci_packet_parser_get_interface() {