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;
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);
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)
{
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);
_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");
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)
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;
+}