OSDN Git Service

Bluetooth: Add support to send/receive raw command/event
authorSrinu Jella <sjella@codeaurora.org>
Fri, 6 Dec 2013 09:55:26 +0000 (15:25 +0530)
committerLinux Build Service Account <lnxbuild@localhost>
Wed, 24 Aug 2016 14:09:32 +0000 (08:09 -0600)
Bluetooth: Add support to send/receive raw command/event

Support added to send/Receive raw command/event.

Change-Id: I194e9ceed29d60de492427784ae340691e4254e7
CRsFixed: 598650

Bluetooth: Support to send HCI raw command to stack.

Provide an interface in stack to send
HCI raw commands to stack.

Change-Id: Id70d419c19a2b983450ebc113b8d0cca2b36ecf9
CRs-fixed: 751111

17 files changed:
bta/dm/bta_dm_act.c
bta/dm/bta_dm_api.c
bta/dm/bta_dm_int.h
bta/dm/bta_dm_main.c
bta/include/bta_api.h
btif/include/btif_api.h
btif/src/bluetooth.c
btif/src/btif_core.c
include/bt_target.h
service/hal/bluetooth_interface.cpp
service/hal/fake_bluetooth_interface.cpp
stack/btm/btm_devctl.c
stack/btm/btm_int.h
stack/btu/btu_hcif.c
stack/hcic/hcicmds.c
stack/include/btm_api.h
stack/include/hcimsgs.h

index 0d31138..d520f3a 100644 (file)
@@ -662,7 +662,28 @@ void bta_dm_set_visibility(tBTA_DM_MSG *p_data)
 
 /*******************************************************************************
 **
-** Function         bta_dm_process_remove_device
+** Function         bta_dm_hci_raw_command
+**
+** Description      Send a HCI RAW command to the controller
+**
+**
+** Returns          void
+**
+*******************************************************************************/
+void bta_dm_hci_raw_command (tBTA_DM_MSG *p_data)
+{
+    tBTM_STATUS status;
+    APPL_TRACE_API("bta_dm_hci_raw_command");
+    status = BTM_Hci_Raw_Command(p_data->btc_command.opcode,p_data->btc_command.param_len,p_data->btc_command.p_param_buf, p_data->btc_command.p_cback);
+
+}
+
+/*******************************************************************************
+**
+** Function         bta_dm_process_remove_deviced
+**
+**
+** Returns          void
 **
 ** Description      Removes device, Disconnects ACL link if required.
 ****
index 82dd8b2..099126b 100644 (file)
@@ -194,6 +194,43 @@ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 p
 
 /*******************************************************************************
 **
+** Function         BTA_DmHciRawCommand
+**
+** Description      This function sends the HCI Raw  command
+**                  to the controller
+**
+**
+** Returns          tBTA_STATUS
+**
+*******************************************************************************/
+tBTA_STATUS BTA_DmHciRawCommand (UINT16 opcode, UINT8 param_len,
+                                         UINT8 *p_param_buf,
+                                         tBTA_RAW_CMPL_CBACK *p_cback)
+{
+
+    tBTA_DM_API_RAW_COMMAND    *p_msg;
+    UINT16 size;
+
+    size = sizeof (tBTA_DM_API_RAW_COMMAND) + param_len;
+    p_msg = (tBTA_DM_API_RAW_COMMAND *) osi_malloc(size);
+    if (p_msg != NULL)
+    {
+        p_msg->hdr.event = BTA_DM_API_HCI_RAW_COMMAND_EVT;
+        p_msg->opcode = opcode;
+        p_msg->param_len = param_len;
+        p_msg->p_param_buf = (UINT8 *)(p_msg + 1);
+        p_msg->p_cback = p_cback;
+
+        memcpy (p_msg->p_param_buf, p_param_buf, param_len);
+
+        bta_sys_sendmsg(p_msg);
+    }
+    return BTA_SUCCESS;
+
+}
+
+/*******************************************************************************
+**
 ** Function         BTA_DmSearch
 **
 ** Description      This function searches for peer Bluetooth devices. It performs
index a5fe0ad..ca55713 100644 (file)
@@ -122,6 +122,7 @@ enum
     BTA_DM_API_EXECUTE_CBACK_EVT,
     BTA_DM_API_REMOVE_ALL_ACL_EVT,
     BTA_DM_API_REMOVE_DEVICE_EVT,
+    BTA_DM_API_HCI_RAW_COMMAND_EVT,
     BTA_DM_MAX_EVT
 };
 
@@ -167,6 +168,16 @@ typedef struct
     UINT8           conn_paired_only;
 } tBTA_DM_API_SET_VISIBILITY;
 
+/* data type for BTA_DM_API_HCI_RAW_COMMAND_EVT */
+typedef struct
+{
+    BT_HDR              hdr;
+    UINT16              opcode;
+    UINT8               param_len;
+    UINT8               *p_param_buf;
+    tBTA_RAW_CMPL_CBACK *p_cback;
+} tBTA_DM_API_RAW_COMMAND;
+
 enum
 {
     BTA_DM_RS_NONE,     /* straight API call */
@@ -740,6 +751,7 @@ typedef union
 
     tBTA_DM_API_REMOVE_ACL              remove_acl;
     tBTA_DM_API_REMOVE_ALL_ACL          remove_all_acl;
+    tBTA_DM_API_RAW_COMMAND btc_command;
 
 } tBTA_DM_MSG;
 
