summaryrefslogtreecommitdiffstats
path: root/btif/src/btif_hh.c
diff options
context:
space:
mode:
Diffstat (limited to 'btif/src/btif_hh.c')
-rw-r--r--btif/src/btif_hh.c233
1 files changed, 90 insertions, 143 deletions
diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c
index cdc80f5..4046964 100644
--- a/btif/src/btif_hh.c
+++ b/btif/src/btif_hh.c
@@ -118,7 +118,8 @@ static int btif_hh_keylockstates=0; //The current key state of each key
typedef enum
{
BTIF_HH_CONNECT_REQ_EVT = 0,
- BTIF_HH_DISCONNECT_REQ_EVT
+ BTIF_HH_DISCONNECT_REQ_EVT,
+ BTIF_HH_VUP_REQ_EVT
} btif_hh_req_evt_t;
@@ -164,6 +165,8 @@ extern void bta_hh_co_send_hid_info(btif_hh_device_t *p_dev, char *dev_name, UIN
UINT16 product_id, UINT16 version, UINT8 ctry_code,
int dscp_len, UINT8 *p_dscp);
extern BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
+extern void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr);
+
extern int scru_ascii_2_hex(char *p_ascii, int len, UINT8 *p_hex);
@@ -259,54 +262,6 @@ static btif_hh_device_t *btif_hh_find_connected_dev_by_bda(bt_bdaddr_t *bd_addr)
return NULL;
}
-static void btif_hh_update_keyboard_lockstates(btif_hh_device_t *p_dev)
-{
- UINT8 len = 2; //reportid + 1 byte report
-}
-
-/*******************************************************************************
-**
-** Function btif_hh_update_keyevents
-**
-** Description Called by bta_co_hh.c when a key with a
-** lock state is pressed OR released.
-**
-** Returns void
-*******************************************************************************/
-void btif_hh_update_keyevents(UINT8 dev_handle, int keyevents)
-{
- int keys_pressed_released;
-
- BTIF_TRACE_DEBUG4("%s, dev_handle %d, previous keyevents 0x%x, current keyevents 0x%x",
- __FUNCTION__, dev_handle, btif_hh_prev_keyevents,keyevents);
-
- //Determines which keys have been pressed and released
- //Bit set ==> key pressed
- //Bit unset ==> key no longer pressed
- //A key was pressed and released if bit from previous event was set
- //And current bit is not set. We detect this by bitwise anding prev
- //key event with the XOR of prev keyevents and the current key events.
- keys_pressed_released = (btif_hh_prev_keyevents) &
- (btif_hh_prev_keyevents ^ keyevents);
- BTIF_TRACE_DEBUG2("%s, keys_pressed_released 0x%x", __FUNCTION__,keys_pressed_released);
-
- //Set the prev_keyevents to the most recent key events.
- btif_hh_prev_keyevents = keyevents;
-
-
- if (keys_pressed_released)
- {
- //Determine state of the keys. (Caps/num/scroll engaged or not)
- btif_hh_keylockstates = btif_hh_keylockstates ^ keys_pressed_released;
-
- BTIF_TRACE_WARNING3("%s, keys_pressed_released 0x%x, btif_hh_keylockstates 0x%x",
- __FUNCTION__,keys_pressed_released,btif_hh_keylockstates);
-
- // btapp_hh_write_keylockstates();
- // btapp_hh_update_all_keyboard_lockstates();
- }
-}
-
/*******************************************************************************
**
** Function btif_hh_add_added_dev
@@ -393,14 +348,11 @@ void btif_hh_remove_device(bt_bdaddr_t bd_addr)
GKI_freebuf(p_dev->p_buf);
p_dev->p_buf = NULL;
}
-
-#if (defined(HH_USE_BTHID) && (HH_USE_BTHID == TRUE))
BTIF_TRACE_DEBUG2("%s: bthid fd = %d", __FUNCTION__, p_dev->fd);
if (p_dev->fd >= 0) {
close(p_dev->fd);
p_dev->fd = -1;
}
-#endif /* (defined(HH_USE_BTHID) && (HH_USE_BTHID == TRUE)) */
}
@@ -425,48 +377,80 @@ BOOLEAN btif_hh_copy_hid_info(tBTA_HH_DEV_DSCP_INFO* dest , tBTA_HH_DEV_DSCP_INF
return TRUE;
}
+
/*******************************************************************************
- **
- ** Function btif_hh_mouse_pairing
- **
- ** Description btif_dm uses this method to inform btif_hh that the mouse
- ** did fake pairing. A mouse is virtually plugged (paired)
- ** dircetly by connecting. If the connection is failed, we need
- ** remove the bonding.
- ** Returns void
- *******************************************************************************/
-void btif_hh_mouse_pairing(bt_bdaddr_t bd_addr)
+**
+** Function btif_btif_hh_virtual_unpug
+**
+** Description Virtual unplug initiated from the BTIF thread context
+** Special handling for HID mouse-
+**
+** Returns void
+**
+*******************************************************************************/
+
+void btif_hh_virtual_unpug(bt_bdaddr_t *bd_addr)
{
BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
- if (btif_hh_cb.status != BTIF_HH_ENABLED) {
- BTIF_TRACE_ERROR2("%s: Error, HH status = %d", __FUNCTION__, btif_hh_cb.status);
- return;
+ btif_hh_device_t *p_dev;
+ char bd_str[18];
+ sprintf(bd_str, "%02X:%02X:%02X:%02X:%02X:%02X",
+ bd_addr->address[0], bd_addr->address[1], bd_addr->address[2], bd_addr->address[3],
+ bd_addr->address[4], bd_addr->address[5]);
+ p_dev = btif_hh_find_dev_by_bda(bd_addr);
+ if (p_dev != NULL)
+ {
+ if(p_dev->attr_mask & HID_VIRTUAL_CABLE)
+ {
+ BTIF_TRACE_DEBUG1("%s Sending BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG", __FUNCTION__);
+ BTA_HhSendCtrl(p_dev->dev_handle, BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG);
+ }
+ else
+ BTA_HhClose(p_dev->dev_handle);
}
-
- btif_hh_cb.mouse_pairing = TRUE;
- memcpy(&(btif_hh_cb.mouse_pairing_bda), &bd_addr, BD_ADDR_LEN);
+ else
+ BTIF_TRACE_ERROR2("%s: Error, device %s not opened.", __FUNCTION__, bd_str);
+ return ;
}
+/*******************************************************************************
+**
+** Function btif_btif_hh_connect
+**
+** Description connection initiated from the BTIF thread context
+**
+** Returns void
+**
+*******************************************************************************/
+
+void btif_hh_connect(bt_bdaddr_t *bd_addr)
+{
+ tBTA_SEC sec_mask = BTUI_HH_SECURITY;
+ BD_ADDR *bda = (BD_ADDR*)bd_addr;
+ BTA_HhOpen(*bda, BTA_HH_PROTO_RPT_MODE, sec_mask);
+}
/*******************************************************************************
- **
- ** Function btif_hh_clear_mouse_pairing
- **
- ** Description btif_dm uses this method to check whether device disconnected
- ** is perform pairing. If yes, remove the bonding.
- ** Returns void
- *******************************************************************************/
-void btif_hh_clear_mouse_pairing(bt_bdaddr_t bd_addr)
+**
+** Function btif_btif_hh_disconnect
+**
+** Description disconnection initiated from the BTIF thread context
+**
+** Returns void
+**
+*******************************************************************************/
+
+void btif_hh_disconnect(bt_bdaddr_t *bd_addr)
{
- BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
- if (btif_hh_cb.mouse_pairing) {
- BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
- if (memcmp(&(btif_hh_cb.mouse_pairing_bda), &bd_addr, BD_ADDR_LEN) == 0) {
- btif_hh_cb.mouse_pairing = FALSE;
- //TODO: Send signal
- // SIG_HH_VUP
- }
+ BD_ADDR *bda = (BD_ADDR*)bd_addr;
+ btif_hh_device_t *p_dev;
+ p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
+ if (p_dev != NULL)
+ {
+ BTA_HhClose(p_dev->dev_handle);
}
+ else
+ BTIF_TRACE_DEBUG1("%s-- Error: device not connected:",__FUNCTION__);
}
/*****************************************************************************
@@ -538,13 +522,6 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
BTA_HhClose(p_data->conn.handle);
p_dev->dev_status = BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER;
HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status);
- if (btif_hh_cb.mouse_pairing &&
- memcmp(&(btif_hh_cb.mouse_pairing_bda), p_data->conn.bda, BD_ADDR_LEN) == 0){
- BTIF_TRACE_DEBUG0("OPEN_EVT: Mouse pairing");
- // VUP the device
- btif_hh_cb.mouse_pairing = FALSE;
- //BTA_HhSendCtrl(p_dev->dev_handle, BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG);
- }
}
else {
BTIF_TRACE_WARNING1("BTA_HH_OPEN_EVT: Found device...Getting dscp info for handle ... %d",p_data->conn.handle);
@@ -554,24 +531,11 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
BTA_HhGetDscpInfo(p_data->conn.handle);
p_dev->dev_status = BTHH_CONN_STATE_CONNECTED;
HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status);
- if (btif_hh_cb.mouse_pairing &&
- memcmp(&(btif_hh_cb.mouse_pairing_bda), p_data->conn.bda, BD_ADDR_LEN) == 0){
- btif_hh_cb.mouse_pairing = FALSE;
- }
}
}
else {
bt_bdaddr_t *bdaddr = (bt_bdaddr_t*)p_data->conn.bda;
HAL_CBACK(bt_hh_callbacks, connection_state_cb, (bt_bdaddr_t*) &p_data->conn.bda,BTHH_CONN_STATE_DISCONNECTED);
- if (btif_hh_cb.mouse_pairing &&
- memcmp(&(btif_hh_cb.mouse_pairing_bda), p_data->conn.bda, BD_ADDR_LEN) == 0)
- {
- BTIF_TRACE_WARNING0("BTA_HH_OPEN_EVT: Mouse paired but connectio failed. Remove bonding...");
- btif_hh_cb.mouse_pairing = FALSE;
- //TODO remove bonding
- //btif_dm_cb_remove_bond(bdaddr);
- HAL_CBACK(bt_hh_callbacks, virtual_unplug_cb,bdaddr,BTHH_CONN_STATE_DISCONNECTED);
- }
}
break;
case BTA_HH_CLOSE_EVT:
@@ -579,7 +543,6 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
p_data->dev_status.status, p_data->dev_status.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
if (p_dev != NULL) {
-#if (defined(HH_USE_BTHID) && (HH_USE_BTHID == TRUE))
BTIF_TRACE_DEBUG2("%s: bthid fd = %d", __FUNCTION__, p_dev->fd);
if (p_dev->fd >= 0){
UINT8 hidreport[9];
@@ -587,7 +550,6 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
hidreport[0]=1;
write(p_dev->fd, hidreport, 9);
}
-#endif
p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status);
BTIF_TRACE_DEBUG2("%s: Closing bthid.ko fd = %d", __FUNCTION__, p_dev->fd);
@@ -651,13 +613,10 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
BTIF_TRACE_ERROR0("BTA_HH_GET_DSCP_EVT: No HID device is currently connected");
return;
}
-
-#if (defined(HH_USE_BTHID) && (HH_USE_BTHID == TRUE))
if (p_dev->fd < 0) {
LOGE("BTA_HH_GET_DSCP_EVT: Error, failed to find the bthid driver...");
return;
}
-#endif
{
char *cached_name = NULL;
char name[] = "Broadcom Bluetooth HID";
@@ -697,13 +656,13 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
dscp_info.vendor_id,dscp_info.product_id);
BTA_HhAddDev(bda, p_dev->attr_mask,p_dev->sub_class,p_dev->app_id, dscp_info);
//TODO write hid info to nvram
- /*
- ret = btif_storage_add_hid_device_info(&(p_dev->bd_addr), p_dev->attr_mask,p_dev->sub_class,p_dev->app_id,
+ BTIF_TRACE_DEBUG0("BTA_HH_GET_DSCP_EVT:calling storage function");
+ /*ret = btif_storage_add_hid_device_info(&(p_dev->bd_addr), p_dev->attr_mask,p_dev->sub_class,p_dev->app_id,
p_data->dscp_info.vendor_id, p_data->dscp_info.product_id,
p_data->dscp_info.version, p_data->dscp_info.ctry_code,
len, p_data->dscp_info.descriptor.dsc_list);
- ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret);*/
+ //ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret);*/
BTIF_TRACE_WARNING0("BTA_HH_GET_DSCP_EVT: Called add device");
//Free buffer created for dscp_info;
@@ -713,13 +672,6 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
dscp_info.descriptor.dsc_list = NULL;
dscp_info.descriptor.dl_len=0;
}
-
-
-
- //TODO:SEND hid info signal
- //Sync HID Keyboard lockstates
- // btif_hh_sync_lockstate_reconnect(p_dev);
- //End Sync HID Keyboard lockstates
}
else {
//Device already added.
@@ -757,13 +709,10 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
p_data->dev_status.status, p_data->dev_status.handle);
p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
if (p_dev != NULL) {
- //TODO:
- //SEND COnnection signal and VUP signal
- if (btif_hh_cb.mouse_pairing &&
- memcmp(&(btif_hh_cb.mouse_pairing_bda), &(p_dev->bd_addr), BD_ADDR_LEN) == 0)
- {
- btif_hh_cb.mouse_pairing = FALSE;
- }
+ p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED;
+ HAL_CBACK(bt_hh_callbacks, connection_state_cb,&(p_dev->bd_addr), p_dev->dev_status);
+ btif_dm_cb_remove_bond(&(p_dev->bd_addr));
+ HAL_CBACK(bt_hh_callbacks, virtual_unplug_cb,&(p_dev->bd_addr),BTHH_CONN_STATE_DISCONNECTED);
}
break;
@@ -837,16 +786,26 @@ static void btif_hh_handle_evt(UINT16 event, char *p_param)
{
case BTIF_HH_CONNECT_REQ_EVT:
{
+ btif_hh_connect(bd_addr);
HAL_CBACK(bt_hh_callbacks, connection_state_cb,bd_addr,BTHH_CONN_STATE_CONNECTING);
}
break;
+
case BTIF_HH_DISCONNECT_REQ_EVT:
{
BTIF_TRACE_EVENT2("%s: event=%d", __FUNCTION__, event);
+ btif_hh_disconnect(bd_addr);
HAL_CBACK(bt_hh_callbacks, connection_state_cb,bd_addr,BTHH_CONN_STATE_DISCONNECTING);
}
break;
+ case BTIF_HH_VUP_REQ_EVT:
+ {
+ BTIF_TRACE_EVENT2("%s: event=%d", __FUNCTION__, event);
+ btif_hh_virtual_unpug(bd_addr);
+ }
+ break;
+
default:
{
BTIF_TRACE_WARNING2("%s : Unknown event 0x%x", __FUNCTION__, event);
@@ -898,7 +857,6 @@ static bt_status_t connect( bt_bdaddr_t *bd_addr)
BD_ADDR *bda = (BD_ADDR*)bd_addr;
tBTA_HH_CONN conn;
CHECK_BTHH_INIT();
- BTIF_TRACE_EVENT1("%s", __FUNCTION__);
dev = btif_hh_find_dev_by_bda(bd_addr);
sprintf(bda_str, "%02X:%02X:%02X:%02X:%02X:%02X",
(*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]);
@@ -930,12 +888,6 @@ static bt_status_t connect( bt_bdaddr_t *bd_addr)
(added_dev->attr_mask & HID_NORMALLY_CONNECTABLE) != 0 ||
(added_dev->attr_mask & HID_RECONN_INIT) == 0)
{
- tBTA_SEC sec_mask = BTUI_HH_SECURITY;
- if (check_cod(bd_addr, COD_HID_POINTING)){
- sec_mask = BTUI_HH_MOUSE_SECURITY;
- }
- BTA_HhOpen(*bda, BTA_HH_PROTO_RPT_MODE, sec_mask);
- //return BT_STATUS_SUCCESS;
return btif_transfer_context(btif_hh_handle_evt, BTIF_HH_CONNECT_REQ_EVT,
(char*)bd_addr, sizeof(bt_bdaddr_t), NULL);
}
@@ -950,6 +902,7 @@ static bt_status_t connect( bt_bdaddr_t *bd_addr)
else {
// SIG_HH_CONNECTION, *bda, HH_CONN_STATUS_FAILED_KBD_FROM_HOST);
}*/
+ return BT_STATUS_FAIL;
}
return BT_STATUS_BUSY;
@@ -969,17 +922,14 @@ static bt_status_t disconnect( bt_bdaddr_t *bd_addr )
CHECK_BTHH_INIT();
btif_hh_device_t *p_dev;
-
if (btif_hh_cb.status != BTIF_HH_ENABLED)
{
BTIF_TRACE_WARNING2("%s: Error, HH status = %d", __FUNCTION__, btif_hh_cb.status);
return BT_STATUS_FAIL;
}
-
p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
if (p_dev != NULL)
{
- BTA_HhClose(p_dev->dev_handle);
return btif_transfer_context(btif_hh_handle_evt, BTIF_HH_DISCONNECT_REQ_EVT,
(char*)bd_addr, sizeof(bt_bdaddr_t), NULL);
}
@@ -1012,21 +962,18 @@ static bt_status_t virtual_unplug (bt_bdaddr_t *bd_addr)
BTIF_TRACE_ERROR2("%s: Error, HH status = %d", __FUNCTION__, btif_hh_cb.status);
return BT_STATUS_FAIL;
}
-
p_dev = btif_hh_find_dev_by_bda(bd_addr);
- if (p_dev != NULL)
+ if (!p_dev)
{
- BTA_HhSendCtrl(p_dev->dev_handle, BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG);
- return BT_STATUS_FAIL;
- }
- else {
BTIF_TRACE_ERROR2("%s: Error, device %s not opened.", __FUNCTION__, bd_str);
return BT_STATUS_FAIL;
}
-
+ btif_transfer_context(btif_hh_handle_evt, BTIF_HH_VUP_REQ_EVT,
+ (char*)bd_addr, sizeof(bt_bdaddr_t), NULL);
return BT_STATUS_SUCCESS;
}
+
/*******************************************************************************
**
** Function set_info