Link to home
Create AccountLog in
C++

C++

--

Questions

--

Followers

Top Experts

Avatar of edhannon
edhannon

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_WITH_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_WITH_BUFFER io;
            memset(&io, 0, sizeof(io));
            USHORT length = sizeof(SCSI_PASS_THROUGH_DIRECT);
            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_DIRECT);
            io.spt.SenseInfoLength = 32;
            memcpy(io.spt.Cdb, cmd, cmdLen);
            memcpy(io.ucSenseBuf,sense,io.spt.SenseInfoLength);

            DeviceIoControl(sg_fd,IOCTL_SCSI_PASS_THROUGH_DIRECT,
                  &io,length,&io,length,&returned,NULL);

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of jkrjkr🇩🇪

Shouldn't

            USHORT length = sizeof(SCSI_PASS_THROUGH_DIRECT);

be

            USHORT length = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);

?

Avatar of edhannonedhannon

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of edhannonedhannon

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Had to solve it myself!

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

C++

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.