Dave Chapman | 1eca02d | 2009-08-04 20:32:30 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Dominik Riebeling | 7e0fe36 | 2009-11-06 23:20:51 +0000 | [diff] [blame] | 8 | * $Id$ |
Dave Chapman | 1eca02d | 2009-08-04 20:32:30 +0000 | [diff] [blame] | 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 | |
Dominik Riebeling | e23adb5 | 2011-12-07 20:06:48 +0000 | [diff] [blame] | 52 | #if defined(_WIN32) |
Dave Chapman | 1eca02d | 2009-08-04 20:32:30 +0000 | [diff] [blame] | 53 | #include <windows.h> |
| 54 | #include <stddef.h> |
| 55 | #include <stdio.h> |
| 56 | #include <ddk/ntddscsi.h> |
| 57 | |
| 58 | #include "ipodio.h" |
| 59 | |
| 60 | typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS { |
| 61 | SCSI_PASS_THROUGH Spt; |
| 62 | ULONG Filler; /* realign buffers to double word boundary */ |
| 63 | UCHAR SenseBuf[32]; |
| 64 | UCHAR DataBuf[512]; |
| 65 | } SCSI_PASS_THROUGH_WITH_BUFFERS, *PSCSI_PASS_THROUGH_WITH_BUFFERS; |
| 66 | |
| 67 | int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code, |
| 68 | unsigned char* buf, int bufsize) |
| 69 | { |
| 70 | SCSI_PASS_THROUGH_WITH_BUFFERS sptwb; |
| 71 | ULONG length; |
| 72 | DWORD returned; |
| 73 | BOOL status; |
| 74 | |
| 75 | if (bufsize > 255) { |
| 76 | fprintf(stderr,"[ERR] Invalid bufsize in ipod_scsi_inquiry\n"); |
| 77 | return -1; |
| 78 | } |
| 79 | |
| 80 | memset(&sptwb, 0, sizeof(sptwb)); |
| 81 | |
| 82 | sptwb.Spt.Length = sizeof(SCSI_PASS_THROUGH); |
| 83 | sptwb.Spt.PathId = 0; |
| 84 | sptwb.Spt.TargetId = 1; |
| 85 | sptwb.Spt.Lun = 0; |
| 86 | sptwb.Spt.CdbLength = 6; |
| 87 | sptwb.Spt.SenseInfoLength = 32; /* sbuf size */; |
| 88 | sptwb.Spt.DataIn = SCSI_IOCTL_DATA_IN; |
| 89 | sptwb.Spt.DataTransferLength = bufsize; |
| 90 | sptwb.Spt.TimeOutValue = 2; /* 2 seconds */ |
| 91 | sptwb.Spt.DataBufferOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf); |
| 92 | sptwb.Spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, SenseBuf); |
| 93 | length = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf) + |
| 94 | sptwb.Spt.DataTransferLength; |
| 95 | |
| 96 | /* Set cdb info */ |
| 97 | sptwb.Spt.Cdb[0] = 0x12; /* SCSI Inquiry */ |
| 98 | sptwb.Spt.Cdb[1] = 1; |
| 99 | sptwb.Spt.Cdb[2] = page_code; |
| 100 | sptwb.Spt.Cdb[3] = 0; |
| 101 | sptwb.Spt.Cdb[4] = bufsize; |
| 102 | sptwb.Spt.Cdb[5] = 0; |
| 103 | |
| 104 | status = DeviceIoControl(ipod->dh, |
| 105 | IOCTL_SCSI_PASS_THROUGH, |
| 106 | &sptwb, |
| 107 | sizeof(SCSI_PASS_THROUGH), |
| 108 | &sptwb, |
| 109 | length, |
| 110 | &returned, |
| 111 | FALSE); |
| 112 | |
| 113 | if (status) { |
Dominik Riebeling | 0592557 | 2009-08-07 22:58:20 +0000 | [diff] [blame] | 114 | /* W32 sometimes returns more bytes with additional garbage. |
| 115 | * Make sure to not copy that garbage. */ |
| 116 | memcpy(buf, sptwb.DataBuf, |
| 117 | (DWORD)bufsize >= returned ? returned : (DWORD)bufsize); |
Dave Chapman | 1eca02d | 2009-08-04 20:32:30 +0000 | [diff] [blame] | 118 | return 0; |
| 119 | } else { |
| 120 | return -1; |
| 121 | } |
| 122 | } |
Dominik Riebeling | e23adb5 | 2011-12-07 20:06:48 +0000 | [diff] [blame] | 123 | #endif |
| 124 | |