#endif
/******************************************************************************
-** Constants & Macros
-******************************************************************************/
+ * Constants & Macros
+ *****************************************************************************/
#include <stdbool.h>
} 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_HDR* buf);
void bthc_idle_timeout(void);
/** 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;
/*
typedef void* (*malloc_cb)(int size);
/* datapath buffer deallocation callback (callout) */
-typedef void (*mdealloc_cb)(void *p_buf);
+typedef void (*mdealloc_cb)(void* p_buf);
/* define callback of the cmd_xmit_cb
*
* 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)(void* p_mem);
/* hci command packet transmit callback (callout)
*
* 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
*/
*/
extern const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE;
-
#ifdef __cplusplus
}
#endif
#endif /* BT_VENDOR_LIB_H */
-
// 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_HDR* packet, bool is_received);
} btsnoop_t;
-const btsnoop_t *btsnoop_get_interface(void);
+const btsnoop_t* btsnoop_get_interface(void);
#ifdef __cplusplus
}
// 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.
// 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_HDR* p_buf);
#ifdef __cplusplus
}
extern "C" {
#endif
-const allocator_t *buffer_allocator_get_interface();
+const allocator_t* buffer_allocator_get_interface();
#ifdef __cplusplus
}
// 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
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);
} 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);
// 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
// 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_t* hci_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_t* hci_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_t* hci_hal_mct_get_interface(void);
+const hci_hal_t* hci_hal_mct_get_test_interface(vendor_t* vendor_interface);
#ifdef __cplusplus
}
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_t* hci_interface);
// Shuts down the HCI injection module.
void (*close)(void);
} hci_inject_t;
-const hci_inject_t *hci_inject_get_interface();
+const hci_inject_t* hci_inject_get_interface();
#ifdef __cplusplus
}
#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" {
///// 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 /////
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 {
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_t* queue);
// 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, void* data);
} hci_t;
-const hci_t *hci_layer_get_interface();
+const hci_t* hci_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();
#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_t* hci_packet_factory_get_interface();
#ifdef __cplusplus
}
#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
#endif
typedef struct {
- void (*parse_generic_command_complete)(BT_HDR *response);
+ void (*parse_generic_command_complete)(BT_HDR* response);
- 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_t* hci_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
}
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);
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
}
#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.
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_t* result_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_HDR* packet);
} packet_fragmenter_t;
-const packet_fragmenter_t *packet_fragmenter_get_interface();
+const packet_fragmenter_t* packet_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_t* packet_fragmenter_get_test_interface(
+ const controller_t* controller_interface,
+ const allocator_t* buffer_allocator_interface);
#ifdef __cplusplus
}
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.
// 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_t* p_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_t* p_data, uint16_t len);
#ifdef __cplusplus
}
#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, void* param);
// 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, void* param);
// 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_t* vendor_get_interface();
#ifdef __cplusplus
}
// 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_t* stack_config;
static int logfile_fd = INVALID_FD;
static bool module_started;
// 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 void* data, 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_t* start_up(void) {
module_started = true;
update_logging();
return NULL;
}
-static future_t *shut_down(void) {
+static future_t* shut_down(void) {
module_started = false;
update_logging();
}
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
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_HDR* buffer, bool is_received) {
+ const uint8_t* p = 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:
}
}
-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_t* btsnoop_get_interface() {
stack_config = stack_config_get_interface();
return &interface;
}
}
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 char* log_path = stack_config->get_btsnoop_log_path();
// Save the old log if configured to do so
if (stack_config->get_btsnoop_should_save_last()) {
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;
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;
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_t* data = &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);
}
#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_(int* fd);
+static void* listen_fn_(void* context);
-static const char *LISTEN_THREAD_NAME_ = "btsnoop_net_listen";
+static const char* LISTEN_THREAD_NAME_ = "btsnoop_net_listen";
static const int LOCALHOST_ = 0x7F000001;
static const int LISTEN_PORT_ = 8872;
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");
}
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_) {
}
}
-void btsnoop_net_write(const void *data, size_t length) {
+void btsnoop_net_write(const void* data, 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_);
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;
}
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;
}
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_);
return NULL;
}
-static void safe_close_(int *fd) {
+static void safe_close_(int* fd) {
assert(fd != NULL);
if (*fd != -1) {
close(*fd);
#include <assert.h>
-#include "buffer_allocator.h"
#include "bt_common.h"
+#include "buffer_allocator.h"
-static void *buffer_alloc(size_t size) {
+static void* buffer_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; }
#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);
}
#include "hci_hal.h"
-const hci_hal_t *hci_hal_get_interface() {
+const hci_hal_t* hci_hal_get_interface() {
#if (HCI_USE_MCT == TRUE)
return hci_hal_mct_get_interface();
#else
return hci_hal_h4_get_interface();
#endif
}
-
#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_t* upper_callbacks,
+ thread_t* upper_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_t* data,
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_t* buffer,
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_t* callbacks;
+static const vendor_t* vendor;
-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_t* uart_stream;
static serial_data_type_t current_data_type;
static bool stream_has_interpretation;
static bool stream_corruption_detected;
// 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);
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;
}
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;
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;
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;
}
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);
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
// 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;
}
// 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;
}
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;
}
// 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 {
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;
}
}
-const hci_hal_t *hci_hal_h4_get_interface() {
+const hci_hal_t* hci_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;
}
#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_t* upper_callbacks,
+ thread_t* upper_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_t* buffer,
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_t* data,
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_t* callbacks;
+static const vendor_t* vendor;
-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_t* event_stream;
+static eager_reader_t* acl_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);
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;
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) {
// 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) {
// 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_t* data, uint16_t length) {
assert(data != NULL);
assert(length > 0);
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
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_t* hci_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;
}
#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_t* socket;
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_t* hci_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(void* ptr);
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_t* hci;
+static const allocator_t* buffer_allocator;
+static socket_t* listen_socket;
+static thread_t* thread;
+static list_t* clients;
-static bool hci_inject_open(const hci_t *hci_interface) {
+static bool hci_inject_open(const hci_t* hci_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);
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:;
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);
}
}
-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;
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;
client->buffer_size += ret;
while (client->buffer_size > 3) {
- uint8_t *buffer = client->buffer;
+ uint8_t* buffer = 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;
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;
}
}
-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_t* hci_inject_get_interface() {
buffer_allocator = buffer_allocator_get_interface();
return &interface;
}
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_HDR* buffer;
} packet_receive_data_t;
typedef struct {
uint16_t opcode;
- future_t *complete_future;
+ future_t* complete_future;
command_complete_cb complete_callback;
command_status_cb status_callback;
- void *context;
- BT_HDR *command;
+ void* context;
+ BT_HDR* command;
} waiting_command_t;
// Using a define here, because it can be stringified for the property lookup
static const uint32_t EPILOG_TIMEOUT_MS = 3000;
static const uint32_t COMMAND_PENDING_TIMEOUT_MS = 8000;
-static future_t *shut_down();
+static future_t* shut_down();
-static void event_finish_startup(void *context);
+static void event_finish_startup(void* context);
static void firmware_config_callback(bool success);
-static void startup_timer_expired(void *context);
+static void startup_timer_expired(void* context);
-static void event_postload(void *context);
+static void event_postload(void* context);
static void sco_config_callback(bool success);
-static void event_epilog(void *context);
+static void event_epilog(void* context);
static void epilog_finished_callback(bool success);
-static void epilog_timer_expired(void *context);
+static void epilog_timer_expired(void* context);
-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_HDR* packet, bool send_transmit_finished);
+static void fragmenter_transmit_finished(BT_HDR* packet,
bool all_fragments_sent);
-static void dispatch_reassembled(BT_HDR *packet);
-static void command_timed_out(void *context);
+static void dispatch_reassembled(BT_HDR* packet);
+static void command_timed_out(void* context);
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_HDR* packet);
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_t* get_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_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 future_t *startup_future;
-static thread_t *thread; // We own this
+static future_t* startup_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_t* epilog_timer;
+static alarm_t* startup_timer;
// Outbound-related
static int command_credits = 1;
-static fixed_queue_t *command_queue;
-static fixed_queue_t *packet_queue;
+static fixed_queue_t* command_queue;
+static fixed_queue_t* packet_queue;
// Inbound-related
-static alarm_t *command_response_timer;
-static list_t *commands_pending_response;
+static alarm_t* command_response_timer;
+static list_t* commands_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_t* upwards_data_queue;
// Module lifecycle functions
-static future_t *start_up(void) {
+static future_t* start_up(void) {
int power_state = BT_VND_PWR_OFF;
- future_t *local_startup_future;
+ future_t* local_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;
// 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");
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;
}
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);
#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);
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_t* shut_down() {
LOG_INFO(LOG_TAG, "%s", __func__);
hci_inject->close();
}
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
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_t* stream = command->data + command->offset;
STREAM_TO_UINT16(wait_entry->opcode, stream);
wait_entry->complete_callback = complete_callback;
wait_entry->status_callback = status_callback;
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_t* wait_entry =
+ static_cast<waiting_command_t*>(osi_calloc(sizeof(waiting_command_t)));
+ future_t* future = future_new();
- uint8_t *stream = command->data + command->offset;
+ uint8_t* stream = command->data + command->offset;
STREAM_TO_UINT16(wait_entry->opcode, stream);
wait_entry->complete_future = future;
wait_entry->command = command;
return future;
}
-static void transmit_downward(data_dispatcher_type_t type, void *data) {
+static void transmit_downward(data_dispatcher_type_t type, void* data) {
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);
}
// Start up functions
-static void event_finish_startup(UNUSED_ATTR void *context) {
+static void event_finish_startup(UNUSED_ATTR void* context) {
LOG_INFO(LOG_TAG, "%s", __func__);
hal->open();
vendor->send_async_command(VENDOR_CONFIGURE_FIRMWARE, NULL);
pthread_mutex_unlock(&commands_pending_response_lock);
}
-static void startup_timer_expired(UNUSED_ATTR void *context) {
+static void startup_timer_expired(UNUSED_ATTR void* context) {
LOG_ERROR(LOG_TAG, "%s", __func__);
pthread_mutex_lock(&commands_pending_response_lock);
// Postload functions
-static void event_postload(UNUSED_ATTR void *context) {
+static void event_postload(UNUSED_ATTR void* context) {
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);
-
}
}
// Epilog functions
-static void event_epilog(UNUSED_ATTR void *context) {
+static void event_epilog(UNUSED_ATTR void* context) {
vendor->send_async_command(VENDOR_DO_EPILOG, NULL);
}
thread_stop(thread);
}
-static void epilog_timer_expired(UNUSED_ATTR void *context) {
+static void epilog_timer_expired(UNUSED_ATTR void* context) {
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_t* wait_entry =
+ static_cast<waiting_command_t*>(fixed_queue_dequeue(queue));
command_credits--;
// Move it to the list of commands awaiting response
}
}
-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);
}
// Callback for the fragmenter to send a fragment
-static void transmit_fragment(BT_HDR *packet, bool send_transmit_finished) {
+static void transmit_fragment(BT_HDR* packet, bool send_transmit_finished) {
uint16_t event = packet->event & MSG_EVT_MASK;
serial_data_type_t type = event_to_data_type(event);
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 void* context) {
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_t* wait_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);
}
// 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) {
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++;
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;
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;
}
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_t* stream = 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
// 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_HDR* packet) {
+ waiting_command_t* wait_entry = NULL;
+ uint8_t* stream = 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);
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);
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;
}
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
}
// Callback for the fragmenter to dispatch up a completely reassembled packet
-static void dispatch_reassembled(BT_HDR *packet) {
+static void dispatch_reassembled(BT_HDR* packet) {
// 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);
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;
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_t* get_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);
}
}
-const hci_t *hci_layer_get_interface() {
+const hci_t* hci_layer_get_interface() {
buffer_allocator = buffer_allocator_get_interface();
hal = hci_hal_get_interface();
btsnoop = btsnoop_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;
#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_t* buffer_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_HDR* make_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);
return packet;
}
-static BT_HDR *make_read_local_version_info(void) {
+static BT_HDR* make_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_HDR* make_read_bd_addr(void) {
return make_command_no_params(HCI_READ_BD_ADDR);
}
-static BT_HDR *make_read_local_supported_commands(void) {
+static BT_HDR* make_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_HDR* make_read_local_extended_features(uint8_t page_number) {
+ uint8_t* stream;
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_HDR* make_write_simple_pairing_mode(uint8_t mode) {
+ uint8_t* stream;
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_HDR* make_write_secure_connections_host_support(uint8_t mode) {
+ uint8_t* stream;
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_t* stream;
uint8_t parameter_size = sizeof(bt_event_mask_t);
- BT_HDR *packet = make_command(HCI_SET_EVENT_MASK, parameter_size, &stream);
+ BT_HDR* packet = 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_HDR* make_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_HDR* make_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_HDR* make_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_HDR* make_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_HDR* make_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_HDR* make_ble_read_suggested_default_data_length(void) {
+ return make_command_no_params(HCI_BLE_READ_DEFAULT_DATA_LENGTH);
}
-static BT_HDR *make_read_local_supported_codecs(void) {
- return make_command_no_params(HCI_READ_LOCAL_SUPPORTED_CODECS);
+static BT_HDR* make_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_t* stream;
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;
// Internal functions
-static BT_HDR *make_command_no_params(uint16_t opcode) {
+static BT_HDR* make_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_t* stream = 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_HDR* make_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;
}
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;
}
static const command_opcode_t NO_OPCODE_CHECKING = 0;
-static const allocator_t *buffer_allocator;
+static const allocator_t* buffer_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);
}
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_t* local_supported_codecs) {
+ uint8_t* stream = read_command_complete_header(
+ response, HCI_READ_LOCAL_SUPPORTED_CODECS, 0 /* bytes after */);
+ if (stream) {
STREAM_TO_UINT8(*number_of_local_supported_codecs, stream);
- for ( uint8_t i = 0; i < *number_of_local_supported_codecs; i++)
- {
+ for (uint8_t i = 0; i < *number_of_local_supported_codecs; i++) {
STREAM_TO_UINT8(*local_supported_codecs, stream);
local_supported_codecs++;
}
buffer_allocator->free(response);
}
-static void parse_read_bd_addr_response(
- BT_HDR *response,
- bt_bdaddr_t *address_ptr) {
-
- 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);
}
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);
}
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);
}
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);
// 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;
// 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
// 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;
}
}
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_t* hci_packet_parser_get_test_interface(
+ allocator_t* buffer_allocator_interface) {
buffer_allocator = buffer_allocator_interface;
return &interface;
}
LPM_WAKE_ASSERTED,
} wake_state_t;
-static void init(thread_t *post_thread);
+static void init(thread_t* post_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(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 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_t* thread;
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_t* idle_alarm;
static bool transmit_is_done;
static void wake_deassert();
// Interface functions
-static void init(thread_t *post_thread) {
+static void init(thread_t* post_thread) {
assert(post_thread != NULL);
thread = post_thread;
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) {
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);
}
}
stop_idle_timer();
}
-static void idle_timer_expired(UNUSED_ATTR void *context) {
+static void idle_timer_expired(UNUSED_ATTR void* context) {
if (state == LPM_ENABLED && wake_state == LPM_WAKE_W4_TIMEOUT)
thread_post(thread, event_idle_timeout, NULL);
}
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 void* context) {
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)
}
}
-const low_power_manager_t *low_power_manager_get_interface() {
+const low_power_manager_t* low_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;
}
#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_t* buffer_allocator;
+static const controller_t* controller;
+static const packet_fragmenter_callbacks_t* callbacks;
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_t* result_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_HDR* packet) {
assert(packet != NULL);
uint16_t event = packet->event & MSG_EVT_MASK;
- uint8_t *stream = packet->data + packet->offset;
+ uint8_t* stream = packet->data + packet->offset;
// We only fragment ACL packets
if (event != MSG_STACK_TO_HC_HCI_ACL) {
}
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;
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--;
return (UINT16_MAX - a) < b;
}
-static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR *packet) {
+static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR* packet) {
if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) {
- uint8_t *stream = packet->data;
+ uint8_t* stream = packet->data;
uint16_t handle;
uint16_t l2cap_length;
uint16_t acl_length;
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_HDR* hdl = 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;
// 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;
} 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_HDR* partial_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);
}
}
-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_t* packet_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_t* packet_fragmenter_get_test_interface(
+ const controller_t* controller_interface,
+ const allocator_t* buffer_allocator_interface) {
controller = controller_interface;
buffer_allocator = buffer_allocator_interface;
return &interface;
#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, void* param);
+static int send_async_command(vendor_async_opcode_t opcode, void* param);
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 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,
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_t* buffer_allocator;
+static const hci_t* hci;
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 void* lib_handle;
+static bt_vendor_interface_t* lib_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;
}
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, void* param) {
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, void* param) {
assert(lib_interface != NULL);
return lib_interface->op((bt_vendor_opcode_t)opcode, param);
}
}
/******************************************************************************
-**
-** 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);
}
// 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;
}
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_t* vendor_get_interface() {
buffer_allocator = buffer_allocator_get_interface();
return &interface;
}
#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;
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_t* hal;
static int dummy_serial_fd;
static int reentry_i = 0;
-static semaphore_t *done;
-static semaphore_t *reentry_semaphore;
+static semaphore_t* done;
+static semaphore_t* reentry_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;
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) {
}
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, char* data) {
+ int length = strlen(data) + 1; // + 1 for data type code
int i;
for (i = 0; i < length; i++) {
}
}
-static void write_packet(int fd, char first_byte, const void *data,
+static void write_packet(int fd, char first_byte, const void* data,
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 void* data,
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);
}
}
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);
}
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));
}
#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_t* hal;
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_t* done;
+static semaphore_t* reentry_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;
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) {
}
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, char* data) {
int length = strlen(data);
int i;
}
}
-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, char* data) {
int length = strlen(data);
for (int i = 0; i < length; i++) {
write(fd, &data[i], 1);
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);
}
#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_t* done;
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_HDR* data_to_receive;
-static void signal_work_item(UNUSED_ATTR void *context) {
+static void signal_work_item(UNUSED_ATTR void* context) {
semaphore_post(done);
}
-static void flush_thread(thread_t *thread) {
+static void flush_thread(thread_t* thread) {
// Double flush to ensure we get the next reactor cycle
thread_post(thread, signal_work_item, NULL);
semaphore_wait(done);
}
// 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_t* packet_data = packet->data;
if (event == MSG_STACK_TO_HC_HCI_ACL) {
UINT16_TO_STREAM(packet_data, test_handle);
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;
}
}
-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_t* buffer) {
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, void* param))
+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, (void* ptr))
+allocator_malloc.free(ptr);
}
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) {
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);
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);
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_HDR* manufacture_command_complete(command_opcode_t opcode) {
+ BT_HDR* ret = (BT_HDR*)osi_calloc(sizeof(BT_HDR) + 5);
+ uint8_t* stream = 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_HDR* manufacture_command_status(command_opcode_t opcode) {
+ BT_HDR* ret = (BT_HDR*)osi_calloc(sizeof(BT_HDR) + 6);
+ uint8_t* stream = 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;
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);
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);
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);
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);
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);
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);
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
#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_t* manager;
+static thread_t* thread;
+static semaphore_t* done;
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 void* context) {
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) {
}
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) {
#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_t* fragmenter;
-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_t* packet_data = packet->data;
if (event == MSG_STACK_TO_HC_HCI_ACL) {
UINT16_TO_STREAM(packet_data, test_handle_start);
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;
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_t* packet_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);
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;
}
}
-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_t* data = packet->data + packet->offset;
if (event == MSG_HC_TO_STACK_HCI_ACL) {
uint16_t handle;
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++;
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) {
}
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);
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);
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);
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);
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);
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);
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);
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);