]> granicus.if.org Git - esp-idf/commitdiff
Merge branch 'feature/btdm_bluedroid' into feature/btdm_a2dp
authorwangmengyang <wangmengyang@espressif.com>
Fri, 25 Nov 2016 11:45:29 +0000 (19:45 +0800)
committerwangmengyang <wangmengyang@espressif.com>
Fri, 25 Nov 2016 11:45:29 +0000 (19:45 +0800)
# Conflicts:
# components/bt/bluedroid/bta/sys/bta_sys_main.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_api.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_bld_ct.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_bld_tg.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_opt.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_pars_ct.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_pars_tg.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_sdp.c
# components/bt/bluedroid/btc/profile/std/avrc/avrc_utils.c
# components/bt/bluedroid/btc/profile/std/avrc/include/avrc_int.h
# components/bt/bluedroid/btc/profile/std/include/avct_api.h
# components/bt/bluedroid/btc/profile/std/include/avdt_api.h
# components/bt/bluedroid/btc/profile/std/include/avdt_defs.h
# components/bt/bluedroid/btc/profile/std/include/avdtc_api.h
# components/bt/bluedroid/btc/profile/std/include/avrc_api.h
# components/bt/bluedroid/btc/profile/std/include/avrc_defs.h
# components/bt/bluedroid/gki/gki_buffer.c
# components/bt/bluedroid/hci/hci_hal_h4.c
# components/bt/bluedroid/hci/hci_layer.c
# components/bt/bluedroid/hci/packet_fragmenter.c
# components/bt/bluedroid/include/bt_trace.h
# components/bt/bluedroid/osi/alarm.c
# components/bt/bluedroid/profiles/std/avrc/avrc_api.c
# components/bt/bluedroid/profiles/std/avrc/avrc_bld_ct.c
# components/bt/bluedroid/profiles/std/avrc/avrc_bld_tg.c
# components/bt/bluedroid/profiles/std/avrc/avrc_opt.c
# components/bt/bluedroid/profiles/std/avrc/avrc_pars_ct.c
# components/bt/bluedroid/profiles/std/avrc/avrc_pars_tg.c
# components/bt/bluedroid/profiles/std/avrc/avrc_sdp.c
# components/bt/bluedroid/profiles/std/avrc/avrc_utils.c
# components/bt/bluedroid/profiles/std/avrc/include/avrc_int.h
# components/bt/bluedroid/profiles/std/include/avct_api.h
# components/bt/bluedroid/profiles/std/include/avdt_api.h
# components/bt/bluedroid/profiles/std/include/avdt_defs.h
# components/bt/bluedroid/profiles/std/include/avdtc_api.h
# components/bt/bluedroid/profiles/std/include/avrc_api.h
# components/bt/bluedroid/profiles/std/include/avrc_defs.h
# components/bt/bluedroid/stack/avdt/include/avdt_defs.h
# components/bt/bluedroid/stack/avrc/avrc_api.c
# components/bt/bluedroid/stack/avrc/avrc_bld_ct.c
# components/bt/bluedroid/stack/avrc/avrc_bld_tg.c
# components/bt/bluedroid/stack/avrc/avrc_opt.c
# components/bt/bluedroid/stack/avrc/avrc_pars_ct.c
# components/bt/bluedroid/stack/avrc/avrc_pars_tg.c
# components/bt/bluedroid/stack/avrc/avrc_sdp.c
# components/bt/bluedroid/stack/avrc/avrc_utils.c
# components/bt/bluedroid/stack/avrc/include/avrc_int.h
# components/bt/bluedroid/stack/btu/btu_task.c
# components/bt/bluedroid/stack/include/avct_api.h
# components/bt/bluedroid/stack/include/avdt_api.h
# components/bt/bluedroid/stack/include/avdtc_api.h
# components/bt/bluedroid/stack/include/avrc_api.h
# components/bt/bluedroid/stack/include/avrc_defs.h
# components/bt/bluedroid/stack/include/gatt_api.h
# components/bt/bluedroid/stack/l2cap/l2c_main.c
# components/bt/component.mk
# examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c

22 files changed:
1  2 
components/bt/bluedroid/bta/dm/bta_dm_act.c
components/bt/bluedroid/bta/include/bta_api.h
components/bt/bluedroid/bta/include/bta_gattc_int.h
components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c
components/bt/bluedroid/bta/sys/bta_sys_main.c
components/bt/bluedroid/gki/gki_buffer.c
components/bt/bluedroid/hci/hci_hal_h4.c
components/bt/bluedroid/hci/hci_layer.c
components/bt/bluedroid/hci/packet_fragmenter.c
components/bt/bluedroid/include/bt_defs.h
components/bt/bluedroid/include/bt_target.h
components/bt/bluedroid/osi/alarm.c
components/bt/bluedroid/osi/include/alarm.h
components/bt/bluedroid/osi/include/thread.h
components/bt/bluedroid/stack/btu/btu_init.c
components/bt/bluedroid/stack/btu/btu_task.c
components/bt/bluedroid/stack/include/bt_types.h
components/bt/bluedroid/stack/include/btm_ble_int.h
components/bt/bluedroid/stack/include/gatt_api.h
components/bt/component.mk
examples/13_bt_sdp/components/bluedroid_demos/btif/btif_core.c
examples/13_bt_sdp/components/bluedroid_demos/include/btif_util.h

index 08e6d7b12a21fbfb5d97f1fd8656699d11f5ca3d,7b6065569181238a6f53013dadf7d0c0a9c544e5..155602fac72097b7d5b6b73b1a3adc4db02a10cf
mode 100755,100644..100644
index ea39475e133783b4f543c5de806aeeb7d9ab8513,f9c6c154f5447abbede1cf2e22df688719277f21..9b8a4059956149940d986b19b31a3c5b227ccd9d
mode 100755,100644..100644
index aac40831285de32694e9769d95e67140576eb32a,bc200eddc3a6d84db4e8cffdbc620a376350b042..b915005ba800cca9d858751cb1c203d473efb8bb
mode 100755,100644..100644
index 038183c6dbf0c981aaf7fc265ae0c3c5554c623f,f9c6b019a6edaffd55dd60a03d5ec7b455739c73..bfd02d279c3351cfde40583eb0a7de2902588574
mode 100755,100644..100644
index 5a9c414f6175acbd0346b684471367a3b810ca33,68faa99407e4f3727dac7f2a06b627211fc0b345..ca8e26ad0ccb410e4e767f58b618c03cd2b27c47
mode 100755,100644..100644
@@@ -618,33 -592,35 +592,35 @@@ void bta_sys_sendmsg(void *p_msg
  ** Returns          void
  **
  *******************************************************************************/
- void bta_alarm_cb(void *data) {
-   assert(data != NULL);
-   TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
+ void bta_alarm_cb(void *data)
+ {
+     assert(data != NULL);
+     TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
  
-   fixed_queue_enqueue(btu_bta_alarm_queue, p_tle);
+     fixed_queue_enqueue(btu_bta_alarm_queue, p_tle);
  }
  
- void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) {
-   assert(p_tle != NULL);
-   // Get the alarm for this p_tle.
-   pthread_mutex_lock(&bta_alarm_lock);
-   if (!hash_map_has_key(bta_alarm_hash_map, p_tle)) {
-     hash_map_set(bta_alarm_hash_map, p_tle, osi_alarm_new("bta_sys", bta_alarm_cb, p_tle, 0, false));
-   }
-   pthread_mutex_unlock(&bta_alarm_lock);
-  osi_alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle);
-   if (alarm == NULL) {
-     LOG_ERROR("%s unable to create alarm.", __func__);
-     return;
-   }
-   p_tle->event = type;
-   p_tle->ticks = timeout_ms;
-   //osi_alarm_set(alarm, (period_ms_t)timeout_ms, bta_alarm_cb, p_tle);
-  osi_alarm_set(alarm, (period_ms_t)timeout_ms);
+ void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)
+ {
+     assert(p_tle != NULL);
+     // Get the alarm for this p_tle.
+     pthread_mutex_lock(&bta_alarm_lock);
+     if (!hash_map_has_key(bta_alarm_hash_map, p_tle)) {
 -        hash_map_set(bta_alarm_hash_map, p_tle, osi_alarm_new("bta_sys", bta_alarm_cb, p_tle, 0));
++        hash_map_set(bta_alarm_hash_map, p_tle, osi_alarm_new("bta_sys", bta_alarm_cb, p_tle, 0, false));
+     }
+     pthread_mutex_unlock(&bta_alarm_lock);
+     osi_alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle);
+     if (alarm == NULL) {
+         LOG_ERROR("%s unable to create alarm.", __func__);
+         return;
+     }
+     p_tle->event = type;
+     p_tle->ticks = timeout_ms;
+     //osi_alarm_set(alarm, (period_ms_t)timeout_ms, bta_alarm_cb, p_tle);
+     osi_alarm_set(alarm, (period_ms_t)timeout_ms);
  }
  
  bool hash_iter_ro_cb(hash_map_entry_t *hash_map_entry, void *context)
