summaryrefslogtreecommitdiff
path: root/rbutil/ipodpatcher/ipodio-win32-scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/ipodpatcher/ipodio-win32-scsi.c')
-rw-r--r--rbutil/ipodpatcher/ipodio-win32-scsi.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/rbutil/ipodpatcher/ipodio-win32-scsi.c b/rbutil/ipodpatcher/ipodio-win32-scsi.c
new file mode 100644
index 0000000000..5843ce5d2f
--- /dev/null
+++ b/rbutil/ipodpatcher/ipodio-win32-scsi.c
@@ -0,0 +1,118 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ipodio-win32.c 17847 2008-06-28 18:10:04Z bagder $
9 *
10 * Copyright (C) 2009 Dave Chapman
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 *
21 * Based on the getCapsUsingSCSIPassThrough() function from "cddrv.cpp":
22 * - http://www.farmanager.com/svn/trunk/unicode_far/cddrv.cpp
23 *
24 * Copyright (c) 1996 Eugene Roshal
25 * Copyright (c) 2000 Far Group
26 * All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
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.
38 *
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.
49 *
50 ****************************************************************************/
51
52#include <windows.h>
53#include <stddef.h>
54#include <stdio.h>
55#include <ddk/ntddscsi.h>
56
57#include "ipodio.h"
58
59typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS {
60 SCSI_PASS_THROUGH Spt;
61 ULONG Filler; /* realign buffers to double word boundary */
62 UCHAR SenseBuf[32];
63 UCHAR DataBuf[512];
64} SCSI_PASS_THROUGH_WITH_BUFFERS, *PSCSI_PASS_THROUGH_WITH_BUFFERS;
65
66int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code,
67 unsigned char* buf, int bufsize)
68{
69 SCSI_PASS_THROUGH_WITH_BUFFERS sptwb;
70 ULONG length;
71 DWORD returned;
72 BOOL status;
73
74 if (bufsize > 255) {
75 fprintf(stderr,"[ERR] Invalid bufsize in ipod_scsi_inquiry\n");
76 return -1;
77 }
78
79 memset(&sptwb, 0, sizeof(sptwb));
80
81 sptwb.Spt.Length = sizeof(SCSI_PASS_THROUGH);
82 sptwb.Spt.PathId = 0;
83 sptwb.Spt.TargetId = 1;
84 sptwb.Spt.Lun = 0;
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;
94
95 /* Set cdb info */
96 sptwb.Spt.Cdb[0] = 0x12; /* SCSI Inquiry */
97 sptwb.Spt.Cdb[1] = 1;
98 sptwb.Spt.Cdb[2] = page_code;
99 sptwb.Spt.Cdb[3] = 0;
100 sptwb.Spt.Cdb[4] = bufsize;
101 sptwb.Spt.Cdb[5] = 0;
102
103 status = DeviceIoControl(ipod->dh,
104 IOCTL_SCSI_PASS_THROUGH,
105 &sptwb,
106 sizeof(SCSI_PASS_THROUGH),
107 &sptwb,
108 length,
109 &returned,
110 FALSE);
111
112 if (status) {
113 memcpy(buf, sptwb.DataBuf, returned);
114 return 0;
115 } else {
116 return -1;
117 }
118}