From 2270b1b1cbd61d690957985c3174f96ce1f05dfd Mon Sep 17 00:00:00 2001 From: Anupam Roy Date: Mon, 25 Jul 2016 20:02:59 +0530 Subject: [PATCH] [Adapt] Add OAL API & bt-service request handler for 'Set Trust' Change-Id: If5135f45f3eb2af04d663f36adcd1c7d4a5cb039 Signed-off-by: Anupam Roy --- bt-oal/include/oal-device-mgr.h | 15 +++++++++++++++ bt-oal/oal-device-mgr.c | 21 +++++++++++++++++++++ bt-service-adaptation/services/bt-request-handler.c | 10 ++++++++++ .../services/device/bt-service-core-device.c | 18 ++++++++++++++++++ .../services/include/bt-service-core-device.h | 3 ++- 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/bt-oal/include/oal-device-mgr.h b/bt-oal/include/oal-device-mgr.h index 549f30e..ec3ccb5 100755 --- a/bt-oal/include/oal-device-mgr.h +++ b/bt-oal/include/oal-device-mgr.h @@ -249,6 +249,21 @@ oal_status_t device_reply_ssp_consent(bt_address_t * addr, int accept); */ oal_status_t device_reply_auth_request(bt_address_t * addr, oal_service_t service_type, int accept, int always); +/** + * @brief Set a device as authorized or unauthorized + * + * @details authorize = TRUE: all connections from this device will be auto accepted without any auth-event + * authorize = FALSE: all connections from this device will result in auth request event + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + * + * @see OAL_EVENT_DEVICE_AUTHORIZE_REQUEST + */ +oal_status_t device_set_authorized(bt_address_t * addr, int authorize); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/oal-device-mgr.c b/bt-oal/oal-device-mgr.c index 910c7f3..5b2ee4c 100755 --- a/bt-oal/oal-device-mgr.c +++ b/bt-oal/oal-device-mgr.c @@ -327,6 +327,27 @@ oal_status_t device_reply_auth_request(bt_address_t * addr, oal_service_t servic return OAL_STATUS_SUCCESS; } +oal_status_t device_set_authorized(bt_address_t * addr, int authorize) +{ + int res; + bdstr_t bdstr; + + CHECK_OAL_INITIALIZED(); + + OAL_CHECK_PARAMETER(addr, return); + + API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), authorize); + + res = blued_api->set_authorization((bt_bdaddr_t *)addr, authorize); + if (res != BT_STATUS_SUCCESS) { + BT_ERR("set_authorization error: [%s]", status2string(res)); + BT_ERR("%d", authorize); + return convert_to_oal_status(res); + } + + return OAL_STATUS_SUCCESS; +} + void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr, int num_properties, bt_property_t *properties) { diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index 3881c0f..6ed74a6 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -617,6 +617,16 @@ int __bt_bluez_request(int function_name, result = _bt_passkey_confirmation_reply(confirmation_reply); break; } + case BT_SET_AUTHORIZATION: { + bluetooth_device_address_t address = { {0} }; + gboolean authorize; + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &authorize, sizeof(gboolean)); + result = _bt_set_authorization(&address, authorize); + break; + } case BT_HID_CONNECT: { bluetooth_device_address_t address = { {0} }; diff --git a/bt-service-adaptation/services/device/bt-service-core-device.c b/bt-service-adaptation/services/device/bt-service-core-device.c index 64372b3..a2cbe86 100644 --- a/bt-service-adaptation/services/device/bt-service-core-device.c +++ b/bt-service-adaptation/services/device/bt-service-core-device.c @@ -1525,3 +1525,21 @@ int _bt_cancel_search_device(void) return BLUETOOTH_ERROR_NONE; BT_DBG("-"); } + +int _bt_set_authorization(bluetooth_device_address_t *device_address, + gboolean authorize) +{ + int ret = OAL_STATUS_SUCCESS; + BT_DBG("+"); + + BT_CHECK_PARAMETER(device_address, return); + BT_INFO("Device to be Trusted? [%d]", authorize); + + ret = device_set_authorized((bt_address_t*)device_address, authorize); + if (ret != OAL_STATUS_SUCCESS) { + BT_ERR("device_set_authorized: %d", ret); + return BLUETOOTH_ERROR_INTERNAL; + } + + return BLUETOOTH_ERROR_NONE; +} diff --git a/bt-service-adaptation/services/include/bt-service-core-device.h b/bt-service-adaptation/services/include/bt-service-core-device.h index d42b845..9534599 100755 --- a/bt-service-adaptation/services/include/bt-service-core-device.h +++ b/bt-service-adaptation/services/include/bt-service-core-device.h @@ -58,7 +58,8 @@ int _bt_passkey_reply(const char *passkey, gboolean authentication_reply); int _bt_passkey_confirmation_reply(gboolean confirmation_reply); - +int _bt_set_authorization(bluetooth_device_address_t *device_address, + gboolean authorize); #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.7.4