index 7a6031adc6d65bfa95d72ecd24104cef839a2ccc,0ea4f641e003f8c73fd19e3652878d669e9670ec..9ae20df90377ef00e2c704219ffee72db81b981d
mode 100755,100644..100644
@@@ -195,18 -189,13 +189,18 @@@ void GKI_init_q (BUFFER_Q *p_q
  *******************************************************************************/
  void *GKI_getbuf (UINT16 size)
  {
-   BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
-   assert(header != NULL);
-   if (header != NULL) {
-     header->status  = BUF_STATUS_UNLINKED;
-     header->p_next  = NULL;
-     header->Type    = 0;
-     header->size = size;
-     return header + 1;
-   } else {
-       return NULL;
-   }
+     BUFFER_HDR_T *header = osi_malloc(size + BUFFER_HDR_SIZE);
 -    header->status  = BUF_STATUS_UNLINKED;
 -    header->p_next  = NULL;
 -    header->Type    = 0;
 -    header->size = size;
 -
 -    return header + 1;
++    assert(header != NULL);
++    if (header != NULL) {
++        header->status  = BUF_STATUS_UNLINKED;
++        header->p_next  = NULL;
++        header->Type    = 0;
++        header->size = size;
++
++        return header + 1;
++    } else {
++        return NULL;
++    }
  }
  
  
index 3f0e90915225c0dc3dacde2bdd74c0a6aefd26fa,8665dd284eb4bc74680e8da428c07b19c59115c3..0fe9aba6968b995f06a4322d51f83f18bb11014b
mode 100755,100644..100644
@@@ -93,27 -96,28 +96,27 @@@ static void hci_hal_env_deinit(void
  
  static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
  {
-   assert(upper_callbacks != NULL);
-   callbacks = upper_callbacks;
+     assert(upper_callbacks != NULL);
+     callbacks = upper_callbacks;
  
-   hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX);
-   
-   xHciH4Queue = xQueueCreate(60, sizeof(BtTaskEvt_t));
-   xTaskCreate(hci_hal_h4_rx_handler, "HciH4T", 2048+1024, NULL, configMAX_PRIORITIES - 3, &xHciH4TaskHandle);
+     hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX);
  
-   //register vhci host cb
-   API_vhci_host_register_callback(&vhci_host_cb);
+     xHciH4Queue = xQueueCreate(60, sizeof(BtTaskEvt_t));
 -    xTaskCreate(hci_hal_h4_rx_handler, "HciH4T", 4096 + 2048, NULL, configMAX_PRIORITIES - 3, &xHciH4TaskHandle);
++    xTaskCreate(hci_hal_h4_rx_handler, "HciH4T", 2048 + 1024, NULL, configMAX_PRIORITIES - 3, &xHciH4TaskHandle);
  
+     //register vhci host cb
+     API_vhci_host_register_callback(&vhci_host_cb);
  
-   return true;
 -
+     return true;
  }
  
