I am creating a macOS app that will update the firmware of a USB mass storage device. There are only two steps to do this, copy the files to the storage device (done with this) and send a reboot command to the device using SCSI command sets.
I've tried the library below to send a command, however, the device didn't reboot. I am not sure if there's something wrong with my request.
https://github.com/Arti3DPlayer/USBDeviceSwift
I reached to the developer of this library, however, he replied to me "Sorry, I didn't work with USB and Swift about a year, and don't remember this things:)"
The reboot command is 0xdf 0x40
.
This is the request I sent to the device.
guard let deviceInterface = self.deviceInfo.deviceInterfacePtrPtr?.pointee?.pointee else {
throw STM32DeviceError.DeviceInterfaceNotFound
}
var kr:Int32 = 0
let length:Int = 6
var requestPtr:[UInt8] = [UInt8](repeating: 0, count: length)
// Creating request
var request = IOUSBDevRequest(
bmRequestType: USBmakebmRequestType(direction: kUSBIn, type: kUSBDevice, recipient: kUSBStandard),
bRequest: STM32REQUEST.DETACH.rawValue,
wValue: UInt16(0xdf),
wIndex: 0,
wLength: UInt16(length),
pData: &requestPtr,
wLenDone: 255)
kr = deviceInterface.DeviceRequest(self.deviceInfo.deviceInterfacePtrPtr, &request)
if (kr != kIOReturnSuccess) {
throw STM32DeviceError.RequestError(desc: "Get device status request error: \(kr)")
}