Support for internal API for bonding with incoming parameter 01/206901/9
authorSudipto Bal <sudipto.bal@samsung.com>
Mon, 3 Jun 2019 11:35:31 +0000 (17:05 +0530)
committerSudipto Bal <sudipto.bal@samsung.com>
Mon, 3 Jun 2019 11:35:31 +0000 (17:05 +0530)
Change-Id: Ibe3e9010f1244395e81c85f1bc1d32ed429ae142
Signed-off-by: Sudipto Bal <sudipto.bal@samsung.com>
include/bluetooth_internal.h
include/bluetooth_private.h
include/bluetooth_type_internal.h
src/bluetooth-adapter.c
src/bluetooth-common.c
test/bt_unit_test.c
test/bt_unit_test.h

index 0dda44a..213d627 100644 (file)
@@ -250,6 +250,7 @@ int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_vers
 int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode, int duration);
 
 /**
+ * @deprecated Deprecated since 5.5
  * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
  * @brief Registers a callback function that will be invoked when remote device requests authentication.
  * @return 0 on success, otherwise a negative error value.
@@ -267,6 +268,26 @@ int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode, in
 int bt_adapter_set_authentication_req_cb(bt_adapter_authentication_req_cb callback, void *user_data);
 
 /**
+ * @since_tizen 5.5
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
+ * @brief Registers a callback with a incoming parameter to describe direction of pairing request that will be invoked when remote device requests authentication.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
+ * @pre The Bluetooth service must be initialized by bt_initialize().
+ * @param[in] callback  callback function to be set when a request is received.
+ * @param[in] user_data data from application which will be provided in callback.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @see bt_initialize()
+ * @see bt_adapter_authentication_request_cb()
+ */
+
+int bt_adapter_set_authentication_request_cb(bt_adapter_authentication_request_cb callback, void *user_data);
+
+/**
+ * @deprecated Deprecated since 5.5
  * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
  * @brief Unregisters a callback function that will be invoked when remote device requests authentication.
  * @return 0 on success, otherwise a negative error value.
@@ -279,6 +300,21 @@ int bt_adapter_set_authentication_req_cb(bt_adapter_authentication_req_cb callba
 int bt_adapter_unset_authentication_req_cb(void);
 
 /**
+ * @since_tizen 5.5
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
+ * @brief Unregisters a callback function with incoming parameter that will be invoked when remote device requests authentication.
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
+ * @pre The Bluetooth service must be initialized by bt_initialize().
+ * @see bt_initialize()
+ * @see bt_adapter_set_authentication_request_cb()
+ */
+
+int bt_adapter_unset_authentication_request_cb(void);
+
+
+/**
  * @ingroup  CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
  * @brief  API to reply with PIN or PASSKEY with authentication type - TRUE or FALSE.
  * @remarks  This function can be called by application when remote device requests PIN or PASSKEY from
index 6969dd9..ae9d0da 100644 (file)
@@ -77,6 +77,7 @@ typedef enum {
        BT_EVENT_BOND_DESTROYED, /**< A bond is destroyed */
        BT_EVENT_AUTHORIZATION_CHANGED, /**< Authorization is changed */
        BT_EVENT_AUTHENTICATION_REQUEST, /**< Authentication events during pairing process*/
+       BT_EVENT_AUTHENTICATION_REQUEST_NEW,/**< Authentication events during pairing process with incoming parameter*/
        BT_EVENT_SERVICE_SEARCHED, /**< Service search finish */
        BT_EVENT_DATA_RECEIVED, /**< Data is received */
        BT_EVENT_CONNECTION_STATE_CHANGED, /**< Connection state is changed */