- static void hal_close() {
-   hci_hal_env_deinit();
-  
-   /* delete task and queue */ 
-   vTaskDelete(xHciH4TaskHandle);
-   vQueueDelete(xHciH4Queue);
+ static void hal_close()
+ {
+     hci_hal_env_deinit();
+     /* delete task and queue */
+     vTaskDelete(xHciH4TaskHandle);
+     vQueueDelete(xHciH4Queue);
  }
  
  /**
@@@ -178,92 -182,100 +181,97 @@@ void hci_hal_h4_task_post(void
      }
  }
  
- static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet) {
-   uint8_t type, hdr_size;
-   uint16_t length;
-   uint8_t *stream = packet->data + packet->offset;
+ static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet)
+ {
+     uint8_t type, hdr_size;
+     uint16_t length;
+     uint8_t *stream = packet->data + packet->offset;
  
-   if (!packet)
-     return;
-   STREAM_TO_UINT8(type, stream);
-   packet->offset++;
-   packet->len--;
-   if (type == HCI_BLE_EVENT) {
-     uint8_t len;
-     STREAM_TO_UINT8(len, stream);
-     LOG_ERROR("Workround stream corrupted during LE SCAN: pkt_len=%d ble_event_len=%d",
-               packet->len, len);
-     hci_hal_env.allocator->free(packet);
-     return;
-   }
-   if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) {
-     LOG_ERROR("%d Unknown HCI message type. Dropping this byte 0x%x,"
-               " min %x, max %x", __func__, type,
-               DATA_TYPE_ACL, DATA_TYPE_EVENT);
-     hci_hal_env.allocator->free(packet);
-     return;
-   }
-   hdr_size = preamble_sizes[type - 1];
-   if (packet->len < hdr_size) {
-     LOG_ERROR("Wrong packet length type=%s pkt_len=%d hdr_len=%d",
-               type, packet->len, hdr_size);
-     hci_hal_env.allocator->free(packet);
-     return;
-   }
-   if (type == DATA_TYPE_ACL) {
-     stream += hdr_size - 2;
-     STREAM_TO_UINT16(length, stream);
-   } else {
-     stream += hdr_size - 1;
-     STREAM_TO_UINT8(length, stream);
-   }
-   if ((length + hdr_size) != packet->len) {
-     LOG_ERROR("Wrong packet length type=%d hdr_len=%d pd_len=%d "
-               "pkt_len=%d", type, hdr_size, length, packet->len);
-     hci_hal_env.allocator->free(packet);
-     return;
-   }
+     if (!packet) {
+         return;
+     }
+     STREAM_TO_UINT8(type, stream);
+     packet->offset++;
+     packet->len--;
+     if (type == HCI_BLE_EVENT) {
+         uint8_t len;
+         STREAM_TO_UINT8(len, stream);
+         LOG_ERROR("Workround stream corrupted during LE SCAN: pkt_len=%d ble_event_len=%d\n",
+                   packet->len, len);
+         hci_hal_env.allocator->free(packet);
+         return;
+     }
+     if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) {
+         LOG_ERROR("%s Unknown HCI message type. Dropping this byte 0x%x,"
+                   " min %x, max %x\n", __func__, type,
+                   DATA_TYPE_ACL, DATA_TYPE_EVENT);
+         hci_hal_env.allocator->free(packet);
+         return;
+     }
+     hdr_size = preamble_sizes[type - 1];
+     if (packet->len < hdr_size) {
+         LOG_ERROR("Wrong packet length type=%d pkt_len=%d hdr_len=%d",
+                   type, packet->len, hdr_size);
+         hci_hal_env.allocator->free(packet);
+         return;
+     }
+     if (type == DATA_TYPE_ACL) {
 -        packet->offset--;
+         stream += hdr_size - 2;
+         STREAM_TO_UINT16(length, stream);
 -        stream = packet->data + 1;
 -        memcpy(packet->data, stream, packet->len);
+     } else {
+         stream += hdr_size - 1;
+         STREAM_TO_UINT8(length, stream);
+     }
  
-   packet->event = outbound_event_types[PACKET_TYPE_TO_INDEX(type)];
-   callbacks->packet_ready(packet);
+     if ((length + hdr_size) != packet->len) {
+         LOG_ERROR("Wrong packet length type=%d hdr_len=%d pd_len=%d "
+                   "pkt_len=%d", type, hdr_size, length, packet->len);
+         hci_hal_env.allocator->free(packet);
+         return;
+     }
+     packet->event = outbound_event_types[PACKET_TYPE_TO_INDEX(type)];
+     callbacks->packet_ready(packet);
  }
  
- static void event_uart_has_bytes(fixed_queue_t *queue) {
-   BT_HDR *packet;
-   while (!fixed_queue_is_empty(queue)) {
-     packet = fixed_queue_dequeue(queue);
-     hci_hal_h4_hdl_rx_packet(packet);
-   }
+ static void event_uart_has_bytes(fixed_queue_t *queue)
+ {
+     BT_HDR *packet;
+     while (!fixed_queue_is_empty(queue)) {
+         packet = fixed_queue_dequeue(queue);
+         hci_hal_h4_hdl_rx_packet(packet);
+     }
  }
  
- static void host_send_pkt_available_cb(void) {
-   //Controller rx cache buffer is ready for receiving new host packet
-   //Just Call Host main thread task to process pending packets.
-   hci_host_task_post();
+ static void host_send_pkt_available_cb(void)
+ {
+     //Controller rx cache buffer is ready for receiving new host packet
+     //Just Call Host main thread task to process pending packets.
+     hci_host_task_post();
  }
  
- static int host_recv_pkt_cb(uint8_t *data, uint16_t len) {
-   //Target has packet to host, malloc new buffer for packet
-   BT_HDR *pkt;
-   size_t pkt_size;
-   pkt_size = BT_HDR_SIZE + len;
-   pkt = (BT_HDR *)hci_hal_env.allocator->alloc(pkt_size);
-   if (!pkt) {
-     LOG_ERROR("%s couldn't aquire memory for inbound data buffer.", __func__);
-     return -1;
-   }
-   pkt->offset = 0;
-   pkt->len = len;
-   pkt->layer_specific = 0;
-   memcpy(pkt->data, data, len);
-   fixed_queue_enqueue(hci_hal_env.rx_q, pkt);
-   hci_hal_h4_task_post();
-   BTTRC_DUMP_BUFFER("Recv Pkt", pkt->data, len);
-   return 0;
+ static int host_recv_pkt_cb(uint8_t *data, uint16_t len)
+ {
+     //Target has packet to host, malloc new buffer for packet
+     BT_HDR *pkt;
+     size_t pkt_size;
+     pkt_size = BT_HDR_SIZE + len;
+     pkt = (BT_HDR *)hci_hal_env.allocator->alloc(pkt_size);
+     if (!pkt) {
+         LOG_ERROR("%s couldn't aquire memory for inbound data buffer.\n", __func__);
+         return -1;
+     }
+     pkt->offset = 0;
+     pkt->len = len;
+     pkt->layer_specific = 0;
+     memcpy(pkt->data, data, len);
+     fixed_queue_enqueue(hci_hal_env.rx_q, pkt);
+     hci_hal_h4_task_post();
+     BTTRC_DUMP_BUFFER("Recv Pkt", pkt->data, len);
+     return 0;
  }
  
  static const vhci_host_callback_t vhci_host_cb = {
index 128a4f42e0abd3e31f718fdad3819daa0fcd7782,46272689774befd6d7fd204a174ab1579a909ae7..c468039a9d46b5d59d68b4f3158df5c6537ff9f6
mode 100755,100644..100644
@@@ -107,33 -107,36 +107,36 @@@ static waiting_command_t *get_waiting_c
  static void dispatch_reassembled(BT_HDR *packet);
  
  // Module lifecycle functions
- int hci_start_up(void) {
-   if (hci_layer_init_env())
-     goto error;
-   xHciHostQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
-   xTaskCreate(hci_host_thread_handler, "HciHostT", (1024+2048), NULL, configMAX_PRIORITIES - 3, &xHciHostTaskHandle);
-   packet_fragmenter->init(&packet_fragmenter_callbacks);
-   hal->open(&hal_callbacks);
-   
-   hci_host_startup_flag = true;
-   return 0;
+ int hci_start_up(void)
+ {
+     if (hci_layer_init_env()) {
+         goto error;
+     }
+     xHciHostQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
 -    xTaskCreate(hci_host_thread_handler, "HciHostT", (4096 + 2048), NULL, configMAX_PRIORITIES - 3, &xHciHostTaskHandle);
++    xTaskCreate(hci_host_thread_handler, "HciHostT", (2048 + 1024), NULL, configMAX_PRIORITIES - 3, &xHciHostTaskHandle);
+     packet_fragmenter->init(&packet_fragmenter_callbacks);
+     hal->open(&hal_callbacks);
+     hci_host_startup_flag = true;
+     return 0;
  error:
-   hci_shut_down();
-   return -1;
+     hci_shut_down();
+     return -1;
  }
  
- void hci_shut_down(void) {
-   hci_host_startup_flag  = false;
-   hci_layer_deinit_env();
+ void hci_shut_down(void)
+ {
+     hci_host_startup_flag  = false;
+     hci_layer_deinit_env();
  
-   packet_fragmenter->cleanup();
+     packet_fragmenter->cleanup();
  
-   //low_power_manager->cleanup();
-   hal->close();
-   vTaskDelete(xHciHostTaskHandle);
-   vQueueDelete(xHciHostQueue);
+     //low_power_manager->cleanup();
+     hal->close();
+     vTaskDelete(xHciHostTaskHandle);
+     vQueueDelete(xHciHostQueue);
  }
  
  
@@@ -154,44 -158,44 +158,44 @@@ void hci_host_task_post(void
  
  static int hci_layer_init_env(void)
  {
-   command_waiting_response_t *cmd_wait_q;
-   // The host is only allowed to send at most one command initially,
-   // as per the Bluetooth spec, Volume 2, Part E, 4.4 (Command Flow Control)
-   // This value can change when you get a command complete or command status event.
-   hci_host_env.command_credits = 1;
-   hci_host_env.command_queue = fixed_queue_new(SIZE_MAX);
-   if (hci_host_env.command_queue)
-     fixed_queue_register_dequeue(hci_host_env.command_queue, event_command_ready);
-   else {
-     LOG_ERROR("%s unable to create pending command queue.", __func__);
-     return -1;
-   }
+     command_waiting_response_t *cmd_wait_q;
+     // The host is only allowed to send at most one command initially,
+     // as per the Bluetooth spec, Volume 2, Part E, 4.4 (Command Flow Control)
+     // This value can change when you get a command complete or command status event.
+     hci_host_env.command_credits = 1;
+     hci_host_env.command_queue = fixed_queue_new(SIZE_MAX);
+     if (hci_host_env.command_queue) {
+         fixed_queue_register_dequeue(hci_host_env.command_queue, event_command_ready);
+     } else {
+         LOG_ERROR("%s unable to create pending command queue.", __func__);
+         return -1;
+     }
  
-   hci_host_env.packet_queue = fixed_queue_new(SIZE_MAX);
-   if (hci_host_env.packet_queue)
-     fixed_queue_register_dequeue(hci_host_env.packet_queue, event_packet_ready);  
-   else {
-     LOG_ERROR("%s unable to create pending packet queue.", __func__);
-     return -1;
-   }
-   // Init Commands waiting response list and timer
-   cmd_wait_q = &hci_host_env.cmd_waiting_q;
-   cmd_wait_q->timer_is_set = false;
-   cmd_wait_q->commands_pending_response = list_new(NULL);
-   if (!cmd_wait_q->commands_pending_response) {
-     LOG_ERROR("%s unable to create list for commands pending response.", __func__);
-     return -1;
-   }
-   pthread_mutex_init(&cmd_wait_q->commands_pending_response_lock, NULL);
-   cmd_wait_q->command_response_timer = osi_alarm_new("cmd_rsp_to", command_timed_out, cmd_wait_q, COMMAND_PENDING_TIMEOUT, false);
-   if (!cmd_wait_q->command_response_timer) {
-     LOG_ERROR("%s unable to create command response timer.", __func__);
-     return -1;
-   }
+     hci_host_env.packet_queue = fixed_queue_new(SIZE_MAX);
+     if (hci_host_env.packet_queue) {
+         fixed_queue_register_dequeue(hci_host_env.packet_queue, event_packet_ready);
+     } else {
+         LOG_ERROR("%s unable to create pending packet queue.", __func__);
+         return -1;
+     }
  
-   return 0;
+     // Init Commands waiting response list and timer
+     cmd_wait_q = &hci_host_env.cmd_waiting_q;
+     cmd_wait_q->timer_is_set = false;
+     cmd_wait_q->commands_pending_response = list_new(NULL);
+     if (!cmd_wait_q->commands_pending_response) {
+         LOG_ERROR("%s unable to create list for commands pending response.", __func__);
+         return -1;
+     }
+     pthread_mutex_init(&cmd_wait_q->commands_pending_response_lock, NULL);
 -    cmd_wait_q->command_response_timer = osi_alarm_new("cmd_rsp_to", command_timed_out, cmd_wait_q, COMMAND_PENDING_TIMEOUT);
++    cmd_wait_q->command_response_timer = osi_alarm_new("cmd_rsp_to", command_timed_out, cmd_wait_q, COMMAND_PENDING_TIMEOUT, false);
+     if (!cmd_wait_q->command_response_timer) {
+         LOG_ERROR("%s unable to create command response timer.", __func__);
+         return -1;
+     }
+     return 0;
  }
  
  static void hci_layer_deinit_env(void)
@@@ -351,26 -367,30 +366,29 @@@ static void event_packet_ready(fixed_qu
  }
  
  // Callback for the fragmenter to send a fragment
- static void transmit_fragment(BT_HDR *packet, bool send_transmit_finished) {
-   uint16_t event = packet->event & MSG_EVT_MASK;
-   serial_data_type_t type = event_to_data_type(event);
+ static void transmit_fragment(BT_HDR *packet, bool send_transmit_finished)
+ {
+     uint16_t event = packet->event & MSG_EVT_MASK;
+     serial_data_type_t type = event_to_data_type(event);
  
-   hal->transmit_data(type, packet->data + packet->offset, packet->len);
+     hal->transmit_data(type, packet->data + packet->offset, packet->len);
  
-   if (event != MSG_STACK_TO_HC_HCI_CMD && send_transmit_finished)
-     buffer_allocator->free(packet);
+     if (event != MSG_STACK_TO_HC_HCI_CMD && send_transmit_finished) {
+         buffer_allocator->free(packet);
+     }
  }
  
- static void fragmenter_transmit_finished(BT_HDR *packet, bool all_fragments_sent) {
-   if (all_fragments_sent) {
-     buffer_allocator->free(packet);
-   } else {
-     // This is kind of a weird case, since we're dispatching a partially sent packet
-     // up to a higher layer.
-     // TODO(zachoverflow): rework upper layer so this isn't necessary.
-     dispatch_reassembled(packet);
-     //data_dispatcher_dispatch(interface.event_dispatcher, packet->event & MSG_EVT_MASK, packet);
-   }
+ static void fragmenter_transmit_finished(BT_HDR *packet, bool all_fragments_sent)
+ {
+     if (all_fragments_sent) {
+         buffer_allocator->free(packet);
+     } else {
+         // This is kind of a weird case, since we're dispatching a partially sent packet
+         // up to a higher layer.
+         // TODO(zachoverflow): rework upper layer so this isn't necessary.
 -        buffer_allocator->free(packet);
 -        //dispatch_reassembled(packet);
++        dispatch_reassembled(packet);
+         //data_dispatcher_dispatch(interface.event_dispatcher, packet->event & MSG_EVT_MASK, packet);
+     }
  }
  
  static void restart_comamnd_waiting_response_timer(
index 46e419ae2ac2305b91eb41708c92352a9dc152a1,42663a249a47b171f2df720e04c194a6852b0cc7..fe6ca501973ab68b3861058fa886ae6d5d419160
mode 100755,100644..100644
@@@ -50,162 -51,180 +50,169 @@@ static const packet_fragmenter_callback
  static hash_map_t *partial_packets;
  static BT_HDR *current_fragment_packet;
  
- static void init(const packet_fragmenter_callbacks_t *result_callbacks) {
-   current_fragment_packet = NULL;
-   callbacks = result_callbacks;
-   partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL, NULL);
+ static void init(const packet_fragmenter_callbacks_t *result_callbacks)
+ {
+     current_fragment_packet = NULL;
+     callbacks = result_callbacks;
+     partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL, NULL);
  }
  
- static void cleanup() {
-   if (partial_packets)
-     hash_map_free(partial_packets);
+ static void cleanup()
+ {
+     if (partial_packets) {
+         hash_map_free(partial_packets);
+     }
  }
  
- static BT_HDR *fragment_get_current_packet() {
-   return current_fragment_packet;
+ static BT_HDR *fragment_get_current_packet()
+ {
+     return current_fragment_packet;
  }
  
- static void fragment_and_dispatch(BT_HDR *packet) {
-   uint16_t continuation_handle;
-   uint16_t max_data_size, max_packet_size, remaining_length;
-   uint16_t event = packet->event & MSG_EVT_MASK;
-   uint8_t *stream = packet->data + packet->offset;
-   assert(packet != NULL);
-   // We only fragment ACL packets
-   if (event != MSG_STACK_TO_HC_HCI_ACL) {
-     callbacks->fragmented(packet, true);
-     return;
-   }
-   max_data_size =
-     SUB_EVENT(packet->event) == LOCAL_BR_EDR_CONTROLLER_ID ?
-       controller->get_acl_data_size_classic() :
-       controller->get_acl_data_size_ble();
-   max_packet_size = max_data_size + HCI_ACL_PREAMBLE_SIZE;
-   remaining_length = packet->len;
-   STREAM_TO_UINT16(continuation_handle, stream);
-   continuation_handle = APPLY_CONTINUATION_FLAG(continuation_handle);
-   if (remaining_length > max_packet_size) {
-     current_fragment_packet = packet;
-     UINT16_TO_STREAM(stream, max_packet_size);
-     packet->len = max_packet_size;
-     callbacks->fragmented(packet, false);
-     packet->offset += max_data_size;
-     remaining_length -= max_data_size;
-     packet->len = remaining_length;
-     // Write the ACL header for the next fragment
-     stream = packet->data + packet->offset;
-     UINT16_TO_STREAM(stream, continuation_handle);
-     UINT16_TO_STREAM(stream, remaining_length - HCI_ACL_PREAMBLE_SIZE);
-     // Apparently L2CAP can set layer_specific to a max number of segments to transmit
-     if (packet->layer_specific) {
-       packet->layer_specific--;
-       if (packet->layer_specific == 0) {
-         packet->event = MSG_HC_TO_STACK_L2C_SEG_XMIT;
-         callbacks->transmit_finished(packet, false);
+ static void fragment_and_dispatch(BT_HDR *packet)
+ {
+     uint16_t continuation_handle;
+     uint16_t max_data_size, max_packet_size, remaining_length;
+     uint16_t event = packet->event & MSG_EVT_MASK;
+     uint8_t *stream = packet->data + packet->offset;
+     assert(packet != NULL);
+     // We only fragment ACL packets
+     if (event != MSG_STACK_TO_HC_HCI_ACL) {
+         callbacks->fragmented(packet, true);
          return;
-       }
      }
-   } else {
-     current_fragment_packet = NULL;
-     callbacks->fragmented(packet, true);
-   }
+     max_data_size =
+         SUB_EVENT(packet->event) == LOCAL_BR_EDR_CONTROLLER_ID ?
+         controller->get_acl_data_size_classic() :
+         controller->get_acl_data_size_ble();
+     max_packet_size = max_data_size + HCI_ACL_PREAMBLE_SIZE;
+     remaining_length = packet->len;
+     STREAM_TO_UINT16(continuation_handle, stream);
+     continuation_handle = APPLY_CONTINUATION_FLAG(continuation_handle);
+     if (remaining_length > max_packet_size) {
+         current_fragment_packet = packet;
+         UINT16_TO_STREAM(stream, max_packet_size);
+         packet->len = max_packet_size;
+         callbacks->fragmented(packet, false);
+         packet->offset += max_data_size;
+         remaining_length -= max_data_size;
+         packet->len = remaining_length;
+         // Write the ACL header for the next fragment
+         stream = packet->data + packet->offset;
+         UINT16_TO_STREAM(stream, continuation_handle);
+         UINT16_TO_STREAM(stream, remaining_length - HCI_ACL_PREAMBLE_SIZE);
+         // Apparently L2CAP can set layer_specific to a max number of segments to transmit
+         if (packet->layer_specific) {
+             packet->layer_specific--;
+             if (packet->layer_specific == 0) {
+                 packet->event = MSG_HC_TO_STACK_L2C_SEG_XMIT;
+                 callbacks->transmit_finished(packet, false);
+                 return;
+             }
+         }
+     } else {
+         current_fragment_packet = NULL;
+         callbacks->fragmented(packet, true);
+     }
  }
  
- static void reassemble_and_dispatch(BT_HDR *packet) {
-   if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) {
-     uint8_t *stream = packet->data + packet->offset;
-     uint16_t handle;
-     uint16_t l2cap_length;
-     uint16_t acl_length;
-     uint8_t boundary_flag;
-     BT_HDR *partial_packet;
-     STREAM_TO_UINT16(handle, stream);
-     STREAM_TO_UINT16(acl_length, stream);
-     STREAM_TO_UINT16(l2cap_length, stream);
-     assert(acl_length == packet->len - HCI_ACL_PREAMBLE_SIZE);
-     boundary_flag = GET_BOUNDARY_FLAG(handle);
-     handle = handle & HANDLE_MASK;
-     partial_packet = (BT_HDR *)hash_map_get(partial_packets, (void *)(uintptr_t)handle);
-     if (boundary_flag == START_PACKET_BOUNDARY) {
-       uint16_t full_length;
-       if (partial_packet) {
-         LOG_WARN("%s found unfinished packet for handle with start packet. Dropping old.", __func__);
-       hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
-         buffer_allocator->free(partial_packet);
-       }
-       full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
-       if (full_length <= packet->len) {
-         if (full_length < packet->len)
-           LOG_WARN("%s found l2cap full length %d less than the hci length %d.", __func__, l2cap_length, packet->len);
-           
-         callbacks->reassembled(packet);
-         return;
-       }
-       partial_packet = (BT_HDR *)buffer_allocator->alloc(full_length + sizeof(BT_HDR));
-       partial_packet->event = packet->event;
-       partial_packet->len = full_length;
-       partial_packet->offset = packet->len;
-       memcpy(partial_packet->data, packet->data+packet->offset, packet->len);
-       
-       // Update the ACL data size to indicate the full expected length
-       stream = partial_packet->data;
-       STREAM_SKIP_UINT16(stream); // skip the handle
-       UINT16_TO_STREAM(stream, full_length - HCI_ACL_PREAMBLE_SIZE);
-       hash_map_set(partial_packets, (void *)(uintptr_t)handle, partial_packet);
-       // Free the old packet buffer, since we don't need it anymore
-       buffer_allocator->free(packet);
+ static void reassemble_and_dispatch(BT_HDR *packet)
+ {
 -    LOG_DEBUG("reassemble_and_dispatch\n");
 -
+     if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) {
 -        uint8_t *stream = packet->data;
++        uint8_t *stream = packet->data + packet->offset;
+         uint16_t handle;
+         uint16_t l2cap_length;
+         uint16_t acl_length;
++        uint8_t boundary_flag;
++        BT_HDR *partial_packet;
+         STREAM_TO_UINT16(handle, stream);
+         STREAM_TO_UINT16(acl_length, stream);
+         STREAM_TO_UINT16(l2cap_length, stream);
+         assert(acl_length == packet->len - HCI_ACL_PREAMBLE_SIZE);
 -        uint8_t boundary_flag = GET_BOUNDARY_FLAG(handle);
++        boundary_flag = GET_BOUNDARY_FLAG(handle);
+         handle = handle & HANDLE_MASK;
 -        BT_HDR *partial_packet = (BT_HDR *)hash_map_get(partial_packets, (void *)(uintptr_t)handle);
++        partial_packet = (BT_HDR *)hash_map_get(partial_packets, (void *)(uintptr_t)handle);
+         if (boundary_flag == START_PACKET_BOUNDARY) {
++            uint16_t full_length;
+             if (partial_packet) {
 -                LOG_ERROR("%s found unfinished packet for handle with start packet. Dropping old.\n", __func__);
 -                LOG_ERROR("partial_packet->len = %x, offset = %x\n", partial_packet->len, partial_packet->len);
 -
 -                for (int i = 0; i < partial_packet->len; i++) {
 -                    LOG_ERROR("%x", partial_packet->data[i]);
 -                }
 -                LOG_ERROR("\n");
++                LOG_WARN("%s found unfinished packet for handle with start packet. Dropping old.", __func__);
+                 hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
 -                //buffer_allocator->free(partial_packet);
 -                LOG_ERROR("+++++++++++++++++++\n");
++                buffer_allocator->free(partial_packet);
+             }
 -            uint16_t full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
++            full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
+             if (full_length <= packet->len) {
+                 if (full_length < packet->len) {
 -                    LOG_WARN("%s found l2cap full length %d less than the hci length %d.\n", __func__, l2cap_length, packet->len);
++                    LOG_WARN("%s found l2cap full length %d less than the hci length %d.", __func__, l2cap_length, packet->len);
+                 }
+                 callbacks->reassembled(packet);
+                 return;
+             }
+             partial_packet = (BT_HDR *)buffer_allocator->alloc(full_length + sizeof(BT_HDR));
+             partial_packet->event = packet->event;
+             partial_packet->len = full_length;
+             partial_packet->offset = packet->len;
 -            memcpy(partial_packet->data, packet->data, packet->len);
++            memcpy(partial_packet->data, packet->data + packet->offset, packet->len);
+             // Update the ACL data size to indicate the full expected length
+             stream = partial_packet->data;
+             STREAM_SKIP_UINT16(stream); // skip the handle
+             UINT16_TO_STREAM(stream, full_length - HCI_ACL_PREAMBLE_SIZE);
+             hash_map_set(partial_packets, (void *)(uintptr_t)handle, partial_packet);
+             // Free the old packet buffer, since we don't need it anymore
+             buffer_allocator->free(packet);
+         } else {
++            uint16_t projected_offset;
+             if (!partial_packet) {
 -                LOG_ERROR("%s got continuation for unknown packet. Dropping it.\n", __func__);
++                LOG_WARN("%s got continuation for unknown packet. Dropping it.", __func__);
+                 buffer_allocator->free(packet);
+                 return;
+             }
 -            packet->offset = HCI_ACL_PREAMBLE_SIZE;
 -            uint16_t projected_offset = partial_packet->offset + (packet->len - HCI_ACL_PREAMBLE_SIZE);
++            packet->offset += HCI_ACL_PREAMBLE_SIZE; // skip ACL preamble
++            packet->len -= HCI_ACL_PREAMBLE_SIZE;
++
++            projected_offset = partial_packet->offset + packet->len;
+             if (projected_offset > partial_packet->len) { // len stores the expected length
 -                LOG_ERROR("%s got packet which would exceed expected length of %d. Truncating.\n", __func__, partial_packet->len);
++                LOG_WARN("%s got packet which would exceed expected length of %d. Truncating.", __func__, partial_packet->len);
+                 packet->len = partial_packet->len - partial_packet->offset;
+                 projected_offset = partial_packet->len;
+             }
+             memcpy(
+                 partial_packet->data + partial_packet->offset,
+                 packet->data + packet->offset,
 -                packet->len - packet->offset
++                packet->len
+             );
 -
+             // Free the old packet buffer, since we don't need it anymore
+             buffer_allocator->free(packet);
+             partial_packet->offset = projected_offset;
+             if (partial_packet->offset == partial_packet->len) {
 -                stream = partial_packet->data;
 -                STREAM_TO_UINT16(handle, stream);
 -                STREAM_TO_UINT16(acl_length, stream);
 -                STREAM_TO_UINT16(l2cap_length, stream);
 -                LOG_ERROR("partial_packet->offset = %x\n", partial_packet->offset);
+                 hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
+                 partial_packet->offset = 0;
 -
 -
+                 callbacks->reassembled(partial_packet);
+             }
+         }
      } else {
-       uint16_t projected_offset;
-       if (!partial_packet) {
-         LOG_WARN("%s got continuation for unknown packet. Dropping it.", __func__);
-         buffer_allocator->free(packet);
-         return;
-       }
-       packet->offset += HCI_ACL_PREAMBLE_SIZE; // skip ACL preamble
-       packet->len -= HCI_ACL_PREAMBLE_SIZE;
-       projected_offset = partial_packet->offset + packet->len;
-       if (projected_offset > partial_packet->len) { // len stores the expected length
-         LOG_WARN("%s got packet which would exceed expected length of %d. Truncating.", __func__, partial_packet->len);
-         packet->len = partial_packet->len - partial_packet->offset;
-         projected_offset = partial_packet->len;
-       }
-       memcpy(
-         partial_packet->data + partial_packet->offset,
-         packet->data + packet->offset,
-       packet->len
-       );
-       // Free the old packet buffer, since we don't need it anymore
-       buffer_allocator->free(packet);
-       partial_packet->offset = projected_offset;
-       if (partial_packet->offset == partial_packet->len) {
-         hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
-         partial_packet->offset = 0;
-         callbacks->reassembled(partial_packet);
-       }
+         callbacks->reassembled(packet);
      }
-   } else {
-     callbacks->reassembled(packet);
-   }
  }
  
  static const packet_fragmenter_t interface = {
index c98ed0ed82335b13e0f4fa83c7ab393526525998,3f12d578a1e4bb93787e05b58cd0ad4679809887..ef236f663de0a18ed1d96aab5204a58bdd3c0420
mode 100755,100644..100644
index 656af21f9ef3b353b779cc5728f3359d04ebc201,5f894a5d61a37ab31093f52ae05148270e4c0e5f..1bedf45f5282c3fad07b1342757019a75fe30bf9
mode 100755,100644..100644
index 9b24d8e5dd953a13f29fd1c878fc646f1a159aba,3dbeb2d455325159c1fb3f7824177436680dcb0d..7eed98e7c6c84282406f2b1d9f62955f2b482b47
mode 100755,100644..100644
@@@ -59,48 -59,48 +59,49 @@@ static struct alarm_t *alarm_cbs_lookfo
  
  static void alarm_cb_handler(TimerHandle_t xTimer)
  {
-       struct alarm_t *alarm;
-       if (!xTimer) {
-               LOG_DEBUG("TimerName: NULL\n");
-               return;
-       }
-       alarm = pvTimerGetTimerID(xTimer);
-       LOG_DEBUG("TimerID %08x, Name %s\n", alarm, pcTimerGetTimerName(xTimer));
-       if (alarm->cb) {
-               alarm->cb(alarm->cb_data);
-       }
+     struct alarm_t *alarm;
+     if (!xTimer) {
+         LOG_DEBUG("TimerName: NULL\n");
+         return;
+     }
+     alarm = pvTimerGetTimerID(xTimer);
+     LOG_DEBUG("TimerID %08x, Name %s\n", alarm, pcTimerGetTimerName(xTimer));
+     if (alarm->cb) {
+         alarm->cb(alarm->cb_data);
+     }
  }
  
 -osi_alarm_t *osi_alarm_new(char *alarm_name, osi_alarm_callback_t callback, void *data, period_ms_t timer_expire)
 +osi_alarm_t *osi_alarm_new(char *alarm_name, osi_alarm_callback_t callback, void *data, period_ms_t timer_expire, bool is_periodic)
  {
-       struct alarm_t *timer_id;
-       TimerHandle_t t;
-       if (timer_expire == 0)
-               timer_expire = 1000;
-       /* TODO mutex lock */
-       timer_id = alarm_cbs_lookfor_available();
-       if (!timer_id) {
-               LOG_ERROR("%s full\n", __func__);
-               return NULL;
-       }
-       portBASE_TYPE auto_reload = is_periodic ? pdTRUE : pdFALSE;
-       t = xTimerCreate(alarm_name, timer_expire / portTICK_PERIOD_MS, auto_reload, timer_id, alarm_cb_handler);
-       if (!t) {
-               LOG_ERROR("%s error\n", __func__);
-               return NULL;
-       }
-       timer_id->alarm_hdl = t;
-       timer_id->cb = callback;
-       timer_id->cb_data = data;
-       /* TODO mutex unlock */
-       return timer_id;
+     struct alarm_t *timer_id;
+     TimerHandle_t t;
+     if (timer_expire == 0) {
+         timer_expire = 1000;
+     }
+     /* TODO mutex lock */
+     timer_id = alarm_cbs_lookfor_available();
+     if (!timer_id) {
+         LOG_ERROR("%s full\n", __func__);
+         return NULL;
+     }
 -    t = xTimerCreate(alarm_name, timer_expire / portTICK_PERIOD_MS, pdFALSE, timer_id, alarm_cb_handler);
++    portBASE_TYPE auto_reload = is_periodic ? pdTRUE : pdFALSE;
++    t = xTimerCreate(alarm_name, timer_expire / portTICK_PERIOD_MS, auto_reload, timer_id, alarm_cb_handler);
+     if (!t) {
+         LOG_ERROR("%s error\n", __func__);
+         return NULL;
+     }
+     timer_id->alarm_hdl = t;
+     timer_id->cb = callback;
+     timer_id->cb_data = data;
+     /* TODO mutex unlock */
+     return timer_id;
  }
  
  int osi_alarm_free(osi_alarm_t *alarm)
