/** * Callback for passing a new device to the driver. * * @note Currently, only boot-protocol keyboards are supported by this driver. * * @param dev Structure representing the new device. * @return Error code. */ static int usb_hid_device_add(usb_device_t *dev) { usb_log_debug("%s\n", __FUNCTION__); if (dev == NULL) { usb_log_error("Wrong parameter given for add_device().\n"); return EINVAL; } if (usb_device_get_iface_number(dev) < 0) { usb_log_error("Failed to add HID device: endpoints not found." "\n"); return ENOTSUP; } usb_hid_dev_t *hid_dev = usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); if (hid_dev == NULL) { usb_log_error("Failed to create USB/HID device structure.\n"); return ENOMEM; } int rc = usb_hid_init(hid_dev, dev); if (rc != EOK) { usb_log_error("Failed to initialize USB/HID device.\n"); usb_hid_deinit(hid_dev); return rc; } usb_log_debug("USB/HID device structure initialized.\n"); /* Start automated polling function. * This will create a separate fibril that will query the device * for the data continuously. */ rc = usb_device_auto_poll_desc(dev, /* Index of the polling pipe. */ hid_dev->poll_pipe_mapping->description, /* Callback when data arrives. */ usb_hid_polling_callback, /* How much data to request. */ hid_dev->poll_pipe_mapping->pipe.max_packet_size, /* Delay */ -1, /* Callback when the polling ends. */ usb_hid_polling_ended_callback, /* Custom argument. */ hid_dev); if (rc != EOK) { usb_log_error("Failed to start polling fibril for `%s'.\n", usb_device_get_name(dev)); usb_hid_deinit(hid_dev); return rc; } hid_dev->running = true; usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev)); return EOK; }
static int usb_device_removed(const char *devname, void* client_data) { if (sDevice && !strcmp(usb_device_get_name(sDevice), devname)) { usb_device_close(sDevice); sDevice = NULL; // exit when we are disconnected return 1; } return 0; }
// Callback for notification when USB devices are removed. Return true to exit from usb_host_run. int usb_device_removed (const char * devname, void * client_data) { logd ("usb_device_removed client_data: %p devname: %s", client_data, devname); //pthread_mutex_lock (& device_mutex); // if (current_device) { // If we have a current device... const char * curr_devname = usb_device_get_name (current_device); if (! strcmp (curr_devname, devname)) { // If current device was removed... logd ("usb_device_removed current device disconnected"); usb_device_close (current_device); current_device = NULL; } } //pthread_mutex_unlock (& device_mutex); return (0); // 0 = Leave usb_host_run() running }
/** * Callback for removing a device from the driver. * * @param dev Structure representing the device. * @return Error code. */ static int usb_hid_device_gone(usb_device_t *dev) { assert(dev); usb_hid_dev_t *hid_dev = usb_device_data_get(dev); assert(hid_dev); unsigned tries = 100; /* Wait for fail. */ while (hid_dev->running && tries--) { async_usleep(100000); } if (hid_dev->running) { usb_log_error("Can't remove hid, still running.\n"); return EBUSY; } usb_hid_deinit(hid_dev); usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev)); return EOK; }
const char* MtpDevice::getDeviceName() { if (mDevice) return usb_device_get_name(mDevice); else return "???"; }