C++
--
Questions
--
Followers
Top Experts
deviceiocontrol error 87 - ERROR_INVALID_PARAMETER
I am trying to send a direct command to a camera connected via the USB. I open the camera with createfile using "\\.\PhysicalDrive1" with the structure and call listed below.
I get an error 87 - invalid parameter. I suspect that I am not setting up the SCSI_PASS_THROUGH_DIRECT command correctly.
Does anyone have an example setup that works or see what I am doing wrong?
Command structure:
typedef struct {
SCSI_PASS_THROUGH_DIRECT spt;
ULONG Filler;
UCHAR ucSenseBuf[32];
}
SCSI_PASS_THROUGH_DIRECT_W ITH_BUFFER ;
Command buffer:
uint8_t cmd[8] = { 0xf0, 0x24, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 };
Then I set up for the call:
SCSI_PASS_THROUGH_DIRECT_W ITH_BUFFER io;
memset(&io, 0, sizeof(io));
USHORT length = sizeof(SCSI_PASS_THROUGH_D IRECT);
DWORD returned = 0;
io.spt.Length= length;
io.spt.CdbLength = cmdLen;
io.spt.DataIn = SCSI_IOCTL_DATA_IN;
io.spt.DataTransferLength = bufLen;
io.spt.TimeOutValue = 60;
io.spt.DataBuffer = io.spt.DataTransferLength ? buf : NULL;
io.spt.SenseInfoOffset = sizeof(SCSI_PASS_THROUGH_D IRECT);
io.spt.SenseInfoLength = 32;
memcpy(io.spt.Cdb, cmd, cmdLen);
memcpy(io.ucSenseBuf,sense ,io.spt.Se nseInfoLen gth);
DeviceIoControl(sg_fd,IOCT L_SCSI_PAS S_THROUGH_ DIRECT,
&io,length,&io,length,&ret urned,NULL );
I get an error 87 - invalid parameter. I suspect that I am not setting up the SCSI_PASS_THROUGH_DIRECT command correctly.
Does anyone have an example setup that works or see what I am doing wrong?
Command structure:
typedef struct {
SCSI_PASS_THROUGH_DIRECT spt;
ULONG Filler;
UCHAR ucSenseBuf[32];
}
SCSI_PASS_THROUGH_DIRECT_W
Command buffer:
uint8_t cmd[8] = { 0xf0, 0x24, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 };
Then I set up for the call:
SCSI_PASS_THROUGH_DIRECT_W
memset(&io, 0, sizeof(io));
USHORT length = sizeof(SCSI_PASS_THROUGH_D
DWORD returned = 0;
io.spt.Length= length;
io.spt.CdbLength = cmdLen;
io.spt.DataIn = SCSI_IOCTL_DATA_IN;
io.spt.DataTransferLength = bufLen;
io.spt.TimeOutValue = 60;
io.spt.DataBuffer = io.spt.DataTransferLength ? buf : NULL;
io.spt.SenseInfoOffset = sizeof(SCSI_PASS_THROUGH_D
io.spt.SenseInfoLength = 32;
memcpy(io.spt.Cdb, cmd, cmdLen);
memcpy(io.ucSenseBuf,sense
DeviceIoControl(sg_fd,IOCT
&io,length,&io,length,&ret
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Shouldn't
USHORT length = sizeof(SCSI_PASS_THROUGH_D IRECT);
be
USHORT length = sizeof(SCSI_PASS_THROUGH_D IRECT_WITH _BUFFER);
?
USHORT length = sizeof(SCSI_PASS_THROUGH_D
be
USHORT length = sizeof(SCSI_PASS_THROUGH_D
?
jkr,
I thought so too but when use that I get an error code that says wrong version. Googled it and found that setting it to sizeof (SCSI_PASS+THROUGH_DIRECT) makes that ewrror go away.
I thought so too but when use that I get an error code that says wrong version. Googled it and found that setting it to sizeof (SCSI_PASS+THROUGH_DIRECT)
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Had to solve it myself!






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
C++
--
Questions
--
Followers
Top Experts
C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.