static gboolean input_device_auto_reconnect(gpointer user_data) { struct input_device *idev = user_data; DBG("path=%s, attempt=%d", idev->path, idev->reconnect_attempt); /* Stop the recurrent reconnection attempts if the device is reconnected * or is marked for removal. */ if (device_is_temporary(idev->device) || btd_device_is_connected(idev->device)) return FALSE; /* Only attempt an auto-reconnect for at most 3 minutes (6 * 30s). */ if (idev->reconnect_attempt >= 6) return FALSE; /* Check if the profile is already connected. */ if (idev->ctrl_io) return FALSE; if (is_connected(idev)) return FALSE; idev->reconnect_attempt++; dev_connect(idev); return TRUE; }
static void input_device_enter_reconnect_mode(struct input_device *idev) { DBG("path=%s reconnect_mode=%s", idev->path, reconnect_mode_to_string(idev->reconnect_mode)); /* Only attempt an auto-reconnect when the device is required to accept * reconnections from the host. */ if (idev->reconnect_mode != RECONNECT_ANY && idev->reconnect_mode != RECONNECT_HOST) return; /* If the device is temporary we are not required to reconnect with the * device. This is likely the case of a removing device. */ if (device_is_temporary(idev->device) || btd_device_is_connected(idev->device)) return; if (idev->reconnect_timer > 0) g_source_remove(idev->reconnect_timer); DBG("registering auto-reconnect"); idev->reconnect_attempt = 0; idev->reconnect_timer = g_timeout_add_seconds(30, input_device_auto_reconnect, idev); }
static bool setup_device(int fd, int index, struct btd_adapter *adapter) { char device_addr[18], master_addr[18], adapter_addr[18]; bdaddr_t device_bdaddr, master_bdaddr; const bdaddr_t *adapter_bdaddr; struct btd_device *device; if (get_device_bdaddr(fd, &device_bdaddr) < 0) return false; if (get_master_bdaddr(fd, &master_bdaddr) < 0) return false; /* This can happen if controller was plugged while already connected * eg. to charge up battery. * Don't set LEDs in that case, hence return false */ device = btd_adapter_find_device(adapter, &device_bdaddr, BDADDR_BREDR); if (device && btd_device_is_connected(device)) return false; adapter_bdaddr = btd_adapter_get_address(adapter); if (bacmp(adapter_bdaddr, &master_bdaddr)) { if (set_master_bdaddr(fd, adapter_bdaddr) < 0) return false; } ba2str(&device_bdaddr, device_addr); ba2str(&master_bdaddr, master_addr); ba2str(adapter_bdaddr, adapter_addr); DBG("remote %s old_master %s new_master %s", device_addr, master_addr, adapter_addr); device = btd_adapter_get_device(adapter, &device_bdaddr, BDADDR_BREDR); if (g_slist_find_custom(btd_device_get_uuids(device), HID_UUID, (GCompareFunc)strcasecmp)) { DBG("device %s already known, skipping", device_addr); return true; } info("sixaxis: setting up new device"); btd_device_device_set_name(device, devices[index].name); btd_device_set_pnpid(device, devices[index].source, devices[index].vid, devices[index].pid, devices[index].version); btd_device_set_temporary(device, FALSE); return true; }