Device::Device(usb_device device) : fStatus(B_ERROR), fOpen(false), fRemoved(false), fInsideNotify(0), fDevice(device), fNonBlocking(false), fAudioControl(this), fControlEndpoint(0), fInStreamEndpoint(0), fOutStreamEndpoint(0), fNotifyReadSem(-1), fNotifyWriteSem(-1), fNotifyBuffer(NULL), fNotifyBufferLength(0), fBuffersReadySem(-1) { const usb_device_descriptor* deviceDescriptor = gUSBModule->get_device_descriptor(device); if (deviceDescriptor == NULL) { TRACE_ALWAYS("Error of getting USB device descriptor.\n"); return; } fVendorID = deviceDescriptor->vendor_id; fProductID = deviceDescriptor->product_id; fNotifyReadSem = create_sem(0, DRIVER_NAME"_notify_read"); if (fNotifyReadSem < B_OK) { TRACE_ALWAYS("Error of creating read notify semaphore:%#010x\n", fNotifyReadSem); return; } fNotifyWriteSem = create_sem(0, DRIVER_NAME"_notify_write"); if (fNotifyWriteSem < B_OK) { TRACE_ALWAYS("Error of creating write notify semaphore:%#010x\n", fNotifyWriteSem); return; } fBuffersReadySem = create_sem(0, DRIVER_NAME "_buffers_ready"); if (fBuffersReadySem < B_OK) { TRACE_ALWAYS("Error of creating ready buffers semaphore:%#010x\n", fBuffersReadySem); return; } if (_SetupEndpoints() != B_OK) { return; } // must be set in derived class constructor fStatus = B_OK; }
DavicomDevice::DavicomDevice(usb_device device, const char *description) : fStatus(B_ERROR), fOpen(false), fRemoved(false), fInsideNotify(0), fDevice(device), fDescription(description), fNonBlocking(false), fNotifyEndpoint(0), fReadEndpoint(0), fWriteEndpoint(0), fNotifyReadSem(-1), fNotifyWriteSem(-1), fNotifyBuffer(NULL), fLinkStateChangeSem(-1), fHasConnection(false) { const usb_device_descriptor *deviceDescriptor = gUSBModule->get_device_descriptor(device); if (deviceDescriptor == NULL) { TRACE_ALWAYS("Error of getting USB device descriptor.\n"); return; } fVendorID = deviceDescriptor->vendor_id; fProductID = deviceDescriptor->product_id; fNotifyReadSem = create_sem(0, DRIVER_NAME"_notify_read"); if (fNotifyReadSem < B_OK) { TRACE_ALWAYS("Error of creating read notify semaphore:%#010x\n", fNotifyReadSem); return; } fNotifyWriteSem = create_sem(0, DRIVER_NAME"_notify_write"); if (fNotifyWriteSem < B_OK) { TRACE_ALWAYS("Error of creating write notify semaphore:%#010x\n", fNotifyWriteSem); return; } fNotifyBuffer = (uint8*)malloc(kNotifyBufferSize); if (fNotifyBuffer == NULL) { TRACE_ALWAYS("Error allocating notify buffer\n"); return; } if (_SetupEndpoints() != B_OK) { return; } // TODO : others inits here ? fStatus = B_OK; }
ASIXDevice::ASIXDevice(usb_device device, DeviceInfo& deviceInfo) : fDevice(device), fStatus(B_ERROR), fOpen(false), fRemoved(false), fHasConnection(false), fNonBlocking(false), fInsideNotify(0), fFrameSize(0), fNotifyEndpoint(0), fReadEndpoint(0), fWriteEndpoint(0), fActualLengthRead(0), fActualLengthWrite(0), fStatusRead(B_OK), fStatusWrite(B_OK), fNotifyReadSem(-1), fNotifyWriteSem(-1), fNotifyBuffer(NULL), fNotifyBufferLength(0), fLinkStateChangeSem(-1), fUseTRXHeader(false), fReadNodeIDRequest(kInvalidRequest) { fDeviceInfo = deviceInfo; fIPG[0] = 0x15; fIPG[1] = 0x0c; fIPG[2] = 0x12; memset(&fMACAddress, 0, sizeof(fMACAddress)); fNotifyReadSem = create_sem(0, DRIVER_NAME"_notify_read"); if (fNotifyReadSem < B_OK) { TRACE_ALWAYS("Error of creating read notify semaphore:%#010x\n", fNotifyReadSem); return; } fNotifyWriteSem = create_sem(0, DRIVER_NAME"_notify_write"); if (fNotifyWriteSem < B_OK) { TRACE_ALWAYS("Error of creating write notify semaphore:%#010x\n", fNotifyWriteSem); return; } if (_SetupEndpoints() != B_OK) { return; } // must be set in derived class constructor // fStatus = B_OK; }
status_t DavicomDevice::CompareAndReattach(usb_device device) { const usb_device_descriptor *deviceDescriptor = gUSBModule->get_device_descriptor(device); if (deviceDescriptor == NULL) { TRACE_ALWAYS("Error getting USB device descriptor.\n"); return B_ERROR; } if (deviceDescriptor->vendor_id != fVendorID && deviceDescriptor->product_id != fProductID) { // this certainly isn't the same device return B_BAD_VALUE; } // this is the same device that was replugged - clear the removed state, // re-setup the endpoints and transfers and open the device if it was // previously opened fDevice = device; fRemoved = false; status_t result = _SetupEndpoints(); if (result != B_OK) { fRemoved = true; return result; } // we need to setup hardware on device replug result = SetupDevice(true); if (result != B_OK) { return result; } if (fOpen) { fOpen = false; result = Open(fNonBlocking ? O_NONBLOCK : 0); } return result; }