index 4fea94c3ed82b999700fe98d383368ebc8c1f098,2e226ed27f62dcaea356ff815b18c9693d067223..480bf73d276014fdf7ae9339d2ccce009266fc17
mode 100755,100644..100644
index 660eb2ff19bd84c3822fc96fb0d4386030c5f7d3,4c59d6f75bbf49644b7abc549131b1e7e47a278c..122c2374c5859d03feb05639d5e497d20986a2fa
mode 100755,100644..100644
@@@ -190,19 -196,20 +196,20 @@@ void BTU_StartUp(void
      pthread_mutex_init(&btu_l2cap_alarm_lock, NULL);
  
      btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX);
-     if (btu_l2cap_alarm_queue == NULL)
-          goto error_exit;
+     if (btu_l2cap_alarm_queue == NULL) {
+         goto error_exit;
+     }
  
      xBtuQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
 -    xTaskCreate(btu_task_thread_handler, "BtuT", 8192, NULL, configMAX_PRIORITIES - 1, &xBtuTaskHandle);
 +    xTaskCreate(btu_task_thread_handler, "BtuT", 4096, NULL, configMAX_PRIORITIES - 1, &xBtuTaskHandle);
      btu_task_post(SIG_BTU_START_UP);
- /*
-     // Continue startup on bt workqueue thread.
-     thread_post(bt_workqueue_thread, btu_task_start_up, NULL);
- */
    /*
+         // Continue startup on bt workqueue thread.
+         thread_post(bt_workqueue_thread, btu_task_start_up, NULL);
    */
      return;
  
  error_exit:;
