Solved

DeviceIOControl, vendor-specific SCSI command blocks

Posted on 2008-10-30
3
1,565 Views
Last Modified: 2013-12-04
Well, I've come to poke Ex-Ex again over this question. I need to use windows to send a SCSI command to a usb device. I have a source for linux but have been told that without rewriting a driver I won't be able to do this. I don't think that's the case(although it very well may be).

I've also been told that I need to use  IOCTL_SCSI_PASS_THROUGH_DIRECT although I've gotten a ERROR_REVISION_MISMATCH error from DeviceIOControl.

Any ideas(I can provide the source for the linux version if need be)?
0
Comment
Question by:ThievingSix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 22849413
That's not much detail...  But, I would suggest you try
IOCTL_SCSI_PASS_THROUGH, IOCTL_IDE_PASS_THROUGH, and IOCTL_IDE_PASS_THROUGH_DIRECT
Is this a mass storage device?   Is this vendor specific command related to mass storage (like a format or volume operation?)
0
 
LVL 13

Author Comment

by:ThievingSix
ID: 22850155
Yes it is. To be exact it's a Sony PSP.

Here is a bit more detail.

When acting as a USB mass storage controller ("USB Connection" mode),
the PSP accepts a few vendor-specific SCSI command blocks.  This
program sends these commands via the Linux generic SCSI interface and
displays the results. To run, pass it the device node of your connected PSP.

I'm supposed to send a sg_io_hdr struct using the generic SCSI interface. I know of those constants for DeviceIOControl() but I don't know how to tie them into the sg_io_hdr_t  struct.




void do_command(int fd, char *desc, unsigned char *cmd, int len)
{
	sg_io_hdr_t io;
	unsigned char buf[512];
	
	memset(buf, 0, sizeof(buf));
 
	memset(&io, 0, sizeof(io));
	io.interface_id = 'S';
	io.cmd_len = len;
	io.mx_sb_len = 0;
	io.dxfer_direction = SG_DXFER_FROM_DEV;
	io.dxfer_len = sizeof(buf);
	io.dxferp = buf;
	io.cmdp = cmd;
	
	printf("Command: %s\n", desc);
	hexdump(cmd, len);
 
	if (ioctl(fd, SG_IO, &io) < 0) {
		printf("Error: %s\n", strerror(errno));
		return;
	}
 
	if ((io.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
		printf("Failed with status 0x%02x\n", io.masked_status);
		return;
	}
 
	len = io.dxfer_len - io.resid;
	printf("Response: %d %s\n", len, (len == 1) ? "byte" : "bytes");
	hexdump(buf, len);
}

Open in new window

0
 
LVL 13

Author Comment

by:ThievingSix
ID: 22851787
After meddling and testing, to my surprise, it has worked. Code below.

Thanks for answering though, I've posted this question 2x before with no one knowing what to do.
var
  PD : DWORD;
  Buffer : PChar;
  BytesReturned : DWORD;
  srb : SCSI_PASS_THROUGH_DIRECT;
begin
  PD := GetPD(GetPhysicalDiskNumber('H'));
  If PD = INVALID_HANDLE_VALUE Then
    begin
    ShowMessage(Format('%d - 1',[GetLastError]));
    Exit;
  end;
  ZeroMemory(@srb,SizeOf(srb));
  Buffer := AllocMem(512);
  BytesReturned := 0;
  srb.Length := sizeof(srb);
  srb.Lun := 2;
  srb.Cdb[0] := Byte(Commands[5].Cmd[1]);
  srb.Cdb[1] := Byte(Commands[5].Cmd[2]);
  srb.Cdb[2] := Byte(Commands[5].Cmd[3]);
  srb.Cdb[3] := Byte(Commands[5].Cmd[4]);
  srb.Cdb[4] := Byte(Commands[5].Cmd[5]);
  srb.Cdb[5] := Byte(Commands[5].Cmd[6]);
  srb.Cdb[6] := Byte(Commands[5].Cmd[7]);
  srb.Cdb[7] := Byte(Commands[5].Cmd[8]);
  srb.Cdb[8] := Byte(Commands[5].Cmd[9]);
  srb.Cdb[9] := Byte(Commands[5].Cmd[10]);
  srb.CdbLength := Commands[5].Len;
  srb.DataIn := 1;
  srb.TimeOutValue := 10;
  srb.DataBuffer := Buffer;
  srb.DataTransferLength := 512;
  If Not(DeviceIOControl(PD,IOCTL_SCSI_PASS_THROUGH_DIRECT,@srb,SizeOf(srb),@srb,SizeOf(srb),BytesReturned,nil)) Then
    begin
    ShowMessage(Format('%d - 2',[GetLastError]));
  end;
  CloseHandle(PD);
  Memo1.Text := HexDump(Buffer,512);
  FreeMem(Buffer,512);

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question