OSDN Git Service

hci: Apply clang-format
authorMyles Watson <mylesgw@google.com>
Mon, 31 Oct 2016 17:53:52 +0000 (10:53 -0700)
committerMyles Watson <mylesgw@google.com>
Mon, 31 Oct 2016 20:51:53 +0000 (13:51 -0700)
Remove double asterisks:
  cd hci/
  find . | grep "\.cc\|\.h\|\.c" | \
     xargs -I REPLACE sed 's/^[*][*]/ \*/' -i REPLACE

Run clang-format:
  find . | grep "\.cc\|\.h\|\.c" | xargs -I REPLACE \
     clang-format --style=file -i REPLACE

Test: mma -j32
Change-Id: Ie74244127c8a264dd087d199155274d4655ccf65

35 files changed:
hci/include/bt_hci_bdroid.h
hci/include/bt_vendor_lib.h
hci/include/btsnoop.h
hci/include/btsnoop_mem.h
hci/include/buffer_allocator.h
hci/include/hci_audio.h
hci/include/hci_hal.h
hci/include/hci_inject.h
hci/include/hci_layer.h
hci/include/hci_packet_factory.h
hci/include/hci_packet_parser.h
hci/include/low_power_manager.h
hci/include/packet_fragmenter.h
hci/include/userial.h
hci/include/vendor.h
hci/src/btsnoop.cc
hci/src/btsnoop_mem.cc
hci/src/btsnoop_net.cc
hci/src/buffer_allocator.cc
hci/src/hci_audio.cc
hci/src/hci_hal.cc
hci/src/hci_hal_h4.cc
hci/src/hci_hal_mct.cc
hci/src/hci_inject.cc
hci/src/hci_layer.cc
hci/src/hci_packet_factory.cc
hci/src/hci_packet_parser.cc
hci/src/low_power_manager.cc
hci/src/packet_fragmenter.cc
hci/src/vendor.cc
hci/test/hci_hal_h4_test.cc
hci/test/hci_hal_mct_test.cc
hci/test/hci_layer_test.cc
hci/test/low_power_manager_test.cc
hci/test/packet_fragmenter_test.cc

index fa880b2..3dd9f44 100644 (file)
@@ -34,8 +34,8 @@
 #endif
 
 /******************************************************************************
-**  Constants & Macros
-******************************************************************************/
+ *  Constants & Macros
+ *****************************************************************************/
 
 #include <stdbool.h>
 
@@ -48,60 +48,58 @@ typedef enum {
 } bthc_event_t;
 
 /* Message event mask across Host/Controller lib and stack */
-#define MSG_EVT_MASK                    0xFF00 /* eq. BT_EVT_MASK */
-#define MSG_SUB_EVT_MASK                0x00FF /* eq. BT_SUB_EVT_MASK */
+#define MSG_EVT_MASK 0xFF00     /* eq. BT_EVT_MASK */
+#define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */
 
 /* Message event ID passed from Host/Controller lib to stack */
-#define MSG_HC_TO_STACK_HCI_ERR        0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */
-#define MSG_HC_TO_STACK_HCI_ACL        0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */
-#define MSG_HC_TO_STACK_HCI_SCO        0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */
-#define MSG_HC_TO_STACK_HCI_EVT        0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */
-#define MSG_HC_TO_STACK_L2C_SEG_XMIT   0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */
+#define MSG_HC_TO_STACK_HCI_ERR 0x1300      /* eq. BT_EVT_TO_BTU_HCIT_ERR */
+#define MSG_HC_TO_STACK_HCI_ACL 0x1100      /* eq. BT_EVT_TO_BTU_HCI_ACL */
+#define MSG_HC_TO_STACK_HCI_SCO 0x1200      /* eq. BT_EVT_TO_BTU_HCI_SCO */
+#define MSG_HC_TO_STACK_HCI_EVT 0x1000      /* eq. BT_EVT_TO_BTU_HCI_EVT */
+#define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* BT_EVT_TO_BTU_L2C_SEG_XMIT */
 
 /* Message event ID passed from stack to vendor lib */
-#define MSG_STACK_TO_HC_HCI_ACL        0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
-#define MSG_STACK_TO_HC_HCI_SCO        0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
-#define MSG_STACK_TO_HC_HCI_CMD        0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
+#define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
+#define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
+#define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
 
 /* Local Bluetooth Controller ID for BR/EDR */
-#define LOCAL_BR_EDR_CONTROLLER_ID      0
+#define LOCAL_BR_EDR_CONTROLLER_ID 0
 
 /******************************************************************************
-**  Type definitions and return values
-******************************************************************************/
-
-typedef struct
-{
-    uint16_t          event;
-    uint16_t          len;
-    uint16_t          offset;
-    uint16_t          layer_specific;
-    uint8_t           data[];
+ *  Type definitions and return values
+ *****************************************************************************/
+
+typedef struct {
+  uint16_t event;
+  uint16_t len;
+  uint16_t offset;
+  uint16_t layer_specific;
+  uint8_t data[];
 } HC_BT_HDR;
 
 #define BT_HC_HDR_SIZE (sizeof(HC_BT_HDR))
 
-typedef struct _hc_buffer_hdr
-{
-    struct _hc_buffer_hdr *p_next;   /* next buffer in the queue */
-    uint8_t   reserved1;
-    uint8_t   reserved2;
-    uint8_t   reserved3;
-    uint8_t   reserved4;
+typedef struct _hc_buffer_hdr {
+  struct _hc_buffer_hdr* p_next; /* next buffer in the queue */
+  uint8_t reserved1;
+  uint8_t reserved2;
+  uint8_t reserved3;
+  uint8_t reserved4;
 } HC_BUFFER_HDR_T;
 
 #define BT_HC_BUFFER_HDR_SIZE (sizeof(HC_BUFFER_HDR_T))
 
 /******************************************************************************
-**  Extern variables and functions
-******************************************************************************/
+ *  Extern variables and functions
+ *****************************************************************************/
 
 /******************************************************************************
-**  Functions
-******************************************************************************/
+ *  Functions
+ *****************************************************************************/
 
 // Called when a buffer has been produced by the serial layer and should be
 // processed by the HCI layer.
 void bthc_rx_ready(void);
-void bthc_tx(HC_BT_HDR *buf);
+void bthc_tx(HC_BT_HDRbuf);
 void bthc_idle_timeout(void);
index 9aa6ec9..edfe757 100644 (file)
@@ -29,220 +29,221 @@ extern "C" {
 
 /** Struct types */
 
-
 /** Typedefs and defines */
 
 /** Vendor specific operations OPCODE */
 typedef enum {
-/*  [operation]
- *      Power on or off the BT Controller.
- *  [input param]
- *      A pointer to int type with content of bt_vendor_power_state_t.
- *      Typecasting conversion: (int *) param.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      None.
- */
-    BT_VND_OP_POWER_CTRL,
-
-/*  [operation]
- *      Perform any vendor specific initialization or configuration
- *      on the BT Controller. This is called before stack initialization.
- *  [input param]
- *      None.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      Must call fwcfg_cb to notify the stack of the completion of vendor
- *      specific initialization once it has been done.
- */
-    BT_VND_OP_FW_CFG,
-
-/*  [operation]
- *      Perform any vendor specific SCO/PCM configuration on the BT Controller.
- *      This is called after stack initialization.
- *  [input param]
- *      None.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      Must call scocfg_cb to notify the stack of the completion of vendor
- *      specific SCO configuration once it has been done.
- */
-    BT_VND_OP_SCO_CFG,
-
-/*  [operation]
- *      Open UART port on where the BT Controller is attached.
- *      This is called before stack initialization.
- *  [input param]
- *      A pointer to int array type for open file descriptors.
- *      The mapping of HCI channel to fd slot in the int array is given in
- *      bt_vendor_hci_channels_t.
- *      And, it requires the vendor lib to fill up the content before returning
- *      the call.
- *      Typecasting conversion: (int (*)[]) param.
- *  [return]
- *      Numbers of opened file descriptors.
- *      Valid number:
- *          1 - CMD/EVT/ACL-In/ACL-Out via the same fd (e.g. UART)
- *          2 - CMD/EVT on one fd, and ACL-In/ACL-Out on the other fd
- *          4 - CMD, EVT, ACL-In, ACL-Out are on their individual fd
- *  [callback]
- *      None.
- */
-    BT_VND_OP_USERIAL_OPEN,
-
-/*  [operation]
- *      Close the previously opened UART port.
- *  [input param]
- *      None.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      None.
- */
-    BT_VND_OP_USERIAL_CLOSE,
-
-/*  [operation]
- *      Get the LPM idle timeout in milliseconds.
- *      The stack uses this information to launch a timer delay before it
- *      attempts to de-assert LPM WAKE signal once downstream HCI packet
- *      has been delivered.
- *  [input param]
- *      A pointer to uint32_t type which is passed in by the stack. And, it
- *      requires the vendor lib to fill up the content before returning
- *      the call.
- *      Typecasting conversion: (uint32_t *) param.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      None.
- */
-    BT_VND_OP_GET_LPM_IDLE_TIMEOUT,
-
-/*  [operation]
- *      Enable or disable LPM mode on BT Controller.
- *  [input param]
- *      A pointer to uint8_t type with content of bt_vendor_lpm_mode_t.
- *      Typecasting conversion: (uint8_t *) param.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      Must call lpm_cb to notify the stack of the completion of LPM
- *      disable/enable process once it has been done.
- */
-    BT_VND_OP_LPM_SET_MODE,
-
-/*  [operation]
- *      Assert or Deassert LPM WAKE on BT Controller.
- *  [input param]
- *      A pointer to uint8_t type with content of bt_vendor_lpm_wake_state_t.
- *      Typecasting conversion: (uint8_t *) param.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      None.
- */
-    BT_VND_OP_LPM_WAKE_SET_STATE,
-
-/*  [operation]
- *      Perform any vendor specific commands related to audio state changes.
- *  [input param]
- *      a pointer to bt_vendor_op_audio_state_t indicating what audio state is
- *      set.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      None.
- */
-    BT_VND_OP_SET_AUDIO_STATE,
-
-/*  [operation]
- *      The epilog call to the vendor module so that it can perform any
- *      vendor-specific processes (e.g. send a HCI_RESET to BT Controller)
- *      before the caller calls for cleanup().
- *  [input param]
- *      None.
- *  [return]
- *      0 - default, don't care.
- *  [callback]
- *      Must call epilog_cb to notify the stack of the completion of vendor
- *      specific epilog process once it has been done.
- */
-    BT_VND_OP_EPILOG,
-
-/*  [operation]
- *      Call to the vendor module so that it can perform all vendor-specific
- *      operations to start offloading a2dp media encode & tx.
- *  [input param]
- *      pointer to bt_vendor_op_a2dp_offload_start_t containing elements
- *      required for VND FW to setup a2dp offload.
- *  [return]
- *      0  - default, dont care.
- *  [callback]
- *      Must call a2dp_offload_start_cb to notify the stack of the
- *      completion of vendor specific setup process once it has been done.
- */
-    BT_VND_OP_A2DP_OFFLOAD_START,
-
-/*  [operation]
- *      Call to the vendor module so that it can perform all vendor-specific
- *      operations to suspend offloading a2dp media encode & tx.
- *  [input param]
- *      pointer to bt_vendor_op_a2dp_offload_t containing elements
- *      required for VND FW to setup a2dp offload.
- *  [return]
- *      0  - default, dont care.
- *  [callback]
- *      Must call a2dp_offload_cb to notify the stack of the
- *      completion of vendor specific setup process once it has been done.
- */
-    BT_VND_OP_A2DP_OFFLOAD_STOP,
+  /*  [operation]
+   *      Power on or off the BT Controller.
+   *  [input param]
+   *      A pointer to int type with content of bt_vendor_power_state_t.
+   *      Typecasting conversion: (int *) param.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      None.
+   */
+  BT_VND_OP_POWER_CTRL,
+
+  /*  [operation]
+   *      Perform any vendor specific initialization or configuration
+   *      on the BT Controller. This is called before stack initialization.
+   *  [input param]
+   *      None.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      Must call fwcfg_cb to notify the stack of the completion of vendor
+   *      specific initialization once it has been done.
+   */
+  BT_VND_OP_FW_CFG,
+
+  /*  [operation]
+   *      Perform any vendor specific SCO/PCM configuration on the BT
+   * Controller.
+   *      This is called after stack initialization.
+   *  [input param]
+   *      None.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      Must call scocfg_cb to notify the stack of the completion of vendor
+   *      specific SCO configuration once it has been done.
+   */
+  BT_VND_OP_SCO_CFG,
+
+  /*  [operation]
+   *      Open UART port on where the BT Controller is attached.
+   *      This is called before stack initialization.
+   *  [input param]
+   *      A pointer to int array type for open file descriptors.
+   *      The mapping of HCI channel to fd slot in the int array is given in
+   *      bt_vendor_hci_channels_t.
+   *      And, it requires the vendor lib to fill up the content before
+   * returning
+   *      the call.
+   *      Typecasting conversion: (int (*)[]) param.
+   *  [return]
+   *      Numbers of opened file descriptors.
+   *      Valid number:
+   *          1 - CMD/EVT/ACL-In/ACL-Out via the same fd (e.g. UART)
+   *          2 - CMD/EVT on one fd, and ACL-In/ACL-Out on the other fd
+   *          4 - CMD, EVT, ACL-In, ACL-Out are on their individual fd
+   *  [callback]
+   *      None.
+   */
+  BT_VND_OP_USERIAL_OPEN,
+
+  /*  [operation]
+   *      Close the previously opened UART port.
+   *  [input param]
+   *      None.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      None.
+   */
+  BT_VND_OP_USERIAL_CLOSE,
+
+  /*  [operation]
+   *      Get the LPM idle timeout in milliseconds.
+   *      The stack uses this information to launch a timer delay before it
+   *      attempts to de-assert LPM WAKE signal once downstream HCI packet
+   *      has been delivered.
+   *  [input param]
+   *      A pointer to uint32_t type which is passed in by the stack. And, it
+   *      requires the vendor lib to fill up the content before returning
+   *      the call.
+   *      Typecasting conversion: (uint32_t *) param.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      None.
+   */
+  BT_VND_OP_GET_LPM_IDLE_TIMEOUT,
+
+  /*  [operation]
+   *      Enable or disable LPM mode on BT Controller.
+   *  [input param]
+   *      A pointer to uint8_t type with content of bt_vendor_lpm_mode_t.
+   *      Typecasting conversion: (uint8_t *) param.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      Must call lpm_cb to notify the stack of the completion of LPM
+   *      disable/enable process once it has been done.
+   */
+  BT_VND_OP_LPM_SET_MODE,
+
+  /*  [operation]
+   *      Assert or Deassert LPM WAKE on BT Controller.
+   *  [input param]
+   *      A pointer to uint8_t type with content of bt_vendor_lpm_wake_state_t.
+   *      Typecasting conversion: (uint8_t *) param.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      None.
+   */
+  BT_VND_OP_LPM_WAKE_SET_STATE,
+
+  /*  [operation]
+   *      Perform any vendor specific commands related to audio state changes.
+   *  [input param]
+   *      a pointer to bt_vendor_op_audio_state_t indicating what audio state is
+   *      set.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      None.
+   */
+  BT_VND_OP_SET_AUDIO_STATE,
+
+  /*  [operation]
+   *      The epilog call to the vendor module so that it can perform any
+   *      vendor-specific processes (e.g. send a HCI_RESET to BT Controller)
+   *      before the caller calls for cleanup().
+   *  [input param]
+   *      None.
+   *  [return]
+   *      0 - default, don't care.
+   *  [callback]
+   *      Must call epilog_cb to notify the stack of the completion of vendor
+   *      specific epilog process once it has been done.
+   */
+  BT_VND_OP_EPILOG,
+
+  /*  [operation]
+   *      Call to the vendor module so that it can perform all vendor-specific
+   *      operations to start offloading a2dp media encode & tx.
+   *  [input param]
+   *      pointer to bt_vendor_op_a2dp_offload_start_t containing elements
+   *      required for VND FW to setup a2dp offload.
+   *  [return]
+   *      0  - default, dont care.
+   *  [callback]
+   *      Must call a2dp_offload_start_cb to notify the stack of the
+   *      completion of vendor specific setup process once it has been done.
+   */
+  BT_VND_OP_A2DP_OFFLOAD_START,
+
+  /*  [operation]
+   *      Call to the vendor module so that it can perform all vendor-specific
+   *      operations to suspend offloading a2dp media encode & tx.
+   *  [input param]
+   *      pointer to bt_vendor_op_a2dp_offload_t containing elements
+   *      required for VND FW to setup a2dp offload.
+   *  [return]
+   *      0  - default, dont care.
+   *  [callback]
+   *      Must call a2dp_offload_cb to notify the stack of the
+   *      completion of vendor specific setup process once it has been done.
+   */
+  BT_VND_OP_A2DP_OFFLOAD_STOP,
 
 } bt_vendor_opcode_t;
 
 /** Power on/off control states */
 typedef enum {
-    BT_VND_PWR_OFF,
-    BT_VND_PWR_ON,
-}  bt_vendor_power_state_t;
+  BT_VND_PWR_OFF,
+  BT_VND_PWR_ON,
+} bt_vendor_power_state_t;
 
 /** Define HCI channel identifier in the file descriptors array
     used in BT_VND_OP_USERIAL_OPEN operation.
  */
 typedef enum {
-    CH_CMD,     // HCI Command channel
-    CH_EVT,     // HCI Event channel
-    CH_ACL_OUT, // HCI ACL downstream channel
-    CH_ACL_IN,  // HCI ACL upstream channel
+  CH_CMD,      // HCI Command channel
+  CH_EVT,      // HCI Event channel
+  CH_ACL_OUT,  // HCI ACL downstream channel
+  CH_ACL_IN,   // HCI ACL upstream channel
 
-    CH_MAX      // Total channels
-}  bt_vendor_hci_channels_t;
+  CH_MAX  // Total channels
+} bt_vendor_hci_channels_t;
 
 /** LPM disable/enable request */
 typedef enum {
-    BT_VND_LPM_DISABLE,
-    BT_VND_LPM_ENABLE,
+  BT_VND_LPM_DISABLE,
+  BT_VND_LPM_ENABLE,
 } bt_vendor_lpm_mode_t;
 
 /** LPM WAKE set state request */
 typedef enum {
-    BT_VND_LPM_WAKE_ASSERT,
-    BT_VND_LPM_WAKE_DEASSERT,
+  BT_VND_LPM_WAKE_ASSERT,
+  BT_VND_LPM_WAKE_DEASSERT,
 } bt_vendor_lpm_wake_state_t;
 
 /** Callback result values */
 typedef enum {
-    BT_VND_OP_RESULT_SUCCESS,
-    BT_VND_OP_RESULT_FAIL,
+  BT_VND_OP_RESULT_SUCCESS,
+  BT_VND_OP_RESULT_FAIL,
 } bt_vendor_op_result_t;
 
 /** audio (SCO) state changes triggering VS commands for configuration */
 typedef struct {
-    uint16_t    handle;
-    uint16_t    peer_codec;
-    uint16_t    state;
+  uint16_t handle;
+  uint16_t peer_codec;
+  uint16_t state;
 } bt_vendor_op_audio_state_t;
 
 /*
@@ -293,7 +294,7 @@ typedef void (*cfg_result_cb)(bt_vendor_op_result_t result);
 typedef void* (*malloc_cb)(int size);
 
 /* datapath buffer deallocation callback (callout) */
-typedef void (*mdealloc_cb)(void *p_buf);
+typedef void (*mdealloc_cb)(voidp_buf);
 
 /* define callback of the cmd_xmit_cb
  *
@@ -301,7 +302,7 @@ typedef void (*mdealloc_cb)(void *p_buf);
  *  complete packet. Vendor lib is responsible for releasing the buffer passed
  *  in at the p_mem parameter by calling dealloc callout function.
  */
-typedef void (*tINT_CMD_CBACK)(void *p_mem);
+typedef void (*tINT_CMD_CBACK)(voidp_mem);
 
 /* hci command packet transmit callback (callout)
  *
@@ -318,86 +319,87 @@ typedef void (*tINT_CMD_CBACK)(void *p_mem);
  *  HCI Command packet. For example, opcode = 0x0c03 for the HCI_RESET command
  *  packet.
  */
-typedef uint8_t (*cmd_xmit_cb)(uint16_t opcode, void *p_buf, tINT_CMD_CBACK p_cback);
+typedef uint8_t (*cmd_xmit_cb)(uint16_t opcode, void* p_buf,
+                               tINT_CMD_CBACK p_cback);
 
-typedef void (*cfg_a2dp_cb)(bt_vendor_op_result_t result, bt_vendor_opcode_t op, uint8_t bta_av_handle);
+typedef void (*cfg_a2dp_cb)(bt_vendor_op_result_t result, bt_vendor_opcode_t op,
+                            uint8_t bta_av_handle);
 
 typedef struct {
-    /** set to sizeof(bt_vendor_callbacks_t) */
-    size_t         size;
+  /** set to sizeof(bt_vendor_callbacks_t) */
+  size_t size;
 
-    /*
-     * Callback and callout functions have implemented in HCI libray
-     * (libbt-hci.so).
-     */
+  /*
+   * Callback and callout functions have implemented in HCI libray
+   * (libbt-hci.so).
+   */
 
-    /* notifies caller result of firmware configuration request */
-    cfg_result_cb  fwcfg_cb;
+  /* notifies caller result of firmware configuration request */
+  cfg_result_cb fwcfg_cb;
 
-    /* notifies caller result of sco configuration request */
-    cfg_result_cb  scocfg_cb;
+  /* notifies caller result of sco configuration request */
+  cfg_result_cb scocfg_cb;
 
-    /* notifies caller result of lpm enable/disable */
-    cfg_result_cb  lpm_cb;
+  /* notifies caller result of lpm enable/disable */
+  cfg_result_cb lpm_cb;
 
-    /* notifies the result of codec setting */
-    cfg_result_cb audio_state_cb;
+  /* notifies the result of codec setting */
+  cfg_result_cb audio_state_cb;
 
-    /* buffer allocation request */
-    malloc_cb   alloc;
+  /* buffer allocation request */
+  malloc_cb alloc;
 
-    /* buffer deallocation request */
-    mdealloc_cb dealloc;
+  /* buffer deallocation request */
+  mdealloc_cb dealloc;
 
-    /* hci command packet transmit request */
-    cmd_xmit_cb xmit_cb;
+  /* hci command packet transmit request */
+  cmd_xmit_cb xmit_cb;
 
-    /* notifies caller completion of epilog process */
-    cfg_result_cb epilog_cb;
+  /* notifies caller completion of epilog process */
+  cfg_result_cb epilog_cb;
 
-    /* notifies status of a2dp offload cmd's */
-    cfg_a2dp_cb a2dp_offload_cb;
+  /* notifies status of a2dp offload cmd's */
+  cfg_a2dp_cb a2dp_offload_cb;
 } bt_vendor_callbacks_t;
 
 /** A2DP offload request */
 typedef struct {
-    uint8_t   bta_av_handle;                 /* BTA_AV Handle for callbacks */
-    uint16_t  xmit_quota;                    /* Total ACL quota for light stack */
-    uint16_t  acl_data_size;                 /* Max ACL data size across HCI transport */
-    uint16_t  stream_mtu;
-    uint16_t  local_cid;
-    uint16_t  remote_cid;
-    uint16_t  lm_handle;
-    uint8_t   is_flushable;                  /* true if flushable channel */
-    uint32_t  stream_source;
-    uint8_t   codec_info[10];                /* Codec capabilities array */
+  uint8_t bta_av_handle;  /* BTA_AV Handle for callbacks */
+  uint16_t xmit_quota;    /* Total ACL quota for light stack */
+  uint16_t acl_data_size; /* Max ACL data size across HCI transport */
+  uint16_t stream_mtu;
+  uint16_t local_cid;
+  uint16_t remote_cid;
+  uint16_t lm_handle;
+  uint8_t is_flushable; /* true if flushable channel */
+  uint32_t stream_source;
+  uint8_t codec_info[10]; /* Codec capabilities array */
 } bt_vendor_op_a2dp_offload_t;
 
 /*
  * Bluetooth Host/Controller VENDOR Interface
  */
 typedef struct {
-    /** Set to sizeof(bt_vndor_interface_t) */
-    size_t          size;
+  /** Set to sizeof(bt_vndor_interface_t) */
+  size_t size;
 
-    /*
-     * Functions need to be implemented in Vendor libray (libbt-vendor.so).
-     */
+  /*
+   * Functions need to be implemented in Vendor libray (libbt-vendor.so).
+   */
 
-    /**
-     * Caller will open the interface and pass in the callback routines
-     * to the implemenation of this interface.
-     */
-    int   (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr);
+  /**
+   * Caller will open the interface and pass in the callback routines
+   * to the implemenation of this interface.
+   */
+  int (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char* local_bdaddr);
 
-    /**  Vendor specific operations */
-    int (*op)(bt_vendor_opcode_t opcode, void *param);
+  /**  Vendor specific operations */
+  int (*op)(bt_vendor_opcode_t opcode, void* param);
 
-    /** Closes the interface */
-    void  (*cleanup)(void);
+  /** Closes the interface */
+  void (*cleanup)(void);
 } bt_vendor_interface_t;
 
-
 /*
  * External shared lib functions/data
  */
@@ -410,10 +412,8 @@ typedef struct {
  */
 extern const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE;
 
-
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* BT_VENDOR_LIB_H */
-
index 99415bc..14896ca 100644 (file)
@@ -37,10 +37,10 @@ typedef struct btsnoop_t {
   // Capture |packet| and dump it to the btsnoop logs. If |is_received| is
   // true, the packet is marked as incoming. Otherwise, the packet is marked
   // as outgoing.
-  void (*capture)(const BT_HDR *packet, bool is_received);
+  void (*capture)(const BT_HDRpacket, bool is_received);
 } btsnoop_t;
 
-const btsnoop_t *btsnoop_get_interface(void);
+const btsnoop_tbtsnoop_get_interface(void);
 
 #ifdef __cplusplus
 }
index dc52865..052b9e8 100644 (file)
@@ -28,7 +28,8 @@ extern "C" {
 
 // Callback invoked for each HCI packet.
 // Highlander mode - there can be only one...
-typedef void (*btsnoop_data_cb)(const uint16_t type, const uint8_t *p_data, const size_t len);
+typedef void (*btsnoop_data_cb)(const uint16_t type, const uint8_t* p_data,
+                                const size_t len);
 
 // This call sets the (one and only) callback that will
 // be invoked once for each HCI packet/event.
@@ -37,7 +38,7 @@ void btsnoop_mem_set_callback(btsnoop_data_cb cb);
 // This function is invoked every time an HCI packet
 // is sent/received. Packets will be filtered  and then
 // forwarded to the |btsnoop_data_cb|.
-void btsnoop_mem_capture(const BT_HDR *p_buf);
+void btsnoop_mem_capture(const BT_HDRp_buf);
 
 #ifdef __cplusplus
 }
index 6c91359..7f650ce 100644 (file)
@@ -24,7 +24,7 @@
 extern "C" {
 #endif
 
-const allocator_t *buffer_allocator_get_interface();
+const allocator_tbuffer_allocator_get_interface();
 
 #ifdef __cplusplus
 }
index f03b647..764ae3e 100644 (file)
@@ -26,17 +26,17 @@ extern "C" {
 
 // Audio state definitions.
 typedef enum {
-    SCO_STATE_OFF = 0,      // Audio is off.
-    SCO_STATE_OFF_TRANSFER, // Closed pending final transfer of audio.
-    SCO_STATE_ON,           // Audio is on.
-    SCO_STATE_SETUP,        // Open pending completion of audio setup.
+  SCO_STATE_OFF = 0,       // Audio is off.
+  SCO_STATE_OFF_TRANSFER,  // Closed pending final transfer of audio.
+  SCO_STATE_ON,            // Audio is on.
+  SCO_STATE_SETUP,         // Open pending completion of audio setup.
 } sco_state_t;
 
 // Codec type definitions.
 typedef enum {
-    SCO_CODEC_NONE = 0x0000,
-    SCO_CODEC_CVSD = 0x0001,
-    SCO_CODEC_MSBC = 0x0002,
+  SCO_CODEC_NONE = 0x0000,
+  SCO_CODEC_CVSD = 0x0001,
+  SCO_CODEC_MSBC = 0x0002,
 } sco_codec_t;
 
 // Set the audio state on the controller for SCO (PCM, WBS, ...) using the
index 764cfe2..74f2f67 100644 (file)
@@ -31,9 +31,9 @@ extern "C" {
 typedef enum {
   DATA_TYPE_UNKNOWN = 0,
   DATA_TYPE_COMMAND = 1,
-  DATA_TYPE_ACL     = 2,
-  DATA_TYPE_SCO     = 3,
-  DATA_TYPE_EVENT   = 4
+  DATA_TYPE_ACL = 2,
+  DATA_TYPE_SCO = 3,
+  DATA_TYPE_EVENT = 4
 } serial_data_type_t;
 
 typedef void (*data_ready_cb)(serial_data_type_t type);
@@ -52,8 +52,10 @@ typedef struct {
 } hci_hal_callbacks_t;
 
 typedef struct hci_hal_t {
-  // Initialize the HAL, with |upper_callbacks| and |upper_thread| to run in the context of.
-  bool (*init)(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper_thread);
+  // Initialize the HAL, with |upper_callbacks| and |upper_thread| to run in the
+  // context of.
+  bool (*init)(const hci_hal_callbacks_t* upper_callbacks,
+               thread_t* upper_thread);
 
   // Connect to the underlying hardware, and let data start flowing.
   bool (*open)(void);
@@ -64,7 +66,8 @@ typedef struct hci_hal_t {
   // Retrieve up to |max_size| bytes for ACL, SCO, or EVENT data packets into
   // |buffer|. Only guaranteed to be correct in the context of a data_ready
   // callback of the corresponding type.
-  size_t (*read_data)(serial_data_type_t type, uint8_t *buffer, size_t max_size);
+  size_t (*read_data)(serial_data_type_t type, uint8_t* buffer,
+                      size_t max_size);
   // The upper layer must call this to notify the HAL that it has finished
   // reading a packet of the specified |type|. Underlying implementations that
   // use shared channels for multiple data types depend on this to know when
@@ -79,17 +82,18 @@ typedef struct hci_hal_t {
   // and then restored to its original value.
   // This is safe in the bluetooth context, because there is always a buffer
   // header that prefixes data you're sending.
-  uint16_t (*transmit_data)(serial_data_type_t type, uint8_t *data, uint16_t length);
+  uint16_t (*transmit_data)(serial_data_type_t type, uint8_t* data,
+                            uint16_t length);
 } hci_hal_t;
 
 // Gets the correct hal implementation, as compiled for.
-const hci_hal_t *hci_hal_get_interface(void);
+const hci_hal_thci_hal_get_interface(void);
 
-const hci_hal_t *hci_hal_h4_get_interface(void);
-const hci_hal_t *hci_hal_h4_get_test_interface(vendor_t *vendor_interface);
+const hci_hal_thci_hal_h4_get_interface(void);
+const hci_hal_t* hci_hal_h4_get_test_interface(vendor_t* vendor_interface);
 
-const hci_hal_t *hci_hal_mct_get_interface(void);
-const hci_hal_t *hci_hal_mct_get_test_interface(vendor_t *vendor_interface);
+const hci_hal_thci_hal_mct_get_interface(void);
+const hci_hal_t* hci_hal_mct_get_test_interface(vendor_t* vendor_interface);
 
 #ifdef __cplusplus
 }
index 30e0be4..f194226 100644 (file)
@@ -29,13 +29,13 @@ typedef struct hci_t hci_t;
 typedef struct hci_inject_t {
   // Starts the HCI injection module. Returns true on success, false on failure.
   // Once started, this module must be shut down with |close|.
-  bool (*open)(const hci_t *hci_interface);
+  bool (*open)(const hci_thci_interface);
 
   // Shuts down the HCI injection module.
   void (*close)(void);
 } hci_inject_t;
 
-const hci_inject_t *hci_inject_get_interface();
+const hci_inject_thci_inject_get_interface();
 
 #ifdef __cplusplus
 }
index a14ee27..1e6d137 100644 (file)
 
 #include <stdbool.h>
 
+#include "bt_types.h"
 #include "osi/include/allocator.h"
 #include "osi/include/data_dispatcher.h"
 #include "osi/include/fixed_queue.h"
 #include "osi/include/future.h"
 #include "osi/include/osi.h"
-#include "bt_types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -36,23 +36,23 @@ static const char HCI_MODULE[] = "hci_module";
 ///// LEGACY DEFINITIONS /////
 
 /* Message event mask across Host/Controller lib and stack */
-#define MSG_EVT_MASK                    0xFF00 /* eq. BT_EVT_MASK */
-#define MSG_SUB_EVT_MASK                0x00FF /* eq. BT_SUB_EVT_MASK */
+#define MSG_EVT_MASK 0xFF00     /* eq. BT_EVT_MASK */
+#define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */
 
 /* Message event ID passed from Host/Controller lib to stack */
-#define MSG_HC_TO_STACK_HCI_ERR        0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */
-#define MSG_HC_TO_STACK_HCI_ACL        0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */
-#define MSG_HC_TO_STACK_HCI_SCO        0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */
-#define MSG_HC_TO_STACK_HCI_EVT        0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */
-#define MSG_HC_TO_STACK_L2C_SEG_XMIT   0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */
+#define MSG_HC_TO_STACK_HCI_ERR 0x1300      /* eq. BT_EVT_TO_BTU_HCIT_ERR */
+#define MSG_HC_TO_STACK_HCI_ACL 0x1100      /* eq. BT_EVT_TO_BTU_HCI_ACL */
+#define MSG_HC_TO_STACK_HCI_SCO 0x1200      /* eq. BT_EVT_TO_BTU_HCI_SCO */
+#define MSG_HC_TO_STACK_HCI_EVT 0x1000      /* eq. BT_EVT_TO_BTU_HCI_EVT */
+#define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* BT_EVT_TO_BTU_L2C_SEG_XMIT */
 
 /* Message event ID passed from stack to vendor lib */
-#define MSG_STACK_TO_HC_HCI_ACL        0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
-#define MSG_STACK_TO_HC_HCI_SCO        0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
-#define MSG_STACK_TO_HC_HCI_CMD        0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
+#define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
+#define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
+#define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
 
 /* Local Bluetooth Controller ID for BR/EDR */
-#define LOCAL_BR_EDR_CONTROLLER_ID      0
+#define LOCAL_BR_EDR_CONTROLLER_ID 0
 
 ///// END LEGACY DEFINITIONS /////
 
@@ -64,7 +64,7 @@ typedef struct packet_fragmenter_t packet_fragmenter_t;
 typedef struct vendor_t vendor_t;
 typedef struct low_power_manager_t low_power_manager_t;
 
-typedef unsigned char * bdaddr_t;
+typedef unsigned char* bdaddr_t;
 typedef uint16_t command_opcode_t;
 
 typedef enum {
@@ -74,46 +74,45 @@ typedef enum {
   LPM_WAKE_DEASSERT
 } low_power_command_t;
 
-typedef void (*command_complete_cb)(BT_HDR *response, void *context);
-typedef void (*command_status_cb)(uint8_t status, BT_HDR *command, void *context);
+typedef void (*command_complete_cb)(BT_HDR* response, void* context);
+typedef void (*command_status_cb)(uint8_t status, BT_HDR* command,
+                                  void* context);
 
 typedef struct hci_t {
-  // Send a low power command, if supported and the low power manager is enabled.
+  // Send a low power command, if supported and the low power manager is
+  // enabled.
   void (*send_low_power_command)(low_power_command_t command);
 
   // Do the postload sequence (call after the rest of the BT stack initializes).
   void (*do_postload)(void);
 
-  // Register with this data dispatcher to receive events flowing upward out of the HCI layer
-  data_dispatcher_t *event_dispatcher;
+  // Register with this data dispatcher to receive events flowing upward out of
+  // the HCI layer
+  data_dispatcher_t* event_dispatcher;
 
   // Set the queue to receive ACL data in
-  void (*set_data_queue)(fixed_queue_t *queue);
+  void (*set_data_queue)(fixed_queue_tqueue);
 
   // Send a command through the HCI layer
-  void (*transmit_command)(
-      BT_HDR *command,
-      command_complete_cb complete_callback,
-      command_status_cb status_cb,
-      void *context
-  );
+  void (*transmit_command)(BT_HDR* command,
+                           command_complete_cb complete_callback,
+                           command_status_cb status_cb, void* context);
 
-  future_t *(*transmit_command_futured)(BT_HDR *command);
+  future_t* (*transmit_command_futured)(BT_HDR* command);
 
   // Send some data downward through the HCI layer
-  void (*transmit_downward)(data_dispatcher_type_t type, void *data);
+  void (*transmit_downward)(data_dispatcher_type_t type, voiddata);
 } hci_t;
 
-const hci_t *hci_layer_get_interface();
+const hci_thci_layer_get_interface();
 
-const hci_t *hci_layer_get_test_interface(
-    const allocator_t *buffer_allocator_interface,
-    const hci_hal_t *hal_interface,
-    const btsnoop_t *btsnoop_interface,
-    const hci_inject_t *hci_inject_interface,
-    const packet_fragmenter_t *packet_fragmenter_interface,
-    const vendor_t *vendor_interface,
-    const low_power_manager_t *low_power_manager_interface);
+const hci_t* hci_layer_get_test_interface(
+    const allocator_t* buffer_allocator_interface,
+    const hci_hal_t* hal_interface, const btsnoop_t* btsnoop_interface,
+    const hci_inject_t* hci_inject_interface,
+    const packet_fragmenter_t* packet_fragmenter_interface,
+    const vendor_t* vendor_interface,
+    const low_power_manager_t* low_power_manager_interface);
 
 void hci_layer_cleanup_interface();
 
index d54922f..e2a5b7b 100644 (file)
@@ -26,28 +26,30 @@ extern "C" {
 #endif
 
 typedef struct {
-  BT_HDR *(*make_reset)(void);
-  BT_HDR *(*make_read_buffer_size)(void);
-  BT_HDR *(*make_host_buffer_size)(uint16_t acl_size, uint8_t sco_size, uint16_t acl_count, uint16_t sco_count);
-  BT_HDR *(*make_read_local_version_info)(void);
-  BT_HDR *(*make_read_bd_addr)(void);
-  BT_HDR *(*make_read_local_supported_commands)(void);
-  BT_HDR *(*make_read_local_extended_features)(uint8_t page_number);
-  BT_HDR *(*make_write_simple_pairing_mode)(uint8_t mode);
-  BT_HDR *(*make_write_secure_connections_host_support)(uint8_t mode);
-  BT_HDR *(*make_set_event_mask)(const bt_event_mask_t *event_mask);
-  BT_HDR *(*make_ble_write_host_support)(uint8_t supported_host, uint8_t simultaneous_host);
-  BT_HDR *(*make_ble_read_white_list_size)(void);
-  BT_HDR *(*make_ble_read_buffer_size)(void);
-  BT_HDR *(*make_ble_read_supported_states)(void);
-  BT_HDR *(*make_ble_read_local_supported_features)(void);
-  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);
+  BT_HDR* (*make_reset)(void);
+  BT_HDR* (*make_read_buffer_size)(void);
+  BT_HDR* (*make_host_buffer_size)(uint16_t acl_size, uint8_t sco_size,
+                                   uint16_t acl_count, uint16_t sco_count);
+  BT_HDR* (*make_read_local_version_info)(void);
+  BT_HDR* (*make_read_bd_addr)(void);
+  BT_HDR* (*make_read_local_supported_commands)(void);
+  BT_HDR* (*make_read_local_extended_features)(uint8_t page_number);
+  BT_HDR* (*make_write_simple_pairing_mode)(uint8_t mode);
+  BT_HDR* (*make_write_secure_connections_host_support)(uint8_t mode);
+  BT_HDR* (*make_set_event_mask)(const bt_event_mask_t* event_mask);
+  BT_HDR* (*make_ble_write_host_support)(uint8_t supported_host,
+                                         uint8_t simultaneous_host);
+  BT_HDR* (*make_ble_read_white_list_size)(void);
+  BT_HDR* (*make_ble_read_buffer_size)(void);
+  BT_HDR* (*make_ble_read_supported_states)(void);
+  BT_HDR* (*make_ble_read_local_supported_features)(void);
+  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();
+const hci_packet_factory_thci_packet_factory_get_interface();
 
 #ifdef __cplusplus
 }
index 7e84417..1604b91 100644 (file)
 
 #include <stdint.h>
 
-#include "osi/include/allocator.h"
 #include "bdaddr.h"
 #include "bt_types.h"
 #include "device_features.h"
 #include "features.h"
+#include "osi/include/allocator.h"
 #include "version.h"
 
 #ifdef __cplusplus
@@ -32,81 +32,56 @@ extern "C" {
 #endif
 
 typedef struct {
-  void (*parse_generic_command_complete)(BT_HDR *response);
+  void (*parse_generic_command_complete)(BT_HDRresponse);
 
-  void (*parse_read_buffer_size_response)(
-    BT_HDR *response,
-    uint16_t *data_size_ptr,
-    uint16_t *acl_buffer_count_ptr
-  );
+  void (*parse_read_buffer_size_response)(BT_HDR* response,
+                                          uint16_t* data_size_ptr,
+                                          uint16_t* acl_buffer_count_ptr);
 
-  void (*parse_read_local_version_info_response)(
-    BT_HDR *response,
-    bt_version_t *bt_version_ptr
-  );
+  void (*parse_read_local_version_info_response)(BT_HDR* response,
+                                                 bt_version_t* bt_version_ptr);
 
-  void (*parse_read_bd_addr_response)(
-    BT_HDR *response,
-    bt_bdaddr_t *address_ptr
-  );
+  void (*parse_read_bd_addr_response)(BT_HDR* response,
+                                      bt_bdaddr_t* address_ptr);
 
   void (*parse_read_local_supported_commands_response)(
-    BT_HDR *response,
-    uint8_t *supported_commands_ptr,
-    size_t supported_commands_length
-  );
+      BT_HDR* response, uint8_t* supported_commands_ptr,
+      size_t supported_commands_length);
 
   void (*parse_read_local_extended_features_response)(
-    BT_HDR *response,
-    uint8_t *page_number_ptr,
-    uint8_t *max_page_number_ptr,
-    bt_device_features_t *feature_pages,
-    size_t feature_pages_count
-  );
-
-  void (*parse_ble_read_white_list_size_response)(
-    BT_HDR *response,
-    uint8_t *white_list_size_ptr
-  );
-
-  void (*parse_ble_read_buffer_size_response)(
-    BT_HDR *response,
-    uint16_t *data_size_ptr,
-    uint8_t *acl_buffer_count_ptr
-  );
+      BT_HDR* response, uint8_t* page_number_ptr, uint8_t* max_page_number_ptr,
+      bt_device_features_t* feature_pages, size_t feature_pages_count);
+
+  void (*parse_ble_read_white_list_size_response)(BT_HDR* response,
+                                                  uint8_t* white_list_size_ptr);
+
+  void (*parse_ble_read_buffer_size_response)(BT_HDR* response,
+                                              uint16_t* data_size_ptr,
+                                              uint8_t* acl_buffer_count_ptr);
 
   void (*parse_ble_read_supported_states_response)(
-    BT_HDR *response,
-    uint8_t *supported_states,
-    size_t supported_states_size
-  );
+      BT_HDR* response, uint8_t* supported_states,
+      size_t supported_states_size);
 
   void (*parse_ble_read_local_supported_features_response)(
-    BT_HDR *response,
-    bt_device_features_t *supported_features
-  );
+      BT_HDR* response, bt_device_features_t* supported_features);
 
-  void (*parse_ble_read_resolving_list_size_response) (
-    BT_HDR *response,
-    uint8_t *resolving_list_size_ptr
-  );
+  void (*parse_ble_read_resolving_list_size_response)(
+      BT_HDR* response, uint8_t* resolving_list_size_ptr);
 
   void (*parse_ble_read_suggested_default_data_length_response)(
-    BT_HDR *response,
-    uint16_t *ble_default_packet_length_ptr
-  );
+      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);
+      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();
+const hci_packet_parser_thci_packet_parser_get_interface();
 
-const hci_packet_parser_t *hci_packet_parser_get_test_interface(
-  allocator_t *buffer_allocator_interface
-);
+const hci_packet_parser_t* hci_packet_parser_get_test_interface(
+    allocator_t* buffer_allocator_interface);
 
 #ifdef __cplusplus
 }
