1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
21 * Based on the getCapsUsingSCSIPassThrough() function from "cddrv.cpp":
22 * - http://www.farmanager.com/svn/trunk/unicode_far/cddrv.cpp
24 * Copyright (c) 1996 Eugene Roshal
25 * Copyright (c) 2000 Far Group
26 * All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. The name of the authors may not be used to endorse or promote products
37 * derived from this software without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
40 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
43 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 ****************************************************************************/
55 #include <ddk/ntddscsi.h>
59 typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS
{
60 SCSI_PASS_THROUGH Spt
;
61 ULONG Filler
; /* realign buffers to double word boundary */
64 } SCSI_PASS_THROUGH_WITH_BUFFERS
, *PSCSI_PASS_THROUGH_WITH_BUFFERS
;
66 int ipod_scsi_inquiry(struct ipod_t
* ipod
, int page_code
,
67 unsigned char* buf
, int bufsize
)
69 SCSI_PASS_THROUGH_WITH_BUFFERS sptwb
;
75 fprintf(stderr
,"[ERR] Invalid bufsize in ipod_scsi_inquiry\n");
79 memset(&sptwb
, 0, sizeof(sptwb
));
81 sptwb
.Spt
.Length
= sizeof(SCSI_PASS_THROUGH
);
83 sptwb
.Spt
.TargetId
= 1;
85 sptwb
.Spt
.CdbLength
= 6;
86 sptwb
.Spt
.SenseInfoLength
= 32; /* sbuf size */;
87 sptwb
.Spt
.DataIn
= SCSI_IOCTL_DATA_IN
;
88 sptwb
.Spt
.DataTransferLength
= bufsize
;
89 sptwb
.Spt
.TimeOutValue
= 2; /* 2 seconds */
90 sptwb
.Spt
.DataBufferOffset
= offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS
, DataBuf
);
91 sptwb
.Spt
.SenseInfoOffset
= offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS
, SenseBuf
);
92 length
= offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS
, DataBuf
) +
93 sptwb
.Spt
.DataTransferLength
;
96 sptwb
.Spt
.Cdb
[0] = 0x12; /* SCSI Inquiry */
98 sptwb
.Spt
.Cdb
[2] = page_code
;
100 sptwb
.Spt
.Cdb
[4] = bufsize
;
101 sptwb
.Spt
.Cdb
[5] = 0;
103 status
= DeviceIoControl(ipod
->dh
,
104 IOCTL_SCSI_PASS_THROUGH
,
106 sizeof(SCSI_PASS_THROUGH
),
113 /* W32 sometimes returns more bytes with additional garbage.
114 * Make sure to not copy that garbage. */
115 memcpy(buf
, sptwb
.DataBuf
,
116 (DWORD
)bufsize
>= returned
? returned
: (DWORD
)bufsize
);