Fix Pairing when headset have PIN other than 0000 19/223019/1
authorAmit Purwar <amit.purwar@samsung.com>
Wed, 22 Jan 2020 03:50:48 +0000 (09:20 +0530)
committerAmit Purwar <amit.purwar@samsung.com>
Wed, 22 Jan 2020 06:54:49 +0000 (12:24 +0530)
Change-Id: If0cc262f86f6734d7dadab0edca2db9f813ac223
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
bt-service-adaptation/services/bt-service-agent-util.c
bt-service-adaptation/services/device/bt-service-core-device.c

index 4881d9f..7d1fc82 100644 (file)
@@ -184,7 +184,7 @@ gboolean _bt_agent_is_auto_response(unsigned int dev_class,
        gboolean is_mouse = FALSE;
        char lap_address[BT_LOWER_ADDRESS_LENGTH];
 
-       BT_DBG("bt_agent_is_headset_class, %d +", dev_class);
+       BT_DBG("bt_agent_is_headset_class, [0x%02x] +", dev_class);
 
        if (address == NULL)
                return FALSE;
index 9a1472a..72fe7eb 100644 (file)
@@ -210,6 +210,7 @@ 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);
 
 static int __bt_get_device_pin_code(const char *address, char *pin_code);
+static gboolean __bt_ignore_auto_pairing_request(const char *address);
 
 gboolean _bt_is_device_creating(void)
 {
@@ -912,6 +913,11 @@ static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_f
                  To be considered later*/
                int result = BLUETOOTH_ERROR_INTERNAL;
                BT_INFO("BT_OPERATION_STATUS_AUTH_FAILED");
+
+               BT_INFO("add device in pairing black list");
+               _bt_set_autopair_status_in_bonding_info(FALSE);
+               __bt_ignore_auto_pairing_request(trigger_bond_info->addr);
+
                if (trigger_bond_info) {
                        BT_ERR("Create Bond procedure could not suceed, check if cancelled by User");
                        if (trigger_bond_info->is_cancelled_by_user) {
@@ -2649,4 +2655,90 @@ int _bt_disconnect_device(bluetooth_device_address_t *device_address)
        return BLUETOOTH_ERROR_NONE;
 }
 
+static gboolean __bt_ignore_auto_pairing_request(const char *address)
+{
+       gchar *buffer;
+       char **lines;
+       int i;
+       char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
+       char *temp_buffer;
+       FILE *fp;
+       long size;
+       size_t result;
+
+       BT_DBG("+\n");
+
+       if (address == NULL)
+               return FALSE;
+
+       /* Get the LAP(Lower Address part) */
+       /* User BT_LOWER_ADDRESS_LENGTH+1 for lap_address to accomodate
+          a "," */
+       snprintf(lap_address, sizeof(lap_address), ",%s", address);
+
+       fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
+
+       if (fp == NULL) {
+               BT_ERR("fopen failed \n");
+               return FALSE;
+       }
+
+       fseek(fp, 0, SEEK_END);
+       size = ftell(fp);
+       rewind(fp);
+
+       if (size < 0) {
+               BT_ERR("Get file size failed \n");
+               fclose(fp);
+               return FALSE;
+       }
+
+       buffer = g_malloc0(sizeof(char) * size);
+       result = fread((char *)buffer, 1, size, fp);
+       fclose(fp);
+       if (result != size) {
+               BT_ERR("Read Error\n");
+               g_free(buffer);
+               return FALSE;
+       }
+
+       BT_DBG("Buffer = %s\n", buffer);
+
+       lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
+       g_free(buffer);
+
+       if (lines == NULL)
+               return FALSE;
+
+       /* Write the data and insert new device data */
+       for (i = 0; lines[i] != NULL; i++) {
+               if (g_str_has_prefix(lines[i], "AddressBlacklist")) {
+                       temp_buffer = g_strconcat(lines[i], lap_address, NULL);
+                       g_free(lines[i]);
+                       lines[i] = temp_buffer;
+               }
+       }
+       buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
+       g_strfreev(lines);
+       /* Fix : NULL_RETURNS */
+       retv_if(buffer == NULL, FALSE);
+
+       fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
+
+       if (fp == NULL) {
+               BT_ERR("fopen failed \n");
+               g_free(buffer);
+               return FALSE;
+       }
+
+       BT_DBG("Buffer = %s\n", buffer);
+       fwrite(buffer, 1, strlen(buffer), fp);
+       fclose(fp);
+
+       g_free(buffer);
+
+       BT_DBG("-\n");
+
+       return FALSE;
+}
 #endif