summaryrefslogtreecommitdiffstats
path: root/btif/src
diff options
context:
space:
mode:
authorHarish Paryani <hparyani@broadcom.com>2012-04-03 19:18:37 -0700
committerMatthew Xie <mattx@google.com>2012-07-14 11:19:14 -0700
commit04db88d9bd23fa98916e031987f3ba2063783acc (patch)
tree2f12d6473787bb060984d126ef341b4aeaa4b22b /btif/src
parentac6d66d9bd6bcd4aafb80d50368167e1b9069a41 (diff)
downloadexternal_bluetooth_bluedroid-04db88d9bd23fa98916e031987f3ba2063783acc.zip
external_bluetooth_bluedroid-04db88d9bd23fa98916e031987f3ba2063783acc.tar.gz
external_bluetooth_bluedroid-04db88d9bd23fa98916e031987f3ba2063783acc.tar.bz2
Check-in Mouse pairing fixes.
Change-Id: I55d018d204a2fd20a934e1521457119fa118ceb6
Diffstat (limited to 'btif/src')
-rwxr-xr-x[-rw-r--r--]btif/src/btif_dm.c55
-rw-r--r--btif/src/btif_hh.c233
-rw-r--r--btif/src/btif_storage.c222
3 files changed, 314 insertions, 196 deletions
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index 40dcdc4..610cd3f 100644..100755
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -318,38 +318,7 @@ static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr)
{
bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
- /* TODO:
- ** 1. Check if ACL is already up with this device
- ** 2. Disable unpaired devices from connecting while we are bonding
- ** 3. special handling for HID devices
- */
- if (check_cod(bd_addr, COD_HID_POINTING))
- {
- /* For HID mouse, no pairing required. Hence we fake the pairing process
- * by retrieving the remote device name.
- */
- BTIF_TRACE_DEBUG0("Create bond for hid mouse");
- tBTM_STATUS status;
- BD_ADDR bda;
- bdcpy(bda, bd_addr->address);
-
- BTIF_TRACE_DEBUG1("%s: Bypass bonding for HID Mouse", __FUNCTION__);
- status = BTM_ReadRemoteDeviceName(bda, hid_remote_name_cback);
-
- if (status != BTM_CMD_STARTED)
- {
- BTIF_TRACE_DEBUG2("%s: status = %d", __FUNCTION__, status);
- bond_state_changed(BT_STATUS_FAIL, bd_addr, BT_BOND_STATE_NONE);
- return;
- }
- /* Trigger SDP on the device */
- BTIF_TRACE_DEBUG1("%s:Starting SDP", __FUNCTION__);
- btif_dm_get_remote_services(bd_addr);
- }
- else
- {
- BTA_DmBond ((UINT8 *)bd_addr->address);
- }
+ BTA_DmBond ((UINT8 *)bd_addr->address);
}
@@ -363,22 +332,9 @@ static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr)
** Returns void
**
*******************************************************************************/
-static void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
+void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
{
bdstr_t bdstr;
- /*special handling for HID devices */
-#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
- if (check_cod(bd_addr, COD_HID_POINTING )) {
- btif_hh_remove_device(*bd_addr);
- //todo
- //virtual_unplug(bd_addr);
- bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_NONE);
- return;
- }
- else if (check_cod(bd_addr, COD_HID_KEYBOARD)|| check_cod(bd_addr, COD_HID_COMBO)) {
- btif_hh_remove_device(*bd_addr);
- }
-#endif
if (BTA_DmRemoveDevice((UINT8 *)bd_addr->address) == BTA_SUCCESS)
{
BTIF_TRACE_DEBUG1("Successfully removed bonding with device: %s",
@@ -388,7 +344,6 @@ static void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
BTIF_TRACE_DEBUG1("Removed bonding with device failed: %s",
bd2str((bt_bdaddr_t *)bd_addr, &bdstr));
-
}
/*******************************************************************************
@@ -957,6 +912,12 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
case BTA_DM_DEV_UNPAIRED_EVT:
bdcpy(bd_addr.address, p_data->link_down.bd_addr);
+ /*special handling for HID devices */
+ #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
+ if (check_cod(&bd_addr, COD_HID_POINTING ) || check_cod(&bd_addr, COD_HID_KEYBOARD )|| check_cod(&bd_addr, COD_HID_COMBO)) {
+ btif_hh_remove_device(bd_addr);
+ }
+ #endif
btif_storage_remove_bonded_device(&bd_addr);
bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
break;
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
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 2e2d0a5..8cb5423 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -262,8 +262,6 @@ static void btif_in_split_uuids_string_to_list(char *str, bt_uuid_t *p_uuid,
do
{
p_needle = strchr(p_start, ';');
- if (!p_needle)
- break;
memset(buf, 0, sizeof(buf));
strncpy(buf, p_start, (p_needle-p_start));
string_to_uuid(buf, p_uuid + num);
@@ -536,12 +534,10 @@ static int hex_str_to_int(const char* str, int size)
char c = *str++;
while (size-- != 0) {
n <<= 4;
- if (c >= '0' && c <= '9')
- {
+ if (c >= '0' && c <= '9') {
n |= c - '0';
}
- else if (c >= 'a' && c <= 'z')
- {
+ else if (c >= 'a' && c <= 'z') {
n |= c - 'a' + 10;
}
else { // (c >= 'A' && c <= 'Z')
@@ -553,6 +549,85 @@ static int hex_str_to_int(const char* str, int size)
return n;
}
+/*******************************************************************************
+**
+** Function btif_in_load_hid_info_iter_cb
+**
+** Description Internal iterator callback from UNV when loading the
+** hid device info
+**
+** Returns
+**
+*******************************************************************************/
+
+int btif_in_load_hid_info_iter_cb(char *key, char *value, void *userdata)
+{
+ btif_bonded_devices_t *p_bonded_devices = (btif_bonded_devices_t *)userdata;
+ bt_bdaddr_t bd_addr;
+ tBTA_HH_DEV_DSCP_INFO dscp_info;
+ uint32_t i;
+ uint16_t attr_mask,a;
+ uint8_t sub_class;
+ uint8_t app_id;
+ BD_ADDR* bda;
+ char *p;
+
+
+ BTIF_TRACE_DEBUG3("%s - %s - %s", __FUNCTION__, key, value);
+
+ p = value;
+ attr_mask = (uint16_t) hex_str_to_int(p, 4);
+ p +=5;
+ sub_class = (uint8_t) hex_str_to_int(p, 2);
+ p +=3;
+ app_id = (uint8_t) hex_str_to_int(p, 2);
+ p +=3;
+ dscp_info.vendor_id = (uint16_t) hex_str_to_int(p, 4);
+ p += 5;
+ dscp_info.product_id = (uint16_t) hex_str_to_int(p, 4);
+ p += 5;
+ dscp_info.version = (uint8_t) hex_str_to_int(p, 4);
+ p += 5;
+ dscp_info.ctry_code = (uint8_t) hex_str_to_int(p, 2);
+ p += 3;
+ dscp_info.descriptor.dl_len = (uint16_t) hex_str_to_int(p, 4);
+ p += 5;
+
+ BTIF_TRACE_DEBUG6("attr_mask=%d,sub_class=%d,app_id=%d,vendor_id=%d,product_id=%d,version=%d",attr_mask,
+ sub_class,app_id,dscp_info.vendor_id,dscp_info.product_id, dscp_info.version);
+ BTIF_TRACE_DEBUG2("country_code=%d,dscp_len=%d",dscp_info.ctry_code, dscp_info.descriptor.dl_len);
+
+ dscp_info.descriptor.dsc_list = (UINT8 *) GKI_getbuf(dscp_info.descriptor.dl_len);
+ if (dscp_info.descriptor.dsc_list == NULL)
+ {
+ LOGE("%s: Failed to allocate DSCP for CB", __FUNCTION__);
+ return BT_STATUS_FAIL;
+ }
+ for (i = 0; i < dscp_info.descriptor.dl_len; i++)
+ {
+ dscp_info.descriptor.dsc_list[i] = (uint8_t) hex_str_to_int(p, 2);
+ p += 2;
+ }
+
+ BTIF_TRACE_DEBUG1("btif_in_load_hid_info_iter_cb: BD-ADDR---%s",key);
+ /* convert bd address (keystring) */
+ //str2bd(key, &bd_addr);
+ //bda = (BD_ADDR*) &bd_addr;
+
+ /* add extracted information to BTA HH
+ if (btif_hh_add_added_dev(bd_addr,attr_mask))
+ {
+ BTA_HhAddDev(bd_addr.address, attr_mask, sub_class,
+ app_id, dscp_info);
+ }*/
+
+ GKI_freebuf(dscp_info.descriptor.dsc_list);
+
+ /* Fill in the bonded devices */
+ //mcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t));
+
+ return 0;
+}
/************************************************************************************
** Externs
@@ -1088,3 +1163,138 @@ bt_status_t btif_storage_load_bonded_devices(void)
return BT_STATUS_SUCCESS;
}
+/*******************************************************************************
+**
+** Function btif_storage_add_hid_device_info
+**
+** Description BTIF storage API - Adds the hid information of bonded hid devices-to NVRAM
+**
+** Returns BT_STATUS_SUCCESS if the store was successful,
+** BT_STATUS_FAIL otherwise
+**
+*******************************************************************************/
+
+bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr,
+ UINT16 attr_mask, UINT8 sub_class,
+ UINT8 app_id, UINT16 vendor_id,
+ UINT16 product_id, UINT16 version,
+ UINT8 ctry_code, UINT16 dl_len, UINT8 *dsc_list)
+{
+ char *hid_info;
+ uint32_t i = 0;
+ char *fname;
+ bdstr_t bdstr;
+ int ret;
+
+ char* p;
+ size_t size;
+
+ fname = btif_in_make_filename(NULL,
+ BTIF_STORAGE_PATH_REMOTE_HIDINFO);
+ if (fname == NULL)
+ {
+ return BT_STATUS_FAIL;
+ }
+ ret = unv_create_file(fname);
+
+ if (ret < 0)
+ {
+ return BT_STATUS_FAIL;
+ }
+ BTIF_TRACE_DEBUG1("%s",__FUNCTION__);
+
+
+ size = 5 + 3 + 3 + 5 + 5 + 5 + 3 + 5 + (2 * dl_len) + 1;
+ hid_info = (char *) malloc(size);
+ if (hid_info == NULL) {
+ BTIF_TRACE_ERROR2("%s: Oops, failed to allocate %d byte buffer for HID info string",
+ __FUNCTION__, size);
+ return BT_STATUS_FAIL;
+ }
+
+
+ sprintf(hid_info, "%04X %02X %02X %04X %04X %04X %02X %04X ",
+ attr_mask,sub_class,app_id,vendor_id,product_id,version,ctry_code,dl_len);
+
+ i = 0;
+ p = &hid_info[strlen(hid_info)];
+ while ((i + 16) <= dl_len) {
+ sprintf(p, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+ dsc_list[i], dsc_list[i+1], dsc_list[i+2], dsc_list[i+3],
+ dsc_list[i+4], dsc_list[i+5], dsc_list[i+6], dsc_list[i+7],
+ dsc_list[i+8], dsc_list[i+9], dsc_list[i+10], dsc_list[i+11],
+ dsc_list[i+12], dsc_list[i+13], dsc_list[i+14], dsc_list[i+15]);
+ p += 32;
+ i += 16;
+ }
+ if ((i + 8) <= dl_len) {
+ sprintf(p, "%02X%02X%02X%02X%02X%02X%02X%02X",
+ dsc_list[i], dsc_list[i+1], dsc_list[i+2], dsc_list[i+3],
+ dsc_list[i+4], dsc_list[i+5], dsc_list[i+6], dsc_list[i+7]);
+ p += 16;
+ i += 8;
+ }
+ if ((i + 4) <= dl_len) {
+ sprintf(p, "%02X%02X%02X%02X",
+ dsc_list[i], dsc_list[i+1], dsc_list[i+2], dsc_list[i+3]);
+ p += 8;
+ i += 4;
+ }
+ if ((i + 3) == dl_len) {
+ sprintf(p, "%02X%02X%02X", dsc_list[i], dsc_list[i+1], dsc_list[i+2]);
+ p += 6;
+ }
+ else if ((i + 2) == dl_len) {
+ sprintf(p, "%02X%02X", dsc_list[i], dsc_list[i+1]);
+ p += 4;
+ }
+ else if ((i + 1) == dl_len) {
+ sprintf(p, "%02X", dsc_list[i]);
+ p += 2;
+ }
+ *p = '\0';
+
+ BTIF_TRACE_DEBUG1("key: %s",bd2str(remote_bd_addr, &bdstr));
+ BTIF_TRACE_DEBUG1("hid info %s",hid_info);
+
+ ret = unv_write_key(fname, bd2str(remote_bd_addr, &bdstr), hid_info);
+
+ if (ret < 0)
+ {
+ return BT_STATUS_FAIL;
+ }
+
+ return BT_STATUS_SUCCESS;
+}
+
+/*******************************************************************************
+**
+** Function btif_storage_load_bonded_hid_info
+**
+** Description BTIF storage API - Loads hid info for all the bonded devices from NVRAM
+** and adds those devices to the BTA_HH.
+**
+** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
+**
+*******************************************************************************/
+bt_status_t btif_storage_load_bonded_hid_info(void)
+{
+ char *fname;
+ btif_bonded_devices_t bonded_devices;
+ int ret;
+
+ memset(&bonded_devices, 0, sizeof(btif_bonded_devices_t));
+
+ fname = btif_in_make_filename(NULL, BTIF_STORAGE_PATH_REMOTE_HIDINFO);
+
+ if (fname == NULL)
+ return BT_STATUS_FAIL;
+
+ ret = unv_read_key_iter(fname, btif_in_load_hid_info_iter_cb, &bonded_devices);
+
+ if (ret < 0)
+ return BT_STATUS_FAIL;
+
+ return BT_STATUS_SUCCESS;
+}
+