+ error_exit:;
      LOG_ERROR("%s Unable to allocate resources for bt_workqueue", __func__);
      BTU_ShutDown();
  }
index 191b4302ecab73ee4f808e6098c7aa3e44d06749,690878d07c6dd231370af9a72ee032f94537fda1..f6f6aeb64f7a60552317e1f05a623a8f38418671
mode 100755,100644..100644
@@@ -500,40 -506,42 +506,42 @@@ static void btu_general_alarm_process(T
      }
  }
  
- void btu_general_alarm_cb(void *data) {
-   assert(data != NULL);
-   TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
+ void btu_general_alarm_cb(void *data)
+ {
+     assert(data != NULL);
+     TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
  
-   fixed_queue_enqueue(btu_general_alarm_queue, p_tle);
-   //ke_event_set(KE_EVENT_BTU_TASK_THREAD);
-   btu_task_post(SIG_BTU_WORK);
+     fixed_queue_enqueue(btu_general_alarm_queue, p_tle);
+     //ke_event_set(KE_EVENT_BTU_TASK_THREAD);
+     btu_task_post(SIG_BTU_WORK);
  }
  
- void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) {
-   osi_alarm_t *alarm = NULL;
-   assert(p_tle != NULL);
-   // Get the alarm for the timer list entry.
-   pthread_mutex_lock(&btu_general_alarm_lock);
-   if (!hash_map_has_key(btu_general_alarm_hash_map, p_tle)) {
-     alarm = osi_alarm_new("btu_gen", btu_general_alarm_cb, (void *)p_tle, 0, false);
-     hash_map_set(btu_general_alarm_hash_map, p_tle, alarm);
-   }
-   pthread_mutex_unlock(&btu_general_alarm_lock);
-   alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
-   if (alarm == NULL) {
-     LOG_ERROR("%s Unable to create alarm", __func__);
-     return;
-   }
-   osi_alarm_cancel(alarm);
-   p_tle->event = type;
-   // NOTE: This value is in seconds but stored in a ticks field.
-   p_tle->ticks = timeout_sec;
-   p_tle->in_use = TRUE;
-   osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
+ void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
+ {
+     osi_alarm_t *alarm = NULL;
+     assert(p_tle != NULL);
+     // Get the alarm for the timer list entry.
+     pthread_mutex_lock(&btu_general_alarm_lock);
+     if (!hash_map_has_key(btu_general_alarm_hash_map, p_tle)) {
 -        alarm = osi_alarm_new("btu_gen", btu_general_alarm_cb, (void *)p_tle, 0);
++        alarm = osi_alarm_new("btu_gen", btu_general_alarm_cb, (void *)p_tle, 0, false);
+         hash_map_set(btu_general_alarm_hash_map, p_tle, alarm);
+     }
+     pthread_mutex_unlock(&btu_general_alarm_lock);
+     alarm = hash_map_get(btu_general_alarm_hash_map, p_tle);
+     if (alarm == NULL) {
+         LOG_ERROR("%s Unable to create alarm", __func__);
+         return;
+     }
+     osi_alarm_cancel(alarm);
+     p_tle->event = type;
+     // NOTE: This value is in seconds but stored in a ticks field.
+     p_tle->ticks = timeout_sec;
+     p_tle->in_use = TRUE;
+     osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
  }
  
  /*******************************************************************************
@@@ -571,54 -581,57 +581,57 @@@ void btu_stop_timer(TIMER_LIST_ENT *p_t
  ** Returns          void
  **
  *******************************************************************************/
- static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle) {
-   assert(p_tle != NULL);
+ static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle)
+ {
+     assert(p_tle != NULL);
  
-   switch (p_tle->event) {
+     switch (p_tle->event) {
      case BTU_TTYPE_L2CAP_CHNL:      /* monitor or retransmission timer */
      case BTU_TTYPE_L2CAP_FCR_ACK:   /* ack timer */
-       l2c_process_timeout (p_tle);
-       break;
+         l2c_process_timeout (p_tle);
+         break;
  
      default:
-       break;
-   }
+         break;
+     }
  }
  