index d2d3a00..e9408bf 100644 (file)
@@ -28,8 +28,9 @@ typedef struct thread_t thread_t;
 typedef struct vendor_t vendor_t;
 
 typedef struct low_power_manager_t {
-  // Initialize the low power manager, and use |post_thread| to synchronize actions.
-  void (*init)(thread_t *post_thread);
+  // Initialize the low power manager, and use |post_thread| to synchronize
+  // actions.
+  void (*init)(thread_t* post_thread);
 
   // Clean up the low power manager and release resources.
   void (*cleanup)(void);
@@ -47,8 +48,9 @@ typedef struct low_power_manager_t {
   void (*transmit_done)(void);
 } low_power_manager_t;
 
-const low_power_manager_t *low_power_manager_get_interface();
-const low_power_manager_t *low_power_manager_get_test_interface(const vendor_t *vendor_interface);
+const low_power_manager_t* low_power_manager_get_interface();
+const low_power_manager_t* low_power_manager_get_test_interface(
+    const vendor_t* vendor_interface);
 
 #ifdef __cplusplus
 }
index 687ba8e..e072d4b 100644 (file)
 
 #pragma once
 
-#include "osi/include/allocator.h"
 #include "bt_types.h"
 #include "hci_layer.h"
+#include "osi/include/allocator.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef void (*transmit_finished_cb)(BT_HDR *packet, bool all_fragments_sent);
-typedef void (*packet_reassembled_cb)(BT_HDR *packet);
-typedef void (*packet_fragmented_cb)(BT_HDR *packet, bool send_transmit_finished);
+typedef void (*transmit_finished_cb)(BT_HDR* packet, bool all_fragments_sent);
+typedef void (*packet_reassembled_cb)(BT_HDR* packet);
+typedef void (*packet_fragmented_cb)(BT_HDR* packet,
+                                     bool send_transmit_finished);
 
 typedef struct {
   // Called for every packet fragment.
@@ -44,24 +45,27 @@ typedef struct {
 
 typedef struct packet_fragmenter_t {
   // Initialize the fragmenter, specifying the |result_callbacks|.
-  void (*init)(const packet_fragmenter_callbacks_t *result_callbacks);
+  void (*init)(const packet_fragmenter_callbacks_tresult_callbacks);
 
   // Release all resources associated with the fragmenter.
   void (*cleanup)(void);
 
-  // Fragments |packet| if necessary and hands off everything to the fragmented callback.
-  void (*fragment_and_dispatch)(BT_HDR *packet);
-  // If |packet| is a complete packet, forwards to the reassembled callback. Otherwise
-  // holds onto it until all fragments arrive, at which point the reassembled callback is called
+  // Fragments |packet| if necessary and hands off everything to the fragmented
+  // callback.
+  void (*fragment_and_dispatch)(BT_HDR* packet);
+  // If |packet| is a complete packet, forwards to the reassembled callback.
+  // Otherwise
+  // holds onto it until all fragments arrive, at which point the reassembled
+  // callback is called
   // with the reassembled data.
-  void (*reassemble_and_dispatch)(BT_HDR *packet);
+  void (*reassemble_and_dispatch)(BT_HDRpacket);
 } packet_fragmenter_t;
 
-const packet_fragmenter_t *packet_fragmenter_get_interface();
+const packet_fragmenter_tpacket_fragmenter_get_interface();
 
-const packet_fragmenter_t *packet_fragmenter_get_test_interface(
-    const controller_t *controller_interface,
-    const allocator_t *buffer_allocator_interface);
+const packet_fragmenter_tpacket_fragmenter_get_test_interface(
+    const controller_tcontroller_interface,
+    const allocator_tbuffer_allocator_interface);
 
 #ifdef __cplusplus
 }
index 3327db6..4aafc11 100644 (file)
@@ -49,8 +49,10 @@ typedef enum {
   USERIAL_PORT_18,
 } userial_port_t;
 
-// Initializes the userial module. This function should only ever be called once.
-// It returns true if the module could be initialized, false if there was an error.
+// Initializes the userial module. This function should only ever be called
+// once.
+// It returns true if the module could be initialized, false if there was an
+// error.
 bool userial_init(void);
 
 // Opens the given serial port. Returns true if successful, false otherwise.
@@ -67,12 +69,12 @@ void userial_close_reader(void);
 // Reads a maximum of |len| bytes from the serial port into |p_buffer|.
 // This function returns the number of bytes actually read, which may be
 // less than |len|. This function will not block.
-uint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len);
+uint16_t userial_read(uint16_t msg_id, uint8_tp_buffer, uint16_t len);
 
 // Writes a maximum of |len| bytes from |p_data| to the serial port.
 // This function returns the number of bytes actually written, which may be
 // less than |len|. This function may block.
-uint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len);
+uint16_t userial_write(uint16_t msg_id, const uint8_tp_data, uint16_t len);
 
 #ifdef __cplusplus
 }