@@ -1175,4 +1187,5 @@ extern void bta_dm_execute_callback(tBTA_DM_MSG *p_data);
 
 
 extern void bta_dm_remove_all_acl(tBTA_DM_MSG *p_data);
+extern void bta_dm_hci_raw_command(tBTA_DM_MSG *p_data);
 #endif /* BTA_DM_INT_H */
index e6d791a..e9caea6 100644 (file)
@@ -119,6 +119,7 @@ const tBTA_DM_ACTION bta_dm_action[] =
 
     bta_dm_remove_all_acl,      /* BTA_DM_API_REMOVE_ALL_ACL_EVT */
     bta_dm_remove_device,       /* BTA_DM_API_REMOVE_DEVICE_EVT */
+    bta_dm_hci_raw_command    /* BTA_DM_API_HCI_RAW_COMMAND_EVT */
 };
 
 
index b305499..13eae45 100644 (file)
@@ -967,6 +967,9 @@ typedef struct
     tBTA_DM_BLE_PF_ADV_TRACK_ENTRIES num_of_tracking_entries;
 } tBTA_DM_BLE_PF_FILT_PARAMS;
 
+/* HCI RAW Command Callback */
+typedef tBTM_RAW_CMPL_CB        tBTA_RAW_CMPL_CBACK;
+
 /* Search callback events */
 #define BTA_DM_INQ_RES_EVT              0       /* Inquiry result for a peer device. */
 #define BTA_DM_INQ_CMPL_EVT             1       /* Inquiry complete. */