- static void btu_l2cap_alarm_cb(void *data) {
-   assert(data != NULL);
-   TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
+ static void btu_l2cap_alarm_cb(void *data)
+ {
+     assert(data != NULL);
+     TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
  
-   fixed_queue_enqueue(btu_l2cap_alarm_queue, p_tle);
-   //ke_event_set(KE_EVENT_BTU_TASK_THREAD);
-   btu_task_post(SIG_BTU_WORK);
+     fixed_queue_enqueue(btu_l2cap_alarm_queue, p_tle);
+     //ke_event_set(KE_EVENT_BTU_TASK_THREAD);
+     btu_task_post(SIG_BTU_WORK);
  }
  
- void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks) {
-   osi_alarm_t *alarm = NULL;
-   assert(p_tle != NULL);
-   // Get the alarm for the timer list entry.
-   pthread_mutex_lock(&btu_l2cap_alarm_lock);
-   if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) {
-     alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0, false);
-     hash_map_set(btu_l2cap_alarm_hash_map, p_tle, (void *)alarm);
-   }
-   pthread_mutex_unlock(&btu_l2cap_alarm_lock);
-   alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
-   if (alarm == NULL) {
-     LOG_ERROR("%s Unable to create alarm", __func__);
-     return;
-   }
-   osi_alarm_cancel(alarm);
-   p_tle->event = type;
-   p_tle->ticks = timeout_ticks;
-   p_tle->in_use = TRUE;
-   // The quick timer ticks are 100ms long.
-   osi_alarm_set(alarm, (period_ms_t)(timeout_ticks * 100));
+ void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks)
+ {
+     osi_alarm_t *alarm = NULL;
+     assert(p_tle != NULL);
+     // Get the alarm for the timer list entry.
+     pthread_mutex_lock(&btu_l2cap_alarm_lock);
+     if (!hash_map_has_key(btu_l2cap_alarm_hash_map, p_tle)) {
 -        alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0);
++        alarm = osi_alarm_new("btu_l2cap", btu_l2cap_alarm_cb, (void *)p_tle, 0, false);
+         hash_map_set(btu_l2cap_alarm_hash_map, p_tle, (void *)alarm);
+     }
+     pthread_mutex_unlock(&btu_l2cap_alarm_lock);
+     alarm = hash_map_get(btu_l2cap_alarm_hash_map, p_tle);
+     if (alarm == NULL) {
+         LOG_ERROR("%s Unable to create alarm", __func__);
+         return;
+     }
+     osi_alarm_cancel(alarm);
+     p_tle->event = type;
+     p_tle->ticks = timeout_ticks;
+     p_tle->in_use = TRUE;
+     // The quick timer ticks are 100ms long.
+     osi_alarm_set(alarm, (period_ms_t)(timeout_ticks * 100));
  }
  
  /*******************************************************************************
@@@ -661,47 -677,50 +677,50 @@@ void btu_oneshot_alarm_cb(void *data
  /*
   * Starts a oneshot timer with a timeout in seconds.
   */
