[bt-service]Added support to enable for Auth notifications 15/161915/1
authorAtul Rai <a.rai@samsung.com>
Tue, 28 Nov 2017 07:15:31 +0000 (12:45 +0530)
committerAtul Rai <a.rai@samsung.com>
Tue, 28 Nov 2017 07:15:31 +0000 (12:45 +0530)
This patch adds support for following APIs:
1/ BT_SET_PASSKEY_NOTIFICATION
2/ BT_SET_PIN_CODE
3/ BT_UNSET_PIN_CODE

Change-Id: I2b73600f8c8e3ed2efc2ac78683637de8318dee1
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/device/bt-service-core-device.c
bt-service-adaptation/services/include/bt-service-core-device.h

index 8abb9d2..1e03a94 100644 (file)
@@ -737,6 +737,38 @@ int __bt_bluez_request(int function_name,
                result = _bt_cancel_search_device();
                break;
        }
+       case BT_SET_PASSKEY_NOTIFICATION: {
+               char *sender = NULL;
+               gboolean enable;
+
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+               __bt_service_get_parameters(in_param1,
+                               &enable, sizeof(gboolean));
+
+               result = _bt_set_passkey_notification(sender, enable);
+               break;
+       }
+       case BT_SET_PIN_CODE: {
+               bluetooth_device_address_t address = { {0} };
+               bluetooth_device_pin_code_t pin_code = { {0} };
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &pin_code, sizeof(bluetooth_device_pin_code_t));
+
+               result = _bt_set_pin_code(&address, &pin_code);
+               break;
+       }
+       case BT_UNSET_PIN_CODE: {
+               bluetooth_device_address_t address = { {0} };
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_unset_pin_code(&address);
+               break;
+       }
        case BT_PASSKEY_REPLY: {
                const char *passkey = NULL;
                gboolean authentication_reply = FALSE;
index 7a5e3cd..41153f6 100644 (file)
@@ -93,9 +93,6 @@ bt_bond_data_t *trigger_bond_info;
 bt_bond_data_t *trigger_unbond_info;
 bt_pairing_data_t *trigger_pairing_info;
 bt_service_search_info_data_t *service_search_info;
-#ifdef TIZEN_FEATURE_BT_OBEX
-gboolean is_device_creating;
-#endif
 
 bt_incoming_bond_data_t *incoming_bond_info;
 
@@ -120,6 +117,9 @@ typedef enum {
 static bt_bond_state_e bt_device_bond_state;
 static int bond_retry_count;
 
+static char *passkey_watcher;
+static GSList *pin_info_list = NULL;
+
 /* Forward declaration */
 static void __bt_device_event_handler(int event_type, gpointer event_data);
 static void __bt_device_remote_device_found_callback(gpointer event_data, gboolean is_ble);
@@ -148,12 +148,14 @@ static void __bt_handle_ongoing_device_service_search(bt_remote_dev_info_t *remo
 
 static void __bt_device_trusted_callback(gboolean trusted, event_dev_trust_t* info);
 
-#ifdef TIZEN_FEATURE_BT_OBEX
+static int __bt_get_device_pin_code(const char *address, char *pin_code);
+
 gboolean _bt_is_device_creating(void)
 {
-       return is_device_creating;
+       if (!trigger_bond_info)
+               return FALSE;
+       return trigger_bond_info->is_device_creating;
 }
-#endif
 
 void _bt_device_state_handle_callback_set_request(void)
 {
@@ -1077,7 +1079,8 @@ static void __bt_device_event_handler(int event_type, gpointer event_data)
 static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
 {
        GVariant *param;
-       gchar address[BT_ADDRESS_STR_LEN];
+       char address[BT_ADDRESS_STRING_SIZE];
+       char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
        BT_DBG("+");
 
        _bt_convert_addr_type_to_string(address, pin_req_event->address.addr);
@@ -1118,6 +1121,9 @@ static void __bt_device_pin_request_callback(remote_device_t* pin_req_event)
                _bt_send_event(BT_ADAPTER_EVENT,
                                BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
                BT_DBG("Key board pairing in process");
+       } else if (BLUETOOTH_ERROR_NONE == __bt_get_device_pin_code(address, pin_code)) {
+               BT_DBG("Use stored PIN code [%s]", pin_code);
+               device_accept_pin_request(&pin_req_event->address, pin_code);
        } else {
                if (_bt_is_bonding_device_address(address) == TRUE) {
                        BT_DBG("Show Pin entry");
@@ -1249,13 +1255,18 @@ static void __bt_device_ssp_passkey_display_callback(event_dev_passkey_t *dev_in
        trigger_pairing_info->is_ssp = TRUE;
 
        BT_DBG("Send BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
-       snprintf(str_passkey, sizeof(str_passkey), "%.6d", dev_info->pass_key);
+       snprintf(str_passkey, sizeof(str_passkey), "%06d", dev_info->pass_key);
 
        param = g_variant_new("(isss)", result, p_addr, name, str_passkey);
-       _bt_send_event(BT_ADAPTER_EVENT,
-                       BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
+       if (passkey_watcher) {
+               BT_INFO("Send passkey to %s", passkey_watcher);
+               _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
+                               BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
+       } else {
+               _bt_send_event(BT_ADAPTER_EVENT,
+                               BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
+       }
        BT_DBG("-");
-
 }
 
 static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
@@ -1977,3 +1988,114 @@ int _bt_get_rssi_strength(bluetooth_device_address_t *addr, int link_type)
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
+
+int _bt_set_passkey_notification(const char *sender, gboolean enable)
+{
+       int result;
+
+       BT_INFO("Set passkey notification(sender:%s, %s)",
+                       sender, enable ? "Enable" : "Disable");
+
+       result = device_enable_gap_auth_notifications(OAL_PASSKEY_DISPLAY,enable);
+       if (OAL_STATUS_SUCCESS != result) {
+               BT_ERR("device_enable_gap_auth_notifications error: [%d]", result);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       g_free(passkey_watcher);
+       if (enable == TRUE)
+               passkey_watcher = g_strdup(sender);
+       else
+               passkey_watcher = NULL;
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_get_device_pin_code(const char *address, char *pin_code)
+{
+       GSList *l = NULL;
+
+       BT_CHECK_PARAMETER(address, return);
+       BT_CHECK_PARAMETER(pin_code, return);
+
+       for (l = pin_info_list; l != NULL; l = l->next) {
+               bt_pin_code_info_t *pin_info = l->data;
+
+               if (!pin_info || !pin_info->address)
+                       continue;
+
+               if (g_strcmp0(pin_info->address, address) == 0) {
+                       g_strlcpy(pin_code, pin_info->pin_code,
+                                       BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
+                       return BLUETOOTH_ERROR_NONE;
+               }
+       }
+
+       return BLUETOOTH_ERROR_NOT_FOUND;
+}
+
+int _bt_set_pin_code(bluetooth_device_address_t *device_address,
+               bluetooth_device_pin_code_t *pin_code)
+{
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       bt_pin_code_info_t *pin_info = NULL;
+       GSList *l = NULL;
+
+       BT_CHECK_PARAMETER(device_address, return);
+       BT_CHECK_PARAMETER(pin_code, return);
+       retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
+                       BLUETOOTH_ERROR_NO_RESOURCES);
+
+       _bt_convert_addr_type_to_string(address, device_address->addr);
+
+       for (l = pin_info_list; l != NULL; l = l->next) {
+               pin_info = l->data;
+
+               if (!pin_info || !pin_info->address)
+                       continue;
+
+               if (g_strcmp0(pin_info->address, address) == 0) {
+                       g_free(pin_info->pin_code);
+                       pin_info->pin_code = g_strdup(pin_code->pin_code);
+                       return BLUETOOTH_ERROR_NONE;
+               }
+       }
+
+       pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
+       pin_info->address = g_strdup(address);
+       pin_info->pin_code = g_strdup(pin_code->pin_code);
+       pin_info_list = g_slist_append(pin_info_list, pin_info);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
+{
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       bt_pin_code_info_t *pin_info = NULL;
+       GSList *l = NULL;
+
+       BT_DBG("+");
+
+       BT_CHECK_PARAMETER(device_address, return);
+
+       _bt_convert_addr_type_to_string(address, device_address->addr);
+
+       for (l = pin_info_list; l != NULL; l = l->next) {
+               pin_info = l->data;
+
+               if (!pin_info || !pin_info->address)
+                       continue;
+
+               if (g_strcmp0(pin_info->address, address) == 0) {
+                       pin_info_list = g_slist_remove(pin_info_list, pin_info);
+                       g_free(pin_info->pin_code);
+                       g_free(pin_info->pin_code);
+                       g_free(pin_info);
+                       break;
+               }
+       }
+
+       BT_DBG("-");
+       return BLUETOOTH_ERROR_NONE;
+}
index b8a273c..b347ef8 100755 (executable)
 extern "C" {
 #endif
 
-#ifdef TIZEN_FEATURE_BT_OBEX
+#define BT_DEVICE_PIN_CODE_SLOT_MAX 10
 typedef struct {
        char *address;
        char *pin_code;
 } bt_pin_code_info_t;
 
-
 gboolean _bt_is_device_creating(void);
 
+#ifdef TIZEN_FEATURE_BT_OBEX
 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid);
-
-int _bt_get_device_pin_code(const char *address, char *pin_code);
 #endif
 
 void _bt_device_state_handle_callback_set_request(void);
@@ -106,6 +104,14 @@ int _bt_enable_rssi(bluetooth_device_address_t *addr, int link_type,
                int low_threshold, int in_range_threshold, int high_threshold);
 
 int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr, int link_type);
+
+int _bt_set_passkey_notification(const char *sender, gboolean enable);
+
+int _bt_set_pin_code(bluetooth_device_address_t *device_address,
+               bluetooth_device_pin_code_t *pin_code);
+
+int _bt_unset_pin_code(bluetooth_device_address_t *device_address);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */