]> git.sesse.net Git - vlc/blob - extras/libdvdcss/ioctl.h
a761cb291259d04c4228abb76988479fbbef6397
[vlc] / extras / libdvdcss / ioctl.h
1 /*****************************************************************************
2  * ioctl.h: DVD ioctl replacement function
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: ioctl.h,v 1.5 2001/07/07 21:10:58 gbazin Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 int ioctl_ReadCopyright     ( int, int, int * );
25 int ioctl_ReadKey           ( int, int *, u8 * );
26
27 int ioctl_ReportAgid        ( int, int * );
28 int ioctl_ReportChallenge   ( int, int *, u8 * );
29 int ioctl_ReportKey1        ( int, int *, u8 * );
30 int ioctl_ReportASF         ( int, int *, int * );
31 int ioctl_InvalidateAgid    ( int, int * );
32 int ioctl_SendChallenge     ( int, int *, u8 * );
33 int ioctl_SendKey2          ( int, int *, u8 * );
34
35 /*****************************************************************************
36  * Common macro, BeOS specific
37  *****************************************************************************/
38 #if defined( SYS_BEOS )
39 #define INIT_RDC( TYPE, SIZE ) \
40     raw_device_command rdc; \
41     u8 p_buffer[ (SIZE) ]; \
42     memset( &rdc, 0, sizeof( raw_device_command ) ); \
43     rdc.data = (char *)p_buffer; \
44     rdc.data_length = (SIZE); \
45     BeInitRDC( &rdc, (TYPE) );
46 #endif
47
48 /*****************************************************************************
49  * Common macro, Darwin specific
50  *****************************************************************************/
51 #if defined( SYS_DARWIN )
52 #define INIT_DVDIOCTL( SIZE ) \
53     dvdioctl_data_t dvdioctl; \
54     u8 p_buffer[ (SIZE) ]; \
55     dvdioctl.p_buffer = p_buffer; \
56     dvdioctl.i_size = (SIZE); \
57     dvdioctl.i_keyclass = kCSS_CSS2_CPRM; \
58     memset( p_buffer, 0, (SIZE) );
59 #endif
60
61 /*****************************************************************************
62  * Common macro, win32 (ASPI) specific
63  *****************************************************************************/
64 #if defined( WIN32 )
65 #define INIT_SSC( TYPE, SIZE ) \
66     struct SRB_ExecSCSICmd ssc; \
67     u8 p_buffer[ (SIZE) ]; \
68     memset( &ssc, 0, sizeof( struct SRB_ExecSCSICmd ) ); \
69     ssc.SRB_BufPointer = (char *)p_buffer; \
70     ssc.SRB_BufLen = (SIZE); \
71     WinInitSSC( &ssc, (TYPE) );
72 #endif
73
74 /*****************************************************************************
75  * Various DVD I/O tables
76  *****************************************************************************/
77
78 #if defined( SYS_BEOS ) || defined( WIN32 )
79     /* The generic packet command opcodes for CD/DVD Logical Units,
80      * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
81 #   define GPCMD_READ_DVD_STRUCTURE 0xad
82 #   define GPCMD_REPORT_KEY         0xa4
83 #   define GPCMD_SEND_KEY           0xa3
84     /* DVD struct types */
85 #   define DVD_STRUCT_COPYRIGHT     0x01
86 #   define DVD_STRUCT_DISCKEY       0x02
87     /* Key formats */
88 #   define DVD_REPORT_AGID          0x00
89 #   define DVD_REPORT_CHALLENGE     0x01
90 #   define DVD_SEND_CHALLENGE       0x01
91 #   define DVD_REPORT_KEY1          0x02
92 #   define DVD_SEND_KEY2            0x03
93 #   define DVD_REPORT_ASF           0x05
94 #   define DVD_INVALIDATE_AGID      0x3f
95 #endif
96
97 #if defined( WIN32 )
98
99 /*****************************************************************************
100  * win32 ioctl specific
101  *****************************************************************************/
102
103 #define IOCTL_DVD_START_SESSION         CTL_CODE(FILE_DEVICE_DVD, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
104 #define IOCTL_DVD_READ_KEY              CTL_CODE(FILE_DEVICE_DVD, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
105 #define IOCTL_DVD_SEND_KEY              CTL_CODE(FILE_DEVICE_DVD, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
106 #define IOCTL_DVD_END_SESSION           CTL_CODE(FILE_DEVICE_DVD, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
107
108 #define IOCTL_SCSI_PASS_THROUGH_DIRECT  CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
109
110 #define DVD_CHALLENGE_KEY_LENGTH        (12 + sizeof(DVD_COPY_PROTECT_KEY))
111 #define DVD_BUS_KEY_LENGTH              (8 + sizeof(DVD_COPY_PROTECT_KEY))
112 #define DVD_DISK_KEY_LENGTH             (2048 + sizeof(DVD_COPY_PROTECT_KEY))
113 #define DVD_ASF_LENGTH                  (sizeof(DVD_ASF) + sizeof(DVD_COPY_PROTECT_KEY))
114
115 #define SCSI_IOCTL_DATA_OUT             0
116 #define SCSI_IOCTL_DATA_IN              1
117
118 typedef ULONG DVD_SESSION_ID, *PDVD_SESSION_ID;
119
120 typedef enum
121 {
122     DvdChallengeKey = 0x01,
123     DvdBusKey1,
124     DvdBusKey2,
125     DvdTitleKey,
126     DvdAsf,
127     DvdSetRpcKey = 0x6,
128     DvdGetRpcKey = 0x8,
129     DvdDiskKey = 0x80,
130     DvdInvalidateAGID = 0x3f
131 } DVD_KEY_TYPE;
132
133 typedef struct _DVD_COPY_PROTECT_KEY
134 {
135     ULONG KeyLength;
136     DVD_SESSION_ID SessionId;
137     DVD_KEY_TYPE KeyType;
138     ULONG KeyFlags;
139     union
140     {
141         struct
142         {
143             ULONG FileHandle;
144             ULONG Reserved;   // used for NT alignment
145         };
146         LARGE_INTEGER TitleOffset;
147     } Parameters;
148     UCHAR KeyData[0];
149 } DVD_COPY_PROTECT_KEY, *PDVD_COPY_PROTECT_KEY;
150
151 typedef struct _DVD_ASF
152 {
153     UCHAR Reserved0[3];
154     UCHAR SuccessFlag:1;
155     UCHAR Reserved1:7;
156 } DVD_ASF, * PDVD_ASF;
157
158 typedef struct _SCSI_PASS_THROUGH_DIRECT
159 {
160     USHORT Length;
161     UCHAR ScsiStatus;
162     UCHAR PathId;
163     UCHAR TargetId;
164     UCHAR Lun;
165     UCHAR CdbLength;
166     UCHAR SenseInfoLength;
167     UCHAR DataIn;
168     ULONG DataTransferLength;
169     ULONG TimeOutValue;
170     PVOID DataBuffer;
171     ULONG SenseInfoOffset;
172     UCHAR Cdb[16];
173 } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
174
175 /*****************************************************************************
176  * win32 aspi specific
177  *****************************************************************************/
178
179 #define WIN2K               ( GetVersion() < 0x80000000 )
180 #define ASPI_HAID           0
181 #define ASPI_TARGET         0
182
183 #define SENSE_LEN           0x0E
184 #define SC_EXEC_SCSI_CMD    0x02
185 #define SC_GET_DISK_INFO    0x06
186 #define SS_COMP             0x01
187 #define SS_PENDING          0x00
188 #define SS_NO_ADAPTERS      0xE8
189 #define SRB_DIR_IN          0x08
190 #define SRB_DIR_OUT         0x10
191 #define SRB_EVENT_NOTIFY    0x40
192
193 struct w32_aspidev
194 {
195     long  hASPI;
196     short i_sid;
197     int   i_blocks;
198     long  (*lpSendCommand)( void* );
199 };
200
201 #pragma pack(1)
202
203 struct SRB_GetDiskInfo
204 {
205     unsigned char   SRB_Cmd;
206     unsigned char   SRB_Status;
207     unsigned char   SRB_HaId;
208     unsigned char   SRB_Flags;
209     unsigned long   SRB_Hdr_Rsvd;
210     unsigned char   SRB_Target;
211     unsigned char   SRB_Lun;
212     unsigned char   SRB_DriveFlags;
213     unsigned char   SRB_Int13HDriveInfo;
214     unsigned char   SRB_Heads;
215     unsigned char   SRB_Sectors;
216     unsigned char   SRB_Rsvd1[22];
217 };
218
219 struct SRB_ExecSCSICmd
220 {
221     unsigned char   SRB_Cmd;
222     unsigned char   SRB_Status;
223     unsigned char   SRB_HaId;
224     unsigned char   SRB_Flags;
225     unsigned long   SRB_Hdr_Rsvd;
226     unsigned char   SRB_Target;
227     unsigned char   SRB_Lun;
228     unsigned short  SRB_Rsvd1;
229     unsigned long   SRB_BufLen;
230     unsigned char   *SRB_BufPointer;
231     unsigned char   SRB_SenseLen;
232     unsigned char   SRB_CDBLen;
233     unsigned char   SRB_HaStat;
234     unsigned char   SRB_TargStat;
235     unsigned long   *SRB_PostProc;
236     unsigned char   SRB_Rsvd2[20];
237     unsigned char   CDBByte[16];
238     unsigned char   SenseArea[SENSE_LEN+2];
239 };
240
241 #pragma pack()
242
243 #endif
244