[Adapt] Add authorization resposne API in OAL 29/81729/1
authorAnupam Roy <anupam.r@samsung.com>
Sat, 23 Jul 2016 13:22:54 +0000 (18:52 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 28 Jul 2016 06:01:50 +0000 (11:31 +0530)
[Note: Currently HID, A2DP and AVRCP service authorization
requests are accepted by default by bt-service]

Change-Id: Iba26c08cc5d8ac30842903a3f7fd154e6c0d522c
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/include/oal-device-mgr.h
bt-oal/oal-device-mgr.c
bt-service-adaptation/services/device/bt-service-core-device.c

index de29e28..549f30e 100755 (executable)
@@ -232,6 +232,22 @@ oal_status_t device_reply_passkey_confirmation(bt_address_t * addr, int accept);
  */
 oal_status_t device_reply_ssp_consent(bt_address_t * addr, int accept);
 
+/**
+ * @brief Accept or reject authorization request for a connection from remote device
+ *
+ * @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
+ *
+ * @param[in] always  If TRUE, future connection requests will be automatically accepted.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS  Successful
+ *
+ * @pre OAL_EVENT_DEVICE_AUTHORIZE_REQUEST should have been recieved by application.
+ *
+ * @see  OAL_EVENT_DEVICE_AUTHORIZE_REQUEST
+ */
+oal_status_t device_reply_auth_request(bt_address_t * addr, oal_service_t service_type, int accept, int always);
 
 #ifdef __cplusplus
 }
index 3da8658..910c7f3 100755 (executable)
@@ -306,6 +306,27 @@ oal_status_t device_reply_ssp_consent(bt_address_t * addr, int accept)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t device_reply_auth_request(bt_address_t * addr, oal_service_t service_type, int accept, int always)
+{
+       int res;
+       bdstr_t bdstr;
+
+       CHECK_OAL_INITIALIZED();
+
+       OAL_CHECK_PARAMETER(addr, return);
+
+       API_TRACE("[%s] Accept: %d, always: %d, service_type: %d", bdt_bd2str(addr, &bdstr), accept, always, service_type);
+
+       res = blued_api->authorize_response((bt_bdaddr_t *)addr, service_type, accept, always);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("authorize_response error: [%s]", status2string(res));
+               BT_ERR("Accept: [%d], always: [%d], service_type: [%d]", accept, always, service_type);
+               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)
 {
index 97e4580..64372b3 100644 (file)
@@ -450,12 +450,12 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
 {
         oal_service_t service_d = auth_event->service_id;
        gchar address[BT_ADDRESS_STR_LEN];
+       int res;
 
         _bt_convert_addr_type_to_string(address, auth_event->address.addr);
 
         BT_INFO("service_d: %d", service_d);
 
-       /* TODO: Add Reply to Authorization requests */
        switch(service_d) {
        case HID_SERVICE_ID:
                BT_INFO("Incoming HID Profile conn Req from device addr [%s]", address);
@@ -467,9 +467,18 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
                BT_INFO("Incoming AVRCP Profile conn Req from device addr [%s]", address);
                break;
        default:
+               /* For now, reject authorization for any service apart from above switch cases */
                BT_INFO("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
-               break;
+               res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, FALSE, FALSE);
+               if (res != OAL_STATUS_SUCCESS)
+                       BT_ERR("authorize_response: %d", res);
+               return;
        }
+
+       /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
+       res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, TRUE, FALSE);
+       if (res != OAL_STATUS_SUCCESS)
+               BT_ERR("authorize_response: %d", res);
        BT_INFO("-");
 }