@@ -1397,6 +1400,20 @@ extern void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode,
 
 /*******************************************************************************
 **
+** Function         BTA_DmHciRawCommand
+**
+** Description      This function sends the HCI RAW command
+**                  to the controller
+**
+**
+** Returns          tBTA_STATUS
+**
+*******************************************************************************/
+extern tBTA_STATUS BTA_DmHciRawCommand (UINT16 opcode, UINT8 param_len,UINT8 *p_param_buf, tBTA_RAW_CMPL_CBACK *p_cback);
+
+
+/*******************************************************************************
+**
 ** Function         BTA_DmSearch
 **
 ** Description      This function searches for peer Bluetooth devices.  It
index 355f188..14e16cb 100644 (file)
@@ -379,6 +379,17 @@ bt_status_t btif_dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len);
 
 /*******************************************************************************
 **
+** Function         btif_hci_cmd_send
+**
+** Description      Sends a HCI Raw command to the controller
+**
+** Returns          BT_STATUS_SUCCESS on success
+**
+*******************************************************************************/
+bt_status_t btif_hci_cmd_send(uint16_t opcode, uint8_t *buf, uint8_t len);
+
+/*******************************************************************************
+**
 ** Function         btif_le_test_mode
 **
 ** Description     Sends a HCI BLE Test command to the Controller
index 1414138..d1d9634 100644 (file)
@@ -435,6 +435,19 @@ int dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len)
     return btif_dut_mode_send(opcode, buf, len);
 }
 
+#if HCI_RAW_CMD_INCLUDED == TRUE
+int hci_cmd_send(uint16_t opcode, uint8_t* buf, uint8_t len)
+{
+    ALOGI("hci_cmd_send");
+
+    /* sanity check */
+    if (interface_ready() == FALSE)
+        return BT_STATUS_NOT_READY;
+
+    return btif_hci_cmd_send(opcode, buf, len);
+}
+#endif
+
 #if BLE_INCLUDED == TRUE
 int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len)
 {
@@ -495,6 +508,11 @@ static const bt_interface_t bluetoothInterface = {
     get_profile_interface,
     dut_mode_configure,
     dut_mode_send,
+#if HCI_RAW_CMD_INCLUDED == TRUE
+    hci_cmd_send,
+#else
+    NULL,
+#endif
 #if BLE_INCLUDED == TRUE
     le_test_mode,
 #else
index 929e23b..6338c49 100644 (file)
@@ -710,6 +710,49 @@ bt_status_t btif_cleanup_bluetooth(void)
 
 /*******************************************************************************
 **
+**   BTIF Test Mode APIs
+**
+*****************************************************************************/
+#if HCI_RAW_CMD_INCLUDED == TRUE
+/*******************************************************************************
+**
+** Function         btif_hci_event_cback
+**
+** Description     Callback invoked on receiving HCI event
+**
+** Returns          None
+**
+*******************************************************************************/
+static void btif_hci_event_cback ( tBTM_RAW_CMPL *p )
+{
+    BTIF_TRACE_DEBUG("%s", __FUNCTION__);
+    if(p != NULL)
+    {
+        HAL_CBACK(bt_hal_cbacks, hci_event_recv_cb, p->event_code, p->p_param_buf,
+                                                                p->param_len);
+    }
+}
+
+/*******************************************************************************
+**
+** Function        btif_hci_cmd_send
+**
+** Description     Sends a HCI raw command to the controller
+**
+** Returns         BT_STATUS_SUCCESS on success
+**
+*******************************************************************************/
+bt_status_t btif_hci_cmd_send(uint16_t opcode, uint8_t *buf, uint8_t len)
+{
+    BTIF_TRACE_DEBUG("%s", __FUNCTION__);
+
+    BTM_Hci_Raw_Command(opcode, len, buf, btif_hci_event_cback);
+    return BT_STATUS_SUCCESS;
+}
+#endif
+
+/*******************************************************************************
+**
 ** Function         btif_dut_mode_cback
 **
 ** Description     Callback invoked on completion of vendor specific test mode command
index 66e6647..58e15cb 100644 (file)
 #endif
 
 
+
+#ifndef HCI_RAW_CMD_INCLUDED
+#define HCI_RAW_CMD_INCLUDED    TRUE
+#endif
+
 /******************************************************************************
 **
 ** BLE
index a551fee..d2e48ea 100644 (file)
@@ -207,7 +207,8 @@ bt_callbacks_t bt_callbacks = {
   ThreadEventCallback,
   nullptr, /* dut_mode_recv_cb */
   nullptr, /* le_test_mode_cb */
-  nullptr  /* energy_info_cb */
+  nullptr, /* energy_info_cb */
+  nullptr  /*hci_event_recv_cb */
 };
 
 bt_os_callouts_t bt_os_callouts = {
index 5036c63..b93470e 100644 (file)
@@ -74,7 +74,8 @@ bt_interface_t fake_bt_iface = {
   nullptr, /* dump */
   nullptr, /* config clear */
   nullptr, /* interop_database_clear */
-  nullptr  /* interop_database_add */
+  nullptr, /* interop_database_add */
+  nullptr  /* hci_cmd_send */
 };
 
 }  // namespace
index 18e20b5..62ed219 100644 (file)
@@ -632,6 +632,58 @@ tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb)
     return (p_prev);
 }
 
