static int udevman_unregister_udevice(IUDEVMAN * idevman, int bus_number, int dev_number) { UDEVMAN * udevman = (UDEVMAN *) idevman; UDEVICE * pdev, * dev; int ret = 0, err = 0; dev = (UDEVICE *)udevman_get_udevice_by_addr(idevman, bus_number, dev_number); idevman->loading_lock(idevman); idevman->rewind(idevman); while (idevman->has_next(idevman) != 0) { pdev = (UDEVICE *)idevman->get_next(idevman); if (pdev == dev) /* device exists */ { /* set previous device to point to next device */ if (dev->prev != NULL) { /* unregistered device is not the head */ pdev = dev->prev; pdev->next = dev->next; } else { /* unregistered device is the head, update head */ udevman->head = (IUDEVICE*)dev->next; } /* set next device to point to previous device */ if (dev->next != NULL) { /* unregistered device is not the tail */ pdev = (UDEVICE *)dev->next; pdev->prev = dev->prev; } else { /* unregistered device is the tail, update tail */ udevman->tail = (IUDEVICE*)dev->prev; } udevman->device_num--; break; } } idevman->loading_unlock(idevman); if (dev) { /* reset device */ if (err != LIBUSB_ERROR_NO_DEVICE) { ret = libusb_reset_device(dev->libusb_handle); if (ret<0){ LLOGLN(10, ("libusb_reset_device: ERROR!!ret:%d\n", ret)); } } /* release all interface and attach kernel driver */ dev->iface.attach_kernel_driver((IUDEVICE*)dev); if(dev->request_queue) zfree(dev->request_queue); /* free the config descriptor that send from windows */ msusb_msconfig_free(dev->MsConfig); libusb_close (dev->libusb_handle); libusb_close (dev->hub_handle); sem_destroy(&dev->sem_id); /* free device info */ if (dev->devDescriptor) zfree(dev->devDescriptor); if (dev) zfree(dev); return 1; /* unregistration successful */ } /* if we reach this point, the device wasn't found */ return 0; }
static int udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_number, int UsbDevice, uint16 idVendor, uint16 idProduct, int flag) { UDEVMAN * udevman = (UDEVMAN *) idevman; IUDEVICE * pdev = NULL; IUDEVICE ** devArray; int i, num, addnum = 0; pdev = (IUDEVICE *)udevman_get_udevice_by_addr(idevman, bus_number, dev_number); if (pdev != NULL) return 0; if (flag == UDEVMAN_FLAG_ADD_BY_ADDR) { pdev = udev_new_by_addr(bus_number, dev_number); if (pdev == NULL) return 0; pdev->set_UsbDevice(pdev, UsbDevice); idevman->loading_lock(idevman); if (udevman->head == NULL) { /* linked list is empty */ udevman->head = pdev; udevman->tail = pdev; } else { /* append device to the end of the linked list */ udevman->tail->set_p_next(udevman->tail, pdev); pdev->set_p_prev(pdev, udevman->tail); udevman->tail = pdev; } udevman->device_num += 1; idevman->loading_unlock(idevman); } else if (flag == UDEVMAN_FLAG_ADD_BY_VID_PID) { addnum = 0; /* register all device that match pid vid */ num = udev_new_by_id(idVendor, idProduct, &devArray); for (i = 0; i < num; i++) { pdev = devArray[i]; if (udevman_get_udevice_by_addr(idevman, pdev->get_bus_number(pdev), pdev->get_dev_number(pdev)) != NULL) { zfree(pdev); continue; } pdev->set_UsbDevice(pdev, UsbDevice); idevman->loading_lock(idevman); if (udevman->head == NULL) { /* linked list is empty */ udevman->head = pdev; udevman->tail = pdev; } else { /* append device to the end of the linked list */ udevman->tail->set_p_next(udevman->tail, pdev); pdev->set_p_prev(pdev, udevman->tail); udevman->tail = pdev; } udevman->device_num += 1; idevman->loading_unlock(idevman); addnum++; } zfree(devArray); return addnum; } else { printf("udevman_register_udevice: function error!!"); return 0; } return 1; }