Hi,
I am developing a driver for a USBSerial device. I have the source code for this device based on your I/O Kit. Now, I have to port my old code to DriverKit.
I found in Apple’s documentation that I have to use IOUserUSBSerial class to implement my driver. But currently, I can’t find any good documents or sample codes for USB2Serial DriverKit type. I found some documents from Apple website but they are very short and they don't have enough details for me to understand them.
So can you provide me some documents or sample codes for it?
Thanks.
Post
Replies
Boosts
Views
Activity
We are developing driver kit for usb to serial.
we testing by connect two usb to serial devices together (rx of device 1 to tx of device 2 and vice versa).
open two terminal windows
one type
echo "hello" > /dev/SerialDevice1
one type
cat < /dev/SerialDevice2
on device 2 only receive "h" character.
we capture by usb analyzer on device 1 and see that, the echo call to send out "hello" then it immediately call to HwResetFIFO causing the device 1 abort remaining characters.
kern_return_t
IMPL(NullDriver, HwResetFIFO) {
		uint8_t purgeMask = 0;
		if (tx) {
				purgeMask |= TX_CLR_MASK;
		}
		if (rx) {
				purgeMask |= RX_CLR_MASK;
		}
		return ivars->provider->DeviceRequest(USBmakeOutbmRequestType,
																					CP210xRequests::PURGE,
																					purgeMask, ivars->interfaceNumber, 0,
																					nullptr, nullptr, 0);
}
what should we do in this case? in driver, should we wait for all characters in device 1 finish sending before calling purge command to clear all characters in device 1?
we are developing USB hid library to interact with HID device, however we're facing on memory lacking when we calling IOCreatePlugInInterfaceForService then calling IODestroyPlugInInterface, the memory is not released and each time of calling it take about 0.3 MB Ram, after long time running, the program crash because runout of memory.
what should we do in this case to avoid memory leak?
// Create a device interface/HANDLE
static BOOL CreateHidDeviceInterface(io_object_t deviceObject, HANDLE* pHandle)
{
BOOL retVal = FALSE;
IOCFPlugInInterface** ppPluginInterface = NULL;
SInt32 score = 0;
IOReturn pluginResult;
HRESULT interfaceResult;
// Create a plugin so we can create an interface
pluginResult = IOCreatePlugInInterfaceForService(deviceObject, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &ppPluginInterface, &score);
if (pluginResult == kIOReturnSuccess)
{
// Create the interface (HANDLE)
interfaceResult = (*ppPluginInterface)->QueryInterface(ppPluginInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void**)pHandle);
if (interfaceResult == S_OK)
{
retVal = TRUE;
}
IODestroyPlugInInterface(ppPluginInterface);
}
return retVal;
}