+
+/*******************************************************************************
+**
+** Function         BTM_Hci_Raw_Command
+**
+** Description      Send  HCI raw command to the controller.
+**
+** Returns
+**      BTM_SUCCESS         Command sent. Does not expect command complete
+**                              event. (command cmpl callback param is NULL)
+**      BTM_CMD_STARTED     Command sent. Waiting for command cmpl event.
+**
+**
+*******************************************************************************/
+tBTM_STATUS BTM_Hci_Raw_Command(UINT16 opcode, UINT8 param_len,
+                              UINT8 *p_param_buf, tBTM_RAW_CMPL_CB *p_cb)
+{
+    void *p_buf;
+#if HCI_RAW_CMD_INCLUDED == TRUE
+    tBTM_DEVCB  *p_devcb = &btm_cb.devcb;
+#endif
+
+    BTM_TRACE_EVENT ("BTM: BTM_Hci_Raw_Command: Opcode: 0x%04X, ParamLen: %i.",
+                      opcode, param_len);
+
+    /* Allocate a buffer to hold HCI command plus the callback function */
+    p_buf = osi_malloc((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) +
+                            param_len + HCIC_PREAMBLE_SIZE));
+    if (p_buf != NULL)
+    {
+        btsnd_hcic_raw_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb);
+
+        /* Return value */
+#if HCI_RAW_CMD_INCLUDED == TRUE
+        if (p_cb != NULL) {
+            if(p_cb != (p_devcb->p_hci_evt_cb)) {
+                p_devcb->p_hci_evt_cb = p_cb;
+            }
+            return BTM_CMD_STARTED;
+        }
+#else
+        if (p_cb != NULL)
+            return BTM_CMD_STARTED;
+#endif
+        else
+            return BTM_SUCCESS;
+    }
+    else
+        return BTM_NO_RESOURCES;
+
+}
+
 /*******************************************************************************
 **
 ** Function         BTM_VendorSpecificCommand
@@ -667,6 +719,33 @@ tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
         return (BTM_SUCCESS);
 }
 
+#if HCI_RAW_CMD_INCLUDED == TRUE
+/*******************************************************************************
+**
+** Function         btm_hci_event
+**
+** Description      This function is called when HCI event is received
+**                  from the HCI layer.
+**
+** Returns          void
+**
+*******************************************************************************/
+void btm_hci_event(UINT8 *p, UINT8 event_code, UINT8 param_len)
+{
+    tBTM_DEVCB     *p_devcb = &btm_cb.devcb;
+    tBTM_RAW_CMPL  raw_cplt_params;
+
+    /* If there was a callback address for raw cmd complete, call it */
+    if (p_devcb->p_hci_evt_cb)
+    {
+        /* Pass paramters to the callback function */
+        raw_cplt_params.event_code = event_code;   /* Number of bytes in return info */
+        raw_cplt_params.param_len = param_len;    /* Number of bytes in return info */
+        raw_cplt_params.p_param_buf = p;
+        (p_devcb->p_hci_evt_cb) (&raw_cplt_params);  /* Call the cmd complete callback function */
+    }
+}
+#endif
 
 /*******************************************************************************
 **
index 923ffb3..b02d51b 100644 (file)
@@ -184,6 +184,11 @@ BT_OCTET16 ble_encryption_key_value; /* BLE encryption key */
 
 #endif  /* BLE_INCLUDED */
 
+#if HCI_RAW_CMD_INCLUDED == TRUE
+    tBTM_RAW_CMPL_CB     *p_hci_evt_cb;       /* Callback function to be called when
+                                                HCI event is received successfully */
+#endif
+
     tBTM_IO_CAP          loc_io_caps;       /* IO capability of the local device */
     tBTM_AUTH_REQ        loc_auth_req;      /* the auth_req flag  */
     BOOLEAN              secure_connections_only;    /* Rejects service level 0 connections if */
@@ -1051,6 +1056,10 @@ extern BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec);
 extern void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec);
 #endif  /* BLE_INCLUDED */
 
+/* HCI event handler */
+#if HCI_RAW_CMD_INCLUDED == TRUE
+extern void btm_hci_event(UINT8 *p, UINT8 event_code, UINT8 param_len);
+#endif
 /* Vendor Specific Command complete evt handler */
 extern void btm_vsc_complete (UINT8 *p, UINT16 cc_opcode, UINT16 evt_len,
                               tBTM_CMPL_CB *p_vsc_cplt_cback);
