From a0ff73591947b02d1a69875a30aef7323ccd6a01 Mon Sep 17 00:00:00 2001 From: Anupam Roy Date: Wed, 6 Jul 2016 14:24:27 -0400 Subject: [PATCH] [Adapt: Bluez HAL] Implement SSP Reply & PIN Reply API's Change-Id: I28fa3710023d3b9318c1803f13f32daf0e02ddb1 Signed-off-by: Anupam Roy --- bt-oal/bluez_hal/src/bt-hal-bluetooth.c | 4 +- bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c | 63 +++++++++++++++++++++++ bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h | 5 ++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index e4edf4b..cb6acb8 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -185,13 +185,13 @@ static int remove_bond(const bt_bdaddr_t *bd_addr) static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept, uint8_t pin_len, bt_pin_code_t *pin_code) { - return BT_STATUS_UNSUPPORTED; + return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code); } static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant, uint8_t accept, uint32_t passkey) { - return BT_STATUS_UNSUPPORTED; + return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey); } static const void *get_profile_interface(const char *profile_id) diff --git a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c index 81199f5..ae17c9d 100644 --- a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c @@ -46,6 +46,7 @@ #include "bt-hal-device-dbus-handler.h" #include "bt-hal-event-receiver.h" #include "bt-hal-agent.h" +#include "bt-hal-gap-agent.h" static handle_stack_msg event_cb = NULL; @@ -226,6 +227,68 @@ int _bt_hal_device_remove_bond(const bt_bdaddr_t *bd_addr) return BT_STATUS_SUCCESS; } +int _bt_hal_device_legacy_pin_reply(const bt_bdaddr_t *bd_addr, + gboolean accept, uint8_t pin_len, char *pincode) +{ + GapAgentPrivate *agent = _bt_hal_get_adapter_agent(); + DBG("+"); + + if (!agent) + return BT_STATUS_FAIL; + + DBG("pin_len [0x%x]", pin_len); + DBG("pincode [%s]", pincode); + + if (accept) { + gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, pincode, NULL); + } else + gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, NULL, NULL); + + DBG("-"); + return BT_STATUS_SUCCESS; +} + +int _bt_hal_device_ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant, + uint8_t accept, uint32_t passkey) +{ + GapAgentPrivate *agent = _bt_hal_get_adapter_agent(); + DBG("+"); + + if (!agent) + return BT_STATUS_FAIL; + + switch (variant) { + case BT_SSP_VARIANT_PASSKEY_CONFIRMATION: + DBG("SSP: PASSKEY_CONFIRMATION"); + if (accept) + gap_agent_reply_confirmation(agent, GAP_AGENT_ACCEPT, NULL); + else + gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL); + break; + case BT_SSP_VARIANT_PASSKEY_NOTIFICATION: + DBG("SSP: PASSKEY_NOTIFICATION"); + break; + case BT_SSP_VARIANT_PASSKEY_ENTRY: + DBG("SSP: PASSKEY_ENTRY"); + if (accept) { + char str_passkey[7]; + snprintf(str_passkey, sizeof(str_passkey), "%.6d", passkey); + DBG("Passkey [%s]", str_passkey); + gap_agent_reply_passkey(agent, GAP_AGENT_ACCEPT, str_passkey, NULL); + } else + gap_agent_reply_passkey(agent, GAP_AGENT_REJECT, NULL, NULL); + break; + case BT_SSP_VARIANT_CONSENT: + DBG("SSP: VARIANT_CONSENT: Unhandled!"); + break; + default: + break; + } + + DBG("-"); + return BT_STATUS_SUCCESS; +} + static void __bt_hal_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { diff --git a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h index 8cfcc83..87e7089 100644 --- a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h +++ b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h @@ -45,6 +45,11 @@ int _bt_hal_dbus_get_remote_device_properties(bt_bdaddr_t *remote_addr); int _bt_hal_dbus_set_remote_device_property( bt_bdaddr_t *remote_addr, const bt_property_t *property); +int _bt_hal_device_legacy_pin_reply(const bt_bdaddr_t *bd_addr, + gboolean accept, uint8_t pin_len, char *pincode); + +int _bt_hal_device_ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant, + uint8_t accept, uint32_t passkey); #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.7.4