- void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec) {
-   osi_alarm_t *alarm = NULL;
-   assert(p_tle != NULL);
-   // Get the alarm for the timer list entry.
-   pthread_mutex_lock(&btu_oneshot_alarm_lock);
-   if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) {
-     alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0, false);
-     hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm);
-   }
-   pthread_mutex_unlock(&btu_oneshot_alarm_lock);
-   alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
-   if (alarm == NULL) {
-     LOG_ERROR("%s Unable to create alarm", __func__);
-     return;
-   }
-   osi_alarm_cancel(alarm);
-   p_tle->event = type;
-   p_tle->in_use = TRUE;
-   // NOTE: This value is in seconds but stored in a ticks field.
-   p_tle->ticks = timeout_sec;
-   osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
+ void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
+ {
+     osi_alarm_t *alarm = NULL;
+     assert(p_tle != NULL);
+     // Get the alarm for the timer list entry.
+     pthread_mutex_lock(&btu_oneshot_alarm_lock);
+     if (!hash_map_has_key(btu_oneshot_alarm_hash_map, p_tle)) {
 -        alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0);
++        alarm = osi_alarm_new("btu_oneshot", btu_oneshot_alarm_cb, (void *)p_tle, 0, false);
+         hash_map_set(btu_oneshot_alarm_hash_map, p_tle, alarm);
+     }
+     pthread_mutex_unlock(&btu_oneshot_alarm_lock);
+     alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
+     if (alarm == NULL) {
+         LOG_ERROR("%s Unable to create alarm", __func__);
+         return;
+     }
+     osi_alarm_cancel(alarm);
+     p_tle->event = type;
+     p_tle->in_use = TRUE;
+     // NOTE: This value is in seconds but stored in a ticks field.
+     p_tle->ticks = timeout_sec;
+     osi_alarm_set(alarm, (period_ms_t)(timeout_sec * 1000));
  }
  