index 3acd05c..d76fe3d 100644 (file)
@@ -339,6 +339,9 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
                 btm_vendor_specific_evt (p, hci_evt_len);
             break;
     }
+#if HCI_RAW_CMD_INCLUDED == TRUE
+    btm_hci_event (p, hci_evt_code , hci_evt_len);
+#endif
 }
 
 /*******************************************************************************
index 34fce49..5d15716 100644 (file)
@@ -1427,6 +1427,26 @@ BOOLEAN btsnd_hcic_write_pagescan_type (UINT8 type)
 #error "HCI_CMD_BUF_SIZE must be larger than 268"
 #endif
 
+
+void btsnd_hcic_raw_cmd (void *buffer, UINT16 opcode, UINT8 len,
+                                 UINT8 *p_data, void *p_cmd_cplt_cback)
+{
+    BT_HDR *p = (BT_HDR *)buffer;
+    UINT8 *pp = (UINT8 *)(p + 1);
+
+    p->len    = HCIC_PREAMBLE_SIZE + len;
+    p->offset = sizeof(void *);
+
+    *((void **)pp) = p_cmd_cplt_cback;  /* Store command complete callback in buffer */
+    pp += sizeof(void *);               /* Skip over callback pointer */
+
+    UINT16_TO_STREAM (pp, opcode);
+    UINT8_TO_STREAM  (pp, len);
+    ARRAY_TO_STREAM  (pp, p_data, len);
+
+    btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
+}
+
 void btsnd_hcic_vendor_spec_cmd (void *buffer, UINT16 opcode, UINT8 len,
                                  UINT8 *p_data, void *p_cmd_cplt_cback)
 {
index 26895b4..4ba608a 100644 (file)
@@ -110,6 +110,14 @@ typedef struct
     UINT8   *p_param_buf;
 } tBTM_VSC_CMPL;
 
+/* Structure returned with HCI Raw Command complete callback */
+typedef struct
+{
+    UINT8  event_code;
+    UINT8  param_len;
+    UINT8   *p_param_buf;
+} tBTM_RAW_CMPL;
+
 #define  BTM_VSC_CMPL_DATA_SIZE  (BTM_MAX_VENDOR_SPECIFIC_LEN + sizeof(tBTM_VSC_CMPL))
 /**************************************************
 **  Device Control and General Callback Functions
@@ -149,6 +157,11 @@ typedef void (tBTM_CMPL_CB) (void *p1);
 */
 typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1);
 
+/* HCI RAW CMD callback function for notifying an application that a synchronous
+** BTM function is complete. The pointer contains the address of any returned data.
+*/
+typedef void (tBTM_RAW_CMPL_CB) (tBTM_RAW_CMPL *p1);
+
 /* Callback for apps to check connection and inquiry filters.
 ** Parameters are the BD Address of remote and the Dev Class of remote.
 ** If the app returns none zero, the connection or inquiry result will be dropped.
@@ -2039,6 +2052,18 @@ extern tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_reg
 
 /*******************************************************************************
 **
+** Function         BTM_Hci_Raw_Command
+**
+** Description      Send a HCI RAW started testingcommand to the controller.
+**
+*******************************************************************************/
+extern tBTM_STATUS BTM_Hci_Raw_Command(UINT16 opcode,
+                                                         UINT8 param_len,
+                                                         UINT8 *p_param_buf,
+                                                         tBTM_RAW_CMPL_CB *p_cb);
+
+/*******************************************************************************
+**
 ** Function         BTM_VendorSpecificCommand
 **
 ** Description      Send a vendor specific HCI command to the controller.
index b59cbfa..779d79e 100644 (file)
@@ -629,6 +629,8 @@ extern BOOLEAN btsnd_hcic_write_inquiry_mode(UINT8 type);              /* Write
 #define HCID_HEADER_SIZE      4
 
 #define HCID_GET_SCO_LEN(p)  (*((UINT8 *)((p) + 1) + p->offset + 2))
+extern void btsnd_hcic_raw_cmd (void *buffer, UINT16 opcode, UINT8 len,
+                                 UINT8 *p_data, void *p_cmd_cplt_cback);
 
 extern void btsnd_hcic_vendor_spec_cmd (void *buffer, UINT16 opcode,
                                         UINT8 len, UINT8 *p_data,