Lines Matching refs:hUSB
168 HUSB hUSB = new(std::nothrow) HdcUSB();
169 if (hUSB == nullptr) {
172 hUSB->device = device;
174 int childRet = OpenDeviceMyNeed(hUSB);
176 delete hUSB;
179 UpdateUSBDaemonInfo(hUSB, STATUS_READY);
181 mapUsbDevice[hUSB->serialNumber] = hUSB;
185 void HostUsb::UpdateUSBDaemonInfo(HUSB hUSB, uint8_t connStatus)
189 di.connectKey = hUSB->serialNumber;
193 di.usbMountPoint = StringFormat("%d-%d", hUSB->busId, hUSB->devId);
197 AdminDaemonMap(OP_QUERY, hUSB->serialNumber, pDi);
199 AdminDaemonMap(OP_ADD, hUSB->serialNumber, hdiNew);
201 AdminDaemonMap(OP_UPDATE, hUSB->serialNumber, hdiNew);
209 int HostUsb::OpenDeviceMyNeed(HUSB hUSB)
211 libusb_device *device = hUSB->device;
213 int openRet = libusb_open(device, &hUSB->devHandle);
218 libusb_device_handle *handle = hUSB->devHandle;
220 if (CheckDescriptor(hUSB, desc)) {
224 if (CheckActiveConfig(device, hUSB, desc)) {
226 if (CheckActiveConfig(device, hUSB)) {
232 ret = libusb_claim_interface(handle, hUSB->interfaceNumber);
237 libusb_close(hUSB->devHandle);
238 hUSB->devHandle = nullptr;
243 int HostUsb::CheckDescriptor(HUSB hUSB, libusb_device_descriptor& desc)
247 uint8_t curBus = libusb_get_bus_number(hUSB->device);
248 uint8_t curDev = libusb_get_device_address(hUSB->device);
249 hUSB->busId = curBus;
250 hUSB->devId = curDev;
251 if (libusb_get_device_descriptor(hUSB->device, &desc)) {
257 childRet = libusb_get_string_descriptor_ascii(hUSB->devHandle, desc.iSerialNumber, (uint8_t *)serialNum,
262 hUSB->serialNumber = serialNum;
268 int HostUsb::CheckActiveConfig(libusb_device *device, HUSB hUSB, libusb_device_descriptor& desc)
270 int HostUsb::CheckActiveConfig(libusb_device *device, HUSB hUSB)
280 ret = libusb_set_configuration(hUSB->devHandle, 1);
296 CheckUsbEndpoint(ret, hUSB, descConfig);
301 void HostUsb::CheckUsbEndpoint(int& ret, HUSB hUSB, libusb_config_descriptor *descConfig)
313 hUSB->interfaceNumber = ifDescriptor->bInterfaceNumber;
321 hUSB->hostBulkIn.endpoint = ep_desc->bEndpointAddress;
322 hUSB->hostBulkIn.bulkInOut = true;
324 hUSB->hostBulkOut.endpoint = ep_desc->bEndpointAddress;
325 hUSB->wMaxPacketSizeSend = ep_desc->wMaxPacketSize;
326 hUSB->hostBulkOut.bulkInOut = false;
329 if (hUSB->hostBulkIn.endpoint == 0 || hUSB->hostBulkOut.endpoint == 0) {
336 bool HostUsb::FindDeviceByID(HUSB hUSB, const char *usbMountPoint, libusb_context *ctxUSB)
368 hUSB->device = listDevices[i];
369 int childRet = OpenDeviceMyNeed(hUSB);
384 void HostUsb::CancelUsbIo(HUSB hUSB)
386 std::unique_lock<std::mutex> lock(hUSB->lockDeviceHandle);
387 if (!hUSB->hostBulkIn.isShutdown) {
388 if (!hUSB->hostBulkIn.isComplete) {
389 libusb_cancel_transfer(hUSB->hostBulkIn.transfer);
390 hUSB->hostBulkIn.cv.notify_one();
392 hUSB->hostBulkIn.isShutdown = true;
395 if (!hUSB->hostBulkOut.isShutdown) {
396 if (!hUSB->hostBulkOut.isComplete) {
397 libusb_cancel_transfer(hUSB->hostBulkOut.transfer);
398 hUSB->hostBulkOut.cv.notify_one();
400 hUSB->hostBulkOut.isShutdown = true;
441 PersistBuffer HostUsb::ReadUsbIO(HUSB hUSB, int exceptedSize)
447 HostUSBEndpoint* ep = &hUSB->hostBulkIn;
453 hUSB->lockDeviceHandle.lock();
457 libusb_fill_bulk_transfer(ep->transfer, hUSB->devHandle, ep->endpoint, g_bufPtr, exceptedSize,
460 hUSB->lockDeviceHandle.unlock();
478 int HostUsb::WriteUsbIO(HUSB hUSB, SerializedBuffer buf)
483 HostUSBEndpoint *ep = &hUSB->hostBulkOut;
485 hUSB->lockDeviceHandle.lock();
491 libusb_fill_bulk_transfer(ep->transfer, hUSB->devHandle, ep->endpoint, ptr, size, USBBulkCallback, ep,
494 hUSB->lockDeviceHandle.unlock();