index 3665566..1910263 100644 (file)
@@ -31,50 +31,47 @@ extern "C" {
 #endif
 
 typedef enum {
-  VENDOR_CHIP_POWER_CONTROL   = BT_VND_OP_POWER_CTRL,
-  VENDOR_OPEN_USERIAL         = BT_VND_OP_USERIAL_OPEN,
-  VENDOR_CLOSE_USERIAL        = BT_VND_OP_USERIAL_CLOSE,
+  VENDOR_CHIP_POWER_CONTROL = BT_VND_OP_POWER_CTRL,
+  VENDOR_OPEN_USERIAL = BT_VND_OP_USERIAL_OPEN,
+  VENDOR_CLOSE_USERIAL = BT_VND_OP_USERIAL_CLOSE,
   VENDOR_GET_LPM_IDLE_TIMEOUT = BT_VND_OP_GET_LPM_IDLE_TIMEOUT,
-  VENDOR_SET_LPM_WAKE_STATE   = BT_VND_OP_LPM_WAKE_SET_STATE,
-  VENDOR_SET_AUDIO_STATE      = BT_VND_OP_SET_AUDIO_STATE
+  VENDOR_SET_LPM_WAKE_STATE = BT_VND_OP_LPM_WAKE_SET_STATE,
+  VENDOR_SET_AUDIO_STATE = BT_VND_OP_SET_AUDIO_STATE
 } vendor_opcode_t;
 
 typedef enum {
-  VENDOR_CONFIGURE_FIRMWARE   = BT_VND_OP_FW_CFG,
-  VENDOR_CONFIGURE_SCO        = BT_VND_OP_SCO_CFG,
-  VENDOR_SET_LPM_MODE         = BT_VND_OP_LPM_SET_MODE,
-  VENDOR_DO_EPILOG            = BT_VND_OP_EPILOG,
-  VENDOR_A2DP_OFFLOAD_START   = BT_VND_OP_A2DP_OFFLOAD_START,
-  VENDOR_A2DP_OFFLOAD_STOP    = BT_VND_OP_A2DP_OFFLOAD_STOP,
+  VENDOR_CONFIGURE_FIRMWARE = BT_VND_OP_FW_CFG,
+  VENDOR_CONFIGURE_SCO = BT_VND_OP_SCO_CFG,
+  VENDOR_SET_LPM_MODE = BT_VND_OP_LPM_SET_MODE,
+  VENDOR_DO_EPILOG = BT_VND_OP_EPILOG,
+  VENDOR_A2DP_OFFLOAD_START = BT_VND_OP_A2DP_OFFLOAD_START,
+  VENDOR_A2DP_OFFLOAD_STOP = BT_VND_OP_A2DP_OFFLOAD_STOP,
   VENDOR_LAST_OP
 } vendor_async_opcode_t;
 
 typedef void (*vendor_cb)(bool success);
 
-typedef struct vendor_t{
+typedef struct vendor_t {
   // Opens the vendor-specific library and sets the Bluetooth
   // address of the adapter to |local_bdaddr|. |hci_interface| is
   // used to send commands on behalf of the vendor library.
-  bool (*open)(
-    const uint8_t *local_bdaddr,
-    const hci_t *hci_interface
-  );
+  bool (*open)(const uint8_t* local_bdaddr, const hci_t* hci_interface);
 
   // Closes the vendor-specific library and frees all associated resources.
   // Only |vendor_open| may be called after |vendor_close|.
   void (*close)(void);
 
   // Sends a vendor-specific command to the library.
-  int (*send_command)(vendor_opcode_t opcode, void *param);
+  int (*send_command)(vendor_opcode_t opcode, voidparam);
 
   // Sends an asynchronous vendor-specific command to the library.
-  int (*send_async_command)(vendor_async_opcode_t opcode, void *param);
+  int (*send_async_command)(vendor_async_opcode_t opcode, voidparam);
 
   // Registers a callback for an asynchronous vendor-specific command.
   void (*set_callback)(vendor_async_opcode_t opcode, vendor_cb callback);
 } vendor_t;
 
-const vendor_t *vendor_get_interface();
+const vendor_tvendor_get_interface();
 
 #ifdef __cplusplus
 }
index a38ec5b..db5fbcc 100644 (file)
@@ -50,7 +50,7 @@ typedef enum {
 // Epoch in microseconds since 01/01/0000.
 static const uint64_t BTSNOOP_EPOCH_DELTA = 0x00dcddb30f2f8000ULL;
 
-static const stack_config_t *stack_config;
+static const stack_config_tstack_config;
 
 static int logfile_fd = INVALID_FD;
 static bool module_started;
@@ -60,21 +60,22 @@ static bool logging_enabled_via_api;
 // TODO(zachoverflow): merge btsnoop and btsnoop_net together
 void btsnoop_net_open();
 void btsnoop_net_close();
-void btsnoop_net_write(const void *data, size_t length);
+void btsnoop_net_write(const voiddata, size_t length);
 
-static void btsnoop_write_packet(packet_type_t type, const uint8_t *packet, bool is_received);
+static void btsnoop_write_packet(packet_type_t type, const uint8_t* packet,
+                                 bool is_received);
 static void update_logging();
 
 // Module lifecycle functions
 
-static future_t *start_up(void) {
+static future_tstart_up(void) {
   module_started = true;
   update_logging();
 
   return NULL;
 }
 
-static future_t *shut_down(void) {
+static future_tshut_down(void) {
   module_started = false;
   update_logging();
 
@@ -82,16 +83,12 @@ static future_t *shut_down(void) {
 }
 
 EXPORT_SYMBOL extern const module_t btsnoop_module = {
-  .name = BTSNOOP_MODULE,
-  .init = NULL,
-  .start_up = start_up,
-  .shut_down = shut_down,
-  .clean_up = NULL,
-  .dependencies = {
-    STACK_CONFIG_MODULE,
-    NULL
-  }
-};
+    .name = BTSNOOP_MODULE,
+    .init = NULL,
+    .start_up = start_up,
+    .shut_down = shut_down,
+    .clean_up = NULL,
+    .dependencies = {STACK_CONFIG_MODULE, NULL}};
 
 // Interface functions
 
@@ -100,13 +97,12 @@ static void set_api_wants_to_log(bool value) {
   update_logging();
 }
 
-static void capture(const BT_HDR *buffer, bool is_received) {
-  const uint8_t *p = buffer->data + buffer->offset;
+static void capture(const BT_HDRbuffer, bool is_received) {
+  const uint8_tp = buffer->data + buffer->offset;
 
   btsnoop_mem_capture(buffer);
 
-  if (logfile_fd == INVALID_FD)
-    return;
+  if (logfile_fd == INVALID_FD) return;
 
   switch (buffer->event & MSG_EVT_MASK) {
     case MSG_HC_TO_STACK_HCI_EVT:
@@ -126,12 +122,9 @@ static void capture(const BT_HDR *buffer, bool is_received) {
   }
 }
 
-static const btsnoop_t interface = {
-  set_api_wants_to_log,
-  capture
-};
+static const btsnoop_t interface = {set_api_wants_to_log, capture};
 
-const btsnoop_t *btsnoop_get_interface() {
+const btsnoop_tbtsnoop_get_interface() {
   stack_config = stack_config_get_interface();
   return &interface;
 }
@@ -151,15 +144,14 @@ static uint64_t btsnoop_timestamp(void) {
 }
 
 static void update_logging() {
-  bool should_log = module_started &&
-    (logging_enabled_via_api || stack_config->get_btsnoop_turned_on());
+  bool should_log = module_started && (logging_enabled_via_api ||
+                                       stack_config->get_btsnoop_turned_on());
 
-  if (should_log == is_logging)
-    return;
+  if (should_log == is_logging) return;
 
   is_logging = should_log;
   if (should_log) {
-    const char *log_path = stack_config->get_btsnoop_log_path();
+    const charlog_path = stack_config->get_btsnoop_log_path();
 
     // Save the old log if configured to do so
     if (stack_config->get_btsnoop_should_save_last()) {
@@ -167,13 +159,16 @@ static void update_logging() {
       snprintf(last_log_path, PATH_MAX, "%s.%" PRIu64, log_path,
                btsnoop_timestamp());
       if (!rename(log_path, last_log_path) && errno != ENOENT)
-        LOG_ERROR(LOG_TAG, "%s unable to rename '%s' to '%s': %s", __func__, log_path, last_log_path, strerror(errno));
+        LOG_ERROR(LOG_TAG, "%s unable to rename '%s' to '%s': %s", __func__,
+                  log_path, last_log_path, strerror(errno));
     }
 
     mode_t prevmask = umask(0);
-    logfile_fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+    logfile_fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC,
+                      S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
     if (logfile_fd == INVALID_FD) {
-      LOG_ERROR(LOG_TAG, "%s unable to open '%s': %s", __func__, log_path, strerror(errno));
+      LOG_ERROR(LOG_TAG, "%s unable to open '%s': %s", __func__, log_path,
+                strerror(errno));
       is_logging = false;
       umask(prevmask);
       return;
@@ -183,22 +178,21 @@ static void update_logging() {
     write(logfile_fd, "btsnoop\0\0\0\0\1\0\0\x3\xea", 16);
     btsnoop_net_open();
   } else {
-    if (logfile_fd != INVALID_FD)
-      close(logfile_fd);
+    if (logfile_fd != INVALID_FD) close(logfile_fd);
 
     logfile_fd = INVALID_FD;
     btsnoop_net_close();
   }
 }
 
-static void btsnoop_write(const void *data, size_t length) {
-  if (logfile_fd != INVALID_FD)
-    write(logfile_fd, data, length);
+static void btsnoop_write(const void* data, size_t length) {
+  if (logfile_fd != INVALID_FD) write(logfile_fd, data, length);
 
   btsnoop_net_write(data, length);
 }
 
-static void btsnoop_write_packet(packet_type_t type, const uint8_t *packet, bool is_received) {
+static void btsnoop_write_packet(packet_type_t type, const uint8_t* packet,
+                                 bool is_received) {
   int length_he = 0;
   int length;
   int flags;
index 6b5d6c5..443dbb9 100644 (file)
 
 static btsnoop_data_cb data_callback = NULL;
 
-void btsnoop_mem_set_callback(btsnoop_data_cb cb) {
-  data_callback = cb;
-}
+void btsnoop_mem_set_callback(btsnoop_data_cb cb) { data_callback = cb; }
 
-void btsnoop_mem_capture(const BT_HDR *packet) {
-  if (!data_callback)
-    return;
+void btsnoop_mem_capture(const BT_HDR* packet) {
+  if (!data_callback) return;
 
   assert(packet);
 
-  const uint8_t *data = &packet->data[packet->offset];
+  const uint8_tdata = &packet->data[packet->offset];
   const uint16_t type = packet->event & BT_EVT_MASK;
   size_t length = 0;
 
   switch (type) {
     case BT_EVT_TO_LM_HCI_CMD:
-      if (packet->len > 2)
-        length = data[2] + 3;
+      if (packet->len > 2) length = data[2] + 3;
       break;
 
     case BT_EVT_TO_BTU_HCI_EVT:
-      if (packet->len > 1)
-        length = data[1] + 2;
+      if (packet->len > 1) length = data[1] + 2;
       break;
 
     case BT_EVT_TO_LM_HCI_ACL:
     case BT_EVT_TO_BTU_HCI_ACL:
-      if (packet->len > 3)
-        length = (data[2] | (data[3] << 8)) + 4;
+      if (packet->len > 3) length = (data[2] | (data[3] << 8)) + 4;
       break;
 
     case BT_EVT_TO_LM_HCI_SCO:
     case BT_EVT_TO_BTU_HCI_SCO:
-      if (packet->len > 2)
-        length = data[2] + 3;
+      if (packet->len > 2) length = data[2] + 3;
       break;
   }
 
-  if (length)
-    (*data_callback)(type, data, length);
+  if (length) (*data_callback)(type, data, length);
 }
index 26605c0..fa48980 100644 (file)
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
-static void safe_close_(int *fd);
-static void *listen_fn_(void *context);
+static void safe_close_(intfd);
+static void* listen_fn_(void* context);
 
-static const char *LISTEN_THREAD_NAME_ = "btsnoop_net_listen";
+static const charLISTEN_THREAD_NAME_ = "btsnoop_net_listen";
 static const int LOCALHOST_ = 0x7F000001;
 static const int LISTEN_PORT_ = 8872;
 
@@ -48,12 +48,14 @@ static int client_socket_ = -1;
 
 void btsnoop_net_open() {
 #if (BT_NET_DEBUG != TRUE)
-  return;               // Disable using network sockets for security reasons
+  return;  // Disable using network sockets for security reasons
 #endif
 
-  listen_thread_valid_ = (pthread_create(&listen_thread_, NULL, listen_fn_, NULL) == 0);
+  listen_thread_valid_ =
+      (pthread_create(&listen_thread_, NULL, listen_fn_, NULL) == 0);
   if (!listen_thread_valid_) {
-    LOG_ERROR(LOG_TAG, "%s pthread_create failed: %s", __func__, strerror(errno));
+    LOG_ERROR(LOG_TAG, "%s pthread_create failed: %s", __func__,
+              strerror(errno));
   } else {
     LOG_DEBUG(LOG_TAG, "initialized");
   }
@@ -61,7 +63,7 @@ void btsnoop_net_open() {
 
 void btsnoop_net_close() {
 #if (BT_NET_DEBUG != TRUE)
-  return;               // Disable using network sockets for security reasons
+  return;  // Disable using network sockets for security reasons
 #endif
 
   if (listen_thread_valid_) {
@@ -72,9 +74,9 @@ void btsnoop_net_close() {
   }
 }
 
-void btsnoop_net_write(const void *data, size_t length) {
+void btsnoop_net_write(const voiddata, size_t length) {
 #if (BT_NET_DEBUG != TRUE)
-  return;               // Disable using network sockets for security reasons
+  return;  // Disable using network sockets for security reasons
 #endif
 
   pthread_mutex_lock(&client_socket_lock_);
@@ -89,19 +91,22 @@ void btsnoop_net_write(const void *data, size_t length) {
   pthread_mutex_unlock(&client_socket_lock_);
 }
 
-static void *listen_fn_(UNUSED_ATTR void *context) {
+static void* listen_fn_(UNUSED_ATTR void* context) {
   int enable = 1;
 
   prctl(PR_SET_NAME, (unsigned long)LISTEN_THREAD_NAME_, 0, 0, 0);
 
   listen_socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   if (listen_socket_ == -1) {
-    LOG_ERROR(LOG_TAG, "%s socket creation failed: %s", __func__, strerror(errno));
+    LOG_ERROR(LOG_TAG, "%s socket creation failed: %s", __func__,
+              strerror(errno));
     goto cleanup;
   }
 
-  if (setsockopt(listen_socket_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) {
-    LOG_ERROR(LOG_TAG, "%s unable to set SO_REUSEADDR: %s", __func__, strerror(errno));
+  if (setsockopt(listen_socket_, SOL_SOCKET, SO_REUSEADDR, &enable,
+                 sizeof(enable)) == -1) {
+    LOG_ERROR(LOG_TAG, "%s unable to set SO_REUSEADDR: %s", __func__,
+              strerror(errno));
     goto cleanup;
   }
 
@@ -109,8 +114,9 @@ static void *listen_fn_(UNUSED_ATTR void *context) {
   addr.sin_family = AF_INET;
   addr.sin_addr.s_addr = htonl(LOCALHOST_);
   addr.sin_port = htons(LISTEN_PORT_);
-  if (bind(listen_socket_, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-    LOG_ERROR(LOG_TAG, "%s unable to bind listen socket: %s", __func__, strerror(errno));
+  if (bind(listen_socket_, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
+    LOG_ERROR(LOG_TAG, "%s unable to bind listen socket: %s", __func__,
+              strerror(errno));
     goto cleanup;
   }
 
@@ -126,11 +132,13 @@ static void *listen_fn_(UNUSED_ATTR void *context) {
       if (errno == EINVAL || errno == EBADF) {
         break;
       }
-      LOG_WARN(LOG_TAG, "%s error accepting socket: %s", __func__, strerror(errno));
+      LOG_WARN(LOG_TAG, "%s error accepting socket: %s", __func__,
+               strerror(errno));
       continue;
     }
 
-    /* When a new client connects, we have to send the btsnoop file header. This allows
+    /* When a new client connects, we have to send the btsnoop file header. This
+       allows
        a decoder to treat the session as a new, valid btsnoop file. */
     pthread_mutex_lock(&client_socket_lock_);
     safe_close_(&client_socket_);
@@ -145,7 +153,7 @@ cleanup:
   return NULL;
 }
 
-static void safe_close_(int *fd) {
+static void safe_close_(intfd) {
   assert(fd != NULL);
   if (*fd != -1) {
     close(*fd);
index e5e3504..3988fc9 100644 (file)
 
 #include <assert.h>
 
-#include "buffer_allocator.h"
 #include "bt_common.h"
+#include "buffer_allocator.h"
 
-static void *buffer_alloc(size_t size) {
+static voidbuffer_alloc(size_t size) {
   assert(size <= BT_DEFAULT_BUFFER_SIZE);
   return osi_malloc(size);
 }
 
-static const allocator_t interface = {
-  buffer_alloc,
-  osi_free
-};
+static const allocator_t interface = {buffer_alloc, osi_free};
 
-const allocator_t *buffer_allocator_get_interface() {
-  return &interface;
-}
+const allocator_t* buffer_allocator_get_interface() { return &interface; }
index ec126b8..1714063 100644 (file)
 #include "hci/include/vendor.h"
 #include "osi/include/log.h"
 
-void set_audio_state(uint16_t handle, sco_codec_t codec, sco_state_t state)
-{
-    LOG_INFO(LOG_TAG, "%s handle:%d codec:0x%x state:%d", __func__, handle, codec, state);
+void set_audio_state(uint16_t handle, sco_codec_t codec, sco_state_t state) {
+  LOG_INFO(LOG_TAG, "%s handle:%d codec:0x%x state:%d", __func__, handle, codec,
+           state);
 
-    bt_vendor_op_audio_state_t audio_state;
+  bt_vendor_op_audio_state_t audio_state;
 
-    audio_state.handle = handle;
-    audio_state.peer_codec = codec;
-    audio_state.state = state;
+  audio_state.handle = handle;
+  audio_state.peer_codec = codec;
+  audio_state.state = state;
 
-    vendor_get_interface()->send_command(VENDOR_SET_AUDIO_STATE, &audio_state);
+  vendor_get_interface()->send_command(VENDOR_SET_AUDIO_STATE, &audio_state);
 }
index 8550f7a..2e83050 100644 (file)
 
 #include "hci_hal.h"
 
-const hci_hal_t *hci_hal_get_interface() {
+const hci_hal_thci_hal_get_interface() {
 #if (HCI_USE_MCT == TRUE)
   return hci_hal_mct_get_interface();
 #else
   return hci_hal_h4_get_interface();
 #endif
 }
-
index 50b9265..ec1cf0f 100644 (file)
 
 #define BT_HCI_UNKNOWN_MESSAGE_TYPE_NUM 1010002
 
-static bool hal_init(const hci_hal_callbacks_t *upper_callbacks,
-                     thread_t *upper_thread);
+static bool hal_init(const hci_hal_callbacks_tupper_callbacks,
+                     thread_tupper_thread);
 static bool hal_open(void);
 static void hal_close(void);
 static void packet_finished(serial_data_type_t type);
-static uint16_t transmit_data(serial_data_type_t type, uint8_t *data,
+static uint16_t transmit_data(serial_data_type_t type, uint8_tdata,
                               uint16_t length);
-static size_t read_data(serial_data_type_t type, uint8_t *buffer,
+static size_t read_data(serial_data_type_t type, uint8_tbuffer,
                         size_t max_size);
-static void event_uart_has_bytes(eager_reader_t *reader, void *context);
+static void event_uart_has_bytes(eager_reader_t* reader, void* context);
 
 // Our interface and modules we import
 static const hci_hal_t interface = {
-  hal_init,
-  hal_open,
-  hal_close,
-  read_data,
-  packet_finished,
-  transmit_data,
+    hal_init, hal_open, hal_close, read_data, packet_finished, transmit_data,
 };
-static const hci_hal_callbacks_t *callbacks;
-static const vendor_t *vendor;
+static const hci_hal_callbacks_tcallbacks;
+static const vendor_tvendor;
 
-static thread_t *thread; // Not owned by us
+static thread_t* thread;  // Not owned by us
 
 static int uart_fd;
-static eager_reader_t *uart_stream;
+static eager_reader_tuart_stream;
 static serial_data_type_t current_data_type;
 static bool stream_has_interpretation;
 static bool stream_corruption_detected;
@@ -74,7 +69,8 @@ static uint8_t stream_corruption_bytes_to_ignore;
 
 // Interface functions
 
-static bool hal_init(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper_thread) {
+static bool hal_init(const hci_hal_callbacks_t* upper_callbacks,
+                     thread_t* upper_thread) {
   assert(upper_callbacks != NULL);
   assert(upper_thread != NULL);
 
@@ -85,13 +81,16 @@ static bool hal_init(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper
 
 static bool hal_open(void) {
   LOG_INFO(LOG_TAG, "%s", __func__);
-  // TODO(zachoverflow): close if already open / or don't reopen (maybe at the hci layer level)
+  // TODO(zachoverflow): close if already open / or don't reopen (maybe at the
+  // hci layer level)
 
   int fd_array[CH_MAX];
   int number_of_ports = vendor->send_command(VENDOR_OPEN_USERIAL, &fd_array);
 
   if (number_of_ports != 1) {
-    LOG_ERROR(LOG_TAG, "%s opened the wrong number of ports: got %d, expected 1.", __func__, number_of_ports);
+    LOG_ERROR(LOG_TAG,
+              "%s opened the wrong number of ports: got %d, expected 1.",
+              __func__, number_of_ports);
     goto error;
   }
 
@@ -101,20 +100,26 @@ static bool hal_open(void) {
     goto error;
   }
 
-  uart_stream = eager_reader_new(uart_fd, &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_single_channel");
+  uart_stream =
+      eager_reader_new(uart_fd, &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE,
+                       SIZE_MAX, "hci_single_channel");
   if (!uart_stream) {
-    LOG_ERROR(LOG_TAG, "%s unable to create eager reader for the uart serial port.", __func__);
+    LOG_ERROR(LOG_TAG,
+              "%s unable to create eager reader for the uart serial port.",
+              __func__);
     goto error;
   }
 
   stream_has_interpretation = false;
   stream_corruption_detected = false;
   stream_corruption_bytes_to_ignore = 0;
-  eager_reader_register(uart_stream, thread_get_reactor(thread), event_uart_has_bytes, NULL);
+  eager_reader_register(uart_stream, thread_get_reactor(thread),
+                        event_uart_has_bytes, NULL);
 
   // Raise thread priorities to keep up with audio
   thread_set_priority(thread, HCI_THREAD_PRIORITY);
-  thread_set_priority(eager_reader_get_read_thread(uart_stream), HCI_THREAD_PRIORITY);
+  thread_set_priority(eager_reader_get_read_thread(uart_stream),
+                      HCI_THREAD_PRIORITY);
 
   return true;
 
@@ -133,7 +138,8 @@ static void hal_close(void) {
   uart_fd = INVALID_FD;
 }
 
-static size_t read_data(serial_data_type_t type, uint8_t *buffer, size_t max_size) {
+static size_t read_data(serial_data_type_t type, uint8_t* buffer,
+                        size_t max_size) {
   if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) {
     LOG_ERROR(LOG_TAG, "%s invalid data type: %d", __func__, type);
     return 0;
@@ -141,7 +147,8 @@ static size_t read_data(serial_data_type_t type, uint8_t *buffer, size_t max_siz
     LOG_ERROR(LOG_TAG, "%s with no valid stream intepretation.", __func__);
     return 0;
   } else if (current_data_type != type) {
-    LOG_ERROR(LOG_TAG, "%s with different type than existing interpretation.", __func__);
+    LOG_ERROR(LOG_TAG, "%s with different type than existing interpretation.",
+              __func__);
     return 0;
   }
 
@@ -152,12 +159,14 @@ static void packet_finished(serial_data_type_t type) {
   if (!stream_has_interpretation)
     LOG_ERROR(LOG_TAG, "%s with no existing stream interpretation.", __func__);
   else if (current_data_type != type)
-    LOG_ERROR(LOG_TAG, "%s with different type than existing interpretation.", __func__);
+    LOG_ERROR(LOG_TAG, "%s with different type than existing interpretation.",
+              __func__);
 
   stream_has_interpretation = false;
 }
 
-static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t length) {
+static uint16_t transmit_data(serial_data_type_t type, uint8_t* data,
+                              uint16_t length) {
   assert(data != NULL);
   assert(length > 0);
 
@@ -178,10 +187,10 @@ static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t l
     OSI_NO_INTR(ret = write(uart_fd, data + transmitted_length, length));
     switch (ret) {
       case -1:
-        if (errno == EAGAIN)
-            continue;
+        if (errno == EAGAIN) continue;
 
-        LOG_ERROR(LOG_TAG, "In %s, error writing to the uart serial port: %s", __func__, strerror(errno));
+        LOG_ERROR(LOG_TAG, "In %s, error writing to the uart serial port: %s",
+                  __func__, strerror(errno));
         goto done;
       case 0:
         // If we wrote nothing, don't loop more because we
@@ -198,9 +207,9 @@ done:;
   // Be nice and restore the old value of that byte
   *(data) = previous_byte;
 
-  // Remove the signal byte from our transmitted length, if it was actually written
-  if (transmitted_length > 0)
-    --transmitted_length;
+  // Remove the signal byte from our transmitted length, if it was actually
+  // written
+  if (transmitted_length > 0) --transmitted_length;
 
   return transmitted_length;
 }
@@ -215,10 +224,11 @@ done:;
 // skip the correct amount of bytes in the stream to re-synchronize onto
 // a packet boundary.
 // Function returns true if |byte_read| has been processed by the workaround.
-static bool stream_corrupted_during_le_scan_workaround(const uint8_t byte_read)
-{
+static bool stream_corrupted_during_le_scan_workaround(
+    const uint8_t byte_read) {
   if (!stream_corruption_detected && byte_read == HCI_BLE_EVENT) {
-    LOG_ERROR(LOG_TAG, "%s HCI stream corrupted (message type 0x3E)!", __func__);
+    LOG_ERROR(LOG_TAG, "%s HCI stream corrupted (message type 0x3E)!",
+              __func__);
     stream_corruption_detected = true;
     return true;
   }
@@ -226,13 +236,15 @@ static bool stream_corrupted_during_le_scan_workaround(const uint8_t byte_read)
   if (stream_corruption_detected) {
     if (stream_corruption_bytes_to_ignore == 0) {
       stream_corruption_bytes_to_ignore = byte_read;
-      LOG_ERROR(LOG_TAG, "%s About to skip %d bytes...", __func__, stream_corruption_bytes_to_ignore);
+      LOG_ERROR(LOG_TAG, "%s About to skip %d bytes...", __func__,
+                stream_corruption_bytes_to_ignore);
     } else {
       --stream_corruption_bytes_to_ignore;
     }
 
     if (stream_corruption_bytes_to_ignore == 0) {
-      LOG_ERROR(LOG_TAG, "%s Back to our regularly scheduled program...", __func__);
+      LOG_ERROR(LOG_TAG, "%s Back to our regularly scheduled program...",
+                __func__);
       stream_corruption_detected = false;
     }
     return true;
@@ -242,7 +254,8 @@ static bool stream_corrupted_during_le_scan_workaround(const uint8_t byte_read)
 }
 
 // See what data is waiting, and notify the upper layer
-static void event_uart_has_bytes(eager_reader_t *reader, UNUSED_ATTR void *context) {
+static void event_uart_has_bytes(eager_reader_t* reader,
+                                 UNUSED_ATTR void* context) {
   if (stream_has_interpretation) {
     callbacks->data_ready(current_data_type);
   } else {
@@ -252,12 +265,13 @@ static void event_uart_has_bytes(eager_reader_t *reader, UNUSED_ATTR void *conte
       return;
     }
 
-    if (stream_corrupted_during_le_scan_workaround(type_byte))
-      return;
+    if (stream_corrupted_during_le_scan_workaround(type_byte)) return;
 
     if (type_byte < DATA_TYPE_ACL || type_byte > DATA_TYPE_EVENT) {
-      LOG_ERROR(LOG_TAG, "%s Unknown HCI message type 0x%x (min=0x%x max=0x%x). Aborting...",
-                __func__, type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT);
+      LOG_ERROR(
+          LOG_TAG,
+          "%s Unknown HCI message type 0x%x (min=0x%x max=0x%x). Aborting...",
+          __func__, type_byte, DATA_TYPE_ACL, DATA_TYPE_EVENT);
       LOG_EVENT_INT(BT_HCI_UNKNOWN_MESSAGE_TYPE_NUM, type_byte);
       assert(false && "Unknown HCI message type");
       return;
@@ -268,12 +282,12 @@ static void event_uart_has_bytes(eager_reader_t *reader, UNUSED_ATTR void *conte
   }
 }
 
-const hci_hal_t *hci_hal_h4_get_interface() {
+const hci_hal_thci_hal_h4_get_interface() {
   vendor = vendor_get_interface();
   return &interface;
 }
 
-const hci_hal_t *hci_hal_h4_get_test_interface(vendor_t *vendor_interface) {
+const hci_hal_t* hci_hal_h4_get_test_interface(vendor_t* vendor_interface) {
   vendor = vendor_interface;
   return &interface;
 }
index 3700e09..0e7db9c 100644 (file)
 
 #define HCI_HAL_SERIAL_BUFFER_SIZE 1026
 
-static bool hal_init(const hci_hal_callbacks_t *upper_callbacks,
-                     thread_t *upper_thread);
+static bool hal_init(const hci_hal_callbacks_tupper_callbacks,
+                     thread_tupper_thread);
 static bool hal_open(void);
 static void hal_close(void);
-static size_t read_data(serial_data_type_t type, uint8_t *buffer,
+static size_t read_data(serial_data_type_t type, uint8_tbuffer,
                         size_t max_size);
 static void packet_finished(UNUSED_ATTR serial_data_type_t type);
-static uint16_t transmit_data(serial_data_type_t type, uint8_t *data,
+static uint16_t transmit_data(serial_data_type_t type, uint8_tdata,
                               uint16_t length);
-static uint16_t transmit_data_on(int fd, uint8_t *data, uint16_t length);
-static void event_event_stream_has_bytes(eager_reader_t *reader, void *context);
-static void event_acl_stream_has_bytes(eager_reader_t *reader, void *context);
-
+static uint16_t transmit_data_on(int fd, uint8_t* data, uint16_t length);
+static void event_event_stream_has_bytes(eager_reader_t* reader, void* context);
+static void event_acl_stream_has_bytes(eager_reader_t* reader, void* context);
 
 // Our interface and modules we import
 static const hci_hal_t interface = {
-  hal_init,
-  hal_open,
-  hal_close,
-  read_data,
-  packet_finished,
-  transmit_data,
+    hal_init, hal_open, hal_close, read_data, packet_finished, transmit_data,
 };
-static const hci_hal_callbacks_t *callbacks;
-static const vendor_t *vendor;
+static const hci_hal_callbacks_tcallbacks;
+static const vendor_tvendor;
 
-static thread_t *thread; // Not owned by us
+static thread_t* thread;  // Not owned by us
 
 static int uart_fds[CH_MAX];
-static eager_reader_t *event_stream;
-static eager_reader_t *acl_stream;
+static eager_reader_tevent_stream;
+static eager_reader_tacl_stream;
 
 // Interface functions
 
-static bool hal_init(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper_thread) {
+static bool hal_init(const hci_hal_callbacks_t* upper_callbacks,
+                     thread_t* upper_thread) {
   assert(upper_callbacks != NULL);
   assert(upper_thread != NULL);
 
@@ -78,52 +73,72 @@ static bool hal_init(const hci_hal_callbacks_t *upper_callbacks, thread_t *upper
 
 static bool hal_open(void) {
   LOG_INFO(LOG_TAG, "%s", __func__);
-  // TODO(zachoverflow): close if already open / or don't reopen (maybe at the hci layer level)
+  // TODO(zachoverflow): close if already open / or don't reopen (maybe at the
+  // hci layer level)
 
   int number_of_ports = vendor->send_command(VENDOR_OPEN_USERIAL, &uart_fds);
 
   if (number_of_ports != 2 && number_of_ports != 4) {
-    LOG_ERROR(LOG_TAG, "%s opened the wrong number of ports: got %d, expected 2 or 4.", __func__, number_of_ports);
+    LOG_ERROR(LOG_TAG,
+              "%s opened the wrong number of ports: got %d, expected 2 or 4.",
+              __func__, number_of_ports);
     goto error;
   }
 
   LOG_INFO(LOG_TAG, "%s got uart fds: CMD=%d, EVT=%d, ACL_OUT=%d, ACL_IN=%d",
-      __func__, uart_fds[CH_CMD], uart_fds[CH_EVT], uart_fds[CH_ACL_OUT], uart_fds[CH_ACL_IN]);
+           __func__, uart_fds[CH_CMD], uart_fds[CH_EVT], uart_fds[CH_ACL_OUT],
+           uart_fds[CH_ACL_IN]);
 
   if (uart_fds[CH_CMD] == INVALID_FD) {
-    LOG_ERROR(LOG_TAG, "%s unable to open the command uart serial port.", __func__);
+    LOG_ERROR(LOG_TAG, "%s unable to open the command uart serial port.",
+              __func__);
     goto error;
   }
 
   if (uart_fds[CH_EVT] == INVALID_FD) {
-    LOG_ERROR(LOG_TAG, "%s unable to open the event uart serial port.", __func__);
+    LOG_ERROR(LOG_TAG, "%s unable to open the event uart serial port.",
+              __func__);
     goto error;
   }
 
   if (uart_fds[CH_ACL_OUT] == INVALID_FD) {
-    LOG_ERROR(LOG_TAG, "%s unable to open the acl-out uart serial port.", __func__);
+    LOG_ERROR(LOG_TAG, "%s unable to open the acl-out uart serial port.",
+              __func__);
     goto error;
   }
 
   if (uart_fds[CH_ACL_IN] == INVALID_FD) {
-    LOG_ERROR(LOG_TAG, "%s unable to open the acl-in uart serial port.", __func__);
+    LOG_ERROR(LOG_TAG, "%s unable to open the acl-in uart serial port.",
+              __func__);
     goto error;
   }
 
-  event_stream = eager_reader_new(uart_fds[CH_EVT], &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_mct");
+  event_stream =
+      eager_reader_new(uart_fds[CH_EVT], &allocator_malloc,
+                       HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_mct");
   if (!event_stream) {
-    LOG_ERROR(LOG_TAG, "%s unable to create eager reader for the event uart serial port.", __func__);
+    LOG_ERROR(
+        LOG_TAG,
+        "%s unable to create eager reader for the event uart serial port.",
+        __func__);
     goto error;
   }
 
-  acl_stream = eager_reader_new(uart_fds[CH_ACL_IN], &allocator_malloc, HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_mct");
+  acl_stream =
+      eager_reader_new(uart_fds[CH_ACL_IN], &allocator_malloc,
+                       HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX, "hci_mct");
   if (!acl_stream) {
-    LOG_ERROR(LOG_TAG, "%s unable to create eager reader for the acl-in uart serial port.", __func__);
+    LOG_ERROR(
+        LOG_TAG,
+        "%s unable to create eager reader for the acl-in uart serial port.",
+        __func__);
     goto error;
   }
 
-  eager_reader_register(event_stream, thread_get_reactor(thread), event_event_stream_has_bytes, NULL);
-  eager_reader_register(acl_stream, thread_get_reactor(thread), event_acl_stream_has_bytes, NULL);
+  eager_reader_register(event_stream, thread_get_reactor(thread),
+                        event_event_stream_has_bytes, NULL);
+  eager_reader_register(acl_stream, thread_get_reactor(thread),
+                        event_acl_stream_has_bytes, NULL);
 
   return true;
 
@@ -143,11 +158,11 @@ static void hal_close(void) {
 
   vendor->send_command(VENDOR_CLOSE_USERIAL, NULL);
 
-  for (int i = 0; i < CH_MAX; i++)
-    uart_fds[i] = INVALID_FD;
+  for (int i = 0; i < CH_MAX; i++) uart_fds[i] = INVALID_FD;
 }
 
-static size_t read_data(serial_data_type_t type, uint8_t *buffer, size_t max_size) {
+static size_t read_data(serial_data_type_t type, uint8_t* buffer,
+                        size_t max_size) {
   if (type == DATA_TYPE_ACL) {
     return eager_reader_read(acl_stream, buffer, max_size);
   } else if (type == DATA_TYPE_EVENT) {
@@ -162,7 +177,8 @@ static void packet_finished(UNUSED_ATTR serial_data_type_t type) {
   // not needed by this protocol
 }
 
-static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t length) {
+static uint16_t transmit_data(serial_data_type_t type, uint8_t* data,
+                              uint16_t length) {
   if (type == DATA_TYPE_ACL) {
     return transmit_data_on(uart_fds[CH_ACL_OUT], data, length);
   } else if (type == DATA_TYPE_COMMAND) {
@@ -175,7 +191,7 @@ static uint16_t transmit_data(serial_data_type_t type, uint8_t *data, uint16_t l
 
 // Internal functions
 
-static uint16_t transmit_data_on(int fd, uint8_t *data, uint16_t length) {
+static uint16_t transmit_data_on(int fd, uint8_tdata, uint16_t length) {
   assert(data != NULL);
   assert(length > 0);
 
@@ -185,7 +201,9 @@ static uint16_t transmit_data_on(int fd, uint8_t *data, uint16_t length) {
     OSI_NO_INTR(ret = write(fd, data + transmitted_length, length));
     switch (ret) {
       case -1:
-        LOG_ERROR(LOG_TAG, "In %s, error writing to the serial port with fd %d: %s", __func__, fd, strerror(errno));
+        LOG_ERROR(LOG_TAG,
+                  "In %s, error writing to the serial port with fd %d: %s",
+                  __func__, fd, strerror(errno));
         return transmitted_length;
       case 0:
         // If we wrote nothing, don't loop more because we
@@ -201,21 +219,23 @@ static uint16_t transmit_data_on(int fd, uint8_t *data, uint16_t length) {
   return transmitted_length;
 }
 
-static void event_event_stream_has_bytes(UNUSED_ATTR eager_reader_t *reader, UNUSED_ATTR void *context) {
+static void event_event_stream_has_bytes(UNUSED_ATTR eager_reader_t* reader,
+                                         UNUSED_ATTR void* context) {
   callbacks->data_ready(DATA_TYPE_EVENT);
 }
 
-static void event_acl_stream_has_bytes(UNUSED_ATTR eager_reader_t *reader, UNUSED_ATTR void *context) {
+static void event_acl_stream_has_bytes(UNUSED_ATTR eager_reader_t* reader,
+                                       UNUSED_ATTR void* context) {
   // No real concept of incoming SCO typed data, just ACL
   callbacks->data_ready(DATA_TYPE_ACL);
 }
 
-const hci_hal_t *hci_hal_mct_get_interface() {
+const hci_hal_thci_hal_mct_get_interface() {
   vendor = vendor_get_interface();
   return &interface;
 }
 
-const hci_hal_t *hci_hal_mct_get_test_interface(vendor_t *vendor_interface) {
+const hci_hal_t* hci_hal_mct_get_test_interface(vendor_t* vendor_interface) {
   vendor = vendor_interface;
   return &interface;
 }
index 2451646..9e4b875 100644 (file)
 #include "osi/include/thread.h"
 
 typedef enum {
-  HCI_PACKET_COMMAND  = 1,
+  HCI_PACKET_COMMAND = 1,
   HCI_PACKET_ACL_DATA = 2,
   HCI_PACKET_SCO_DATA = 3,
-  HCI_PACKET_EVENT    = 4,
+  HCI_PACKET_EVENT = 4,
 } hci_packet_t;
 
 typedef struct {
-  socket_t *socket;
+  socket_tsocket;
   uint8_t buffer[65536 + 3];  // 2 bytes length prefix, 1 byte type prefix.
   size_t buffer_size;
 } client_t;
 
-static bool hci_inject_open(const hci_t *hci_interface);
+static bool hci_inject_open(const hci_thci_interface);
 static void hci_inject_close(void);
 static int hci_packet_to_event(hci_packet_t packet);
-static void accept_ready(socket_t *socket, void *context);
-static void read_ready(socket_t *socket, void *context);
-static void client_free(void *ptr);
+static void accept_ready(socket_t* socket, void* context);
+static void read_ready(socket_t* socket, void* context);
+static void client_free(voidptr);
 
 static const port_t LISTEN_PORT = 8873;
 
-static const hci_inject_t interface = {
-  hci_inject_open,
-  hci_inject_close
-};
+static const hci_inject_t interface = {hci_inject_open, hci_inject_close};
 
-static const hci_t *hci;
-static const allocator_t *buffer_allocator;
-static socket_t *listen_socket;
-static thread_t *thread;
-static list_t *clients;
+static const hci_thci;
+static const allocator_tbuffer_allocator;
+static socket_tlisten_socket;
+static thread_tthread;
+static list_tclients;
 
-static bool hci_inject_open(const hci_t *hci_interface) {
+static bool hci_inject_open(const hci_thci_interface) {
 #if (BT_NET_DEBUG != TRUE)
-  return true;          // Disable using network sockets for security reasons
+  return true;  // Disable using network sockets for security reasons
 #endif
 
   assert(listen_socket == NULL);
@@ -80,21 +77,18 @@ static bool hci_inject_open(const hci_t *hci_interface) {
   hci = hci_interface;
 
   thread = thread_new("hci_inject");
-  if (!thread)
-    goto error;
+  if (!thread) goto error;
 
   clients = list_new(client_free);
-  if (!clients)
-    goto error;
+  if (!clients) goto error;
 
   listen_socket = socket_new();
-  if (!listen_socket)
-    goto error;
+  if (!listen_socket) goto error;
 
-  if (!socket_listen(listen_socket, LISTEN_PORT))
-    goto error;
+  if (!socket_listen(listen_socket, LISTEN_PORT)) goto error;
 
-  socket_register(listen_socket, thread_get_reactor(thread), NULL, accept_ready, NULL);
+  socket_register(listen_socket, thread_get_reactor(thread), NULL, accept_ready,
+                  NULL);
   return true;
 
 error:;
@@ -104,7 +98,7 @@ error:;
 
 static void hci_inject_close(void) {
 #if (BT_NET_DEBUG != TRUE)
-  return;               // Disable using network sockets for security reasons
+  return;  // Disable using network sockets for security reasons
 #endif
 
   socket_free(listen_socket);
@@ -130,15 +124,14 @@ static int hci_packet_to_event(hci_packet_t packet) {
   }
 }
 
-static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) {
+static void accept_ready(socket_t* socket, UNUSED_ATTR void* context) {
   assert(socket != NULL);
   assert(socket == listen_socket);
 
   socket = socket_accept(socket);
-  if (!socket)
-    return;
+  if (!socket) return;
 
-  client_t *client = (client_t *)osi_calloc(sizeof(client_t));
+  client_t* client = (client_t*)osi_calloc(sizeof(client_t));
 
   client->socket = socket;
 
@@ -151,13 +144,15 @@ static void accept_ready(socket_t *socket, UNUSED_ATTR void *context) {
   socket_register(socket, thread_get_reactor(thread), client, read_ready, NULL);
 }
 
-static void read_ready(UNUSED_ATTR socket_t *socket, void *context) {
+static void read_ready(UNUSED_ATTR socket_t* socket, void* context) {
   assert(socket != NULL);
   assert(context != NULL);
 
-  client_t *client = (client_t *)context;
+  client_t* client = (client_t*)context;
 
-  ssize_t ret = socket_read(client->socket, client->buffer + client->buffer_size, sizeof(client->buffer) - client->buffer_size);
+  ssize_t ret =
+      socket_read(client->socket, client->buffer + client->buffer_size,
+                  sizeof(client->buffer) - client->buffer_size);
   if (ret == 0 || (ret == -1 && ret != EWOULDBLOCK && ret != EAGAIN)) {
     list_remove(clients, client);
     return;
@@ -165,19 +160,18 @@ static void read_ready(UNUSED_ATTR socket_t *socket, void *context) {
   client->buffer_size += ret;
 
   while (client->buffer_size > 3) {
-    uint8_t *buffer = client->buffer;
+    uint8_tbuffer = client->buffer;
     hci_packet_t packet_type = (hci_packet_t)buffer[0];
     size_t packet_len = (buffer[2] << 8) | buffer[1];
     size_t frame_len = 3 + packet_len;
 
-    if (client->buffer_size < frame_len)
-      break;
+    if (client->buffer_size < frame_len) break;
 
     // TODO(sharvil): validate incoming HCI messages.
     // TODO(sharvil): once we have an HCI parser, we can eliminate
     //   the 2-byte size field since it will be contained in the packet.
 
-    BT_HDR *buf = (BT_HDR *)buffer_allocator->alloc(BT_HDR_SIZE + packet_len);
+    BT_HDR* buf = (BT_HDR*)buffer_allocator->alloc(BT_HDR_SIZE + packet_len);
     if (buf) {
       buf->event = hci_packet_to_event(packet_type);
       buf->offset = 0;
@@ -186,7 +180,8 @@ static void read_ready(UNUSED_ATTR socket_t *socket, void *context) {
       memcpy(buf->data, buffer + 3, packet_len);
       hci->transmit_downward(buf->event, buf);
     } else {
-      LOG_ERROR(LOG_TAG, "%s dropping injected packet of length %zu", __func__, packet_len);
+      LOG_ERROR(LOG_TAG, "%s dropping injected packet of length %zu", __func__,
+                packet_len);
     }
 
     size_t remainder = client->buffer_size - frame_len;
@@ -195,16 +190,15 @@ static void read_ready(UNUSED_ATTR socket_t *socket, void *context) {
   }
 }
 
-static void client_free(void *ptr) {
-  if (!ptr)
-    return;
+static void client_free(void* ptr) {
+  if (!ptr) return;
 
-  client_t *client = (client_t *)ptr;
+  client_t* client = (client_t*)ptr;
   socket_free(client->socket);
   osi_free(client);
 }
 
-const hci_inject_t *hci_inject_get_interface() {
+const hci_inject_thci_inject_get_interface() {
   buffer_allocator = buffer_allocator_get_interface();
   return &interface;
 }
index 0cd351f..485659e 100644 (file)
 extern bt_bdaddr_t btif_local_bd_addr;
 
 #define INBOUND_PACKET_TYPE_COUNT 3
-#define PACKET_TYPE_TO_INBOUND_INDEX(type) ((type) - 2)
-#define PACKET_TYPE_TO_INDEX(type) ((type) - 1)
+#define PACKET_TYPE_TO_INBOUND_INDEX(type) ((type)-2)
+#define PACKET_TYPE_TO_INDEX(type) ((type)-1)
 
-#define PREAMBLE_BUFFER_SIZE 4 // max preamble size, ACL
+#define PREAMBLE_BUFFER_SIZE 4  // max preamble size, ACL
 #define RETRIEVE_ACL_LENGTH(preamble) ((((preamble)[3]) << 8) | (preamble)[2])
 
 #define BT_HCI_TIMEOUT_TAG_NUM 1010000
 
 static const uint8_t preamble_sizes[] = {
-  HCI_COMMAND_PREAMBLE_SIZE,
-  HCI_ACL_PREAMBLE_SIZE,
-  HCI_SCO_PREAMBLE_SIZE,
-  HCI_EVENT_PREAMBLE_SIZE
-};
-
-static const uint16_t outbound_event_types[] =
-{
-  MSG_HC_TO_STACK_HCI_ERR,
-  MSG_HC_TO_STACK_HCI_ACL,
-  MSG_HC_TO_STACK_HCI_SCO,
-  MSG_HC_TO_STACK_HCI_EVT
-};
-
-typedef enum {
-  BRAND_NEW,
-  PREAMBLE,
-  BODY,
-  IGNORE,
-  FINISHED
-} receive_state_t;
+    HCI_COMMAND_PREAMBLE_SIZE, HCI_ACL_PREAMBLE_SIZE, HCI_SCO_PREAMBLE_SIZE,
+    HCI_EVENT_PREAMBLE_SIZE};
+
+static const uint16_t outbound_event_types[] = {
+    MSG_HC_TO_STACK_HCI_ERR, MSG_HC_TO_STACK_HCI_ACL, MSG_HC_TO_STACK_HCI_SCO,
+    MSG_HC_TO_STACK_HCI_EVT};
+
+typedef enum { BRAND_NEW, PREAMBLE, BODY, IGNORE, FINISHED } receive_state_t;
 
 typedef struct {
   receive_state_t state;
   uint16_t bytes_remaining;
   uint8_t preamble[PREAMBLE_BUFFER_SIZE];
   uint16_t index;
-  BT_HDR *buffer;
+  BT_HDRbuffer;
 } packet_receive_data_t;
 
 typedef struct {
   uint16_t opcode;
-  future_t *complete_future;
+  future_tcomplete_future;
   command_complete_cb complete_callback;
   command_status_cb status_callback;
-  void *context;
-  BT_HDR *command;
+  voidcontext;
+  BT_HDRcommand;
 } waiting_command_t;
 
 // Using a define here, because it can be stringified for the property lookup
@@ -105,89 +92,84 @@ typedef struct {
 static const uint32_t EPILOG_TIMEOUT_MS = 3000;
 static const uint32_t COMMAND_PENDING_TIMEOUT_MS = 8000;
 
-static future_t *shut_down();
+static future_tshut_down();
 
-static void event_finish_startup(void *context);
+static void event_finish_startup(voidcontext);
 static void firmware_config_callback(bool success);
-static void startup_timer_expired(void *context);
+static void startup_timer_expired(voidcontext);
 
-static void event_postload(void *context);
+static void event_postload(voidcontext);
 static void sco_config_callback(bool success);
 
-static void event_epilog(void *context);
+static void event_epilog(voidcontext);
 static void epilog_finished_callback(bool success);
-static void epilog_timer_expired(void *context);
+static void epilog_timer_expired(voidcontext);
 
-static void event_command_ready(fixed_queue_t *queue, void *context);
-static void event_packet_ready(fixed_queue_t *queue, void *context);
-static void transmit_fragment(BT_HDR *packet, bool send_transmit_finished);
-static void fragmenter_transmit_finished(BT_HDR *packet,
+static void event_command_ready(fixed_queue_t* queue, void* context);
+static void event_packet_ready(fixed_queue_t* queue, void* context);
+static void transmit_fragment(BT_HDRpacket, bool send_transmit_finished);
+static void fragmenter_transmit_finished(BT_HDRpacket,
                                          bool all_fragments_sent);
-static void dispatch_reassembled(BT_HDR *packet);
-static void command_timed_out(void *context);
+static void dispatch_reassembled(BT_HDRpacket);
+static void command_timed_out(voidcontext);
 
 static void hal_says_data_ready(serial_data_type_t type);
-static bool filter_incoming_event(BT_HDR *packet);
+static bool filter_incoming_event(BT_HDRpacket);
 
 static serial_data_type_t event_to_data_type(uint16_t event);
-static waiting_command_t *get_waiting_command(command_opcode_t opcode);
+static waiting_command_tget_waiting_command(command_opcode_t opcode);
 static void update_command_response_timer(void);
 
-
 // Our interface
-static const hci_hal_callbacks_t hal_callbacks = {
-  hal_says_data_ready
-};
+static const hci_hal_callbacks_t hal_callbacks = {hal_says_data_ready};
 
 static const packet_fragmenter_callbacks_t packet_fragmenter_callbacks = {
-  transmit_fragment,
-  dispatch_reassembled,
-  fragmenter_transmit_finished
-};
+    transmit_fragment, dispatch_reassembled, fragmenter_transmit_finished};
 static bool interface_created;
 static hci_t interface;
 
 // Modules we import and callbacks we export
-static const allocator_t *buffer_allocator;
-static const btsnoop_t *btsnoop;
-static const hci_hal_t *hal;
-static const hci_inject_t *hci_inject;
-static const low_power_manager_t *low_power_manager;
-static const packet_fragmenter_t *packet_fragmenter;
-static const vendor_t *vendor;
+static const allocator_tbuffer_allocator;
+static const btsnoop_tbtsnoop;
+static const hci_hal_thal;
+static const hci_inject_thci_inject;
+static const low_power_manager_tlow_power_manager;
+static const packet_fragmenter_tpacket_fragmenter;
+static const vendor_tvendor;
 
-static future_t *startup_future;
-static thread_t *thread; // We own this
+static future_tstartup_future;
+static thread_t* thread;  // We own this
 
 static volatile bool firmware_is_configured = false;
-static alarm_t *epilog_timer;
-static alarm_t *startup_timer;
+static alarm_tepilog_timer;
+static alarm_tstartup_timer;
 
 // Outbound-related
 static int command_credits = 1;
-static fixed_queue_t *command_queue;
-static fixed_queue_t *packet_queue;
+static fixed_queue_tcommand_queue;
+static fixed_queue_tpacket_queue;
 
 // Inbound-related
-static alarm_t *command_response_timer;
-static list_t *commands_pending_response;
+static alarm_tcommand_response_timer;
+static list_tcommands_pending_response;
 static pthread_mutex_t commands_pending_response_lock;
 static packet_receive_data_t incoming_packets[INBOUND_PACKET_TYPE_COUNT];
 
 // The hand-off point for data going to a higher layer, set by the higher layer
-static fixed_queue_t *upwards_data_queue;
+static fixed_queue_tupwards_data_queue;
 
 // Module lifecycle functions
 
-static future_t *start_up(void) {
+static future_tstart_up(void) {
   int power_state = BT_VND_PWR_OFF;
-  future_t *local_startup_future;
+  future_tlocal_startup_future;
 
   LOG_INFO(LOG_TAG, "%s", __func__);
 
   // 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.
+  // This value can change when you get a command complete or command status
+  // event.
   command_credits = 1;
   firmware_is_configured = false;
 
@@ -198,8 +180,9 @@ static future_t *start_up(void) {
 
   // Grab the override startup timeout ms, if present.
   char timeout_prop[PROPERTY_VALUE_MAX];
-  if (!osi_property_get("bluetooth.enable_timeout_ms", timeout_prop, STRING_VALUE_OF(DEFAULT_STARTUP_TIMEOUT_MS))
-      || (startup_timeout_ms = atoi(timeout_prop)) < 100)
+  if (!osi_property_get("bluetooth.enable_timeout_ms", timeout_prop,
+                        STRING_VALUE_OF(DEFAULT_STARTUP_TIMEOUT_MS)) ||
+      (startup_timeout_ms = atoi(timeout_prop)) < 100)
     startup_timeout_ms = DEFAULT_STARTUP_TIMEOUT_MS;
 
   startup_timer = alarm_new("hci.startup_timer");
@@ -240,7 +223,9 @@ static future_t *start_up(void) {
 
   commands_pending_response = list_new(NULL);
   if (!commands_pending_response) {
-    LOG_ERROR(LOG_TAG, "%s unable to create list for commands pending response.", __func__);
+    LOG_ERROR(LOG_TAG,
+              "%s unable to create list for commands pending response.",
+              __func__);
     goto error;
   }
 
@@ -253,8 +238,10 @@ static future_t *start_up(void) {
 
   packet_fragmenter->init(&packet_fragmenter_callbacks);
 
-  fixed_queue_register_dequeue(command_queue, thread_get_reactor(thread), event_command_ready, NULL);
-  fixed_queue_register_dequeue(packet_queue, thread_get_reactor(thread), event_packet_ready, NULL);
+  fixed_queue_register_dequeue(command_queue, thread_get_reactor(thread),
+                               event_command_ready, NULL);
+  fixed_queue_register_dequeue(packet_queue, thread_get_reactor(thread),
+                               event_packet_ready, NULL);
 
   vendor->open(btif_local_bd_addr.address, &interface);
   hal->init(&hal_callbacks, thread);
@@ -270,12 +257,13 @@ static future_t *start_up(void) {
 
 #if (BT_CLEAN_TURN_ON_DISABLED == TRUE)
   LOG_WARN(LOG_TAG, "%s not turning off the chip before turning on.", __func__);
-  // So apparently this hack was needed in the past because a Wingray kernel driver
-  // didn't handle power off commands in a powered off state correctly.
+// So apparently this hack was needed in the past because a Wingray kernel
+// driver
+// didn't handle power off commands in a powered off state correctly.
 
-  // The comment in the old code said the workaround should be removed when the
-  // problem was fixed. Sadly, I have no idea if said bug was fixed or if said
-  // kernel is still in use, so we must leave this here for posterity. #sadpanda
+// The comment in the old code said the workaround should be removed when the
+// problem was fixed. Sadly, I have no idea if said bug was fixed or if said
+// kernel is still in use, so we must leave this here for posterity. #sadpanda
 #else
   // cycle power on the chip to ensure it has been reset
   vendor->send_command(VENDOR_CHIP_POWER_CONTROL, &power_state);
@@ -288,11 +276,11 @@ static future_t *start_up(void) {
   return local_startup_future;
 
 error:
-  shut_down(); // returns NULL so no need to wait for it
+  shut_down();  // returns NULL so no need to wait for it
   return future_new_immediate(FUTURE_FAIL);
 }
 
-static future_t *shut_down() {
+static future_tshut_down() {
   LOG_INFO(LOG_TAG, "%s", __func__);
 
   hci_inject->close();
@@ -343,16 +331,12 @@ static future_t *shut_down() {
 }
 
 EXPORT_SYMBOL extern const module_t hci_module = {
-  .name = HCI_MODULE,
-  .init = NULL,
-  .start_up = start_up,
-  .shut_down = shut_down,
-  .clean_up = NULL,
-  .dependencies = {
-    BTSNOOP_MODULE,
-    NULL
-  }
-};
+    .name = HCI_MODULE,
+    .init = NULL,
+    .start_up = start_up,
+    .shut_down = shut_down,
+    .clean_up = NULL,
+    .dependencies = {BTSNOOP_MODULE, NULL}};
 
 // Interface functions
 
@@ -361,19 +345,15 @@ static void do_postload() {
   thread_post(thread, event_postload, NULL);
 }
 
-static void set_data_queue(fixed_queue_t *queue) {
-  upwards_data_queue = queue;
-}
+static void set_data_queue(fixed_queue_t* queue) { upwards_data_queue = queue; }
 
-static void transmit_command(
-    BT_HDR *command,
-    command_complete_cb complete_callback,
-    command_status_cb status_callback,
-    void *context) {
-  waiting_command_t *wait_entry =
-      static_cast<waiting_command_t *>(osi_calloc(sizeof(waiting_command_t)));
+static void transmit_command(BT_HDR* command,
+                             command_complete_cb complete_callback,
+                             command_status_cb status_callback, void* context) {
+  waiting_command_t* wait_entry =
+      static_cast<waiting_command_t*>(osi_calloc(sizeof(waiting_command_t)));
 
-  uint8_t *stream = command->data + command->offset;
+  uint8_tstream = command->data + command->offset;
   STREAM_TO_UINT16(wait_entry->opcode, stream);
   wait_entry->complete_callback = complete_callback;
   wait_entry->status_callback = status_callback;
@@ -387,12 +367,12 @@ static void transmit_command(
   fixed_queue_enqueue(command_queue, wait_entry);
 }
 
-static future_t *transmit_command_futured(BT_HDR *command) {
-  waiting_command_t *wait_entry =
-      static_cast<waiting_command_t *>(osi_calloc(sizeof(waiting_command_t)));
-  future_t *future = future_new();
+static future_t* transmit_command_futured(BT_HDR* command) {
+  waiting_command_twait_entry =
+      static_cast<waiting_command_t*>(osi_calloc(sizeof(waiting_command_t)));
+  future_tfuture = future_new();
 
-  uint8_t *stream = command->data + command->offset;
+  uint8_tstream = command->data + command->offset;
   STREAM_TO_UINT16(wait_entry->opcode, stream);
   wait_entry->complete_future = future;
   wait_entry->command = command;
@@ -405,11 +385,13 @@ static future_t *transmit_command_futured(BT_HDR *command) {
   return future;
 }
 
-static void transmit_downward(data_dispatcher_type_t type, void *data) {
+static void transmit_downward(data_dispatcher_type_t type, voiddata) {
   if (type == MSG_STACK_TO_HC_HCI_CMD) {
     // TODO(zachoverflow): eliminate this call
-    transmit_command((BT_HDR *)data, NULL, NULL, NULL);
-    LOG_WARN(LOG_TAG, "%s legacy transmit of command. Use transmit_command instead.", __func__);
+    transmit_command((BT_HDR*)data, NULL, NULL, NULL);
+    LOG_WARN(LOG_TAG,
+             "%s legacy transmit of command. Use transmit_command instead.",
+             __func__);
   } else {
     fixed_queue_enqueue(packet_queue, data);
   }
@@ -417,7 +399,7 @@ static void transmit_downward(data_dispatcher_type_t type, void *data) {
 
 // Start up functions
 
-static void event_finish_startup(UNUSED_ATTR void *context) {
+static void event_finish_startup(UNUSED_ATTR voidcontext) {
   LOG_INFO(LOG_TAG, "%s", __func__);
   hal->open();
   vendor->send_async_command(VENDOR_CONFIGURE_FIRMWARE, NULL);
@@ -442,7 +424,7 @@ static void firmware_config_callback(bool success) {
   pthread_mutex_unlock(&commands_pending_response_lock);
 }
 
-static void startup_timer_expired(UNUSED_ATTR void *context) {
+static void startup_timer_expired(UNUSED_ATTR voidcontext) {
   LOG_ERROR(LOG_TAG, "%s", __func__);
 
   pthread_mutex_lock(&commands_pending_response_lock);
@@ -453,13 +435,12 @@ static void startup_timer_expired(UNUSED_ATTR void *context) {
 
 // Postload functions
 
-static void event_postload(UNUSED_ATTR void *context) {
+static void event_postload(UNUSED_ATTR voidcontext) {
   LOG_INFO(LOG_TAG, "%s", __func__);
-  if(vendor->send_async_command(VENDOR_CONFIGURE_SCO, NULL) == -1) {
+  if (vendor->send_async_command(VENDOR_CONFIGURE_SCO, NULL) == -1) {
     // If couldn't configure sco, we won't get the sco configuration callback
     // so go pretend to do it now
     sco_config_callback(false);
-
   }
 }
 
@@ -469,7 +450,7 @@ static void sco_config_callback(UNUSED_ATTR bool success) {
 
 // Epilog functions
 
-static void event_epilog(UNUSED_ATTR void *context) {
+static void event_epilog(UNUSED_ATTR voidcontext) {
   vendor->send_async_command(VENDOR_DO_EPILOG, NULL);
 }
 
@@ -479,17 +460,18 @@ static void epilog_finished_callback(UNUSED_ATTR bool success) {
   thread_stop(thread);
 }
 
-static void epilog_timer_expired(UNUSED_ATTR void *context) {
+static void epilog_timer_expired(UNUSED_ATTR voidcontext) {
   LOG_INFO(LOG_TAG, "%s", __func__);
   thread_stop(thread);
 }
 
 // Command/packet transmitting functions
 
-static void event_command_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
+static void event_command_ready(fixed_queue_t* queue,
+                                UNUSED_ATTR void* context) {
   if (command_credits > 0) {
-    waiting_command_t *wait_entry =
-        static_cast<waiting_command_t *>(fixed_queue_dequeue(queue));
+    waiting_command_twait_entry =
+        static_cast<waiting_command_t*>(fixed_queue_dequeue(queue));
     command_credits--;
 
     // Move it to the list of commands awaiting response
@@ -506,9 +488,10 @@ static void event_command_ready(fixed_queue_t *queue, UNUSED_ATTR void *context)
   }
 }
 
-static void event_packet_ready(fixed_queue_t *queue, UNUSED_ATTR void *context) {
+static void event_packet_ready(fixed_queue_t* queue,
+                               UNUSED_ATTR void* context) {
   // The queue may be the command queue or the packet queue, we don't care
-  BT_HDR *packet = (BT_HDR *)fixed_queue_dequeue(queue);
+  BT_HDR* packet = (BT_HDR*)fixed_queue_dequeue(queue);
 
   low_power_manager->wake_assert();
   packet_fragmenter->fragment_and_dispatch(packet);
@@ -516,7 +499,7 @@ static void event_packet_ready(fixed_queue_t *queue, UNUSED_ATTR void *context)
 }
 
 // Callback for the fragmenter to send a fragment
-static void transmit_fragment(BT_HDR *packet, bool send_transmit_finished) {
+static void transmit_fragment(BT_HDRpacket, bool send_transmit_finished) {
   uint16_t event = packet->event & MSG_EVT_MASK;
   serial_data_type_t type = event_to_data_type(event);
 
@@ -527,30 +510,36 @@ static void transmit_fragment(BT_HDR *packet, bool send_transmit_finished) {
     buffer_allocator->free(packet);
 }
 
-static void fragmenter_transmit_finished(BT_HDR *packet, bool all_fragments_sent) {
+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
+    // 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.
-    data_dispatcher_dispatch(interface.event_dispatcher, packet->event & MSG_EVT_MASK, packet);
+    data_dispatcher_dispatch(interface.event_dispatcher,
+                             packet->event & MSG_EVT_MASK, packet);
   }
 }
 
-static void command_timed_out(UNUSED_ATTR void *context) {
+static void command_timed_out(UNUSED_ATTR voidcontext) {
   pthread_mutex_lock(&commands_pending_response_lock);
 
   if (list_is_empty(commands_pending_response)) {
     LOG_ERROR(LOG_TAG, "%s with no commands pending response", __func__);
   } else {
-    waiting_command_t *wait_entry =
-        static_cast<waiting_command_t *>(list_front(commands_pending_response));
+    waiting_command_twait_entry =
+        static_cast<waiting_command_t*>(list_front(commands_pending_response));
     pthread_mutex_unlock(&commands_pending_response_lock);
 
     // We shouldn't try to recover the stack from this command timeout.
     // If it's caused by a software bug, fix it. If it's a hardware bug, fix it.
-    LOG_ERROR(LOG_TAG, "%s hci layer timeout waiting for response to a command. opcode: 0x%x", __func__, wait_entry->opcode);
+    LOG_ERROR(
+        LOG_TAG,
+        "%s hci layer timeout waiting for response to a command. opcode: 0x%x",
+        __func__, wait_entry->opcode);
     LOG_EVENT_INT(BT_HCI_TIMEOUT_TAG_NUM, wait_entry->opcode);
   }
 
@@ -564,7 +553,8 @@ static void command_timed_out(UNUSED_ATTR void *context) {
 // This function is not required to read all of a packet in one go, so
 // be wary of reentry. But this function must return after finishing a packet.
 static void hal_says_data_ready(serial_data_type_t type) {
-  packet_receive_data_t *incoming = &incoming_packets[PACKET_TYPE_TO_INBOUND_INDEX(type)];
+  packet_receive_data_t* incoming =
+      &incoming_packets[PACKET_TYPE_TO_INBOUND_INDEX(type)];
 
   uint8_t byte;
   while (hal->read_data(type, &byte, 1) != 0) {
@@ -575,7 +565,7 @@ static void hal_says_data_ready(serial_data_type_t type) {
         memset(incoming->preamble, 0, PREAMBLE_BUFFER_SIZE);
         incoming->index = 0;
         incoming->state = PREAMBLE;
-        // INTENTIONAL FALLTHROUGH
+      // INTENTIONAL FALLTHROUGH
       case PREAMBLE:
         incoming->preamble[incoming->index] = byte;
         incoming->index++;
@@ -583,47 +573,59 @@ static void hal_says_data_ready(serial_data_type_t type) {
 
         if (incoming->bytes_remaining == 0) {
           // For event and sco preambles, the last byte we read is the length
-          incoming->bytes_remaining = (type == DATA_TYPE_ACL) ? RETRIEVE_ACL_LENGTH(incoming->preamble) : byte;
+          incoming->bytes_remaining =
+              (type == DATA_TYPE_ACL) ? RETRIEVE_ACL_LENGTH(incoming->preamble)
+                                      : byte;
 
-          size_t buffer_size = BT_HDR_SIZE + incoming->index + incoming->bytes_remaining;
-          incoming->buffer = (BT_HDR *)buffer_allocator->alloc(buffer_size);
+          size_t buffer_size =
+              BT_HDR_SIZE + incoming->index + incoming->bytes_remaining;
+          incoming->buffer = (BT_HDR*)buffer_allocator->alloc(buffer_size);
 
           if (!incoming->buffer) {
-            LOG_ERROR(LOG_TAG, "%s error getting buffer for incoming packet of type %d and size %zd", __func__, type, buffer_size);
+            LOG_ERROR(LOG_TAG,
+                      "%s error getting buffer for incoming packet of type %d "
+                      "and size %zd",
+                      __func__, type, buffer_size);
             // Can't read any more of this current packet, so jump out
-            incoming->state = incoming->bytes_remaining == 0 ? BRAND_NEW : IGNORE;
+            incoming->state =
+                incoming->bytes_remaining == 0 ? BRAND_NEW : IGNORE;
             break;
           }
 
           // Initialize the buffer
           incoming->buffer->offset = 0;
           incoming->buffer->layer_specific = 0;
-          incoming->buffer->event = outbound_event_types[PACKET_TYPE_TO_INDEX(type)];
+          incoming->buffer->event =
+              outbound_event_types[PACKET_TYPE_TO_INDEX(type)];
           memcpy(incoming->buffer->data, incoming->preamble, incoming->index);
 
           incoming->state = incoming->bytes_remaining > 0 ? BODY : FINISHED;
         }
 
         break;
-      case BODY:
-      {
+      case BODY: {
         incoming->buffer->data[incoming->index] = byte;
         incoming->index++;
         incoming->bytes_remaining--;
 
-        size_t bytes_read = hal->read_data(type, (incoming->buffer->data + incoming->index), incoming->bytes_remaining);
+        size_t bytes_read =
+            hal->read_data(type, (incoming->buffer->data + incoming->index),
+                           incoming->bytes_remaining);
         incoming->index += bytes_read;
         incoming->bytes_remaining -= bytes_read;
 
-        incoming->state = incoming->bytes_remaining == 0 ? FINISHED : incoming->state;
+        incoming->state =
+            incoming->bytes_remaining == 0 ? FINISHED : incoming->state;
         break;
       }
       case IGNORE:
         incoming->bytes_remaining--;
         if (incoming->bytes_remaining == 0) {
           incoming->state = BRAND_NEW;
-          // Don't forget to let the hal know we finished the packet we were ignoring.
-          // Otherwise we'll get out of sync with hals that embed extra information
+          // Don't forget to let the hal know we finished the packet we were
+          // ignoring.
+          // Otherwise we'll get out of sync with hals that embed extra
+          // information
           // in the uart stream (like H4). #badnewsbears
           hal->packet_finished(type);
           return;
@@ -631,7 +633,10 @@ static void hal_says_data_ready(serial_data_type_t type) {
 
         break;
       case FINISHED:
-        LOG_ERROR(LOG_TAG, "%s the state machine should not have been left in the finished state.", __func__);
+        LOG_ERROR(LOG_TAG,
+                  "%s the state machine should not have been left in the "
+                  "finished state.",
+                  __func__);
         break;
     }
 
@@ -643,15 +648,12 @@ static void hal_says_data_ready(serial_data_type_t type) {
         packet_fragmenter->reassemble_and_dispatch(incoming->buffer);
       } else if (!filter_incoming_event(incoming->buffer)) {
         // Dispatch the event by event code
-        uint8_t *stream = incoming->buffer->data;
+        uint8_tstream = incoming->buffer->data;
         uint8_t event_code;
         STREAM_TO_UINT8(event_code, stream);
 
-        data_dispatcher_dispatch(
-          interface.event_dispatcher,
-          event_code,
-          incoming->buffer
-        );
+        data_dispatcher_dispatch(interface.event_dispatcher, event_code,
+                                 incoming->buffer);
       }
 
       // We don't control the buffer anymore
@@ -670,14 +672,14 @@ static void hal_says_data_ready(serial_data_type_t type) {
 // Returns true if the event was intercepted and should not proceed to
 // higher layers. Also inspects an incoming event for interesting
 // information, like how many commands are now able to be sent.
-static bool filter_incoming_event(BT_HDR *packet) {
-  waiting_command_t *wait_entry = NULL;
-  uint8_t *stream = packet->data;
+static bool filter_incoming_event(BT_HDRpacket) {
+  waiting_command_twait_entry = NULL;
+  uint8_tstream = packet->data;
   uint8_t event_code;
   command_opcode_t opcode;
 
   STREAM_TO_UINT8(event_code, stream);
-  STREAM_SKIP_UINT8(stream); // Skip the parameter total length field
+  STREAM_SKIP_UINT8(stream);  // Skip the parameter total length field
 
   if (event_code == HCI_COMMAND_COMPLETE_EVT) {
     STREAM_TO_UINT8(command_credits, stream);
@@ -685,10 +687,13 @@ static bool filter_incoming_event(BT_HDR *packet) {
 
     wait_entry = get_waiting_command(opcode);
     if (!wait_entry) {
-      // TODO: Currently command_credits aren't parsed at all; here or in higher layers...
+      // TODO: Currently command_credits aren't parsed at all; here or in higher
+      // layers...
       if (opcode != HCI_COMMAND_NONE) {
-        LOG_WARN(LOG_TAG, "%s command complete event with no matching command (opcode: 0x%04x).",
-            __func__, opcode);
+        LOG_WARN(LOG_TAG,
+                 "%s command complete event with no matching command (opcode: "
+                 "0x%04x).",
+                 __func__, opcode);
       }
     } else if (wait_entry->complete_callback) {
       wait_entry->complete_callback(packet, wait_entry->context);
@@ -703,13 +708,17 @@ static bool filter_incoming_event(BT_HDR *packet) {
     STREAM_TO_UINT8(command_credits, stream);
     STREAM_TO_UINT16(opcode, stream);
 
-    // If a command generates a command status event, it won't be getting a command complete event
+    // If a command generates a command status event, it won't be getting a
+    // command complete event
 
     wait_entry = get_waiting_command(opcode);
     if (!wait_entry)
-      LOG_WARN(LOG_TAG, "%s command status event with no matching command. opcode: 0x%x", __func__, opcode);
+      LOG_WARN(LOG_TAG,
+               "%s command status event with no matching command. opcode: 0x%x",
+               __func__, opcode);
     else if (wait_entry->status_callback)
-      wait_entry->status_callback(status, wait_entry->command, wait_entry->context);
+      wait_entry->status_callback(status, wait_entry->command,
+                                  wait_entry->context);
 
     goto intercepted;
   }
@@ -721,7 +730,8 @@ intercepted:
 
   if (wait_entry) {
     // If it has a callback, it's responsible for freeing the packet
-    if (event_code == HCI_COMMAND_STATUS_EVT || (!wait_entry->complete_callback && !wait_entry->complete_future))
+    if (event_code == HCI_COMMAND_STATUS_EVT ||
+        (!wait_entry->complete_callback && !wait_entry->complete_future))
       buffer_allocator->free(packet);
 
     // If it has a callback, it's responsible for freeing the command
@@ -737,7 +747,7 @@ intercepted:
 }
 
 // Callback for the fragmenter to dispatch up a completely reassembled packet
-static void dispatch_reassembled(BT_HDR *packet) {
+static void dispatch_reassembled(BT_HDRpacket) {
   // Events should already have been dispatched before this point
   assert((packet->event & MSG_EVT_MASK) != MSG_HC_TO_STACK_HCI_EVT);
   assert(upwards_data_queue != NULL);
@@ -745,14 +755,18 @@ static void dispatch_reassembled(BT_HDR *packet) {
   if (upwards_data_queue) {
     fixed_queue_enqueue(upwards_data_queue, packet);
   } else {
-    LOG_ERROR(LOG_TAG, "%s had no queue to place upwards data packet in. Dropping it on the floor.", __func__);
+    LOG_ERROR(LOG_TAG,
+              "%s had no queue to place upwards data packet in. Dropping it on "
+              "the floor.",
+              __func__);
     buffer_allocator->free(packet);
   }
 }
 
 // Misc internal functions
 
-// TODO(zachoverflow): we seem to do this a couple places, like the HCI inject module. #centralize
+// TODO(zachoverflow): we seem to do this a couple places, like the HCI inject
+// module. #centralize
 static serial_data_type_t event_to_data_type(uint16_t event) {
   if (event == MSG_STACK_TO_HC_HCI_ACL)
     return DATA_TYPE_ACL;
@@ -761,22 +775,21 @@ static serial_data_type_t event_to_data_type(uint16_t event) {
   else if (event == MSG_STACK_TO_HC_HCI_CMD)
     return DATA_TYPE_COMMAND;
   else
-    LOG_ERROR(LOG_TAG, "%s invalid event type, could not translate 0x%x", __func__, event);
+    LOG_ERROR(LOG_TAG, "%s invalid event type, could not translate 0x%x",
+              __func__, event);
 
   return DATA_TYPE_UNKNOWN;
 }
 
-static waiting_command_t *get_waiting_command(command_opcode_t opcode) {
+static waiting_command_tget_waiting_command(command_opcode_t opcode) {
   pthread_mutex_lock(&commands_pending_response_lock);
 
-  for (const list_node_t *node = list_begin(commands_pending_response);
-      node != list_end(commands_pending_response);
-      node = list_next(node)) {
-    waiting_command_t *wait_entry =
-        static_cast<waiting_command_t *>(list_node(node));
+  for (const list_node_t* node = list_begin(commands_pending_response);
+       node != list_end(commands_pending_response); node = list_next(node)) {
+    waiting_command_t* wait_entry =
+        static_cast<waiting_command_t*>(list_node(node));
 
-    if (!wait_entry || wait_entry->opcode != opcode)
-      continue;
+    if (!wait_entry || wait_entry->opcode != opcode) continue;
 
     list_remove(commands_pending_response, wait_entry);
 
@@ -834,7 +847,7 @@ void hci_layer_cleanup_interface() {
   }
 }
 
-const hci_t *hci_layer_get_interface() {
+const hci_thci_layer_get_interface() {
   buffer_allocator = buffer_allocator_get_interface();
   hal = hci_hal_get_interface();
   btsnoop = btsnoop_get_interface();
@@ -847,15 +860,13 @@ const hci_t *hci_layer_get_interface() {
   return &interface;
 }
 
-const hci_t *hci_layer_get_test_interface(
-    const allocator_t *buffer_allocator_interface,
-    const hci_hal_t *hal_interface,
-    const btsnoop_t *btsnoop_interface,
-    const hci_inject_t *hci_inject_interface,
-    const packet_fragmenter_t *packet_fragmenter_interface,
-    const vendor_t *vendor_interface,
-    const low_power_manager_t *low_power_manager_interface) {
-
+const hci_t* hci_layer_get_test_interface(
+    const allocator_t* buffer_allocator_interface,
+    const hci_hal_t* hal_interface, const btsnoop_t* btsnoop_interface,
+    const hci_inject_t* hci_inject_interface,
+    const packet_fragmenter_t* packet_fragmenter_interface,
+    const vendor_t* vendor_interface,
+    const low_power_manager_t* low_power_manager_interface) {
   buffer_allocator = buffer_allocator_interface;
   hal = hal_interface;
   btsnoop = btsnoop_interface;
index 96f578a..261d7cf 100644 (file)
 
 #include <assert.h>
 
-#include "osi/include/allocator.h"
 #include "bt_types.h"
 #include "buffer_allocator.h"
-#include "hcidefs.h"
-#include "hcimsgs.h"
 #include "hci_internals.h"
 #include "hci_layer.h"
 #include "hci_packet_factory.h"
+#include "hcidefs.h"
+#include "hcimsgs.h"
+#include "osi/include/allocator.h"
 
-static const allocator_t *buffer_allocator;
+static const allocator_tbuffer_allocator;
 
-static BT_HDR *make_packet(size_t data_size);
-static BT_HDR *make_command_no_params(uint16_t opcode);
-static BT_HDR *make_command(uint16_t opcode, size_t parameter_size, uint8_t **stream_out);
+static BT_HDR* make_packet(size_t data_size);
+static BT_HDR* make_command_no_params(uint16_t opcode);
+static BT_HDR* make_command(uint16_t opcode, size_t parameter_size,
+                            uint8_t** stream_out);
 
 // Interface functions
 
-static BT_HDR *make_reset(void) {
-  return make_command_no_params(HCI_RESET);
-}
+static BT_HDR* make_reset(void) { return make_command_no_params(HCI_RESET); }
 
-static BT_HDR *make_read_buffer_size(void) {
+static BT_HDRmake_read_buffer_size(void) {
   return make_command_no_params(HCI_READ_BUFFER_SIZE);
 }
 
-static BT_HDR *make_host_buffer_size(uint16_t acl_size, uint8_t sco_size, uint16_t acl_count, uint16_t sco_count) {
-  uint8_t *stream;
-  const uint8_t parameter_size = 2 + 1 + 2 + 2; // from each of the parameters
-  BT_HDR *packet = make_command(HCI_HOST_BUFFER_SIZE, parameter_size, &stream);
+static BT_HDR* make_host_buffer_size(uint16_t acl_size, uint8_t sco_size,
+                                     uint16_t acl_count, uint16_t sco_count) {
+  uint8_t* stream;
+  const uint8_t parameter_size = 2 + 1 + 2 + 2;  // from each of the parameters
+  BT_HDR* packet = make_command(HCI_HOST_BUFFER_SIZE, parameter_size, &stream);
 
   UINT16_TO_STREAM(stream, acl_size);
   UINT8_TO_STREAM(stream, sco_size);
@@ -55,96 +55,102 @@ static BT_HDR *make_host_buffer_size(uint16_t acl_size, uint8_t sco_size, uint16
   return packet;
 }
 
-static BT_HDR *make_read_local_version_info(void) {
+static BT_HDRmake_read_local_version_info(void) {
   return make_command_no_params(HCI_READ_LOCAL_VERSION_INFO);
 }
 
-static BT_HDR *make_read_bd_addr(void) {
+static BT_HDRmake_read_bd_addr(void) {
   return make_command_no_params(HCI_READ_BD_ADDR);
 }
 
-static BT_HDR *make_read_local_supported_commands(void) {
+static BT_HDRmake_read_local_supported_commands(void) {
   return make_command_no_params(HCI_READ_LOCAL_SUPPORTED_CMDS);
 }
 
-static BT_HDR *make_read_local_extended_features(uint8_t page_number) {
-  uint8_t *stream;
+static BT_HDRmake_read_local_extended_features(uint8_t page_number) {
+  uint8_tstream;
   const uint8_t parameter_size = 1;
-  BT_HDR *packet = make_command(HCI_READ_LOCAL_EXT_FEATURES, parameter_size, &stream);
+  BT_HDR* packet =
+      make_command(HCI_READ_LOCAL_EXT_FEATURES, parameter_size, &stream);
 
   UINT8_TO_STREAM(stream, page_number);
   return packet;
 }
 
-static BT_HDR *make_write_simple_pairing_mode(uint8_t mode) {
-  uint8_t *stream;
+static BT_HDRmake_write_simple_pairing_mode(uint8_t mode) {
+  uint8_tstream;
   const uint8_t parameter_size = 1;
-  BT_HDR *packet = make_command(HCI_WRITE_SIMPLE_PAIRING_MODE, parameter_size, &stream);
+  BT_HDR* packet =
+      make_command(HCI_WRITE_SIMPLE_PAIRING_MODE, parameter_size, &stream);
 
   UINT8_TO_STREAM(stream, mode);
   return packet;
 }
 
-static BT_HDR *make_write_secure_connections_host_support(uint8_t mode) {
-  uint8_t *stream;
+static BT_HDRmake_write_secure_connections_host_support(uint8_t mode) {
+  uint8_tstream;
   const uint8_t parameter_size = 1;
-  BT_HDR *packet = make_command(HCI_WRITE_SECURE_CONNS_SUPPORT, parameter_size, &stream);
+  BT_HDR* packet =
+      make_command(HCI_WRITE_SECURE_CONNS_SUPPORT, parameter_size, &stream);
 
   UINT8_TO_STREAM(stream, mode);
   return packet;
 }
 
-static BT_HDR *make_set_event_mask(const bt_event_mask_t *event_mask) {
-  uint8_t *stream;
+static BT_HDR* make_set_event_mask(const bt_event_mask_t* event_mask) {
+  uint8_tstream;
   uint8_t parameter_size = sizeof(bt_event_mask_t);
-  BT_HDR *packet = make_command(HCI_SET_EVENT_MASK, parameter_size, &stream);
+  BT_HDRpacket = make_command(HCI_SET_EVENT_MASK, parameter_size, &stream);
 
   ARRAY8_TO_STREAM(stream, event_mask->as_array);
   return packet;
 }
 
-static BT_HDR *make_ble_write_host_support(uint8_t supported_host, uint8_t simultaneous_host) {
-  uint8_t *stream;
+static BT_HDR* make_ble_write_host_support(uint8_t supported_host,
+                                           uint8_t simultaneous_host) {
+  uint8_t* stream;
   const uint8_t parameter_size = 1 + 1;
-  BT_HDR *packet = make_command(HCI_WRITE_LE_HOST_SUPPORT, parameter_size, &stream);
+  BT_HDR* packet =
+      make_command(HCI_WRITE_LE_HOST_SUPPORT, parameter_size, &stream);
 
   UINT8_TO_STREAM(stream, supported_host);
   UINT8_TO_STREAM(stream, simultaneous_host);
   return packet;
 }
 
-static BT_HDR *make_ble_read_white_list_size(void) {
+static BT_HDRmake_ble_read_white_list_size(void) {
   return make_command_no_params(HCI_BLE_READ_WHITE_LIST_SIZE);
 }
 
-static BT_HDR *make_ble_read_buffer_size(void) {
+static BT_HDRmake_ble_read_buffer_size(void) {
   return make_command_no_params(HCI_BLE_READ_BUFFER_SIZE);
 }
 
-static BT_HDR *make_ble_read_supported_states(void) {
+static BT_HDRmake_ble_read_supported_states(void) {
   return make_command_no_params(HCI_BLE_READ_SUPPORTED_STATES);
 }
 
-static BT_HDR *make_ble_read_local_supported_features(void) {
+static BT_HDRmake_ble_read_local_supported_features(void) {
   return make_command_no_params(HCI_BLE_READ_LOCAL_SPT_FEAT);
 }
 
-static BT_HDR *make_ble_read_resolving_list_size(void) {
+static BT_HDRmake_ble_read_resolving_list_size(void) {
   return make_command_no_params(HCI_BLE_READ_RESOLVING_LIST_SIZE);
 }
 
-static BT_HDR *make_ble_read_suggested_default_data_length(void) {
-    return make_command_no_params(HCI_BLE_READ_DEFAULT_DATA_LENGTH);
+static BT_HDRmake_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_HDRmake_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;
+static BT_HDR* make_ble_set_event_mask(const bt_event_mask_t* event_mask) {
+  uint8_tstream;
   uint8_t parameter_size = sizeof(bt_event_mask_t);
-  BT_HDR *packet = make_command(HCI_BLE_SET_EVENT_MASK, parameter_size, &stream);
+  BT_HDR* packet =
+      make_command(HCI_BLE_SET_EVENT_MASK, parameter_size, &stream);
 
   ARRAY8_TO_STREAM(stream, event_mask->as_array);
   return packet;
@@ -152,25 +158,25 @@ static BT_HDR *make_ble_set_event_mask(const bt_event_mask_t *event_mask) {
 
 // Internal functions
 
-static BT_HDR *make_command_no_params(uint16_t opcode) {
+static BT_HDRmake_command_no_params(uint16_t opcode) {
   return make_command(opcode, 0, NULL);
 }
 
-static BT_HDR *make_command(uint16_t opcode, size_t parameter_size, uint8_t **stream_out) {
-  BT_HDR *packet = make_packet(HCI_COMMAND_PREAMBLE_SIZE + parameter_size);
+static BT_HDR* make_command(uint16_t opcode, size_t parameter_size,
+                            uint8_t** stream_out) {
+  BT_HDR* packet = make_packet(HCI_COMMAND_PREAMBLE_SIZE + parameter_size);
 
-  uint8_t *stream = packet->data;
+  uint8_tstream = packet->data;
   UINT16_TO_STREAM(stream, opcode);
   UINT8_TO_STREAM(stream, parameter_size);
 
-  if (stream_out != NULL)
-    *stream_out = stream;
+  if (stream_out != NULL) *stream_out = stream;
 
   return packet;
 }
 
-static BT_HDR *make_packet(size_t data_size) {
-  BT_HDR *ret = (BT_HDR *)buffer_allocator->alloc(sizeof(BT_HDR) + data_size);
+static BT_HDRmake_packet(size_t data_size) {
+  BT_HDR* ret = (BT_HDR*)buffer_allocator->alloc(sizeof(BT_HDR) + data_size);
   assert(ret);
   ret->event = 0;
   ret->offset = 0;
@@ -180,28 +186,27 @@ static BT_HDR *make_packet(size_t data_size) {
 }
 
 static const hci_packet_factory_t interface = {
-  make_reset,
-  make_read_buffer_size,
-  make_host_buffer_size,
-  make_read_local_version_info,
-  make_read_bd_addr,
-  make_read_local_supported_commands,
-  make_read_local_extended_features,
-  make_write_simple_pairing_mode,
-  make_write_secure_connections_host_support,
-  make_set_event_mask,
-  make_ble_write_host_support,
-  make_ble_read_white_list_size,
-  make_ble_read_buffer_size,
-  make_ble_read_supported_states,
-  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_read_local_supported_codecs
-};
-
-const hci_packet_factory_t *hci_packet_factory_get_interface() {
+    make_reset,
+    make_read_buffer_size,
+    make_host_buffer_size,
+    make_read_local_version_info,
+    make_read_bd_addr,
+    make_read_local_supported_commands,
+    make_read_local_extended_features,
+    make_write_simple_pairing_mode,
+    make_write_secure_connections_host_support,
+    make_set_event_mask,
+    make_ble_write_host_support,
+    make_ble_read_white_list_size,
+    make_ble_read_buffer_size,
+    make_ble_read_supported_states,
+    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_read_local_supported_codecs};
+
+const hci_packet_factory_t* hci_packet_factory_get_interface() {
   buffer_allocator = buffer_allocator_get_interface();
   return &interface;
 }
index 9f7dae8..7242f05 100644 (file)
 
 static const command_opcode_t NO_OPCODE_CHECKING = 0;
 
-static const allocator_t *buffer_allocator;
+static const allocator_tbuffer_allocator;
 
-static uint8_t *read_command_complete_header(
-  BT_HDR *response,
-  command_opcode_t expected_opcode,
-  size_t minimum_bytes_after);
+static uint8_t* read_command_complete_header(BT_HDR* response,
+                                             command_opcode_t expected_opcode,
+                                             size_t minimum_bytes_after);
 
-static void parse_generic_command_complete(BT_HDR *response) {
-  read_command_complete_header(response, NO_OPCODE_CHECKING, 0 /* bytes after */);
+static void parse_generic_command_complete(BT_HDR* response) {
+  read_command_complete_header(response, NO_OPCODE_CHECKING,
+                               0 /* bytes after */);
 
   buffer_allocator->free(response);
 }
 
-static void parse_read_buffer_size_response(
-    BT_HDR *response,
-    uint16_t *data_size_ptr,
-    uint16_t *acl_buffer_count_ptr) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_READ_BUFFER_SIZE, 5 /* bytes after */);
+static void parse_read_buffer_size_response(BT_HDR* response,
+                                            uint16_t* data_size_ptr,
+                                            uint16_t* acl_buffer_count_ptr) {
+  uint8_t* stream = read_command_complete_header(response, HCI_READ_BUFFER_SIZE,
+                                                 5 /* bytes after */);
   assert(stream != NULL);
   STREAM_TO_UINT16(*data_size_ptr, stream);
-  STREAM_SKIP_UINT8(stream); // skip the sco packet length
+  STREAM_SKIP_UINT8(stream);  // skip the sco packet length
   STREAM_TO_UINT16(*acl_buffer_count_ptr, stream);
 
   buffer_allocator->free(response);
 }
 
-static void parse_read_local_version_info_response(
-    BT_HDR *response,
-    bt_version_t *bt_version) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_READ_LOCAL_VERSION_INFO, 8 /* bytes after */);
+static void parse_read_local_version_info_response(BT_HDR* response,
+                                                   bt_version_t* bt_version) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_READ_LOCAL_VERSION_INFO, 8 /* bytes after */);
   assert(stream != NULL);
   STREAM_TO_UINT8(bt_version->hci_version, stream);
   STREAM_TO_UINT16(bt_version->hci_revision, stream);
@@ -72,14 +70,13 @@ static void parse_read_local_version_info_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) {
+    BT_HDR* response, uint8_t* number_of_local_supported_codecs,
+    uint8_tlocal_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++)
-    {
+    for (uint8_t i = 0; i < *number_of_local_supported_codecs; i++) {
       STREAM_TO_UINT8(*local_supported_codecs, stream);
       local_supported_codecs++;
     }
@@ -88,11 +85,10 @@ static void parse_read_local_supported_codecs_response(
   buffer_allocator->free(response);
 }
 
-static void parse_read_bd_addr_response(
-    BT_HDR *response,
-    bt_bdaddr_t *address_ptr) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_READ_BD_ADDR, sizeof(bt_bdaddr_t) /* bytes after */);
+static void parse_read_bd_addr_response(BT_HDR* response,
+                                        bt_bdaddr_t* address_ptr) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_READ_BD_ADDR, sizeof(bt_bdaddr_t) /* bytes after */);
   assert(stream != NULL);
   STREAM_TO_BDADDR(address_ptr->address, stream);
 
@@ -100,56 +96,56 @@ static void parse_read_bd_addr_response(
 }
 
 static void parse_read_local_supported_commands_response(
-    BT_HDR *response,
-    uint8_t *supported_commands_ptr,
+    BT_HDR* response, uint8_t* supported_commands_ptr,
     size_t supported_commands_length) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_READ_LOCAL_SUPPORTED_CMDS, supported_commands_length /* bytes after */);
+  uint8_t* stream =
+      read_command_complete_header(response, HCI_READ_LOCAL_SUPPORTED_CMDS,
+                                   supported_commands_length /* bytes after */);
   assert(stream != NULL);
-  STREAM_TO_ARRAY(supported_commands_ptr, stream, (int)supported_commands_length);
+  STREAM_TO_ARRAY(supported_commands_ptr, stream,
+                  (int)supported_commands_length);
 
   buffer_allocator->free(response);
 }
 
 static void parse_read_local_extended_features_response(
-    BT_HDR *response,
-    uint8_t *page_number_ptr,
-    uint8_t *max_page_number_ptr,
-    bt_device_features_t *feature_pages,
-    size_t feature_pages_count) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_READ_LOCAL_EXT_FEATURES, 2 + sizeof(bt_device_features_t) /* bytes after */);
+    BT_HDR* response, uint8_t* page_number_ptr, uint8_t* max_page_number_ptr,
+    bt_device_features_t* feature_pages, size_t feature_pages_count) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_READ_LOCAL_EXT_FEATURES,
+      2 + sizeof(bt_device_features_t) /* bytes after */);
   if (stream != NULL) {
     STREAM_TO_UINT8(*page_number_ptr, stream);
     STREAM_TO_UINT8(*max_page_number_ptr, stream);
 
     assert(*page_number_ptr < feature_pages_count);
-    STREAM_TO_ARRAY(feature_pages[*page_number_ptr].as_array, stream, (int)sizeof(bt_device_features_t));
+    STREAM_TO_ARRAY(feature_pages[*page_number_ptr].as_array, stream,
+                    (int)sizeof(bt_device_features_t));
   } else {
-    LOG_ERROR(LOG_TAG, "%s() - WARNING: READING EXTENDED FEATURES FAILED. "
-                "THIS MAY INDICATE A FIRMWARE/CONTROLLER ISSUE.", __func__);
+    LOG_ERROR(LOG_TAG,
+              "%s() - WARNING: READING EXTENDED FEATURES FAILED. "
+              "THIS MAY INDICATE A FIRMWARE/CONTROLLER ISSUE.",
+              __func__);
   }
 
   buffer_allocator->free(response);
 }
 
 static void parse_ble_read_white_list_size_response(
-    BT_HDR *response,
-    uint8_t *white_list_size_ptr) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_WHITE_LIST_SIZE, 1 /* byte after */);
+    BT_HDR* response, uint8_t* white_list_size_ptr) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_BLE_READ_WHITE_LIST_SIZE, 1 /* byte after */);
   assert(stream != NULL);
   STREAM_TO_UINT8(*white_list_size_ptr, stream);
 
   buffer_allocator->free(response);
 }
 
-static void parse_ble_read_buffer_size_response(
-    BT_HDR *response,
-    uint16_t *data_size_ptr,
-    uint8_t *acl_buffer_count_ptr) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_BUFFER_SIZE, 3 /* bytes after */);
+static void parse_ble_read_buffer_size_response(BT_HDR* response,
+                                                uint16_t* data_size_ptr,
+                                                uint8_t* acl_buffer_count_ptr) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_BLE_READ_BUFFER_SIZE, 3 /* bytes after */);
   assert(stream != NULL);
   STREAM_TO_UINT16(*data_size_ptr, stream);
   STREAM_TO_UINT8(*acl_buffer_count_ptr, stream);
@@ -158,11 +154,10 @@ static void parse_ble_read_buffer_size_response(
 }
 
 static void parse_ble_read_supported_states_response(
-    BT_HDR *response,
-    uint8_t *supported_states,
-    size_t supported_states_size) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_SUPPORTED_STATES, supported_states_size /* bytes after */);
+    BT_HDR* response, uint8_t* supported_states, size_t supported_states_size) {
+  uint8_t* stream =
+      read_command_complete_header(response, HCI_BLE_READ_SUPPORTED_STATES,
+                                   supported_states_size /* bytes after */);
   assert(stream != NULL);
   STREAM_TO_ARRAY(supported_states, stream, (int)supported_states_size);
 
@@ -170,31 +165,30 @@ static void parse_ble_read_supported_states_response(
 }
 
 static void parse_ble_read_local_supported_features_response(
-    BT_HDR *response,
-    bt_device_features_t *supported_features) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_LOCAL_SPT_FEAT, sizeof(bt_device_features_t) /* bytes after */);
+    BT_HDR* response, bt_device_features_t* supported_features) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_BLE_READ_LOCAL_SPT_FEAT,
+      sizeof(bt_device_features_t) /* bytes after */);
   assert(stream != NULL);
-  STREAM_TO_ARRAY(supported_features->as_array, stream, (int)sizeof(bt_device_features_t));
+  STREAM_TO_ARRAY(supported_features->as_array, stream,
+                  (int)sizeof(bt_device_features_t));
 
   buffer_allocator->free(response);
 }
 
 static void parse_ble_read_resolving_list_size_response(
-    BT_HDR *response,
-    uint8_t *resolving_list_size_ptr) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_RESOLVING_LIST_SIZE, 1 /* bytes after */);
+    BT_HDR* response, uint8_t* resolving_list_size_ptr) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_BLE_READ_RESOLVING_LIST_SIZE, 1 /* bytes after */);
   STREAM_TO_UINT8(*resolving_list_size_ptr, stream);
 
   buffer_allocator->free(response);
 }
 
 static void parse_ble_read_suggested_default_data_length_response(
-    BT_HDR *response,
-    uint16_t *ble_default_packet_length_ptr) {
-
-  uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_DEFAULT_DATA_LENGTH, 2 /* bytes after */);
+    BT_HDR* response, uint16_t* ble_default_packet_length_ptr) {
+  uint8_t* stream = read_command_complete_header(
+      response, HCI_BLE_READ_DEFAULT_DATA_LENGTH, 2 /* bytes after */);
   STREAM_TO_UINT8(*ble_default_packet_length_ptr, stream);
 
   buffer_allocator->free(response);
@@ -202,12 +196,10 @@ static void parse_ble_read_suggested_default_data_length_response(
 
 // Internal functions
 
-static uint8_t *read_command_complete_header(
-    BT_HDR *response,
-    command_opcode_t expected_opcode,
-    size_t minimum_bytes_after) {
-
-  uint8_t *stream = response->data + response->offset;
+static uint8_t* read_command_complete_header(BT_HDR* response,
+                                             command_opcode_t expected_opcode,
+                                             size_t minimum_bytes_after) {
+  uint8_t* stream = response->data + response->offset;
 
   // Read the event header
   uint8_t event_code;
@@ -219,12 +211,13 @@ static uint8_t *read_command_complete_header(
 
   // Check the event header values against what we expect
   assert(event_code == HCI_COMMAND_COMPLETE_EVT);
-  assert(parameter_length >= (parameter_bytes_we_read_here + minimum_bytes_after));
+  assert(parameter_length >=
+         (parameter_bytes_we_read_here + minimum_bytes_after));
 
   // Read the command complete header
   command_opcode_t opcode;
   uint8_t status;
-  STREAM_SKIP_UINT8(stream); // skip the number of hci command packets field
+  STREAM_SKIP_UINT8(stream);  // skip the number of hci command packets field
   STREAM_TO_UINT16(opcode, stream);
 
   // Check the command complete header values against what we expect
@@ -235,7 +228,7 @@ 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(LOG_TAG, "%s: return status - 0x%x", __func__, status);
     return NULL;
   }
@@ -244,28 +237,27 @@ static uint8_t *read_command_complete_header(
 }
 
 static const hci_packet_parser_t interface = {
-  parse_generic_command_complete,
-  parse_read_buffer_size_response,
-  parse_read_local_version_info_response,
-  parse_read_bd_addr_response,
-  parse_read_local_supported_commands_response,
-  parse_read_local_extended_features_response,
-  parse_ble_read_white_list_size_response,
-  parse_ble_read_buffer_size_response,
-  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_read_local_supported_codecs_response
-};
-
-const hci_packet_parser_t *hci_packet_parser_get_interface() {
+    parse_generic_command_complete,
+    parse_read_buffer_size_response,
+    parse_read_local_version_info_response,
+    parse_read_bd_addr_response,
+    parse_read_local_supported_commands_response,
+    parse_read_local_extended_features_response,
+    parse_ble_read_white_list_size_response,
+    parse_ble_read_buffer_size_response,
+    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_read_local_supported_codecs_response};
+
+const hci_packet_parser_t* hci_packet_parser_get_interface() {
   buffer_allocator = buffer_allocator_get_interface();
   return &interface;
 }
 
-const hci_packet_parser_t *hci_packet_parser_get_test_interface(
-    allocator_t *buffer_allocator_interface) {
+const hci_packet_parser_thci_packet_parser_get_test_interface(
+    allocator_tbuffer_allocator_interface) {
   buffer_allocator = buffer_allocator_interface;
   return &interface;
 }
index cac5285..c328ca8 100644 (file)
@@ -43,52 +43,42 @@ typedef enum {
   LPM_WAKE_ASSERTED,
 } wake_state_t;
 
-static void init(thread_t *post_thread);
+static void init(thread_tpost_thread);
 static void cleanup(void);
 static void post_command(low_power_command_t command);
 static void wake_assert(void);
 static void transmit_done(void);
 static void vendor_enable_disable_callback(bool success);
 
-static void event_disable(void *context);
-static void event_enable(void *context);
-static void event_wake_assert(void *context);
-static void event_allow_device_sleep(void *context);
-static void event_idle_timeout(void *context);
+static void event_disable(voidcontext);
+static void event_enable(voidcontext);
+static void event_wake_assert(voidcontext);
+static void event_allow_device_sleep(voidcontext);
+static void event_idle_timeout(voidcontext);
 
 static void reset_state();
 static void start_idle_timer();
 static void stop_idle_timer();
 
-
 // Our interface and modules we import
-static const low_power_manager_t interface = {
-  init,
-  cleanup,
-  post_command,
-  wake_assert,
-  transmit_done
-};
-static const vendor_t *vendor;
+static const low_power_manager_t interface = {init, cleanup, post_command,
+                                              wake_assert, transmit_done};
+static const vendor_t* vendor;
 
 static thread_fn event_functions[] = {
-  event_disable,
-  event_enable,
-  event_wake_assert,
-  event_allow_device_sleep
-};
+    event_disable, event_enable, event_wake_assert, event_allow_device_sleep};
 
-static thread_t *thread;
+static thread_tthread;
 static low_power_mode_state_t state;
 static wake_state_t wake_state;
 static uint32_t idle_timeout_ms;
-static alarm_t *idle_alarm;
+static alarm_tidle_alarm;
 static bool transmit_is_done;
 static void wake_deassert();
 
 // Interface functions
 
-static void init(thread_t *post_thread) {
+static void init(thread_tpost_thread) {
   assert(post_thread != NULL);
   thread = post_thread;
 
@@ -145,14 +135,24 @@ static void transmit_done(void) {
 static void enable(bool enable) {
   if (state == LPM_DISABLING) {
     if (enable)
-      LOG_ERROR(LOG_TAG, "%s still processing prior disable request, cannot enable.", __func__);
+      LOG_ERROR(LOG_TAG,
+                "%s still processing prior disable request, cannot enable.",
+                __func__);
     else
-      LOG_WARN(LOG_TAG, "%s still processing prior disable request, ignoring new request to disable.", __func__);
+      LOG_WARN(LOG_TAG,
+               "%s still processing prior disable request, ignoring new "
+               "request to disable.",
+               __func__);
   } else if (state == LPM_ENABLING) {
     if (enable)
-      LOG_ERROR(LOG_TAG, "%s still processing prior enable request, ignoring new request to enable.", __func__);
+      LOG_ERROR(LOG_TAG,
+                "%s still processing prior enable request, ignoring new "
+                "request to enable.",
+                __func__);
     else
-      LOG_WARN(LOG_TAG, "%s still processing prior enable request, cannot disable.", __func__);
+      LOG_WARN(LOG_TAG,
+               "%s still processing prior enable request, cannot disable.",
+               __func__);
   } else if (state == LPM_ENABLED && enable) {
     LOG_INFO(LOG_TAG, "%s already enabled.", __func__);
   } else if (state == LPM_DISABLED && !enable) {
@@ -161,7 +161,7 @@ static void enable(bool enable) {
     uint8_t command = enable ? BT_VND_LPM_ENABLE : BT_VND_LPM_DISABLE;
     state = enable ? LPM_ENABLING : LPM_DISABLING;
     if (state == LPM_ENABLING)
-        vendor->send_command(VENDOR_GET_LPM_IDLE_TIMEOUT, &idle_timeout_ms);
+      vendor->send_command(VENDOR_GET_LPM_IDLE_TIMEOUT, &idle_timeout_ms);
     vendor->send_async_command(VENDOR_SET_LPM_MODE, &command);
   }
 }
@@ -192,7 +192,7 @@ static void reset_state() {
   stop_idle_timer();
 }
 
-static void idle_timer_expired(UNUSED_ATTR void *context) {
+static void idle_timer_expired(UNUSED_ATTR voidcontext) {
   if (state == LPM_ENABLED && wake_state == LPM_WAKE_W4_TIMEOUT)
     thread_post(thread, event_idle_timeout, NULL);
 }
@@ -200,36 +200,26 @@ static void idle_timer_expired(UNUSED_ATTR void *context) {
 static void start_idle_timer() {
   if (state == LPM_ENABLED) {
     if (idle_timeout_ms == 0) {
-       wake_deassert();
+      wake_deassert();
     } else {
-       alarm_set(idle_alarm, idle_timeout_ms, idle_timer_expired, NULL);
+      alarm_set(idle_alarm, idle_timeout_ms, idle_timer_expired, NULL);
     }
   }
 }
 
-static void stop_idle_timer() {
-  alarm_cancel(idle_alarm);
-}
+static void stop_idle_timer() { alarm_cancel(idle_alarm); }
 
-static void event_disable(UNUSED_ATTR void *context) {
-  enable(false);
-}
+static void event_disable(UNUSED_ATTR void* context) { enable(false); }
 
-static void event_enable(UNUSED_ATTR void *context) {
-  enable(true);
-}
+static void event_enable(UNUSED_ATTR void* context) { enable(true); }
 
-static void event_wake_assert(UNUSED_ATTR void *context) {
-  wake_assert();
-}
+static void event_wake_assert(UNUSED_ATTR void* context) { wake_assert(); }
 
-static void event_allow_device_sleep(UNUSED_ATTR void *context) {
+static void event_allow_device_sleep(UNUSED_ATTR voidcontext) {
   allow_device_sleep();
 }
 
-static void event_idle_timeout(UNUSED_ATTR void *context) {
-  wake_deassert();
-}
+static void event_idle_timeout(UNUSED_ATTR void* context) { wake_deassert(); }
 
 static void vendor_enable_disable_callback(bool success) {
   if (success)
@@ -242,12 +232,13 @@ static void vendor_enable_disable_callback(bool success) {
   }
 }
 
-const low_power_manager_t *low_power_manager_get_interface() {
+const low_power_manager_tlow_power_manager_get_interface() {
   vendor = vendor_get_interface();
   return &interface;
 }
 
-const low_power_manager_t *low_power_manager_get_test_interface(const vendor_t *vendor_interface) {
+const low_power_manager_t* low_power_manager_get_test_interface(
+    const vendor_t* vendor_interface) {
   vendor = vendor_interface;
   return &interface;
 }
index 1c8a145..f148363 100644 (file)
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
-#define APPLY_CONTINUATION_FLAG(handle) (((handle) & 0xCFFF) | 0x1000)
-#define APPLY_START_FLAG(handle) (((handle) & 0xCFFF) | 0x2000)
-#define SUB_EVENT(event) ((event) & MSG_SUB_EVT_MASK)
+#define APPLY_CONTINUATION_FLAG(handle) (((handle)&0xCFFF) | 0x1000)
+#define APPLY_START_FLAG(handle) (((handle)&0xCFFF) | 0x2000)
+#define SUB_EVENT(event) ((event)&MSG_SUB_EVT_MASK)
 #define GET_BOUNDARY_FLAG(handle) (((handle) >> 12) & 0x0003)
 
 #define HANDLE_MASK 0x0FFF
 #define START_PACKET_BOUNDARY 2
 #define CONTINUATION_PACKET_BOUNDARY 1
-#define L2CAP_HEADER_SIZE       4
+#define L2CAP_HEADER_SIZE 4
 
 // Our interface and callbacks
 
-static const allocator_t *buffer_allocator;
-static const controller_t *controller;
-static const packet_fragmenter_callbacks_t *callbacks;
+static const allocator_tbuffer_allocator;
+static const controller_tcontroller;
+static const packet_fragmenter_callbacks_tcallbacks;
 
 static std::unordered_map<uint16_t /* handle */, BT_HDR*> partial_packets;
 
-static void init(const packet_fragmenter_callbacks_t *result_callbacks) {
+static void init(const packet_fragmenter_callbacks_tresult_callbacks) {
   callbacks = result_callbacks;
 }
 
-static void cleanup() {
-  partial_packets.clear();
-}
+static void cleanup() { partial_packets.clear(); }
 
-static void fragment_and_dispatch(BT_HDR *packet) {
+static void fragment_and_dispatch(BT_HDRpacket) {
   assert(packet != NULL);
 
   uint16_t event = packet->event & MSG_EVT_MASK;
-  uint8_t *stream = packet->data + packet->offset;
+  uint8_tstream = packet->data + packet->offset;
 
   // We only fragment ACL packets
   if (event != MSG_STACK_TO_HC_HCI_ACL) {
@@ -70,9 +68,9 @@ static void fragment_and_dispatch(BT_HDR *packet) {
   }
 
   uint16_t max_data_size =
-    SUB_EVENT(packet->event) == LOCAL_BR_EDR_CONTROLLER_ID ?
-      controller->get_acl_data_size_classic() :
-      controller->get_acl_data_size_ble();
+      SUB_EVENT(packet->event) == LOCAL_BR_EDR_CONTROLLER_ID
+          ? controller->get_acl_data_size_classic()
+          : controller->get_acl_data_size_ble();
 
   uint16_t max_packet_size = max_data_size + HCI_ACL_PREAMBLE_SIZE;
   uint16_t remaining_length = packet->len;
@@ -99,7 +97,8 @@ static void fragment_and_dispatch(BT_HDR *packet) {
     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
+    // Apparently L2CAP can set layer_specific to a max number of segments to
+    // transmit
     if (packet->layer_specific) {
       packet->layer_specific--;
 
@@ -118,9 +117,9 @@ static bool check_uint16_overflow(uint16_t a, uint16_t b) {
   return (UINT16_MAX - a) < b;
 }
 
-static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) {
+static void reassemble_and_dispatch(UNUSED_ATTR BT_HDRpacket) {
   if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) {
-    uint8_t *stream = packet->data;
+    uint8_tstream = packet->data;
     uint16_t handle;
     uint16_t l2cap_length;
     uint16_t acl_length;
@@ -137,39 +136,51 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) {
     if (boundary_flag == START_PACKET_BOUNDARY) {
       auto map_iter = partial_packets.find(handle);
       if (map_iter != partial_packets.end()) {
-        LOG_WARN(LOG_TAG, "%s found unfinished packet for handle with start packet. Dropping old.", __func__);
+        LOG_WARN(LOG_TAG,
+                 "%s found unfinished packet for handle with start packet. "
+                 "Dropping old.",
+                 __func__);
 
-        BT_HDR *hdl = map_iter->second;
+        BT_HDRhdl = map_iter->second;
         partial_packets.erase(map_iter);
         buffer_allocator->free(hdl);
       }
 
       if (acl_length < L2CAP_HEADER_SIZE) {
-        LOG_WARN(LOG_TAG, "%s L2CAP packet too small (%d < %d). Dropping it.", __func__, packet->len, L2CAP_HEADER_SIZE);
+        LOG_WARN(LOG_TAG, "%s L2CAP packet too small (%d < %d). Dropping it.",
+                 __func__, packet->len, L2CAP_HEADER_SIZE);
         buffer_allocator->free(packet);
         return;
       }
 
-      uint16_t full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
+      uint16_t full_length =
+          l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
 
-      // Check for buffer overflow and that the full packet size + BT_HDR size is less than
+      // Check for buffer overflow and that the full packet size + BT_HDR size
+      // is less than
       // the max buffer size
-      if (check_uint16_overflow(l2cap_length, (L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE)) ||
+      if (check_uint16_overflow(l2cap_length,
+                                (L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE)) ||
           ((full_length + sizeof(BT_HDR)) > BT_DEFAULT_BUFFER_SIZE)) {
-        LOG_ERROR(LOG_TAG, "%s L2CAP packet has invalid length (%d). Dropping it.", __func__, l2cap_length);
+        LOG_ERROR(LOG_TAG,
+                  "%s L2CAP packet has invalid length (%d). Dropping it.",
+                  __func__, l2cap_length);
         buffer_allocator->free(packet);
         return;
       }
 
       if (full_length <= packet->len) {
         if (full_length < packet->len)
-          LOG_WARN(LOG_TAG, "%s found l2cap full length %d less than the hci length %d.", __func__, l2cap_length, packet->len);
+          LOG_WARN(LOG_TAG,
+                   "%s found l2cap full length %d less than the hci length %d.",
+                   __func__, l2cap_length, packet->len);
 
         callbacks->reassembled(packet);
         return;
       }
 
-      BT_HDR *partial_packet = (BT_HDR *)buffer_allocator->alloc(full_length + sizeof(BT_HDR));
+      BT_HDR* 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;
@@ -178,7 +189,7 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) {
 
       // Update the ACL data size to indicate the full expected length
       stream = partial_packet->data;
-      STREAM_SKIP_UINT16(stream); // skip the handle
+      STREAM_SKIP_UINT16(stream);  // skip the handle
       UINT16_TO_STREAM(stream, full_length - HCI_ACL_PREAMBLE_SIZE);
 
       partial_packets[handle] = partial_packet;
@@ -188,25 +199,29 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) {
     } else {
       auto map_iter = partial_packets.find(handle);
       if (map_iter == partial_packets.end()) {
-        LOG_WARN(LOG_TAG, "%s got continuation for unknown packet. Dropping it.", __func__);
+        LOG_WARN(LOG_TAG,
+                 "%s got continuation for unknown packet. Dropping it.",
+                 __func__);
         buffer_allocator->free(packet);
         return;
       }
-      BT_HDR *partial_packet = map_iter->second;
+      BT_HDRpartial_packet = map_iter->second;
 
       packet->offset = HCI_ACL_PREAMBLE_SIZE;
-      uint16_t projected_offset = partial_packet->offset + (packet->len - HCI_ACL_PREAMBLE_SIZE);
-      if (projected_offset > partial_packet->len) { // len stores the expected length
-        LOG_WARN(LOG_TAG, "%s got packet which would exceed expected length of %d. Truncating.", __func__, partial_packet->len);
+      uint16_t projected_offset =
+          partial_packet->offset + (packet->len - HCI_ACL_PREAMBLE_SIZE);
+      if (projected_offset >
+          partial_packet->len) {  // len stores the expected length
+        LOG_WARN(LOG_TAG,
+                 "%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
-      );
+      memcpy(partial_packet->data + partial_packet->offset,
+             packet->data + packet->offset, packet->len - packet->offset);
 
       // Free the old packet buffer, since we don't need it anymore
       buffer_allocator->free(packet);
@@ -223,23 +238,20 @@ static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) {
   }
 }
 
-static const packet_fragmenter_t interface = {
-  init,
-  cleanup,
+static const packet_fragmenter_t interface = {init, cleanup,
 
-  fragment_and_dispatch,
-  reassemble_and_dispatch
-};
+                                              fragment_and_dispatch,
+                                              reassemble_and_dispatch};
 
-const packet_fragmenter_t *packet_fragmenter_get_interface() {
+const packet_fragmenter_tpacket_fragmenter_get_interface() {
   controller = controller_get_interface();
   buffer_allocator = buffer_allocator_get_interface();
   return &interface;
 }
 
-const packet_fragmenter_t *packet_fragmenter_get_test_interface(
-    const controller_t *controller_interface,
-    const allocator_t *buffer_allocator_interface) {
+const packet_fragmenter_tpacket_fragmenter_get_test_interface(
+    const controller_tcontroller_interface,
+    const allocator_tbuffer_allocator_interface) {
   controller = controller_interface;
   buffer_allocator = buffer_allocator_interface;
   return &interface;
index bc90229..1c1ab8c 100644 (file)
 #include <assert.h>
 #include <dlfcn.h>
 
-#include "buffer_allocator.h"
 #include "bt_vendor_lib.h"
 #include "bta_av_api.h"
+#include "buffer_allocator.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
-
-static bool vendor_open(const uint8_t *local_bdaddr,
-                        const hci_t *hci_interface);
+static bool vendor_open(const uint8_t* local_bdaddr,
+                        const hci_t* hci_interface);
 static void vendor_close(void);
-static int send_command(vendor_opcode_t opcode, void *param);
-static int send_async_command(vendor_async_opcode_t opcode, void *param);
+static int send_command(vendor_opcode_t opcode, voidparam);
+static int send_async_command(vendor_async_opcode_t opcode, voidparam);
 static void set_callback(vendor_async_opcode_t opcode, vendor_cb callback);
 
 static void firmware_config_cb(bt_vendor_op_result_t result);
 static void sco_config_cb(bt_vendor_op_result_t result);
 static void low_power_mode_cb(bt_vendor_op_result_t result);
 static void sco_audiostate_cb(bt_vendor_op_result_t result);
-static void *buffer_alloc_cb(int size);
-static void buffer_free_cb(void *buffer);
-static uint8_t transmit_cb(UNUSED_ATTR uint16_t opcode, void *buffer,
+static voidbuffer_alloc_cb(int size);
+static void buffer_free_cb(voidbuffer);
+static uint8_t transmit_cb(UNUSED_ATTR uint16_t opcode, voidbuffer,
                            tINT_CMD_CBACK callback);
 static void epilog_cb(bt_vendor_op_result_t result);
-static void a2dp_offload_cb(bt_vendor_op_result_t result,
-                            bt_vendor_opcode_t op, uint8_t bta_av_handle);
+static void a2dp_offload_cb(bt_vendor_op_result_t result, bt_vendor_opcode_t op,
+                            uint8_t bta_av_handle);
 
-static const char *VENDOR_LIBRARY_NAME = "libbt-vendor.so";
-static const char *VENDOR_LIBRARY_SYMBOL_NAME = "BLUETOOTH_VENDOR_LIB_INTERFACE";
+static const char* VENDOR_LIBRARY_NAME = "libbt-vendor.so";
+static const char* VENDOR_LIBRARY_SYMBOL_NAME =
+    "BLUETOOTH_VENDOR_LIB_INTERFACE";
 
-static const allocator_t *buffer_allocator;
-static const hci_t *hci;
+static const allocator_tbuffer_allocator;
+static const hci_thci;
 static vendor_cb callbacks[VENDOR_LAST_OP];
 
 static const bt_vendor_callbacks_t lib_callbacks = {
-  sizeof(lib_callbacks),
-  firmware_config_cb,
-  sco_config_cb,
-  low_power_mode_cb,
-  sco_audiostate_cb,
-  buffer_alloc_cb,
-  buffer_free_cb,
-  transmit_cb,
-  epilog_cb,
-  a2dp_offload_cb
-};
+    sizeof(lib_callbacks), firmware_config_cb, sco_config_cb,
+    low_power_mode_cb,     sco_audiostate_cb,  buffer_alloc_cb,
+    buffer_free_cb,        transmit_cb,        epilog_cb,
+    a2dp_offload_cb};
 
 static const vendor_t interface = {
-  vendor_open,
-  vendor_close,
-  send_command,
-  send_async_command,
-  set_callback,
+    vendor_open, vendor_close, send_command, send_async_command, set_callback,
 };
 
-static void *lib_handle;
-static bt_vendor_interface_t *lib_interface;
+static voidlib_handle;
+static bt_vendor_interface_tlib_interface;
 
 // Interface functions
 
-static bool vendor_open(
-    const uint8_t *local_bdaddr,
-    const hci_t *hci_interface) {
+static bool vendor_open(const uint8_t* local_bdaddr,
+                        const hci_t* hci_interface) {
   int status;
   assert(lib_handle == NULL);
   hci = hci_interface;
 
   lib_handle = dlopen(VENDOR_LIBRARY_NAME, RTLD_NOW);
   if (!lib_handle) {
-    LOG_ERROR(LOG_TAG, "%s unable to open %s: %s", __func__, VENDOR_LIBRARY_NAME, dlerror());
+    LOG_ERROR(LOG_TAG, "%s unable to open %s: %s", __func__,
+              VENDOR_LIBRARY_NAME, dlerror());
     goto error;
   }
 
-  lib_interface = (bt_vendor_interface_t *)dlsym(lib_handle, VENDOR_LIBRARY_SYMBOL_NAME);
+  lib_interface =
+      (bt_vendor_interface_t*)dlsym(lib_handle, VENDOR_LIBRARY_SYMBOL_NAME);
   if (!lib_interface) {
-    LOG_ERROR(LOG_TAG, "%s unable to find symbol %s in %s: %s", __func__, VENDOR_LIBRARY_SYMBOL_NAME, VENDOR_LIBRARY_NAME, dlerror());
+    LOG_ERROR(LOG_TAG, "%s unable to find symbol %s in %s: %s", __func__,
+              VENDOR_LIBRARY_SYMBOL_NAME, VENDOR_LIBRARY_NAME, dlerror());
     goto error;
   }
 
   LOG_INFO(LOG_TAG, "alloc value %p", lib_callbacks.alloc);
 
-  status = lib_interface->init(&lib_callbacks, (unsigned char *)local_bdaddr);
+  status = lib_interface->init(&lib_callbacks, (unsigned char*)local_bdaddr);
   if (status) {
-    LOG_ERROR(LOG_TAG, "%s unable to initialize vendor library: %d", __func__, status);
+    LOG_ERROR(LOG_TAG, "%s unable to initialize vendor library: %d", __func__,
+              status);
     goto error;
   }
 
@@ -113,29 +105,26 @@ static bool vendor_open(
 
 error:;
   lib_interface = NULL;
-  if (lib_handle)
-    dlclose(lib_handle);
+  if (lib_handle) dlclose(lib_handle);
   lib_handle = NULL;
   return false;
 }
 
 static void vendor_close(void) {
-  if (lib_interface)
-    lib_interface->cleanup();
+  if (lib_interface) lib_interface->cleanup();
 
-  if (lib_handle)
-    dlclose(lib_handle);
+  if (lib_handle) dlclose(lib_handle);
 
   lib_interface = NULL;
   lib_handle = NULL;
 }
 
-static int send_command(vendor_opcode_t opcode, void *param) {
+static int send_command(vendor_opcode_t opcode, voidparam) {
   assert(lib_interface != NULL);
   return lib_interface->op((bt_vendor_opcode_t)opcode, param);
 }
 
-static int send_async_command(vendor_async_opcode_t opcode, void *param) {
+static int send_async_command(vendor_async_opcode_t opcode, voidparam) {
   assert(lib_interface != NULL);
   return lib_interface->op((bt_vendor_opcode_t)opcode, param);
 }
@@ -175,35 +164,30 @@ static void low_power_mode_cb(bt_vendor_op_result_t result) {
 }
 
 /******************************************************************************
-**
-** Function         sco_audiostate_cb
-**
-** Description      HOST/CONTROLLER VENDOR LIB CALLBACK API - This function is
-**                  called when the libbt-vendor completed vendor specific codec
-**                  setup request
-**
-** Returns          None
-**
-******************************************************************************/
-static void sco_audiostate_cb(bt_vendor_op_result_t result)
-{
-    uint8_t status = (result == BT_VND_OP_RESULT_SUCCESS) ? 0 : 1;
-
-    LOG_INFO(LOG_TAG, "sco_audiostate_cb(status: %d)",status);
+ *
+ * Function         sco_audiostate_cb
+ *
+ * Description      HOST/CONTROLLER VENDOR LIB CALLBACK API - This function is
+ *                  called when the libbt-vendor completed vendor specific codec
+ *                  setup request
+ *
+ * Returns          None
+ *
+ *****************************************************************************/
+static void sco_audiostate_cb(bt_vendor_op_result_t result) {
+  uint8_t status = (result == BT_VND_OP_RESULT_SUCCESS) ? 0 : 1;
+
+  LOG_INFO(LOG_TAG, "sco_audiostate_cb(status: %d)", status);
 }
 
 // Called by vendor library when it needs an HCI buffer.
-static void *buffer_alloc_cb(int size) {
-  return buffer_allocator->alloc(size);
-}
+static void* buffer_alloc_cb(int size) { return buffer_allocator->alloc(size); }
 
 // Called by vendor library when it needs to free a buffer allocated with
 // |buffer_alloc_cb|.
-static void buffer_free_cb(void *buffer) {
-  buffer_allocator->free(buffer);
-}
+static void buffer_free_cb(void* buffer) { buffer_allocator->free(buffer); }
 
-static void transmit_completed_callback(BT_HDR *response, void *context) {
+static void transmit_completed_callback(BT_HDR* response, void* context) {
   // Call back to the vendor library if it provided a callback to call.
   if (context) {
     ((tINT_CMD_CBACK)context)(response);
@@ -214,10 +198,11 @@ static void transmit_completed_callback(BT_HDR *response, void *context) {
 }
 
 // Called back from vendor library when it wants to send an HCI command.
-static uint8_t transmit_cb(UNUSED_ATTR uint16_t opcode, void *buffer, tINT_CMD_CBACK callback) {
+static uint8_t transmit_cb(UNUSED_ATTR uint16_t opcode, void* buffer,
+                           tINT_CMD_CBACK callback) {
   assert(hci != NULL);
-  hci->transmit_command((BT_HDR *)buffer, transmit_completed_callback, NULL,
-                        reinterpret_cast<void *>(callback));
+  hci->transmit_command((BT_HDR*)buffer, transmit_completed_callback, NULL,
+                        reinterpret_cast<void*>(callback));
   return true;
 }
 
@@ -231,17 +216,21 @@ static void epilog_cb(bt_vendor_op_result_t result) {
   callback(result == BT_VND_OP_RESULT_SUCCESS);
 }
 
-// Called back from vendor library when the a2dp offload machine has to report status of
+// Called back from vendor library when the a2dp offload machine has to report
+// status of
 // an a2dp offload command.
-static void a2dp_offload_cb(bt_vendor_op_result_t result, bt_vendor_opcode_t op, uint8_t bta_av_handle) {
-  tBTA_AV_STATUS status = (result == BT_VND_OP_RESULT_SUCCESS) ? BTA_AV_SUCCESS : BTA_AV_FAIL_RESOURCES;
+static void a2dp_offload_cb(bt_vendor_op_result_t result, bt_vendor_opcode_t op,
+                            uint8_t bta_av_handle) {
+  tBTA_AV_STATUS status = (result == BT_VND_OP_RESULT_SUCCESS)
+                              ? BTA_AV_SUCCESS
+                              : BTA_AV_FAIL_RESOURCES;
 
   if (op == BT_VND_OP_A2DP_OFFLOAD_START) {
-      BTA_AvOffloadStartRsp(bta_av_handle, status);
+    BTA_AvOffloadStartRsp(bta_av_handle, status);
   }
 }
 
-const vendor_t *vendor_get_interface() {
+const vendor_tvendor_get_interface() {
   buffer_allocator = buffer_allocator_get_interface();
   return &interface;
 }
index 9ea6cdf..4d9ff86 100644 (file)
 #include "AllocationTestHarness.h"
 
 #include <stdint.h>
-#include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <unistd.h>
 
+#include "hci_hal.h"
 #include "osi/include/osi.h"
 #include "osi/include/semaphore.h"
-#include "hci_hal.h"
 #include "test_stubs.h"
 #include "vendor.h"
 
-DECLARE_TEST_MODES(
-  init,
-  open,
-  close_fn,
-  transmit,
-  read_synchronous,
-  read_async_reentry,
-  type_byte_only
-);
+DECLARE_TEST_MODES(init, open, close_fn, transmit, read_synchronous,
+                   read_async_reentry, type_byte_only);
 
 // Use as packet type to test stream_corrupted_during_le_scan_workaround()
 static const uint8_t HCI_BLE_EVENT = 0x3e;
@@ -47,21 +40,25 @@ static const uint8_t HCI_BLE_EVENT = 0x3e;
 static char sample_data1[100] = "A point is that which has no part.";
 static char sample_data2[100] = "A line is breadthless length.";
 static char sample_data3[100] = "The ends of a line are points.";
-static char acl_data[100] =     "A straight line is a line which lies evenly with the points on itself.";
-static char sco_data[100] =     "A surface is that which has length and breadth only.";
-static char event_data[100] =   "The edges of a surface are lines.";
+static char acl_data[100] =
+    "A straight line is a line which lies evenly with the points on itself.";
+static char sco_data[100] =
+    "A surface is that which has length and breadth only.";
+static char event_data[100] = "The edges of a surface are lines.";
 
 // Test data for stream_corrupted_during_le_scan_workaround()
-static char corrupted_data[] = { 0x5 /* length of remaining data */, 'H', 'e', 'l', 'l', 'o' };
+static char corrupted_data[] = {
+    0x5 /* length of remaining data */, 'H', 'e', 'l', 'l', 'o'};
 
-static const hci_hal_t *hal;
+static const hci_hal_thal;
 static int dummy_serial_fd;
 static int reentry_i = 0;
 
-static semaphore_t *done;
-static semaphore_t *reentry_semaphore;
+static semaphore_tdone;
+static semaphore_treentry_semaphore;
 
-static void expect_packet_synchronous(serial_data_type_t type, char *packet_data) {
+static void expect_packet_synchronous(serial_data_type_t type,
+                                      char* packet_data) {
   int length = strlen(packet_data);
   for (int i = 0; i < length; i++) {
     uint8_t byte;
@@ -72,62 +69,62 @@ static void expect_packet_synchronous(serial_data_type_t type, char *packet_data
   hal->packet_finished(type);
 }
 
-STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void *param))
-  DURING(open) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_OPEN_USERIAL, opcode);
-    // Give back the dummy fd and the number 1 to say we opened 1 port
-    ((int *)param)[0] = dummy_serial_fd;
-    return 1;
-  }
-
-  DURING(close_fn) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_CLOSE_USERIAL, opcode);
-    return 0;
-  }
+STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void* param))
+DURING(open) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_OPEN_USERIAL, opcode);
+  // Give back the dummy fd and the number 1 to say we opened 1 port
+  ((int*)param)[0] = dummy_serial_fd;
+  return 1;
+}
 
-  UNEXPECTED_CALL;
+DURING(close_fn) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_CLOSE_USERIAL, opcode);
   return 0;
 }
 
-STUB_FUNCTION(void, data_ready_callback, (serial_data_type_t type))
-  DURING(read_synchronous) {
-    AT_CALL(0) {
-      EXPECT_EQ(DATA_TYPE_ACL, type);
-      expect_packet_synchronous(type, acl_data);
-      return;
-    }
-    AT_CALL(1) {
-      EXPECT_EQ(DATA_TYPE_SCO, type);
-      expect_packet_synchronous(type, sco_data);
-      return;
-    }
-    AT_CALL(2) {
-      EXPECT_EQ(DATA_TYPE_EVENT, type);
-      expect_packet_synchronous(type, event_data);
-      semaphore_post(done);
-      return;
-    }
-  }
+UNEXPECTED_CALL;
+return 0;
+}
 
-  DURING(read_async_reentry) {
+STUB_FUNCTION(void, data_ready_callback, (serial_data_type_t type))
+DURING(read_synchronous) {
+  AT_CALL(0) {
     EXPECT_EQ(DATA_TYPE_ACL, type);
+    expect_packet_synchronous(type, acl_data);
+    return;
+  }
+  AT_CALL(1) {
+    EXPECT_EQ(DATA_TYPE_SCO, type);
+    expect_packet_synchronous(type, sco_data);
+    return;
+  }
+  AT_CALL(2) {
+    EXPECT_EQ(DATA_TYPE_EVENT, type);
+    expect_packet_synchronous(type, event_data);
+    semaphore_post(done);
+    return;
+  }
+}
 
-    uint8_t byte;
-    size_t bytes_read;
-    while ((bytes_read = hal->read_data(type, &byte, 1)) != 0) {
-      EXPECT_EQ(sample_data3[reentry_i], byte);
-      semaphore_post(reentry_semaphore);
-      reentry_i++;
-      if (reentry_i == (int)strlen(sample_data3)) {
-        hal->packet_finished(type);
-        return;
-      }
+DURING(read_async_reentry) {
+  EXPECT_EQ(DATA_TYPE_ACL, type);
+
+  uint8_t byte;
+  size_t bytes_read;
+  while ((bytes_read = hal->read_data(type, &byte, 1)) != 0) {
+    EXPECT_EQ(sample_data3[reentry_i], byte);
+    semaphore_post(reentry_semaphore);
+    reentry_i++;
+    if (reentry_i == (int)strlen(sample_data3)) {
+      hal->packet_finished(type);
+      return;
     }
-
-    return;
   }
 
-  UNEXPECTED_CALL;
+  return;
+}
+
+UNEXPECTED_CALL;
 }
 
 static void reset_for(TEST_MODES_T next) {
@@ -137,44 +134,44 @@ static void reset_for(TEST_MODES_T next) {
 }
 
 class HciHalH4Test : public AllocationTestHarness {
 protected:
-    virtual void SetUp() {
-      AllocationTestHarness::SetUp();
-      hal = hci_hal_h4_get_test_interface(&vendor);
-      vendor.send_command = vendor_send_command;
-      callbacks.data_ready = data_ready_callback;
-
-      socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd);
-      dummy_serial_fd = sockfd[0];
-      done = semaphore_new(0);
-      thread = thread_new("hal_test");
-
-      reset_for(init);
-      EXPECT_TRUE(hal->init(&callbacks, thread));
-
-      reset_for(open);
-      EXPECT_TRUE(hal->open());
-      EXPECT_CALL_COUNT(vendor_send_command, 1);
-    }
+ protected:
+  virtual void SetUp() {
+    AllocationTestHarness::SetUp();
+    hal = hci_hal_h4_get_test_interface(&vendor);
+    vendor.send_command = vendor_send_command;
+    callbacks.data_ready = data_ready_callback;
+
+    socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd);
+    dummy_serial_fd = sockfd[0];
+    done = semaphore_new(0);
+    thread = thread_new("hal_test");
+
+    reset_for(init);
+    EXPECT_TRUE(hal->init(&callbacks, thread));
+
+    reset_for(open);
+    EXPECT_TRUE(hal->open());
+    EXPECT_CALL_COUNT(vendor_send_command, 1);
+  }
 
-    virtual void TearDown() {
-      reset_for(close_fn);
-      hal->close();
-      EXPECT_CALL_COUNT(vendor_send_command, 1);
+  virtual void TearDown() {
+    reset_for(close_fn);
+    hal->close();
+    EXPECT_CALL_COUNT(vendor_send_command, 1);
 
-      semaphore_free(done);
-      thread_free(thread);
-      AllocationTestHarness::TearDown();
-    }
+    semaphore_free(done);
+    thread_free(thread);
+    AllocationTestHarness::TearDown();
+  }
 
-    int sockfd[2];
-    vendor_t vendor;
-    thread_t *thread;
-    hci_hal_callbacks_t callbacks;
+  int sockfd[2];
+  vendor_t vendor;
+  thread_t* thread;
+  hci_hal_callbacks_t callbacks;
 };
 
-static void expect_socket_data(int fd, char first_byte, char *data) {
-  int length = strlen(data) + 1; // + 1 for data type code
+static void expect_socket_data(int fd, char first_byte, chardata) {
+  int length = strlen(data) + 1;  // + 1 for data type code
   int i;
 
   for (i = 0; i < length; i++) {
@@ -190,18 +187,18 @@ static void expect_socket_data(int fd, char first_byte, char *data) {
   }
 }
 
-static void write_packet(int fd, char first_byte, const void *data,
+static void write_packet(int fd, char first_byte, const voiddata,
                          size_t datalen) {
   write(fd, &first_byte, 1);
   write(fd, data, datalen);
 }
 
-static void write_packet_reentry(int fd, char first_byte, const void *data,
+static void write_packet_reentry(int fd, char first_byte, const voiddata,
                                  size_t datalen) {
   write(fd, &first_byte, 1);
 
   for (size_t i = 0; i < datalen; i++) {
-    write(fd, static_cast<const uint8_t *>(data) + i, 1);
+    write(fd, static_cast<const uint8_t*>(data) + i, 1);
     semaphore_wait(reentry_semaphore);
   }
 }
@@ -210,15 +207,18 @@ TEST_F(HciHalH4Test, test_transmit) {
   reset_for(transmit);
 
   // Send a command packet
-  hal->transmit_data(DATA_TYPE_COMMAND, (uint8_t *)(sample_data1 + 1), strlen(sample_data1 + 1));
+  hal->transmit_data(DATA_TYPE_COMMAND, (uint8_t*)(sample_data1 + 1),
+                     strlen(sample_data1 + 1));
   expect_socket_data(sockfd[1], DATA_TYPE_COMMAND, sample_data1 + 1);
 
   // Send an acl packet
-  hal->transmit_data(DATA_TYPE_ACL, (uint8_t *)(sample_data2 + 1), strlen(sample_data2 + 1));
+  hal->transmit_data(DATA_TYPE_ACL, (uint8_t*)(sample_data2 + 1),
+                     strlen(sample_data2 + 1));
   expect_socket_data(sockfd[1], DATA_TYPE_ACL, sample_data2 + 1);
 
   // Send an sco packet
-  hal->transmit_data(DATA_TYPE_SCO, (uint8_t *)(sample_data3 + 1), strlen(sample_data3 + 1));
+  hal->transmit_data(DATA_TYPE_SCO, (uint8_t*)(sample_data3 + 1),
+                     strlen(sample_data3 + 1));
   expect_socket_data(sockfd[1], DATA_TYPE_SCO, sample_data3 + 1);
 }
 
@@ -267,5 +267,5 @@ TEST_F(HciHalH4Test, test_type_byte_only_must_not_signal_data_ready) {
     timeout.tv_usec = 0;
 
     select(sockfd[0] + 1, &read_fds, NULL, NULL, &timeout);
-  } while(FD_ISSET(sockfd[0], &read_fds));
+  } while (FD_ISSET(sockfd[0], &read_fds));
 }
index caf81ec..dd1b70d 100644 (file)
 #include "AllocationTestHarness.h"
 
 #include <stdint.h>
-#include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <unistd.h>
 
+#include "hci_hal.h"
 #include "osi/include/osi.h"
 #include "osi/include/semaphore.h"
-#include "hci_hal.h"
 #include "test_stubs.h"
 #include "vendor.h"
 
-DECLARE_TEST_MODES(
-  init,
-  open,
-  close_fn,
-  transmit,
-  read_synchronous,
-  read_async_reentry
-);
+DECLARE_TEST_MODES(init, open, close_fn, transmit, read_synchronous,
+                   read_async_reentry);
 
 static char sample_data1[100] = "A point is that which has no part.";
 static char sample_data2[100] = "A line is breadthless length.";
 static char sample_data3[100] = "The ends of a line are points.";
-static char acl_data[100] =     "A straight line is a line which lies evenly with the points on itself.";
-static char event_data[100] =   "The edges of a surface are lines.";
+static char acl_data[100] =
+    "A straight line is a line which lies evenly with the points on itself.";
+static char event_data[100] = "The edges of a surface are lines.";
 
-static const hci_hal_t *hal;
+static const hci_hal_thal;
 static int command_out_fd;
 static int acl_out_fd;
 static int acl_in_fd;
 static int event_in_fd;
 static int reentry_i = 0;
 
-static semaphore_t *done;
-static semaphore_t *reentry_semaphore;
+static semaphore_tdone;
+static semaphore_treentry_semaphore;
 
-static void expect_packet_synchronous(serial_data_type_t type, char *packet_data) {
+static void expect_packet_synchronous(serial_data_type_t type,
+                                      char* packet_data) {
   int length = strlen(packet_data);
   for (int i = 0; i < length; i++) {
     uint8_t byte;
@@ -67,60 +63,60 @@ static void expect_packet_synchronous(serial_data_type_t type, char *packet_data
   hal->packet_finished(type);
 }
 
-STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void *param))
-  DURING(open) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_OPEN_USERIAL, opcode);
-    ((int *)param)[CH_CMD] = command_out_fd;
-    ((int *)param)[CH_ACL_OUT] = acl_out_fd;
-    ((int *)param)[CH_ACL_IN] = acl_in_fd;
-    ((int *)param)[CH_EVT] = event_in_fd;
-    return 4;
-  }
-
-  DURING(close_fn) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_CLOSE_USERIAL, opcode);
-    return 0;
-  }
+STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void* param))
+DURING(open) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_OPEN_USERIAL, opcode);
+  ((int*)param)[CH_CMD] = command_out_fd;
+  ((int*)param)[CH_ACL_OUT] = acl_out_fd;
+  ((int*)param)[CH_ACL_IN] = acl_in_fd;
+  ((int*)param)[CH_EVT] = event_in_fd;
+  return 4;
+}
 
-  UNEXPECTED_CALL;
+DURING(close_fn) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_CLOSE_USERIAL, opcode);
   return 0;
 }
 
-STUB_FUNCTION(void, data_ready_callback, (serial_data_type_t type))
-  DURING(read_synchronous) {
-    AT_CALL(0) {
-      EXPECT_EQ(DATA_TYPE_ACL, type);
-      expect_packet_synchronous(type, acl_data);
-      semaphore_post(done);
-      return;
-    }
-    AT_CALL(1) {
-      EXPECT_EQ(DATA_TYPE_EVENT, type);
-      expect_packet_synchronous(type, event_data);
-      semaphore_post(done);
-      return;
-    }
-  }
+UNEXPECTED_CALL;
+return 0;
+}
 
-  DURING(read_async_reentry) {
+STUB_FUNCTION(void, data_ready_callback, (serial_data_type_t type))
+DURING(read_synchronous) {
+  AT_CALL(0) {
     EXPECT_EQ(DATA_TYPE_ACL, type);
+    expect_packet_synchronous(type, acl_data);
+    semaphore_post(done);
+    return;
+  }
+  AT_CALL(1) {
+    EXPECT_EQ(DATA_TYPE_EVENT, type);
+    expect_packet_synchronous(type, event_data);
+    semaphore_post(done);
+    return;
+  }
+}
 
-    uint8_t byte;
-    size_t bytes_read;
-    while ((bytes_read = hal->read_data(type, &byte, 1)) != 0) {
-      EXPECT_EQ(sample_data3[reentry_i], byte);
-      semaphore_post(reentry_semaphore);
-      reentry_i++;
-      if (reentry_i == (int)strlen(sample_data3)) {
-        hal->packet_finished(type);
-        return;
-      }
+DURING(read_async_reentry) {
+  EXPECT_EQ(DATA_TYPE_ACL, type);
+
+  uint8_t byte;
+  size_t bytes_read;
+  while ((bytes_read = hal->read_data(type, &byte, 1)) != 0) {
+    EXPECT_EQ(sample_data3[reentry_i], byte);
+    semaphore_post(reentry_semaphore);
+    reentry_i++;
+    if (reentry_i == (int)strlen(sample_data3)) {
+      hal->packet_finished(type);
+      return;
     }
-
-    return;
   }
 
-  UNEXPECTED_CALL;
+  return;
+}
+
+UNEXPECTED_CALL;
 }
 
 static void reset_for(TEST_MODES_T next) {
@@ -130,53 +126,53 @@ static void reset_for(TEST_MODES_T next) {
 }
 
 class HciHalMctTest : public AllocationTestHarness {
 protected:
-    virtual void SetUp() {
-      AllocationTestHarness::SetUp();
-      hal = hci_hal_mct_get_test_interface(&vendor);
-      vendor.send_command = vendor_send_command;
-      callbacks.data_ready = data_ready_callback;
-
-      socketpair(AF_LOCAL, SOCK_STREAM, 0, command_sockfd);
-      socketpair(AF_LOCAL, SOCK_STREAM, 0, event_sockfd);
-      socketpair(AF_LOCAL, SOCK_STREAM, 0, acl_in_sockfd);
-      socketpair(AF_LOCAL, SOCK_STREAM, 0, acl_out_sockfd);
-      command_out_fd = command_sockfd[0];
-      acl_out_fd = acl_out_sockfd[0];
-      acl_in_fd = acl_in_sockfd[0];
-      event_in_fd = event_sockfd[0];
-
-      done = semaphore_new(0);
-      thread = thread_new("hal_test");
-
-      reset_for(init);
-      EXPECT_TRUE(hal->init(&callbacks, thread));
-
-      reset_for(open);
-      EXPECT_TRUE(hal->open());
-      EXPECT_CALL_COUNT(vendor_send_command, 1);
-    }
+ protected:
+  virtual void SetUp() {
+    AllocationTestHarness::SetUp();
+    hal = hci_hal_mct_get_test_interface(&vendor);
+    vendor.send_command = vendor_send_command;
+    callbacks.data_ready = data_ready_callback;
+
+    socketpair(AF_LOCAL, SOCK_STREAM, 0, command_sockfd);
+    socketpair(AF_LOCAL, SOCK_STREAM, 0, event_sockfd);
+    socketpair(AF_LOCAL, SOCK_STREAM, 0, acl_in_sockfd);
+    socketpair(AF_LOCAL, SOCK_STREAM, 0, acl_out_sockfd);
+    command_out_fd = command_sockfd[0];
+    acl_out_fd = acl_out_sockfd[0];
+    acl_in_fd = acl_in_sockfd[0];
+    event_in_fd = event_sockfd[0];
+
+    done = semaphore_new(0);
+    thread = thread_new("hal_test");
+
+    reset_for(init);
+    EXPECT_TRUE(hal->init(&callbacks, thread));
+
+    reset_for(open);
+    EXPECT_TRUE(hal->open());
+    EXPECT_CALL_COUNT(vendor_send_command, 1);
+  }
 
-    virtual void TearDown() {
-      reset_for(close_fn);
-      hal->close();
-      EXPECT_CALL_COUNT(vendor_send_command, 1);
+  virtual void TearDown() {
+    reset_for(close_fn);
+    hal->close();
+    EXPECT_CALL_COUNT(vendor_send_command, 1);
 
-      semaphore_free(done);
-      thread_free(thread);
-      AllocationTestHarness::TearDown();
-    }
+    semaphore_free(done);
+    thread_free(thread);
+    AllocationTestHarness::TearDown();
+  }
 
-    int command_sockfd[2];
-    int event_sockfd[2];
-    int acl_in_sockfd[2];
-    int acl_out_sockfd[2];
-    vendor_t vendor;
-    thread_t *thread;
-    hci_hal_callbacks_t callbacks;
+  int command_sockfd[2];
+  int event_sockfd[2];
+  int acl_in_sockfd[2];
+  int acl_out_sockfd[2];
+  vendor_t vendor;
+  thread_t* thread;
+  hci_hal_callbacks_t callbacks;
 };
 
-static void expect_socket_data(int fd, char *data) {
+static void expect_socket_data(int fd, chardata) {
   int length = strlen(data);
   int i;
 
@@ -193,11 +189,9 @@ static void expect_socket_data(int fd, char *data) {
   }
 }
 
-static void write_packet(int fd, char *data) {
-  write(fd, data, strlen(data));
-}
+static void write_packet(int fd, char* data) { write(fd, data, strlen(data)); }
 
-static void write_packet_reentry(int fd, char *data) {
+static void write_packet_reentry(int fd, chardata) {
   int length = strlen(data);
   for (int i = 0; i < length; i++) {
     write(fd, &data[i], 1);
@@ -209,11 +203,13 @@ TEST_F(HciHalMctTest, test_transmit) {
   reset_for(transmit);
 
   // Send a command packet
-  hal->transmit_data(DATA_TYPE_COMMAND, (uint8_t *)(sample_data1), strlen(sample_data1));
+  hal->transmit_data(DATA_TYPE_COMMAND, (uint8_t*)(sample_data1),
+                     strlen(sample_data1));
   expect_socket_data(command_sockfd[1], sample_data1);
 
   // Send an acl packet
-  hal->transmit_data(DATA_TYPE_ACL, (uint8_t *)(sample_data2), strlen(sample_data2));
+  hal->transmit_data(DATA_TYPE_ACL, (uint8_t*)(sample_data2),
+                     strlen(sample_data2));
   expect_socket_data(acl_out_sockfd[1], sample_data2);
 }
 
index 8db5331..913c8c0 100644 (file)
 
 #include <stdint.h>
 
-#include "device/include/controller.h"
-#include "osi/include/allocation_tracker.h"
-#include "osi/include/allocator.h"
-#include "osi/include/osi.h"
-#include "osi/include/semaphore.h"
 #include "btsnoop.h"
-#include "hcimsgs.h"
+#include "device/include/controller.h"
 #include "hci_hal.h"
 #include "hci_inject.h"
 #include "hci_layer.h"
+#include "hcimsgs.h"
 #include "low_power_manager.h"
 #include "module.h"
+#include "osi/include/allocation_tracker.h"
+#include "osi/include/allocator.h"
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
 #include "packet_fragmenter.h"
 #include "test_stubs.h"
 #include "vendor.h"
 
 extern const module_t hci_module;
 
-DECLARE_TEST_MODES(
-  start_up_async,
-  shut_down,
-  postload,
-  transmit_simple,
-  receive_simple,
-  transmit_command_no_callbacks,
-  transmit_command_command_status,
-  transmit_command_command_complete,
-  ignoring_packets_ignored_packet,
-  ignoring_packets_following_packet
-);
+DECLARE_TEST_MODES(start_up_async, shut_down, postload, transmit_simple,
+                   receive_simple, transmit_command_no_callbacks,
+                   transmit_command_command_status,
+                   transmit_command_command_complete,
+                   ignoring_packets_ignored_packet,
+                   ignoring_packets_following_packet);
 
 // TODO: Ugly hack to get around another ugly hack in hci_layer.cc
 bt_bdaddr_t btif_local_bd_addr;
 
-static const char *small_sample_data = "\"It is easy to see,\" replied Don Quixote";
-static const char *command_sample_data = "that thou art not used to this business of adventures; those are giants";
-static const char *ignored_data = "and if thou art afraid, away with thee out of this and betake thyself to prayer";
-static const char *unignored_data = "while I engage them in fierce and unequal combat";
-
-static const hci_t *hci;
-static const hci_hal_callbacks_t *hal_callbacks;
-static thread_t *internal_thread;
+static const char* small_sample_data =
+    "\"It is easy to see,\" replied Don Quixote";
+static const char* command_sample_data =
+    "that thou art not used to this business of adventures; those are giants";
+static const char* ignored_data =
+    "and if thou art afraid, away with thee out of this and betake thyself to "
+    "prayer";
+static const char* unignored_data =
+    "while I engage them in fierce and unequal combat";
+
+static const hci_t* hci;
+static const hci_hal_callbacks_t* hal_callbacks;
+static thread_t* internal_thread;
 static vendor_cb firmware_config_callback;
 static vendor_cb sco_config_callback;
 static vendor_cb epilog_callback;
-static semaphore_t *done;
+static semaphore_tdone;
 static const uint16_t test_handle = (0x1992 & 0xCFFF);
 static const uint16_t test_handle_continuation = (0x1992 & 0xCFFF) | 0x1000;
 static int packet_index;
 static unsigned int data_size_sum;
-static BT_HDR *data_to_receive;
+static BT_HDRdata_to_receive;
 
-static void signal_work_item(UNUSED_ATTR void *context) {
+static void signal_work_item(UNUSED_ATTR voidcontext) {
   semaphore_post(done);
 }
 
-static void flush_thread(thread_t *thread) {
+static void flush_thread(thread_tthread) {
   // Double flush to ensure we get the next reactor cycle
   thread_post(thread, signal_work_item, NULL);
   semaphore_wait(done);
@@ -87,24 +86,23 @@ static void flush_thread(thread_t *thread) {
 }
 
 // TODO move this to a common packet testing helper
-static BT_HDR *manufacture_packet(uint16_t event, const char *data) {
+static BT_HDR* manufacture_packet(uint16_t event, const char* data) {
   uint16_t data_length = strlen(data);
   uint16_t size = data_length;
   if (event == MSG_STACK_TO_HC_HCI_ACL) {
-    size += 4; // 2 for the handle, 2 for the length;
+    size += 4;  // 2 for the handle, 2 for the length;
   }
 
-  BT_HDR *packet = (BT_HDR *)osi_malloc(size + sizeof(BT_HDR));
+  BT_HDR* packet = (BT_HDR*)osi_malloc(size + sizeof(BT_HDR));
   packet->len = size;
   packet->offset = 0;
   packet->layer_specific = 0;
 
   // The command transmit interface adds the event type automatically.
   // Make sure it works but omitting it here.
-  if (event != MSG_STACK_TO_HC_HCI_CMD)
-    packet->event = event;
+  if (event != MSG_STACK_TO_HC_HCI_CMD) packet->event = event;
 
-  uint8_t *packet_data = packet->data;
+  uint8_tpacket_data = packet->data;
 
   if (event == MSG_STACK_TO_HC_HCI_ACL) {
     UINT16_TO_STREAM(packet_data, test_handle);
@@ -126,7 +124,9 @@ static BT_HDR *manufacture_packet(uint16_t event, const char *data) {
   return packet;
 }
 
-static void expect_packet(uint16_t event, int max_acl_data_size, const uint8_t *data, uint16_t data_length, const char *expected_data) {
+static void expect_packet(uint16_t event, int max_acl_data_size,
+                          const uint8_t* data, uint16_t data_length,
+                          const char* expected_data) {
   int expected_data_offset;
   int length_to_check;
 
@@ -168,333 +168,326 @@ static void expect_packet(uint16_t event, int max_acl_data_size, const uint8_t *
   }
 }
 
-STUB_FUNCTION(bool, hal_init, (const hci_hal_callbacks_t *callbacks, thread_t *working_thread))
-  DURING(start_up_async) AT_CALL(0) {
-    hal_callbacks = callbacks;
-    internal_thread = working_thread;
-    return true;
-  }
+STUB_FUNCTION(bool, hal_init,
+              (const hci_hal_callbacks_t* callbacks, thread_t* working_thread))
+DURING(start_up_async) AT_CALL(0) {
+  hal_callbacks = callbacks;
+  internal_thread = working_thread;
+  return true;
+}
 
-  UNEXPECTED_CALL;
-  return false;
+UNEXPECTED_CALL;
+return false;
 }
 
 STUB_FUNCTION(bool, hal_open, ())
-  DURING(start_up_async) AT_CALL(0) return true;
-  UNEXPECTED_CALL;
-  return false;
+DURING(start_up_async) AT_CALL(0) return true;
+UNEXPECTED_CALL;
+return false;
 }
 
 STUB_FUNCTION(void, hal_close, ())
-  DURING(shut_down) AT_CALL(0) return;
-  UNEXPECTED_CALL;
+DURING(shut_down) AT_CALL(0) return;
+UNEXPECTED_CALL;
 }
 
-STUB_FUNCTION(uint16_t, hal_transmit_data, (serial_data_type_t type, uint8_t *data, uint16_t length))
-  DURING(transmit_simple) AT_CALL(0) {
-    EXPECT_EQ(DATA_TYPE_ACL, type);
-    expect_packet(MSG_STACK_TO_HC_HCI_ACL, 1021, data, length, small_sample_data);
-    return length;
-  }
+STUB_FUNCTION(uint16_t, hal_transmit_data,
+              (serial_data_type_t type, uint8_t* data, uint16_t length))
+DURING(transmit_simple) AT_CALL(0) {
+  EXPECT_EQ(DATA_TYPE_ACL, type);
+  expect_packet(MSG_STACK_TO_HC_HCI_ACL, 1021, data, length, small_sample_data);
+  return length;
+}
 
-  DURING(
-      transmit_command_no_callbacks,
-      transmit_command_command_status,
-      transmit_command_command_complete
-    ) AT_CALL(0) {
-    EXPECT_EQ(DATA_TYPE_COMMAND, type);
-    expect_packet(MSG_STACK_TO_HC_HCI_CMD, 1021, data, length, command_sample_data);
-    return length;
-  }
+DURING(transmit_command_no_callbacks, transmit_command_command_status,
+       transmit_command_command_complete)
+AT_CALL(0) {
+  EXPECT_EQ(DATA_TYPE_COMMAND, type);
+  expect_packet(MSG_STACK_TO_HC_HCI_CMD, 1021, data, length,
+                command_sample_data);
+  return length;
+}
 
-  UNEXPECTED_CALL;
-  return 0;
+UNEXPECTED_CALL;
+return 0;
 }
 
-static size_t replay_data_to_receive(size_t max_size, uint8_t *buffer) {
+static size_t replay_data_to_receive(size_t max_size, uint8_tbuffer) {
   for (size_t i = 0; i < max_size; i++) {
-    if (data_to_receive->offset >= data_to_receive->len)
-      break;
+    if (data_to_receive->offset >= data_to_receive->len) break;
 
     buffer[i] = data_to_receive->data[data_to_receive->offset++];
 
     if (i == (max_size - 1))
-      return i + 1; // We return the length, not the index;
+      return i + 1;  // We return the length, not the index;
   }
 
   return 0;
 }
 
-STUB_FUNCTION(size_t, hal_read_data, (serial_data_type_t type, uint8_t *buffer, size_t max_size))
-  DURING(receive_simple, ignoring_packets_following_packet) {
-    EXPECT_EQ(DATA_TYPE_ACL, type);
-    return replay_data_to_receive(max_size, buffer);
-  }
+STUB_FUNCTION(size_t, hal_read_data,
+              (serial_data_type_t type, uint8_t* buffer, size_t max_size))
+DURING(receive_simple, ignoring_packets_following_packet) {
+  EXPECT_EQ(DATA_TYPE_ACL, type);
+  return replay_data_to_receive(max_size, buffer);
+}
 
-  DURING(ignoring_packets_ignored_packet) {
-    EXPECT_EQ(DATA_TYPE_EVENT, type);
-    return replay_data_to_receive(max_size, buffer);
-  }
+DURING(ignoring_packets_ignored_packet) {
+  EXPECT_EQ(DATA_TYPE_EVENT, type);
+  return replay_data_to_receive(max_size, buffer);
+}
 
-  DURING(
-      transmit_command_no_callbacks,
-      transmit_command_command_status,
-      transmit_command_command_complete) {
-    EXPECT_EQ(DATA_TYPE_EVENT, type);
-    return replay_data_to_receive(max_size, buffer);
-  }
+DURING(transmit_command_no_callbacks, transmit_command_command_status,
+       transmit_command_command_complete) {
+  EXPECT_EQ(DATA_TYPE_EVENT, type);
+  return replay_data_to_receive(max_size, buffer);
+}
 
-  UNEXPECTED_CALL;
-  return 0;
+UNEXPECTED_CALL;
+return 0;
 }
 
 STUB_FUNCTION(void, hal_packet_finished, (serial_data_type_t type))
-  DURING(receive_simple, ignoring_packets_following_packet) AT_CALL(0) {
-    EXPECT_EQ(DATA_TYPE_ACL, type);
-    return;
-  }
+DURING(receive_simple, ignoring_packets_following_packet) AT_CALL(0) {
+  EXPECT_EQ(DATA_TYPE_ACL, type);
+  return;
+}
 
-  DURING(ignoring_packets_ignored_packet) AT_CALL(0) {
-    EXPECT_EQ(DATA_TYPE_EVENT, type);
-    return;
-  }
+DURING(ignoring_packets_ignored_packet) AT_CALL(0) {
+  EXPECT_EQ(DATA_TYPE_EVENT, type);
+  return;
+}
 
-  DURING(
-      transmit_command_no_callbacks,
-      transmit_command_command_status,
-      transmit_command_command_complete
-    ) AT_CALL(0) {
-    EXPECT_EQ(DATA_TYPE_EVENT, type);
-    return;
-  }
+DURING(transmit_command_no_callbacks, transmit_command_command_status,
+       transmit_command_command_complete)
+AT_CALL(0) {
+  EXPECT_EQ(DATA_TYPE_EVENT, type);
+  return;
+}
 
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
 }
 
-STUB_FUNCTION(bool, hci_inject_open, (
-    UNUSED_ATTR const hci_t *hci_interface))
-  DURING(start_up_async) AT_CALL(0) return true;
-  UNEXPECTED_CALL;
-  return false;
+STUB_FUNCTION(bool, hci_inject_open, (UNUSED_ATTR const hci_t* hci_interface))
+DURING(start_up_async) AT_CALL(0) return true;
+UNEXPECTED_CALL;
+return false;
 }
 
 STUB_FUNCTION(void, hci_inject_close, ())
-  DURING(shut_down) AT_CALL(0) return;
-  UNEXPECTED_CALL;
+DURING(shut_down) AT_CALL(0) return;
+UNEXPECTED_CALL;
+}
+
+STUB_FUNCTION(void, btsnoop_capture, (const BT_HDR* buffer, bool is_received))
+DURING(transmit_simple) AT_CALL(0) {
+  EXPECT_FALSE(is_received);
+  expect_packet(MSG_STACK_TO_HC_HCI_ACL, 1021, buffer->data + buffer->offset,
+                buffer->len, small_sample_data);
+  packet_index = 0;
+  data_size_sum = 0;
+  return;
 }
 
-STUB_FUNCTION(void, btsnoop_capture, (const BT_HDR *buffer, bool is_received))
-  DURING(transmit_simple) AT_CALL(0) {
+DURING(transmit_command_no_callbacks, transmit_command_command_status,
+       transmit_command_command_complete) {
+  AT_CALL(0) {
     EXPECT_FALSE(is_received);
-    expect_packet(MSG_STACK_TO_HC_HCI_ACL, 1021, buffer->data + buffer->offset, buffer->len, small_sample_data);
+    expect_packet(MSG_STACK_TO_HC_HCI_CMD, 1021, buffer->data + buffer->offset,
+                  buffer->len, command_sample_data);
     packet_index = 0;
     data_size_sum = 0;
     return;
   }
-
-
-  DURING(
-      transmit_command_no_callbacks,
-      transmit_command_command_status,
-      transmit_command_command_complete) {
-    AT_CALL(0) {
-      EXPECT_FALSE(is_received);
-      expect_packet(MSG_STACK_TO_HC_HCI_CMD, 1021, buffer->data + buffer->offset, buffer->len, command_sample_data);
-      packet_index = 0;
-      data_size_sum = 0;
-      return;
-    }
-    AT_CALL(1) {
-      EXPECT_TRUE(is_received);
-      // not super important to verify the contents right now
-      return;
-    }
-  }
-
-  DURING(
-      receive_simple,
-      ignoring_packets_following_packet
-    ) AT_CALL(0) {
+  AT_CALL(1) {
     EXPECT_TRUE(is_received);
-    EXPECT_TRUE(buffer->len == data_to_receive->len);
-    const uint8_t *buffer_base = buffer->data + buffer->offset;
-    const uint8_t *expected_base = data_to_receive->data;
-    for (int i = 0; i < buffer->len; i++) {
-      EXPECT_EQ(expected_base[i], buffer_base[i]);
-    }
-
+    // not super important to verify the contents right now
     return;
   }
+}
 
-  UNEXPECTED_CALL;
+DURING(receive_simple, ignoring_packets_following_packet) AT_CALL(0) {
+  EXPECT_TRUE(is_received);
+  EXPECT_TRUE(buffer->len == data_to_receive->len);
+  const uint8_t* buffer_base = buffer->data + buffer->offset;
+  const uint8_t* expected_base = data_to_receive->data;
+  for (int i = 0; i < buffer->len; i++) {
+    EXPECT_EQ(expected_base[i], buffer_base[i]);
+  }
+
+  return;
 }
 
-STUB_FUNCTION(void, low_power_init, (UNUSED_ATTR thread_t *thread))
-  DURING(start_up_async) AT_CALL(0) return;
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
+}
+
+STUB_FUNCTION(void, low_power_init, (UNUSED_ATTR thread_t * thread))
+DURING(start_up_async) AT_CALL(0) return;
+UNEXPECTED_CALL;
 }
 
 STUB_FUNCTION(void, low_power_cleanup, ())
-  DURING(shut_down) AT_CALL(0) return;
-  UNEXPECTED_CALL;
+DURING(shut_down) AT_CALL(0) return;
+UNEXPECTED_CALL;
 }
 
 STUB_FUNCTION(void, low_power_wake_assert, ())
-  DURING(
-      transmit_simple,
-      transmit_command_no_callbacks,
-      transmit_command_command_status,
-      transmit_command_command_complete) {
-    AT_CALL(0) return;
-  }
+DURING(transmit_simple, transmit_command_no_callbacks,
+       transmit_command_command_status, transmit_command_command_complete) {
+  AT_CALL(0) return;
+}
 
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
 }
 
 STUB_FUNCTION(void, low_power_transmit_done, ())
-  DURING(
-      transmit_simple,
-      transmit_command_no_callbacks,
-      transmit_command_command_status,
-      transmit_command_command_complete) {
-    AT_CALL(0) return;
-  }
-
-  UNEXPECTED_CALL;
+DURING(transmit_simple, transmit_command_no_callbacks,
+       transmit_command_command_status, transmit_command_command_complete) {
+  AT_CALL(0) return;
 }
 
-STUB_FUNCTION(bool, vendor_open, (UNUSED_ATTR const uint8_t *addr, const hci_t *hci_interface))
-  DURING(start_up_async) AT_CALL(0) {
-    // TODO(zachoverflow): check address value when it gets put into a module
-    EXPECT_EQ(hci, hci_interface);
-    return true;
-  }
+UNEXPECTED_CALL;
+}
 
-  UNEXPECTED_CALL;
+STUB_FUNCTION(bool, vendor_open,
+              (UNUSED_ATTR const uint8_t* addr, const hci_t* hci_interface))
+DURING(start_up_async) AT_CALL(0) {
+  // TODO(zachoverflow): check address value when it gets put into a module
+  EXPECT_EQ(hci, hci_interface);
   return true;
 }
 
+UNEXPECTED_CALL;
+return true;
+}
+
 STUB_FUNCTION(void, vendor_close, ())
-  DURING(shut_down) AT_CALL(0) return;
-  UNEXPECTED_CALL;
+DURING(shut_down) AT_CALL(0) return;
+UNEXPECTED_CALL;
 }
 
-STUB_FUNCTION(void, vendor_set_callback, (vendor_async_opcode_t opcode, UNUSED_ATTR vendor_cb callback))
-  DURING(start_up_async) {
-    AT_CALL(0) {
-      EXPECT_EQ(VENDOR_CONFIGURE_FIRMWARE, opcode);
-      firmware_config_callback = callback;
-      return;
-    }
-    AT_CALL(1) {
-      EXPECT_EQ(VENDOR_CONFIGURE_SCO, opcode);
-      sco_config_callback = callback;
-      return;
-    }
-    AT_CALL(2) {
-      EXPECT_EQ(VENDOR_DO_EPILOG, opcode);
-      epilog_callback = callback;
-      return;
-    }
+STUB_FUNCTION(void, vendor_set_callback,
+              (vendor_async_opcode_t opcode, UNUSED_ATTR vendor_cb callback))
+DURING(start_up_async) {
+  AT_CALL(0) {
+    EXPECT_EQ(VENDOR_CONFIGURE_FIRMWARE, opcode);
+    firmware_config_callback = callback;
+    return;
   }
+  AT_CALL(1) {
+    EXPECT_EQ(VENDOR_CONFIGURE_SCO, opcode);
+    sco_config_callback = callback;
+    return;
+  }
+  AT_CALL(2) {
+    EXPECT_EQ(VENDOR_DO_EPILOG, opcode);
+    epilog_callback = callback;
+    return;
+  }
+}
 
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
 }
 
-STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void *param))
-  DURING(start_up_async) {
+STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, voidparam))
+DURING(start_up_async) {
 #if (BT_CLEAN_TURN_ON_DISABLED == TRUE)
-    AT_CALL(0) {
-      EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
-      EXPECT_EQ(BT_VND_PWR_ON, *(int *)param);
-      return 0;
-    }
+  AT_CALL(0) {
+    EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
+    EXPECT_EQ(BT_VND_PWR_ON, *(int*)param);
+    return 0;
+  }
 #else
-    AT_CALL(0) {
-      EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
-      EXPECT_EQ(BT_VND_PWR_OFF, *(int *)param);
-      return 0;
-    }
-    AT_CALL(1) {
-      EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
-      EXPECT_EQ(BT_VND_PWR_ON, *(int *)param);
-      return 0;
-    }
-#endif
+  AT_CALL(0) {
+    EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
+    EXPECT_EQ(BT_VND_PWR_OFF, *(int*)param);
+    return 0;
   }
-
-  DURING(shut_down) AT_CALL(0) {
+  AT_CALL(1) {
     EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
-    EXPECT_EQ(BT_VND_PWR_OFF, *(int *)param);
+    EXPECT_EQ(BT_VND_PWR_ON, *(int*)param);
     return 0;
   }
+#endif
+}
 
-  UNEXPECTED_CALL;
+DURING(shut_down) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_CHIP_POWER_CONTROL, opcode);
+  EXPECT_EQ(BT_VND_PWR_OFF, *(int*)param);
   return 0;
 }
 
-STUB_FUNCTION(int, vendor_send_async_command, (UNUSED_ATTR vendor_async_opcode_t opcode, UNUSED_ATTR void *param))
-  DURING(start_up_async) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_CONFIGURE_FIRMWARE, opcode);
-    firmware_config_callback(true);
-    return 0;
-  }
+UNEXPECTED_CALL;
+return 0;
+}
 
-  DURING(postload) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_CONFIGURE_SCO, opcode);
-    sco_config_callback(true);
-    return 0;
-  }
+STUB_FUNCTION(int, vendor_send_async_command,
+              (UNUSED_ATTR vendor_async_opcode_t opcode,
+               UNUSED_ATTR void* param))
+DURING(start_up_async) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_CONFIGURE_FIRMWARE, opcode);
+  firmware_config_callback(true);
+  return 0;
+}
 
-  DURING(shut_down) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_DO_EPILOG, opcode);
-    epilog_callback(true);
-    return 0;
-  }
+DURING(postload) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_CONFIGURE_SCO, opcode);
+  sco_config_callback(true);
+  return 0;
+}
 
-  UNEXPECTED_CALL;
+DURING(shut_down) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_DO_EPILOG, opcode);
+  epilog_callback(true);
   return 0;
 }
 
-STUB_FUNCTION(void, command_complete_callback, (BT_HDR *response, UNUSED_ATTR void *context))
-  DURING(transmit_command_command_complete) AT_CALL(0) {
-    osi_free(response);
-    return;
-  }
+UNEXPECTED_CALL;
+return 0;
+}
 
-  UNEXPECTED_CALL;
+STUB_FUNCTION(void, command_complete_callback,
+              (BT_HDR * response, UNUSED_ATTR void* context))
+DURING(transmit_command_command_complete) AT_CALL(0) {
+  osi_free(response);
+  return;
 }
 
-STUB_FUNCTION(void, command_status_callback, (UNUSED_ATTR uint8_t status, BT_HDR *command, UNUSED_ATTR void *context))
-  DURING(transmit_command_command_status) AT_CALL(0) {
-    osi_free(command);
-    return;
-  }
+UNEXPECTED_CALL;
+}
 
-  UNEXPECTED_CALL;
+STUB_FUNCTION(void, command_status_callback,
+              (UNUSED_ATTR uint8_t status, BT_HDR* command,
+               UNUSED_ATTR void* context))
+DURING(transmit_command_command_status) AT_CALL(0) {
+  osi_free(command);
+  return;
+}
+
+UNEXPECTED_CALL;
 }
 
 STUB_FUNCTION(uint16_t, controller_get_acl_data_size_classic, (void))
-  return 2048;
+return 2048;
 }
 
 STUB_FUNCTION(uint16_t, controller_get_acl_data_size_ble, (void))
-  return 2048;
+return 2048;
 }
 
-STUB_FUNCTION(void *, buffer_allocator_alloc, (size_t size))
-  DURING(ignoring_packets_ignored_packet) {
-    AT_CALL(0)
-      return NULL;
+STUB_FUNCTION(void*, buffer_allocator_alloc, (size_t size))
+DURING(ignoring_packets_ignored_packet) {
+  AT_CALL(0)
+  return NULL;
 
-    UNEXPECTED_CALL;
-  }
+  UNEXPECTED_CALL;
+}
 
-  return allocator_malloc.alloc(size);
+return allocator_malloc.alloc(size);
 }
 
-STUB_FUNCTION(void, buffer_allocator_free, (void *ptr))
-  allocator_malloc.free(ptr);
+STUB_FUNCTION(void, buffer_allocator_free, (voidptr))
+allocator_malloc.free(ptr);
 }
 
 static void reset_for(TEST_MODES_T next) {
@@ -526,82 +519,77 @@ static void reset_for(TEST_MODES_T next) {
 }
 
 class HciLayerTest : public AlarmTestHarness {
-  protected:
-    virtual void SetUp() {
-      AlarmTestHarness::SetUp();
-      module_management_start();
-
-      hci = hci_layer_get_test_interface(
-        &buffer_allocator,
-        &hal,
-        &btsnoop,
-        &hci_inject,
+ protected:
+  virtual void SetUp() {
+    AlarmTestHarness::SetUp();
+    module_management_start();
+
+    hci = hci_layer_get_test_interface(
+        &buffer_allocator, &hal, &btsnoop, &hci_inject,
         packet_fragmenter_get_test_interface(&controller, &allocator_malloc),
-        &vendor,
-        &low_power_manager
-      );
-
-      packet_index = 0;
-      data_size_sum = 0;
-
-      vendor.open = vendor_open;
-      vendor.close = vendor_close;
-      vendor.set_callback = vendor_set_callback;
-      vendor.send_command = vendor_send_command;
-      vendor.send_async_command = vendor_send_async_command;
-      hal.init = hal_init;
-      hal.open = hal_open;
-      hal.close = hal_close;
-      hal.read_data = hal_read_data;
-      hal.packet_finished = hal_packet_finished;
-      hal.transmit_data = hal_transmit_data;
-      btsnoop.capture = btsnoop_capture;
-      hci_inject.open = hci_inject_open;
-      hci_inject.close = hci_inject_close;
-      low_power_manager.init = low_power_init;
-      low_power_manager.cleanup = low_power_cleanup;
-      low_power_manager.wake_assert = low_power_wake_assert;
-      low_power_manager.transmit_done = low_power_transmit_done;
-      controller.get_acl_data_size_classic = controller_get_acl_data_size_classic;
-      controller.get_acl_data_size_ble = controller_get_acl_data_size_ble;
-      buffer_allocator.alloc = buffer_allocator_alloc;
-      buffer_allocator.free = buffer_allocator_free;
-
-      done = semaphore_new(0);
-
-      reset_for(start_up_async);
-      EXPECT_TRUE(module_start_up(&hci_module));
-
-      EXPECT_CALL_COUNT(vendor_open, 1);
-      EXPECT_CALL_COUNT(hal_init, 1);
-      EXPECT_CALL_COUNT(low_power_init, 1);
-      EXPECT_CALL_COUNT(vendor_set_callback, 3);
-      EXPECT_CALL_COUNT(hal_open, 1);
-      EXPECT_CALL_COUNT(vendor_send_async_command, 1);
-    }
-
-    virtual void TearDown() {
-      reset_for(shut_down);
-      module_shut_down(&hci_module);
-
-      EXPECT_CALL_COUNT(low_power_cleanup, 1);
-      EXPECT_CALL_COUNT(hal_close, 1);
-      EXPECT_CALL_COUNT(vendor_send_command, 1);
-      EXPECT_CALL_COUNT(vendor_close, 1);
-
-      semaphore_free(done);
-      hci_layer_cleanup_interface();
-      module_management_stop();
-      AlarmTestHarness::TearDown();
-    }
-
-    hci_hal_t hal;
-    btsnoop_t btsnoop;
-    controller_t controller;
-    hci_inject_t hci_inject;
-    vendor_t vendor;
-    low_power_manager_t low_power_manager;
-    allocator_t buffer_allocator;
+        &vendor, &low_power_manager);
+
+    packet_index = 0;
+    data_size_sum = 0;
+
+    vendor.open = vendor_open;
+    vendor.close = vendor_close;
+    vendor.set_callback = vendor_set_callback;
+    vendor.send_command = vendor_send_command;
+    vendor.send_async_command = vendor_send_async_command;
+    hal.init = hal_init;
+    hal.open = hal_open;
+    hal.close = hal_close;
+    hal.read_data = hal_read_data;
+    hal.packet_finished = hal_packet_finished;
+    hal.transmit_data = hal_transmit_data;
+    btsnoop.capture = btsnoop_capture;
+    hci_inject.open = hci_inject_open;
+    hci_inject.close = hci_inject_close;
+    low_power_manager.init = low_power_init;
+    low_power_manager.cleanup = low_power_cleanup;
+    low_power_manager.wake_assert = low_power_wake_assert;
+    low_power_manager.transmit_done = low_power_transmit_done;
+    controller.get_acl_data_size_classic = controller_get_acl_data_size_classic;
+    controller.get_acl_data_size_ble = controller_get_acl_data_size_ble;
+    buffer_allocator.alloc = buffer_allocator_alloc;
+    buffer_allocator.free = buffer_allocator_free;
+
+    done = semaphore_new(0);
+
+    reset_for(start_up_async);
+    EXPECT_TRUE(module_start_up(&hci_module));
+
+    EXPECT_CALL_COUNT(vendor_open, 1);
+    EXPECT_CALL_COUNT(hal_init, 1);
+    EXPECT_CALL_COUNT(low_power_init, 1);
+    EXPECT_CALL_COUNT(vendor_set_callback, 3);
+    EXPECT_CALL_COUNT(hal_open, 1);
+    EXPECT_CALL_COUNT(vendor_send_async_command, 1);
+  }
+
+  virtual void TearDown() {
+    reset_for(shut_down);
+    module_shut_down(&hci_module);
+
+    EXPECT_CALL_COUNT(low_power_cleanup, 1);
+    EXPECT_CALL_COUNT(hal_close, 1);
+    EXPECT_CALL_COUNT(vendor_send_command, 1);
+    EXPECT_CALL_COUNT(vendor_close, 1);
+
+    semaphore_free(done);
+    hci_layer_cleanup_interface();
+    module_management_stop();
+    AlarmTestHarness::TearDown();
+  }
+
+  hci_hal_t hal;
+  btsnoop_t btsnoop;
+  controller_t controller;
+  hci_inject_t hci_inject;
+  vendor_t vendor;
+  low_power_manager_t low_power_manager;
+  allocator_t buffer_allocator;
 };
 
 TEST_F(HciLayerTest, test_postload) {
@@ -614,7 +602,8 @@ TEST_F(HciLayerTest, test_postload) {
 
 TEST_F(HciLayerTest, test_transmit_simple) {
   reset_for(transmit_simple);
-  BT_HDR *packet = manufacture_packet(MSG_STACK_TO_HC_HCI_ACL, small_sample_data);
+  BT_HDR* packet =
+      manufacture_packet(MSG_STACK_TO_HC_HCI_ACL, small_sample_data);
   hci->transmit_downward(MSG_STACK_TO_HC_HCI_ACL, packet);
 
   flush_thread(internal_thread);
@@ -626,7 +615,8 @@ TEST_F(HciLayerTest, test_transmit_simple) {
 
 TEST_F(HciLayerTest, test_receive_simple) {
   reset_for(receive_simple);
-  data_to_receive = manufacture_packet(MSG_STACK_TO_HC_HCI_ACL, small_sample_data);
+  data_to_receive =
+      manufacture_packet(MSG_STACK_TO_HC_HCI_ACL, small_sample_data);
 
   // Not running on the internal thread, unlike the real hal
   hal_callbacks->data_ready(DATA_TYPE_ACL);
@@ -636,25 +626,25 @@ TEST_F(HciLayerTest, test_receive_simple) {
   osi_free(data_to_receive);
 }
 
-static BT_HDR *manufacture_command_complete(command_opcode_t opcode) {
-  BT_HDR *ret = (BT_HDR *)osi_calloc(sizeof(BT_HDR) + 5);
-  uint8_t *stream = ret->data;
+static BT_HDRmanufacture_command_complete(command_opcode_t opcode) {
+  BT_HDR* ret = (BT_HDR*)osi_calloc(sizeof(BT_HDR) + 5);
+  uint8_tstream = ret->data;
   UINT8_TO_STREAM(stream, HCI_COMMAND_COMPLETE_EVT);
-  UINT8_TO_STREAM(stream, 3); // length of the event parameters
-  UINT8_TO_STREAM(stream, 1); // the number of commands that can be sent
+  UINT8_TO_STREAM(stream, 3);  // length of the event parameters
+  UINT8_TO_STREAM(stream, 1);  // the number of commands that can be sent
   UINT16_TO_STREAM(stream, opcode);
   ret->len = 5;
 
   return ret;
 }
 
-static BT_HDR *manufacture_command_status(command_opcode_t opcode) {
-  BT_HDR *ret = (BT_HDR *)osi_calloc(sizeof(BT_HDR) + 6);
-  uint8_t *stream = ret->data;
+static BT_HDRmanufacture_command_status(command_opcode_t opcode) {
+  BT_HDR* ret = (BT_HDR*)osi_calloc(sizeof(BT_HDR) + 6);
+  uint8_tstream = ret->data;
   UINT8_TO_STREAM(stream, HCI_COMMAND_STATUS_EVT);
-  UINT8_TO_STREAM(stream, 4); // length of the event parameters
-  UINT8_TO_STREAM(stream, HCI_PENDING); // status
-  UINT8_TO_STREAM(stream, 1); // the number of commands that can be sent
+  UINT8_TO_STREAM(stream, 4);            // length of the event parameters
+  UINT8_TO_STREAM(stream, HCI_PENDING);  // status
+  UINT8_TO_STREAM(stream, 1);  // the number of commands that can be sent
   UINT16_TO_STREAM(stream, opcode);
   ret->len = 6;
 
@@ -664,7 +654,8 @@ static BT_HDR *manufacture_command_status(command_opcode_t opcode) {
 TEST_F(HciLayerTest, test_transmit_command_no_callbacks) {
   // Send a test command
   reset_for(transmit_command_no_callbacks);
-  data_to_receive = manufacture_packet(MSG_STACK_TO_HC_HCI_CMD, command_sample_data);
+  data_to_receive =
+      manufacture_packet(MSG_STACK_TO_HC_HCI_CMD, command_sample_data);
   hci->transmit_command(data_to_receive, NULL, NULL, NULL);
 
   flush_thread(internal_thread);
@@ -674,7 +665,7 @@ TEST_F(HciLayerTest, test_transmit_command_no_callbacks) {
   EXPECT_CALL_COUNT(low_power_wake_assert, 1);
 
   // Send a response
-  command_opcode_t opcode = *((uint16_t *)command_sample_data);
+  command_opcode_t opcode = *((uint16_t*)command_sample_data);
   data_to_receive = manufacture_command_complete(opcode);
 
   hal_callbacks->data_ready(DATA_TYPE_EVENT);
@@ -687,8 +678,10 @@ TEST_F(HciLayerTest, test_transmit_command_no_callbacks) {
 TEST_F(HciLayerTest, test_transmit_command_command_status) {
   // Send a test command
   reset_for(transmit_command_command_status);
-  data_to_receive = manufacture_packet(MSG_STACK_TO_HC_HCI_CMD, command_sample_data);
-  hci->transmit_command(data_to_receive, command_complete_callback, command_status_callback, NULL);
+  data_to_receive =
+      manufacture_packet(MSG_STACK_TO_HC_HCI_CMD, command_sample_data);
+  hci->transmit_command(data_to_receive, command_complete_callback,
+                        command_status_callback, NULL);
 
   flush_thread(internal_thread);
   EXPECT_CALL_COUNT(hal_transmit_data, 1);
@@ -696,7 +689,7 @@ TEST_F(HciLayerTest, test_transmit_command_command_status) {
   EXPECT_CALL_COUNT(low_power_transmit_done, 1);
   EXPECT_CALL_COUNT(low_power_wake_assert, 1);
 
-  command_opcode_t opcode = *((uint16_t *)command_sample_data);
+  command_opcode_t opcode = *((uint16_t*)command_sample_data);
 
   // Send status event response
   data_to_receive = manufacture_command_status(opcode);
@@ -712,8 +705,10 @@ TEST_F(HciLayerTest, test_transmit_command_command_status) {
 TEST_F(HciLayerTest, test_transmit_command_command_complete) {
   // Send a test command
   reset_for(transmit_command_command_complete);
-  data_to_receive = manufacture_packet(MSG_STACK_TO_HC_HCI_CMD, command_sample_data);
-  hci->transmit_command(data_to_receive, command_complete_callback, command_status_callback, NULL);
+  data_to_receive =
+      manufacture_packet(MSG_STACK_TO_HC_HCI_CMD, command_sample_data);
+  hci->transmit_command(data_to_receive, command_complete_callback,
+                        command_status_callback, NULL);
 
   flush_thread(internal_thread);
   EXPECT_CALL_COUNT(hal_transmit_data, 1);
@@ -721,7 +716,7 @@ TEST_F(HciLayerTest, test_transmit_command_command_complete) {
   EXPECT_CALL_COUNT(low_power_transmit_done, 1);
   EXPECT_CALL_COUNT(low_power_wake_assert, 1);
 
-  command_opcode_t opcode = *((uint16_t *)command_sample_data);
+  command_opcode_t opcode = *((uint16_t*)command_sample_data);
 
   // Send complete event response
   data_to_receive = manufacture_command_complete(opcode);
@@ -754,4 +749,5 @@ TEST_F(HciLayerTest, test_ignoring_packets) {
   osi_free(data_to_receive);
 }
 
-// TODO(zachoverflow): test post-reassembly better, stub out fragmenter instead of using it
+// TODO(zachoverflow): test post-reassembly better, stub out fragmenter instead
+// of using it
index 07e255d..cef6ce0 100644 (file)
 #include "test_stubs.h"
 #include "vendor.h"
 
-DECLARE_TEST_MODES(
-  init,
-  cleanup,
-  enable_disable
-);
+DECLARE_TEST_MODES(init, cleanup, enable_disable);
 
-static const low_power_manager_t *manager;
-static thread_t *thread;
-static semaphore_t *done;
+static const low_power_manager_tmanager;
+static thread_tthread;
+static semaphore_tdone;
 
 static vendor_cb low_power_state_callback;
 
-static void flush_work_queue_item(UNUSED_ATTR void *context) {
+static void flush_work_queue_item(UNUSED_ATTR voidcontext) {
   semaphore_post(done);
 }
 
-STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void *param))
-  DURING(enable_disable) AT_CALL(0) {
-    EXPECT_EQ(VENDOR_GET_LPM_IDLE_TIMEOUT, opcode);
-    *((uint32_t *)param) = 100;
-    return 0;
-  }
-
-  UNEXPECTED_CALL;
+STUB_FUNCTION(int, vendor_send_command, (vendor_opcode_t opcode, void* param))
+DURING(enable_disable) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_GET_LPM_IDLE_TIMEOUT, opcode);
+  *((uint32_t*)param) = 100;
   return 0;
 }
 
-STUB_FUNCTION(int, vendor_send_async_command, (vendor_async_opcode_t opcode, void *param))
-  DURING(enable_disable) {
-    AT_CALL(0) {
-      EXPECT_EQ(VENDOR_SET_LPM_MODE, opcode);
-      EXPECT_EQ(BT_VND_LPM_ENABLE, *(uint8_t *)param);
-      low_power_state_callback(true);
-      thread_post(thread, flush_work_queue_item, NULL);
-      return 0;
-    }
-    AT_CALL(1) {
-      EXPECT_EQ(VENDOR_SET_LPM_MODE, opcode);
-      EXPECT_EQ(BT_VND_LPM_DISABLE, *(uint8_t *)param);
-      low_power_state_callback(true);
-      thread_post(thread, flush_work_queue_item, NULL);
-      return 0;
-    }
-  }
-
-  UNEXPECTED_CALL;
-  return 0;
+UNEXPECTED_CALL;
+return 0;
 }
 
-STUB_FUNCTION(void, vendor_set_callback, (vendor_async_opcode_t opcode, vendor_cb callback))
-  DURING(init) AT_CALL(0) {
+STUB_FUNCTION(int, vendor_send_async_command,
+              (vendor_async_opcode_t opcode, void* param))
+DURING(enable_disable) {
+  AT_CALL(0) {
     EXPECT_EQ(VENDOR_SET_LPM_MODE, opcode);
-    low_power_state_callback = callback;
-    return;
+    EXPECT_EQ(BT_VND_LPM_ENABLE, *(uint8_t*)param);
+    low_power_state_callback(true);
+    thread_post(thread, flush_work_queue_item, NULL);
+    return 0;
+  }
+  AT_CALL(1) {
+    EXPECT_EQ(VENDOR_SET_LPM_MODE, opcode);
+    EXPECT_EQ(BT_VND_LPM_DISABLE, *(uint8_t*)param);
+    low_power_state_callback(true);
+    thread_post(thread, flush_work_queue_item, NULL);
+    return 0;
   }
+}
+
+UNEXPECTED_CALL;
+return 0;
+}
+
+STUB_FUNCTION(void, vendor_set_callback,
+              (vendor_async_opcode_t opcode, vendor_cb callback))
+DURING(init) AT_CALL(0) {
+  EXPECT_EQ(VENDOR_SET_LPM_MODE, opcode);
+  low_power_state_callback = callback;
+  return;
+}
 
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
 }
 
 static void reset_for(TEST_MODES_T next) {
@@ -96,33 +94,33 @@ static void reset_for(TEST_MODES_T next) {
 }
 
 class LowPowerManagerTest : public AlarmTestHarness {
 protected:
-    virtual void SetUp() {
-      AlarmTestHarness::SetUp();
-      low_power_state_callback = NULL;
-      vendor.send_command = vendor_send_command;
-      vendor.send_async_command = vendor_send_async_command;
-      vendor.set_callback = vendor_set_callback;
-      manager = low_power_manager_get_test_interface(&vendor);
-      thread = thread_new("test_thread");
-      done = semaphore_new(0);
-
-      reset_for(init);
-      manager->init(thread);
-
-      EXPECT_CALL_COUNT(vendor_set_callback, 1);
-    }
-
-    virtual void TearDown() {
-      reset_for(cleanup);
-      manager->cleanup();
-
-      semaphore_free(done);
-      thread_free(thread);
-      AlarmTestHarness::TearDown();
-    }
-
-    vendor_t vendor;
+ protected:
+  virtual void SetUp() {
+    AlarmTestHarness::SetUp();
+    low_power_state_callback = NULL;
+    vendor.send_command = vendor_send_command;
+    vendor.send_async_command = vendor_send_async_command;
+    vendor.set_callback = vendor_set_callback;
+    manager = low_power_manager_get_test_interface(&vendor);
+    thread = thread_new("test_thread");
+    done = semaphore_new(0);
+
+    reset_for(init);
+    manager->init(thread);
+
+    EXPECT_CALL_COUNT(vendor_set_callback, 1);
+  }
+
+  virtual void TearDown() {
+    reset_for(cleanup);
+    manager->cleanup();
+
+    semaphore_free(done);
+    thread_free(thread);
+    AlarmTestHarness::TearDown();
+  }
+
+  vendor_t vendor;
 };
 
 TEST_F(LowPowerManagerTest, test_enable_disable) {
index 73dceff..29c130d 100644 (file)
 #include <stdint.h>
 
 #include "device/include/controller.h"
+#include "hci_internals.h"
 #include "osi/include/allocator.h"
 #include "osi/include/osi.h"
-#include "hci_internals.h"
 #include "packet_fragmenter.h"
 #include "test_stubs.h"
 
-DECLARE_TEST_MODES(
-  init,
-  set_data_sizes,
-  no_fragmentation,
-  fragmentation,
-  ble_no_fragmentation,
-  ble_fragmentation,
-  non_acl_passthrough_fragmentation,
-  no_reassembly,
-  reassembly,
-  non_acl_passthrough_reassembly
-);
+DECLARE_TEST_MODES(init, set_data_sizes, no_fragmentation, fragmentation,
+                   ble_no_fragmentation, ble_fragmentation,
+                   non_acl_passthrough_fragmentation, no_reassembly, reassembly,
+                   non_acl_passthrough_reassembly);
 
 #define LOCAL_BLE_CONTROLLER_ID 1
 
-static const char *sample_data =
-  "At this point they came in sight of thirty forty windmills that there are on plain, and "
-  "as soon as Don Quixote saw them he said to his squire, \"Fortune is arranging matters "
-  "for us better than we could have shaped our desires ourselves, for look there, friend "
-  "Sancho Panza, where thirty or more monstrous giants present themselves, all of whom I "
-  "mean to engage in battle and slay, and with whose spoils we shall begin to make our "
-  "fortunes; for this is righteous warfare, and it is God's good service to sweep so evil "
-  "a breed from off the face of the earth.\"";
-
-static const char *small_sample_data = "\"What giants?\" said Sancho Panza.";
+static const char* sample_data =
+    "At this point they came in sight of thirty forty windmills that there are "
+    "on plain, and "
+    "as soon as Don Quixote saw them he said to his squire, \"Fortune is "
+    "arranging matters "
+    "for us better than we could have shaped our desires ourselves, for look "
+    "there, friend "
+    "Sancho Panza, where thirty or more monstrous giants present themselves, "
+    "all of whom I "
+    "mean to engage in battle and slay, and with whose spoils we shall begin "
+    "to make our "
+    "fortunes; for this is righteous warfare, and it is God's good service to "
+    "sweep so evil "
+    "a breed from off the face of the earth.\"";
+
+static const char* small_sample_data = "\"What giants?\" said Sancho Panza.";
 static const uint16_t test_handle_start = (0x1992 & 0xCFFF) | 0x2000;
 static const uint16_t test_handle_continuation = (0x1992 & 0xCFFF) | 0x1000;
 static int packet_index;
 static unsigned int data_size_sum;
 
-static const packet_fragmenter_t *fragmenter;
+static const packet_fragmenter_tfragmenter;
 
-static BT_HDR *manufacture_packet_for_fragmentation(uint16_t event, const char *data) {
+static BT_HDR* manufacture_packet_for_fragmentation(uint16_t event,
+                                                    const char* data) {
   uint16_t data_length = strlen(data);
   uint16_t size = data_length;
   if (event == MSG_STACK_TO_HC_HCI_ACL) {
-    size += 4; // 2 for the handle, 2 for the length;
+    size += 4;  // 2 for the handle, 2 for the length;
   }
 
-  BT_HDR *packet = (BT_HDR *)osi_malloc(size + sizeof(BT_HDR));
+  BT_HDR* packet = (BT_HDR*)osi_malloc(size + sizeof(BT_HDR));
   packet->len = size;
   packet->offset = 0;
   packet->event = event;
   packet->layer_specific = 0;
-  uint8_t *packet_data = packet->data;
+  uint8_tpacket_data = packet->data;
 
   if (event == MSG_STACK_TO_HC_HCI_ACL) {
     UINT16_TO_STREAM(packet_data, test_handle_start);
@@ -84,8 +83,10 @@ static BT_HDR *manufacture_packet_for_fragmentation(uint16_t event, const char *
   return packet;
 }
 
-static void expect_packet_fragmented(uint16_t event, int max_acl_data_size, BT_HDR *packet, const char *expected_data, bool send_complete) {
-  uint8_t *data = packet->data + packet->offset;
+static void expect_packet_fragmented(uint16_t event, int max_acl_data_size,
+                                     BT_HDR* packet, const char* expected_data,
+                                     bool send_complete) {
+  uint8_t* data = packet->data + packet->offset;
   int expected_data_offset;
   int length_to_check;
 
@@ -123,28 +124,33 @@ static void expect_packet_fragmented(uint16_t event, int max_acl_data_size, BT_H
   if (event == MSG_STACK_TO_HC_HCI_ACL)
     EXPECT_TRUE(send_complete == (data_size_sum == strlen(expected_data)));
 
-  if (send_complete)
-    osi_free(packet);
+  if (send_complete) osi_free(packet);
 }
 
-static void manufacture_packet_and_then_reassemble(uint16_t event, uint16_t acl_size, const char *data) {
+static void manufacture_packet_and_then_reassemble(uint16_t event,
+                                                   uint16_t acl_size,
+                                                   const char* data) {
   uint16_t data_length = strlen(data);
 
   if (event == MSG_HC_TO_STACK_HCI_ACL) {
-    uint16_t total_length = data_length + 2; // 2 for l2cap length;
+    uint16_t total_length = data_length + 2;  // 2 for l2cap length;
     uint16_t length_sent = 0;
-    uint16_t l2cap_length = data_length - 2; // l2cap length field, 2 for the pretend channel id borrowed from the data
+    uint16_t l2cap_length = data_length - 2;  // l2cap length field, 2 for the
+                                              // pretend channel id borrowed
+                                              // from the data
 
     do {
-      int length_to_send = (length_sent + (acl_size - 4) < total_length) ? (acl_size - 4) : (total_length - length_sent);
-      BT_HDR *packet = (BT_HDR *)osi_malloc(length_to_send + 4 + sizeof(BT_HDR));
+      int length_to_send = (length_sent + (acl_size - 4) < total_length)
+                               ? (acl_size - 4)
+                               : (total_length - length_sent);
+      BT_HDR* packet = (BT_HDR*)osi_malloc(length_to_send + 4 + sizeof(BT_HDR));
       packet->len = length_to_send + 4;
       packet->offset = 0;
       packet->event = event;
       packet->layer_specific = 0;
 
-      uint8_t *packet_data = packet->data;
-      if (length_sent == 0) { // first packet
+      uint8_tpacket_data = packet->data;
+      if (length_sent == 0) {  // first packet
         UINT16_TO_STREAM(packet_data, test_handle_start);
         UINT16_TO_STREAM(packet_data, length_to_send);
         UINT16_TO_STREAM(packet_data, l2cap_length);
@@ -159,7 +165,7 @@ static void manufacture_packet_and_then_reassemble(uint16_t event, uint16_t acl_
       fragmenter->reassemble_and_dispatch(packet);
     } while (length_sent < total_length);
   } else {
-    BT_HDR *packet = (BT_HDR *)osi_malloc(data_length + sizeof(BT_HDR));
+    BT_HDR* packet = (BT_HDR*)osi_malloc(data_length + sizeof(BT_HDR));
     packet->len = data_length;
     packet->offset = 0;
     packet->event = event;
@@ -170,9 +176,10 @@ static void manufacture_packet_and_then_reassemble(uint16_t event, uint16_t acl_
   }
 }
 
-static void expect_packet_reassembled(uint16_t event, BT_HDR *packet, const char *expected_data) {
+static void expect_packet_reassembled(uint16_t event, BT_HDR* packet,
+                                      const char* expected_data) {
   uint16_t expected_data_length = strlen(expected_data);
-  uint8_t *data = packet->data + packet->offset;
+  uint8_tdata = packet->data + packet->offset;
 
   if (event == MSG_HC_TO_STACK_HCI_ACL) {
     uint16_t handle;
@@ -184,10 +191,10 @@ static void expect_packet_reassembled(uint16_t event, BT_HDR *packet, const char
 
     EXPECT_EQ(test_handle_start, handle);
     EXPECT_EQ(expected_data_length + 2, length);
-    EXPECT_EQ(expected_data_length - 2, l2cap_length); // -2 for the pretend channel id
+    EXPECT_EQ(expected_data_length - 2,
+              l2cap_length);  // -2 for the pretend channel id
   }
 
-
   for (int i = 0; i < expected_data_length; i++) {
     EXPECT_EQ(expected_data[i], data[i]);
     data_size_sum++;
@@ -196,75 +203,81 @@ static void expect_packet_reassembled(uint16_t event, BT_HDR *packet, const char
   osi_free(packet);
 }
 
-STUB_FUNCTION(void, fragmented_callback, (BT_HDR *packet, bool send_complete))
-  DURING(no_fragmentation) AT_CALL(0) {
-    expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 42, packet, small_sample_data, send_complete);
-    return;
-  }
+STUB_FUNCTION(void, fragmented_callback, (BT_HDR * packet, bool send_complete))
+DURING(no_fragmentation) AT_CALL(0) {
+  expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 42, packet,
+                           small_sample_data, send_complete);
+  return;
+}
 
-  DURING(fragmentation) {
-    expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 10, packet, sample_data, send_complete);
-    return;
-  }
+DURING(fragmentation) {
+  expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 10, packet, sample_data,
+                           send_complete);
+  return;
+}
 
-  DURING(ble_no_fragmentation) AT_CALL(0) {
-    expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 42, packet, small_sample_data, send_complete);
-    return;
-  }
+DURING(ble_no_fragmentation) AT_CALL(0) {
+  expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 42, packet,
+                           small_sample_data, send_complete);
+  return;
+}
 
-  DURING(ble_fragmentation) {
-    expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 10, packet, sample_data, send_complete);
-    return;
-  }
+DURING(ble_fragmentation) {
+  expect_packet_fragmented(MSG_STACK_TO_HC_HCI_ACL, 10, packet, sample_data,
+                           send_complete);
+  return;
+}
 
-  DURING(non_acl_passthrough_fragmentation) AT_CALL(0) {
-    expect_packet_fragmented(MSG_STACK_TO_HC_HCI_CMD, 10, packet, sample_data, send_complete);
-    return;
-  }
+DURING(non_acl_passthrough_fragmentation) AT_CALL(0) {
+  expect_packet_fragmented(MSG_STACK_TO_HC_HCI_CMD, 10, packet, sample_data,
+                           send_complete);
+  return;
+}
 
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
 }
 
-STUB_FUNCTION(void, reassembled_callback, (BT_HDR *packet))
-  DURING(no_reassembly) AT_CALL(0) {
-    expect_packet_reassembled(MSG_HC_TO_STACK_HCI_ACL, packet, small_sample_data);
-    return;
-  }
+STUB_FUNCTION(void, reassembled_callback, (BT_HDR * packet))
+DURING(no_reassembly) AT_CALL(0) {
+  expect_packet_reassembled(MSG_HC_TO_STACK_HCI_ACL, packet, small_sample_data);
+  return;
+}
 
-  DURING(reassembly) AT_CALL(0) {
-    expect_packet_reassembled(MSG_HC_TO_STACK_HCI_ACL, packet, sample_data);
-    return;
-  }
+DURING(reassembly) AT_CALL(0) {
+  expect_packet_reassembled(MSG_HC_TO_STACK_HCI_ACL, packet, sample_data);
+  return;
+}
 
-  DURING(non_acl_passthrough_reassembly) AT_CALL(0) {
-    expect_packet_reassembled(MSG_HC_TO_STACK_HCI_EVT, packet, sample_data);
-    return;
-  }
+DURING(non_acl_passthrough_reassembly) AT_CALL(0) {
+  expect_packet_reassembled(MSG_HC_TO_STACK_HCI_EVT, packet, sample_data);
+  return;
+}
 
-  UNEXPECTED_CALL;
+UNEXPECTED_CALL;
 }
 
-STUB_FUNCTION(void, transmit_finished_callback, (UNUSED_ATTR BT_HDR *packet, UNUSED_ATTR bool sent_all_fragments))
-  UNEXPECTED_CALL;
+STUB_FUNCTION(void, transmit_finished_callback,
+              (UNUSED_ATTR BT_HDR * packet,
+               UNUSED_ATTR bool sent_all_fragments))
+UNEXPECTED_CALL;
 }
 
 STUB_FUNCTION(uint16_t, get_acl_data_size_classic, (void))
-  DURING(no_fragmentation,
-         non_acl_passthrough_fragmentation,
-         no_reassembly) return 42;
-  DURING(fragmentation) return 10;
-  DURING(no_reassembly) return 1337;
-
-  UNEXPECTED_CALL;
-  return 0;
+DURING(no_fragmentation, non_acl_passthrough_fragmentation, no_reassembly)
+return 42;
+DURING(fragmentation) return 10;
+DURING(no_reassembly) return 1337;
+
+UNEXPECTED_CALL;
+return 0;
 }
 
 STUB_FUNCTION(uint16_t, get_acl_data_size_ble, (void))
-  DURING(ble_no_fragmentation) return 42;
-  DURING(ble_fragmentation) return 10;
+DURING(ble_no_fragmentation) return 42;
+DURING(ble_fragmentation) return 10;
 
-  UNEXPECTED_CALL;
-  return 0;
+UNEXPECTED_CALL;
+return 0;
 }
 
 static void reset_for(TEST_MODES_T next) {
@@ -277,38 +290,38 @@ static void reset_for(TEST_MODES_T next) {
 }
 
 class PacketFragmenterTest : public AllocationTestHarness {
-  protected:
-    virtual void SetUp() {
-      AllocationTestHarness::SetUp();
-      fragmenter = packet_fragmenter_get_test_interface(
-        &controller,
-        &allocator_malloc);
-
-      packet_index = 0;
-      data_size_sum = 0;
-
-      callbacks.fragmented = fragmented_callback;
-      callbacks.reassembled = reassembled_callback;
-      callbacks.transmit_finished = transmit_finished_callback;
-      controller.get_acl_data_size_classic = get_acl_data_size_classic;
-      controller.get_acl_data_size_ble = get_acl_data_size_ble;
-
-      reset_for(init);
-      fragmenter->init(&callbacks);
-    }
-
-    virtual void TearDown() {
-      fragmenter->cleanup();
-      AllocationTestHarness::TearDown();
-    }
-
-    controller_t controller;
-    packet_fragmenter_callbacks_t callbacks;
+ protected:
+  virtual void SetUp() {
+    AllocationTestHarness::SetUp();
+    fragmenter =
+        packet_fragmenter_get_test_interface(&controller, &allocator_malloc);
+
+    packet_index = 0;
+    data_size_sum = 0;
+
+    callbacks.fragmented = fragmented_callback;
+    callbacks.reassembled = reassembled_callback;
+    callbacks.transmit_finished = transmit_finished_callback;
+    controller.get_acl_data_size_classic = get_acl_data_size_classic;
+    controller.get_acl_data_size_ble = get_acl_data_size_ble;
+
+    reset_for(init);
+    fragmenter->init(&callbacks);
+  }
+
+  virtual void TearDown() {
+    fragmenter->cleanup();
+    AllocationTestHarness::TearDown();
+  }
+
+  controller_t controller;
+  packet_fragmenter_callbacks_t callbacks;
 };
 
 TEST_F(PacketFragmenterTest, test_no_fragment_necessary) {
   reset_for(no_fragmentation);
-  BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, small_sample_data);
+  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL,
+                                                        small_sample_data);
   fragmenter->fragment_and_dispatch(packet);
 
   EXPECT_EQ(strlen(small_sample_data), data_size_sum);
@@ -317,7 +330,8 @@ TEST_F(PacketFragmenterTest, test_no_fragment_necessary) {
 
 TEST_F(PacketFragmenterTest, test_fragment_necessary) {
   reset_for(fragmentation);
-  BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, sample_data);
+  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL,
+                                                        sample_data);
   fragmenter->fragment_and_dispatch(packet);
 
   EXPECT_EQ(strlen(sample_data), data_size_sum);
@@ -325,7 +339,8 @@ TEST_F(PacketFragmenterTest, test_fragment_necessary) {
 
 TEST_F(PacketFragmenterTest, test_ble_no_fragment_necessary) {
   reset_for(ble_no_fragmentation);
-  BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, small_sample_data);
+  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL,
+                                                        small_sample_data);
   packet->event |= LOCAL_BLE_CONTROLLER_ID;
   fragmenter->fragment_and_dispatch(packet);
 
@@ -335,7 +350,8 @@ TEST_F(PacketFragmenterTest, test_ble_no_fragment_necessary) {
 
 TEST_F(PacketFragmenterTest, test_ble_fragment_necessary) {
   reset_for(ble_fragmentation);
-  BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL, sample_data);
+  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ACL,
+                                                        sample_data);
   packet->event |= LOCAL_BLE_CONTROLLER_ID;
   fragmenter->fragment_and_dispatch(packet);
 
@@ -344,7 +360,8 @@ TEST_F(PacketFragmenterTest, test_ble_fragment_necessary) {
 
 TEST_F(PacketFragmenterTest, test_non_acl_passthrough_fragmentation) {
   reset_for(non_acl_passthrough_fragmentation);
-  BT_HDR *packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_CMD, sample_data);
+  BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_CMD,
+                                                        sample_data);
   fragmenter->fragment_and_dispatch(packet);
 
   EXPECT_EQ(strlen(sample_data), data_size_sum);
@@ -353,7 +370,8 @@ TEST_F(PacketFragmenterTest, test_non_acl_passthrough_fragmentation) {
 
 TEST_F(PacketFragmenterTest, test_no_reassembly_necessary) {
   reset_for(no_reassembly);
-  manufacture_packet_and_then_reassemble(MSG_HC_TO_STACK_HCI_ACL, 1337, small_sample_data);
+  manufacture_packet_and_then_reassemble(MSG_HC_TO_STACK_HCI_ACL, 1337,
+                                         small_sample_data);
 
   EXPECT_EQ(strlen(small_sample_data), data_size_sum);
   EXPECT_CALL_COUNT(reassembled_callback, 1);
@@ -361,7 +379,8 @@ TEST_F(PacketFragmenterTest, test_no_reassembly_necessary) {
 
 TEST_F(PacketFragmenterTest, test_reassembly_necessary) {
   reset_for(reassembly);
-  manufacture_packet_and_then_reassemble(MSG_HC_TO_STACK_HCI_ACL, 42, sample_data);
+  manufacture_packet_and_then_reassemble(MSG_HC_TO_STACK_HCI_ACL, 42,
+                                         sample_data);
 
   EXPECT_EQ(strlen(sample_data), data_size_sum);
   EXPECT_CALL_COUNT(reassembled_callback, 1);
@@ -369,7 +388,8 @@ TEST_F(PacketFragmenterTest, test_reassembly_necessary) {
 
 TEST_F(PacketFragmenterTest, test_non_acl_passthrough_reasseembly) {
   reset_for(non_acl_passthrough_reassembly);
-  manufacture_packet_and_then_reassemble(MSG_HC_TO_STACK_HCI_EVT, 42, sample_data);
+  manufacture_packet_and_then_reassemble(MSG_HC_TO_STACK_HCI_EVT, 42,
+                                         sample_data);
 
   EXPECT_EQ(strlen(sample_data), data_size_sum);
   EXPECT_CALL_COUNT(reassembled_callback, 1);