summaryrefslogtreecommitdiffstats
path: root/btif
diff options
context:
space:
mode:
authorSen-Der Huang <sdhuang@broadcom.com>2012-05-04 16:50:23 -0700
committerMatthew Xie <mattx@google.com>2012-07-14 11:19:20 -0700
commita858acd87bb1cb8f584b66a50e16b1adcfd6a42f (patch)
tree0aeee0882bbcb6152d924a7487ee76c04fc67616 /btif
parent32f0db60f911ed0b7f3bca0210a4568621b99074 (diff)
downloadexternal_bluetooth_bluedroid-a858acd87bb1cb8f584b66a50e16b1adcfd6a42f.zip
external_bluetooth_bluedroid-a858acd87bb1cb8f584b66a50e16b1adcfd6a42f.tar.gz
external_bluetooth_bluedroid-a858acd87bb1cb8f584b66a50e16b1adcfd6a42f.tar.bz2
Added OOB test
Change-Id: I7a494866eec45724e03a145394e032eb0930fceb
Diffstat (limited to 'btif')
-rw-r--r--btif/co/bta_dm_co.c26
-rw-r--r--btif/include/btif_common.h1
-rw-r--r--btif/include/btif_dm.h9
-rwxr-xr-xbtif/src/btif_core.c6
-rwxr-xr-xbtif/src/btif_dm.c145
5 files changed, 184 insertions, 3 deletions
diff --git a/btif/co/bta_dm_co.c b/btif/co/bta_dm_co.c
index da9a5ce..7c85476 100644
--- a/btif/co/bta_dm_co.c
+++ b/btif/co/bta_dm_co.c
@@ -51,8 +51,9 @@
#include "bta_sys.h"
#include "bta_dm_co.h"
#include "bta_dm_ci.h"
-
-
+#if (BTM_OOB_INCLUDED == TRUE)
+#include "btif_dm.h"
+#endif
/*******************************************************************************
**
** Function bta_dm_co_get_compress_memory
@@ -89,6 +90,13 @@ BOOLEAN bta_dm_co_get_compress_memory(tBTA_SYS_ID id, UINT8 **memory_p, UINT32 *
void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
{
+#if (BTM_OOB_INCLUDED == TRUE)
+ btif_dm_set_oob_for_io_req(p_oob_data);
+#endif
+ BTIF_TRACE_DEBUG1("bta_dm_co_io_req *p_oob_data = %d", *p_oob_data);
+ BTIF_TRACE_DEBUG1("bta_dm_co_io_req *p_io_cap = %d", *p_io_cap);
+ BTIF_TRACE_DEBUG1("bta_dm_co_io_req *p_auth_req = %d", *p_auth_req);
+ BTIF_TRACE_DEBUG1("bta_dm_co_io_req is_orig = %d", is_orig);
}
/*******************************************************************************
@@ -145,6 +153,10 @@ void bta_dm_co_lk_upgrade(BD_ADDR bd_addr, BOOLEAN *p_upgrade )
*******************************************************************************/
void bta_dm_co_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
{
+ BTIF_TRACE_DEBUG1("bta_dm_co_loc_oob, valid = %d", valid);
+#ifdef BTIF_DM_OOB_TEST
+ btif_dm_proc_loc_oob(valid, c, r);
+#endif
}
/*******************************************************************************
@@ -162,6 +174,16 @@ void bta_dm_co_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
*******************************************************************************/
void bta_dm_co_rmt_oob(BD_ADDR bd_addr)
{
+ BT_OCTET16 p_c;
+ BT_OCTET16 p_r;
+ BOOLEAN result = FALSE;
+
+#ifdef BTIF_DM_OOB_TEST
+ result = btif_dm_proc_rmt_oob(bd_addr, p_c, p_r);
+#endif
+
+ BTIF_TRACE_DEBUG1("bta_dm_co_rmt_oob: result=%d",result);
+ bta_dm_ci_rmt_oob(result, bd_addr, p_c, p_r);
}
#endif /* BTM_OOB_INCLUDED */
diff --git a/btif/include/btif_common.h b/btif/include/btif_common.h
index 3ecea9f..6e119c0 100644
--- a/btif/include/btif_common.h
+++ b/btif/include/btif_common.h
@@ -138,6 +138,7 @@ enum
BTIF_DM_CB_CREATE_BOND, /* Create bond */
BTIF_DM_CB_REMOVE_BOND, /*Remove bond */
BTIF_DM_CB_HID_REMOTE_NAME, /* Remote name callback for HID device */
+ BTIF_DM_CB_BOND_STATE_BONDING
};
/* Macro definitions for BD ADDR persistence */
diff --git a/btif/include/btif_dm.h b/btif/include/btif_dm.h
index 45e3e98..9af0a04 100644
--- a/btif/include/btif_dm.h
+++ b/btif/include/btif_dm.h
@@ -67,4 +67,13 @@
*******************************************************************************/
void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data);
+#if (BTM_OOB_INCLUDED == TRUE)
+void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data);
+#ifdef BTIF_DM_OOB_TEST
+void btif_dm_load_local_oob(void);
+void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r);
+BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r);
+#endif /* BTIF_DM_OOB_TEST */
+#endif /* BTM_OOB_INCLUDED */
+
#endif
diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c
index aa755ef..c8b0c8f 100755
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -158,6 +158,9 @@ void bte_main_enable_lpm(BOOLEAN enable);
#endif
void bte_main_postload_cfg(void);
void btif_dm_execute_service_request(UINT16 event, char *p_param);
+#ifdef BTIF_DM_OOB_TEST
+void btif_dm_load_local_oob(void);
+#endif
/************************************************************************************
** Functions
@@ -538,6 +541,9 @@ void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd)
/* load did configuration */
bte_load_did_conf(BTE_DID_CONF_FILE);
+#ifdef BTIF_DM_OOB_TEST
+ btif_dm_load_local_oob();
+#endif
/* now fully enabled, update state */
btif_core_state = BTIF_CORE_STATE_ENABLED;
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index ba63613..da37db5 100755
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -60,7 +60,7 @@
#include <hardware/bluetooth.h>
#include <utils/Log.h>
-
+#include <cutils/properties.h>
#include "gki.h"
#include "btu.h"
#include "bd.h"
@@ -103,6 +103,12 @@ typedef struct {
BD_NAME bd_name;
} btif_dm_remote_name_t;
+typedef struct
+{
+ BT_OCTET16 sp_c;
+ BT_OCTET16 sp_r;
+ BD_ADDR oob_bdaddr; /* peer bdaddr*/
+} btif_dm_oob_cb_t;
#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
/* This flag will be true if HCI_Inquiry is in progress */
@@ -112,6 +118,7 @@ static BOOLEAN btif_dm_inquiry_in_progress = FALSE;
** Static functions
******************************************************************************/
static btif_dm_pairing_cb_t pairing_cb;
+static btif_dm_oob_cb_t oob_cb;
static void btif_dm_generic_evt(UINT16 event, char* p_param);
static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr);
static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name);
@@ -1257,6 +1264,11 @@ static void btif_dm_generic_evt(UINT16 event, char* p_param)
}
break;
+ case BTIF_DM_CB_BOND_STATE_BONDING:
+ {
+ bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
+ }
+ break;
default:
{
BTIF_TRACE_WARNING2("%s : Unknown event 0x%x", __FUNCTION__, event);
@@ -1686,3 +1698,134 @@ void btif_dm_execute_service_request(UINT16 event, char *p_param)
}
return;
}
+
+#if (BTM_OOB_INCLUDED == TRUE)
+void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
+{
+ if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
+ oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
+ {
+ *p_oob_data = FALSE;
+ }
+ else
+ {
+ *p_oob_data = TRUE;
+ }
+ BTIF_TRACE_DEBUG1("btif_dm_set_oob_for_io_req *p_oob_data=%d", *p_oob_data);
+}
+#endif /* BTM_OOB_INCLUDED */
+
+#ifdef BTIF_DM_OOB_TEST
+void btif_dm_load_local_oob(void)
+{
+ char prop_oob[32];
+ property_get("service.brcm.bt.oob", prop_oob, "3");
+ BTIF_TRACE_DEBUG1("btif_dm_load_local_oob prop_oob = %s",prop_oob);
+ if (prop_oob[0] != '3')
+ {
+#if (BTM_OOB_INCLUDED == TRUE)
+ if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
+ oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
+ {
+ BTIF_TRACE_DEBUG0("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
+ BTA_DmLocalOob();
+ }
+#else
+ BTIF_TRACE_ERROR0("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
+#endif
+ }
+}
+
+void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
+{
+ FILE *fp;
+ char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
+ char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
+ char *path = NULL;
+ char prop_oob[32];
+ BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob: valid=%d", valid);
+ if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
+ oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
+ valid)
+ {
+ BTIF_TRACE_DEBUG0("save local OOB data in memory");
+ memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
+ memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
+ property_get("service.brcm.bt.oob", prop_oob, "3");
+ BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
+ if (prop_oob[0] == '1')
+ path = path_a;
+ else if (prop_oob[0] == '2')
+ path = path_b;
+ if (path)
+ {
+ fp = fopen(path, "wb+");
+ if (fp == NULL)
+ {
+ BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob: failed to save local OOB data to %s", path);
+ }
+ else
+ {
+ BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob: save local OOB data into file %s",path);
+ fwrite (c , 1 , BT_OCTET16_LEN , fp );
+ fwrite (r , 1 , BT_OCTET16_LEN , fp );
+ fclose(fp);
+ }
+ }
+ }
+}
+BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
+{
+ char t[128];
+ FILE *fp;
+ char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
+ char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
+ char *path = NULL;
+ char prop_oob[32];
+ BOOLEAN result = FALSE;
+ bt_bdaddr_t bt_bd_addr;
+ bdcpy(oob_cb.oob_bdaddr, bd_addr);
+ property_get("service.brcm.bt.oob", prop_oob, "3");
+ BTIF_TRACE_DEBUG1("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
+ if (prop_oob[0] == '1')
+ path = path_b;
+ else if (prop_oob[0] == '2')
+ path = path_a;
+ if (path)
+ {
+ fp = fopen(path, "rb");
+ if (fp == NULL)
+ {
+ BTIF_TRACE_DEBUG1("btapp_dm_rmt_oob_reply: failed to read OOB keys from %s",path);
+ return FALSE;
+ }
+ else
+ {
+ BTIF_TRACE_DEBUG1("btif_dm_proc_rmt_oob: read OOB data from %s",path);
+ fread (p_c , 1 , BT_OCTET16_LEN , fp );
+ fread (p_r , 1 , BT_OCTET16_LEN , fp );
+ fclose(fp);
+ }
+ BTIF_TRACE_DEBUG0("----btif_dm_proc_rmt_oob: TRUE");
+ sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
+ oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
+ oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
+ BTIF_TRACE_DEBUG1("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
+ sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
+ p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
+ p_c[8], p_c[9], p_c[10], p_c[11], p_c[12], p_c[13], p_c[14], p_c[15]);
+ BTIF_TRACE_DEBUG1("----btif_dm_proc_rmt_oob: c = %s",t);
+ sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
+ p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
+ p_r[8], p_r[9], p_r[10], p_r[11], p_r[12], p_r[13], p_r[14], p_r[15]);
+ BTIF_TRACE_DEBUG1("----btif_dm_proc_rmt_oob: r = %s",t);
+ bdcpy(bt_bd_addr.address, bd_addr);
+ btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
+ (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
+ result = TRUE;
+ }
+ BTIF_TRACE_DEBUG1("btif_dm_proc_rmt_oob result=%d",result);
+ return result;
+}
+#endif /* BTIF_DM_OOB_TEST */
+