index 7e78416..e52cd6b 100644 (file)
@@ -862,6 +862,7 @@ typedef struct {
 } bt_tds_transport_block_list_s;
 
 /**
+ * @deprecated Depricated since 5.5
  * @internal
  * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
  * @brief Called when remote device requests authentication.
@@ -893,6 +894,38 @@ typedef void (*bt_adapter_authentication_req_cb)(int result, bt_authentication_t
                                                char *pass_key, void *user_data);
 
 /**
+ * @internal
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
+ * @brief Called when remote device requests authentication and direction of pairing request (incoming or not)
+ * @since_tizen 5.5
+ * @param[in] incoming     Direction of pairing. It is set to true if the pairing request is incoming.
+ * @param[in] auth_type    Event whose occurence has invoked this callback
+ *             typedef enum {
+ *              BT_AUTH_KEYBOARD_PASSKEY_DISPLAY = 0, : PIN display event to user for entering PIN in keyboard
+ *              BT_AUTH_PIN_REQUEST,                  : Legacy PIN or PASSKEY request event
+ *              BT_AUTH_PASSKEY_CONFIRM_REQUEST,      : PASSKEY confirmation event to match PASSKEY in remote device
+ *             } bt_authentication_type_info_e;
+ * @param[in] device_name  Name of the remote device
+ * @param[in] remote_addr  Remote BD address
+ * @param[in] pass_key     PASSKEY string
+ *            PASSKEY string is valid only if authentication types are following
+ *             a/ BT_AUTH_KEYBOARD_PASSKEY_DISPLAY
+ *             b/ BT_AUTH_PASSKEY_CONFIRM_REQUEST
+ *            pass_key string will be invalid if authentication event is of type BT_AUTH_PIN_REQUEST
+ *            as this event indicates that user MUST enter PIN or PASSKEY and perform authentication.
+ *
+ *            Upon receiving BT_AUTH_KEYBOARD_PASSKEY_DISPLAY event, user should enter PASSKEY in keyboard
+ *            Application can also call bt_device_cancel_bonding() Upon receiving BT_AUTH_KEYBOARD_PASSKEY_DISPLAY
+ *            event which will fail the on-going pairing with remote device.
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see bt_adapter_set_authentication_request_cb()
+ */
+
+typedef void (*bt_adapter_authentication_request_cb)(bool incoming, bt_authentication_type_info_e auth_type,
+                                                char *device_name, char *remote_addr,
+                                                char *pass_key, void *user_data);
+
+/**
  * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE
  * @brief  Samsung XSAT Vendor dependent command.
  * @since_tizen 2.3.2
index 77ef92a..9a959c8 100644 (file)
@@ -3748,6 +3748,15 @@ int bt_adapter_set_authentication_req_cb(bt_adapter_authentication_req_cb callba
        return BT_ERROR_NONE;
 }
 
+int bt_adapter_set_authentication_request_cb(bt_adapter_authentication_request_cb callback,
+                                                       void *user_data)
+{
+       BT_CHECK_INIT_STATUS();
+       BT_INFO("Setting callback for bt_adapter_authentication_request_cb for event %d", BT_EVENT_AUTHENTICATION_REQUEST_NEW);
+       _bt_set_cb(BT_EVENT_AUTHENTICATION_REQUEST_NEW, callback, user_data);
+       return BT_ERROR_NONE;
+}
+
 int bt_adapter_unset_authentication_req_cb(void)
 {
        BT_CHECK_INIT_STATUS();
@@ -3755,6 +3764,13 @@ int bt_adapter_unset_authentication_req_cb(void)
        return BT_ERROR_NONE;
 }
 
+int bt_adapter_unset_authentication_request_cb(void)
+{
+       BT_CHECK_INIT_STATUS();
+       _bt_unset_cb(BT_EVENT_AUTHENTICATION_REQUEST_NEW);
+       return BT_ERROR_NONE;
+}
+
 int bt_adapter_le_scan_filter_set_ibeacon(bt_scan_filter_h scan_filter)
 {
        bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter;
index b03e99b..c92cb0a 100644 (file)
@@ -1400,38 +1400,58 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                device_addr = NULL;
                break;
        case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
-               BT_INFO("bt_adapter_authentication_req_cb() will be called with \
+               BT_INFO("Callbacks will be called for \
                        BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
                auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
                _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
-               BT_DBG("BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY: name = %s address = %s passkey = %s", auth_information->device_name.name,
-                       device_addr, auth_information->str_passkey);
+               BT_DBG("BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY: name = %s address = %s passkey = %s incoming = %d", auth_information->device_name.name,
+                       device_addr, auth_information->str_passkey, auth_information->incoming);
 
-               ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
-                       (_bt_get_error_code(param->result), BT_AUTH_KEYBOARD_PASSKEY_DISPLAY, auth_information->device_name.name,
-                               device_addr, auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               if (bt_event_slot_container[event_index].callback != NULL)
+               {
+                       ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), BT_AUTH_KEYBOARD_PASSKEY_DISPLAY, auth_information->device_name.name,
+                                       device_addr, auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               }
+
+               if (bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
+               {
+                       ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
+                               (auth_information->incoming, BT_AUTH_KEYBOARD_PASSKEY_DISPLAY, auth_information->device_name.name,
+                                       device_addr, auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
+               }
 
                if (device_addr != NULL)
                        free(device_addr);
                break;
        case BLUETOOTH_EVENT_PIN_REQUEST:
-               BT_INFO("bt_adapter_authentication_req_cb() will be called with \
+               BT_INFO("Callbacks will be called for \
                                BLUETOOTH_EVENT_PIN_REQUEST");
                auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
                _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
 
-               BT_DBG("BUETOOTH_EVENT_PIN_REQUEST: name = %s address = %s", auth_information->device_name.name,
-                       device_addr);
+               BT_DBG("BUETOOTH_EVENT_PIN_REQUEST: name = %s address = %s incoming = %d", auth_information->device_name.name,
+                       device_addr, auth_information->incoming);
 
-               ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
-                       (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
-                               auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               if(bt_event_slot_container[event_index].callback != NULL)
+               {
+                       ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
+                                       auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               }
+
+               if(bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
+               {
+                       ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
+                               (auth_information->incoming, BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
+                                       auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
+               }
 
                if (device_addr != NULL)
                        free(device_addr);
                break;
        case BLUETOOTH_EVENT_PASSKEY_REQUEST:
-               BT_INFO("bt_adapter_authentication_req_cb will be called with \
+               BT_INFO("Callbacks will be called for \
                                BLUETOOTH_EVENT_PASSKEY_REQUEST");
 
                auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
@@ -1439,26 +1459,45 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
 
                BT_DBG("BLUETOOTH_EVENT_PASSKEY_REQUEST: name = %s address = %s", auth_information->device_name.name,
                        device_addr);
+               if(bt_event_slot_container[event_index].callback != NULL)
+               {
+                       ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
+                                       auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               }
 
-               ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
-                       (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
-                               auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               if(bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
+               {
+                       ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
+                               (auth_information->incoming, BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
+                                       auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
+               }
 
                if (device_addr != NULL)
                        free(device_addr);
                break;
        case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
-               BT_INFO("bt_adapter_authentication_req_cb will be called with \
+               BT_INFO("Callbacks will be called for \
                        BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST");
 
                auth_information = (bluetooth_authentication_request_info_t *)(param->param_data);
                _bt_convert_address_to_string(&device_addr, &auth_information->device_address);
 
-               BT_DBG("BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST: name = %s address = %s passkey = %s ",
-                               auth_information->device_name.name, device_addr, auth_information->str_passkey);
-               ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
-                       (_bt_get_error_code(param->result), BT_AUTH_PASSKEY_CONFIRM_REQUEST, auth_information->device_name.name, device_addr,
-                               auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               BT_DBG("BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST: name = %s address = %s passkey = %s incoming = %d",
+                               auth_information->device_name.name, device_addr, auth_information->str_passkey, auth_information->incoming);
+               if (bt_event_slot_container[event_index].callback != NULL)
+               {
+                       ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), BT_AUTH_PASSKEY_CONFIRM_REQUEST, auth_information->device_name.name, device_addr,
+                                       auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+               }
+
+               if (bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback != NULL)
+               {
+                       ((bt_adapter_authentication_request_cb)bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].callback)
+                               (auth_information->incoming, BT_AUTH_PASSKEY_CONFIRM_REQUEST, auth_information->device_name.name, device_addr,
+                                       auth_information->str_passkey, bt_event_slot_container[BT_EVENT_AUTHENTICATION_REQUEST_NEW].user_data);
+               }
 
                if (device_addr != NULL)
                        free(device_addr);
index 66abf01..45b462a 100644 (file)
@@ -268,8 +268,12 @@ tc_table_t tc_adapter[] = {
                , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA},
        {"bt_adapter_set_authentication_req_cb"
                , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_AUTHENTICATION_REQUSET_CB},
+       {"bt_adapter_set_authentication_request_cb"
+               , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_AUTHENTICATION_REQUEST_CB_NEW},
        {"bt_adapter_unset_authentication_req_cb"
                , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_AUTHENTICATION_REQUSET_CB},
+       {"bt_adapter_unset_authentication_request_cb"
+               , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_AUTHENTICATION_REQUEST_CB_NEW},
        {"bt_adapter_passkey_reply(passkey, TRUE)"
                , BT_UNIT_TEST_FUNCTION_ADAPTER_PASSKEY_REPLY_ACCEPT},
        {"bt_adapter_passkey_reply(passkey, FALSE)"
@@ -1510,6 +1514,32 @@ static void __bt_adapter_authentication_req_cb(
        }
 }
 
+static void __bt_adapter_authentication_request_cb(
+       bool incoming, bt_authentication_type_info_e auth_type,
+       char *device_name, char *remote_addr,
+       char *pass_key, void *user_data)
+{
+       TC_PRT("__bt_adapter_authentication_request_cb:"
+               " device name = %s", device_name);
+       TC_PRT("__bt_adapter_authentication_request_cb:"
+               " device address = %s", remote_addr);
+
+       if (incoming == TRUE)
+               TC_PRT("It is an incoming request");
+       else
+               TC_PRT("It is not an incoming request");
+
+       if (auth_type == BT_AUTH_PIN_REQUEST) {
+               TC_PRT("Auth Type = BT_AUTH_PIN_REQUEST");
+       } else if (auth_type == BT_AUTH_PASSKEY_CONFIRM_REQUEST) {
+               TC_PRT("Auth Type = BT_AUTH_PASSKEY_CONFIRM_REQUEST");
+               TC_PRT("Passkey: [%s]", pass_key);
+       } else if (auth_type == BT_AUTH_KEYBOARD_PASSKEY_DISPLAY) {
+               TC_PRT("Auth Type = BT_AUTH_KEYBOARD_PASSKEY_DISPLAY");
+               TC_PRT("Passkey: [%s]", pass_key);
+       }
+}
+
 static bool __bt_adapter_bonded_device_cb(bt_device_info_s *device_info,
        void *user_data)
 {
@@ -4349,12 +4379,25 @@ int test_input_callback(void *data)
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
+               case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_AUTHENTICATION_REQUEST_CB_NEW:
+               {
+                       ret = bt_adapter_set_authentication_request_cb(
+                               __bt_adapter_authentication_request_cb, NULL);
+                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       break;
+               }
                case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_AUTHENTICATION_REQUSET_CB:
                {
                        ret = bt_adapter_unset_authentication_req_cb();
                        TC_PRT("returns %s\n", __bt_get_error_message(ret));
                        break;
                }
+               case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_AUTHENTICATION_REQUEST_CB_NEW:
+               {
+                       ret = bt_adapter_unset_authentication_request_cb();
+                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       break;
+               }
                case BT_UNIT_TEST_FUNCTION_ADAPTER_PASSKEY_REPLY_ACCEPT:
                {
                        char *passkey = NULL;
index 7919c40..404f347 100644 (file)
@@ -98,7 +98,9 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_MANUFACTURER_DATA_CHANGED_CB,
        BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA,
        BT_UNIT_TEST_FUNCTION_ADAPTER_SET_AUTHENTICATION_REQUSET_CB,
+       BT_UNIT_TEST_FUNCTION_ADAPTER_SET_AUTHENTICATION_REQUEST_CB_NEW,
        BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_AUTHENTICATION_REQUSET_CB,
+       BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_AUTHENTICATION_REQUEST_CB_NEW,
        BT_UNIT_TEST_FUNCTION_ADAPTER_PASSKEY_REPLY_ACCEPT,
        BT_UNIT_TEST_FUNCTION_ADAPTER_PASSKEY_REPLY_CANCEL,
        BT_UNIT_TEST_FUNCTION_ADAPTER_PASSKEY_CONFIRMATION_REPLY_ACCEPT,