- void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle) {
-   assert(p_tle != NULL);
+ void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle)
+ {
+     assert(p_tle != NULL);
  
-   if (p_tle->in_use == FALSE)
-     return;
-   p_tle->in_use = FALSE;
+     if (p_tle->in_use == FALSE) {
+         return;
+     }
+     p_tle->in_use = FALSE;
  
-   // Get the alarm for the timer list entry.
-   osi_alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
-   if (alarm == NULL) {
-     LOG_WARN("%s Unable to find expected alarm in hashmap", __func__);
-     return;
-   }
-   osi_alarm_cancel(alarm);
+     // Get the alarm for the timer list entry.
+     osi_alarm_t *alarm = hash_map_get(btu_oneshot_alarm_hash_map, p_tle);
+     if (alarm == NULL) {
+         LOG_WARN("%s Unable to find expected alarm in hashmap", __func__);
+         return;
+     }
+     osi_alarm_cancel(alarm);
  }
  
  #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
index 78c144d2a05187f516f9b1c7bdbc253927e445f7,f2110150917e9d51a4f28132f354f3ff78881cbf..fdcd15629ec78b71c8d6c4e12bcf31c4eaf6b6b5
mode 100755,100644..100644
index 18dffb48cec1fe6553decdd805877827e16f6807,8345777c1a8ca5448be848846bfb9f4caa1cde77..adedc6add5065986ba16b5cdec2893f169ccf844
mode 100755,100644..100644
@@@ -182,10 -178,9 +178,9 @@@ typedef struct 
      TIMER_LIST_ENT              raddr_timer_ent;
  } tBTM_LE_RANDOM_CB;
  
 -#define BTM_BLE_MAX_BG_CONN_DEV_NUM    10
 +#define BTM_BLE_MAX_BG_CONN_DEV_NUM    2
  
- typedef struct
- {
+ typedef struct {
      UINT16              min_conn_int;
      UINT16              max_conn_int;
      UINT16              slave_latency;
index 339700047c5feadf38f0f0d899852be9d94086f4,a365ca9deec4c1bec7a98b7096fa636db4e8d065..8eea25cee7d4a548466b6cad419fe5e742c20bcc
mode 100755,100644..100644
index 814ed44ef2483f1a214b9286f1e9815a75547e25,0d4f7b280d42fd3345d4924d7076035550a6162f..35c34e773b34c5e8bb2187d3109ddf4f2858cd48
@@@ -9,15 -9,14 +9,15 @@@ COMPONENT_ADD_INCLUDEDIRS :=  bluedroid/
                                bluedroid/gki/include                   \
                                bluedroid/hci/include                   \
                                bluedroid/osi/include                   \
-                               bluedroid/profiles/core/include                 \
-                               bluedroid/profiles/esp/blufi/include            \
-                               bluedroid/profiles/esp/include          \
-                               bluedroid/profiles/std/battery/include  \
-                               bluedroid/profiles/std/dis/include      \
-                               bluedroid/profiles/std/hid/include      \
-                               bluedroid/profiles/std/rfcomm/include   \
-                               bluedroid/profiles/std/include          \
 +                              bluedroid/utils/include                 \
+                               bluedroid/btc/core/include              \
+                               bluedroid/btc/profile/esp/blufi/include         \
+                               bluedroid/btc/profile/esp/include               \
+                               bluedroid/btc/profile/std/gatt/include  \
+                               bluedroid/btc/profile/std/gap/include   \
+                               bluedroid/btc/profile/std/sdp/include   \
+                               bluedroid/btc/profile/std/include       \
+                               bluedroid/btc/include           \
                                bluedroid/stack/btm/include             \
                                bluedroid/stack/btu/include             \
                                bluedroid/stack/gap/include             \