7027
|
1 /*****************************************************************************
|
|
2 * ioctl.h: DVD ioctl replacement function
|
|
3 *****************************************************************************
|
|
4 * Copyright (C) 1999-2001 VideoLAN
|
|
5 * $Id$
|
|
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_ReadDiscKey ( int, int *, u8 * );
|
|
26 int ioctl_ReadTitleKey ( int, int *, int, u8 * );
|
|
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 #define DVD_KEY_SIZE 5
|
|
36 #define DVD_CHALLENGE_SIZE 10
|
|
37 #define DVD_DISCKEY_SIZE 2048
|
|
38
|
|
39 /*****************************************************************************
|
|
40 * Common macro, BeOS specific
|
|
41 *****************************************************************************/
|
|
42 #if defined( SYS_BEOS )
|
|
43 #define INIT_RDC( TYPE, SIZE ) \
|
|
44 raw_device_command rdc; \
|
|
45 u8 p_buffer[ (SIZE) ]; \
|
|
46 memset( &rdc, 0, sizeof( raw_device_command ) ); \
|
|
47 rdc.data = (char *)p_buffer; \
|
|
48 rdc.data_length = (SIZE); \
|
|
49 BeInitRDC( &rdc, (TYPE) );
|
|
50 #endif
|
|
51
|
|
52 /*****************************************************************************
|
|
53 * Common macro, HP-UX specific
|
|
54 *****************************************************************************/
|
|
55 #if defined( HPUX_SCTL_IO )
|
|
56 #define INIT_SCTL_IO( TYPE, SIZE ) \
|
|
57 struct sctl_io sctl_io; \
|
|
58 u8 p_buffer[ (SIZE) ]; \
|
|
59 memset( &sctl_io, 0, sizeof( sctl_io ) ); \
|
|
60 sctl_io.data = (void *)p_buffer; \
|
|
61 sctl_io.data_length = (SIZE); \
|
|
62 HPUXInitSCTL( &sctl_io, (TYPE) );
|
|
63 #endif
|
|
64
|
|
65 /*****************************************************************************
|
|
66 * Common macro, Solaris specific
|
|
67 *****************************************************************************/
|
|
68 #if defined( SOLARIS_USCSI )
|
|
69 #define USCSI_TIMEOUT( SC, TO ) ( (SC)->uscsi_timeout = (TO) )
|
|
70 #define USCSI_RESID( SC ) ( (SC)->uscsi_resid )
|
|
71 #define INIT_USCSI( TYPE, SIZE ) \
|
|
72 struct uscsi_cmd sc; \
|
|
73 union scsi_cdb rs_cdb; \
|
|
74 u8 p_buffer[ (SIZE) ]; \
|
|
75 memset( &sc, 0, sizeof( struct uscsi_cmd ) ); \
|
|
76 sc.uscsi_cdb = (caddr_t)&rs_cdb; \
|
|
77 sc.uscsi_bufaddr = p_buffer; \
|
|
78 sc.uscsi_buflen = (SIZE); \
|
|
79 SolarisInitUSCSI( &sc, (TYPE) );
|
|
80 #endif
|
|
81
|
|
82 /*****************************************************************************
|
|
83 * Common macro, Darwin specific
|
|
84 *****************************************************************************/
|
|
85 #if defined( DARWIN_DVD_IOCTL )
|
|
86 #define INIT_DVDIOCTL( DKDVD_TYPE, BUFFER_TYPE, FORMAT ) \
|
|
87 DKDVD_TYPE dvd; \
|
|
88 BUFFER_TYPE dvdbs; \
|
|
89 memset( &dvd, 0, sizeof(dvd) ); \
|
|
90 memset( &dvdbs, 0, sizeof(dvdbs) ); \
|
|
91 dvd.format = FORMAT; \
|
|
92 dvd.buffer = &dvdbs; \
|
|
93 dvd.bufferLength = sizeof(dvdbs);
|
|
94 #endif
|
|
95
|
|
96 /*****************************************************************************
|
|
97 * Common macro, win32 (ASPI) specific
|
|
98 *****************************************************************************/
|
|
99 #if defined( WIN32 )
|
|
100 #define INIT_SSC( TYPE, SIZE ) \
|
|
101 struct SRB_ExecSCSICmd ssc; \
|
|
102 u8 p_buffer[ (SIZE) ]; \
|
|
103 memset( &ssc, 0, sizeof( struct SRB_ExecSCSICmd ) ); \
|
|
104 ssc.SRB_BufPointer = (char *)p_buffer; \
|
|
105 ssc.SRB_BufLen = (SIZE); \
|
|
106 WinInitSSC( &ssc, (TYPE) );
|
|
107 #endif
|
|
108
|
|
109 /*****************************************************************************
|
|
110 * Common macro, QNX specific
|
|
111 *****************************************************************************/
|
|
112 #if defined( __QNXNTO__ )
|
|
113 #define INIT_CPT( TYPE, SIZE ) \
|
|
114 CAM_PASS_THRU * p_cpt; \
|
|
115 uint8_t * p_buffer; \
|
|
116 int structSize = sizeof( CAM_PASS_THRU ) + (SIZE); \
|
|
117 p_cpt = (CAM_PASS_THRU *) malloc ( structSize ); \
|
|
118 p_buffer = (uint8_t *) p_cpt + sizeof( CAM_PASS_THRU ); \
|
|
119 memset( p_cpt, 0, structSize ); \
|
|
120 p_cpt->cam_data_ptr = sizeof( CAM_PASS_THRU ); \
|
|
121 p_cpt->cam_dxfer_len = (SIZE); \
|
|
122 QNXInitCPT( p_cpt, (TYPE) );
|
|
123 #endif
|
|
124
|
|
125 /*****************************************************************************
|
|
126 * Common macro, OS2 specific
|
|
127 *****************************************************************************/
|
|
128 #if defined( SYS_OS2 )
|
|
129 #define INIT_SSC( TYPE, SIZE ) \
|
|
130 struct OS2_ExecSCSICmd sdc; \
|
|
131 u8 p_buffer[ (SIZE) ]; \
|
|
132 unsigned long ulParamLen; \
|
|
133 unsigned long ulDataLen; \
|
|
134 memset( &sdc, 0, sizeof( OS2_ExecSCSICmd ) ); \
|
|
135 memset( &p_buffer, 0, SIZE ); \
|
|
136 sdc.data_length = (SIZE); \
|
|
137 ulParamLen = sizeof(sdc); \
|
|
138 OS2InitSDC( &sdc, (TYPE) )
|
|
139 #endif
|
|
140
|
|
141 /*****************************************************************************
|
|
142 * Additional types, OpenBSD specific
|
|
143 *****************************************************************************/
|
|
144 #if defined( HAVE_OPENBSD_DVD_STRUCT )
|
|
145 typedef union dvd_struct dvd_struct;
|
|
146 typedef union dvd_authinfo dvd_authinfo;
|
|
147 #endif
|
|
148
|
|
149 /*****************************************************************************
|
|
150 * Various DVD I/O tables
|
|
151 *****************************************************************************/
|
|
152 #if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO ) || defined ( __QNXNTO__ ) || defined ( SYS_OS2 )
|
|
153 /* The generic packet command opcodes for CD/DVD Logical Units,
|
|
154 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
|
|
155 # define GPCMD_READ_DVD_STRUCTURE 0xad
|
|
156 # define GPCMD_REPORT_KEY 0xa4
|
|
157 # define GPCMD_SEND_KEY 0xa3
|
|
158 /* DVD struct types */
|
|
159 # define DVD_STRUCT_PHYSICAL 0x00
|
|
160 # define DVD_STRUCT_COPYRIGHT 0x01
|
|
161 # define DVD_STRUCT_DISCKEY 0x02
|
|
162 # define DVD_STRUCT_BCA 0x03
|
|
163 # define DVD_STRUCT_MANUFACT 0x04
|
|
164 /* Key formats */
|
|
165 # define DVD_REPORT_AGID 0x00
|
|
166 # define DVD_REPORT_CHALLENGE 0x01
|
|
167 # define DVD_SEND_CHALLENGE 0x01
|
|
168 # define DVD_REPORT_KEY1 0x02
|
|
169 # define DVD_SEND_KEY2 0x03
|
|
170 # define DVD_REPORT_TITLE_KEY 0x04
|
|
171 # define DVD_REPORT_ASF 0x05
|
|
172 # define DVD_SEND_RPC 0x06
|
|
173 # define DVD_REPORT_RPC 0x08
|
|
174 # define DVD_INVALIDATE_AGID 0x3f
|
|
175 #endif
|
|
176
|
|
177 /*****************************************************************************
|
|
178 * win32 ioctl specific
|
|
179 *****************************************************************************/
|
|
180 #if defined( WIN32 )
|
|
181
|
|
182 #define WIN32_LEAN_AND_MEAN
|
|
183 #include <windows.h>
|
|
184
|
|
185 #define IOCTL_DVD_START_SESSION CTL_CODE(FILE_DEVICE_DVD, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
|
|
186 #define IOCTL_DVD_READ_KEY CTL_CODE(FILE_DEVICE_DVD, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
|
|
187 #define IOCTL_DVD_SEND_KEY CTL_CODE(FILE_DEVICE_DVD, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
|
|
188 #define IOCTL_DVD_END_SESSION CTL_CODE(FILE_DEVICE_DVD, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
|
|
189 #define IOCTL_DVD_GET_REGION CTL_CODE(FILE_DEVICE_DVD, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
|
|
190 #define IOCTL_DVD_SEND_KEY2 CTL_CODE(FILE_DEVICE_DVD, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
|
|
191
|
|
192 #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
|
|
193
|
|
194 #define DVD_CHALLENGE_KEY_LENGTH (12 + sizeof(DVD_COPY_PROTECT_KEY))
|
|
195 #define DVD_BUS_KEY_LENGTH (8 + sizeof(DVD_COPY_PROTECT_KEY))
|
|
196 #define DVD_TITLE_KEY_LENGTH (8 + sizeof(DVD_COPY_PROTECT_KEY))
|
|
197 #define DVD_DISK_KEY_LENGTH (2048 + sizeof(DVD_COPY_PROTECT_KEY))
|
|
198 #define DVD_ASF_LENGTH (sizeof(DVD_ASF) + sizeof(DVD_COPY_PROTECT_KEY))
|
|
199 #define DVD_REGION_LENGTH (sizeof(DVD_REGION))
|
|
200
|
|
201 #define SCSI_IOCTL_DATA_OUT 0
|
|
202 #define SCSI_IOCTL_DATA_IN 1
|
|
203
|
|
204 typedef ULONG DVD_SESSION_ID, *PDVD_SESSION_ID;
|
|
205
|
|
206 typedef enum
|
|
207 {
|
|
208 DvdChallengeKey = 0x01,
|
|
209 DvdBusKey1,
|
|
210 DvdBusKey2,
|
|
211 DvdTitleKey,
|
|
212 DvdAsf,
|
|
213 DvdSetRpcKey = 0x6,
|
|
214 DvdGetRpcKey = 0x8,
|
|
215 DvdDiskKey = 0x80,
|
|
216 DvdInvalidateAGID = 0x3f
|
|
217 } DVD_KEY_TYPE;
|
|
218
|
|
219 typedef struct _DVD_COPY_PROTECT_KEY
|
|
220 {
|
|
221 ULONG KeyLength;
|
|
222 DVD_SESSION_ID SessionId;
|
|
223 DVD_KEY_TYPE KeyType;
|
|
224 ULONG KeyFlags;
|
|
225 union
|
|
226 {
|
|
227 struct
|
|
228 {
|
|
229 ULONG FileHandle;
|
|
230 ULONG Reserved; // used for NT alignment
|
|
231 };
|
|
232 LARGE_INTEGER TitleOffset;
|
|
233 } Parameters;
|
|
234 UCHAR KeyData[0];
|
|
235 } DVD_COPY_PROTECT_KEY, *PDVD_COPY_PROTECT_KEY;
|
|
236
|
|
237 typedef struct _DVD_ASF
|
|
238 {
|
|
239 UCHAR Reserved0[3];
|
|
240 UCHAR SuccessFlag:1;
|
|
241 UCHAR Reserved1:7;
|
|
242 } DVD_ASF, * PDVD_ASF;
|
|
243
|
|
244 typedef struct _DVD_REGION {
|
|
245 UCHAR CopySystem;
|
|
246 UCHAR RegionData;
|
|
247 UCHAR SystemRegion;
|
|
248 UCHAR ResetCount;
|
|
249 } DVD_REGION, *PDVD_REGION;
|
|
250
|
|
251 typedef struct _SCSI_PASS_THROUGH_DIRECT
|
|
252 {
|
|
253 USHORT Length;
|
|
254 UCHAR ScsiStatus;
|
|
255 UCHAR PathId;
|
|
256 UCHAR TargetId;
|
|
257 UCHAR Lun;
|
|
258 UCHAR CdbLength;
|
|
259 UCHAR SenseInfoLength;
|
|
260 UCHAR DataIn;
|
|
261 ULONG DataTransferLength;
|
|
262 ULONG TimeOutValue;
|
|
263 PVOID DataBuffer;
|
|
264 ULONG SenseInfoOffset;
|
|
265 UCHAR Cdb[16];
|
|
266 } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
|
|
267
|
|
268 /*****************************************************************************
|
|
269 * win32 aspi specific
|
|
270 *****************************************************************************/
|
|
271
|
|
272 #define WIN2K ( GetVersion() < 0x80000000 )
|
|
273 #define ASPI_HAID 0
|
|
274 #define ASPI_TARGET 0
|
|
275
|
|
276 #define SENSE_LEN 0x0E
|
|
277 #define SC_EXEC_SCSI_CMD 0x02
|
|
278 #define SC_GET_DISK_INFO 0x06
|
|
279 #define SS_COMP 0x01
|
|
280 #define SS_PENDING 0x00
|
|
281 #define SS_NO_ADAPTERS 0xE8
|
|
282 #define SRB_DIR_IN 0x08
|
|
283 #define SRB_DIR_OUT 0x10
|
|
284 #define SRB_EVENT_NOTIFY 0x40
|
|
285
|
|
286 struct w32_aspidev
|
|
287 {
|
|
288 long hASPI;
|
|
289 short i_sid;
|
|
290 int i_blocks;
|
|
291 long (*lpSendCommand)( void* );
|
|
292 };
|
|
293
|
|
294 #pragma pack(1)
|
|
295
|
|
296 struct SRB_GetDiskInfo
|
|
297 {
|
|
298 unsigned char SRB_Cmd;
|
|
299 unsigned char SRB_Status;
|
|
300 unsigned char SRB_HaId;
|
|
301 unsigned char SRB_Flags;
|
|
302 unsigned long SRB_Hdr_Rsvd;
|
|
303 unsigned char SRB_Target;
|
|
304 unsigned char SRB_Lun;
|
|
305 unsigned char SRB_DriveFlags;
|
|
306 unsigned char SRB_Int13HDriveInfo;
|
|
307 unsigned char SRB_Heads;
|
|
308 unsigned char SRB_Sectors;
|
|
309 unsigned char SRB_Rsvd1[22];
|
|
310 };
|
|
311
|
|
312 struct SRB_ExecSCSICmd
|
|
313 {
|
|
314 unsigned char SRB_Cmd;
|
|
315 unsigned char SRB_Status;
|
|
316 unsigned char SRB_HaId;
|
|
317 unsigned char SRB_Flags;
|
|
318 unsigned long SRB_Hdr_Rsvd;
|
|
319 unsigned char SRB_Target;
|
|
320 unsigned char SRB_Lun;
|
|
321 unsigned short SRB_Rsvd1;
|
|
322 unsigned long SRB_BufLen;
|
|
323 unsigned char *SRB_BufPointer;
|
|
324 unsigned char SRB_SenseLen;
|
|
325 unsigned char SRB_CDBLen;
|
|
326 unsigned char SRB_HaStat;
|
|
327 unsigned char SRB_TargStat;
|
|
328 unsigned long *SRB_PostProc;
|
|
329 unsigned char SRB_Rsvd2[20];
|
|
330 unsigned char CDBByte[16];
|
|
331 unsigned char SenseArea[SENSE_LEN+2];
|
|
332 };
|
|
333
|
|
334 #pragma pack()
|
|
335
|
|
336 #endif
|
|
337
|
|
338 /*****************************************************************************
|
|
339 * OS2 ioctl specific
|
|
340 *****************************************************************************/
|
|
341 #if defined( SYS_OS2 )
|
|
342
|
|
343 #define CDROMDISK_EXECMD 0x7A
|
|
344
|
|
345 #define EX_DIRECTION_IN 0x01
|
|
346 #define EX_PLAYING_CHK 0x02
|
|
347
|
|
348 #pragma pack(1)
|
|
349
|
|
350 struct OS2_ExecSCSICmd
|
|
351 {
|
|
352 unsigned long id_code; // 'CD01'
|
|
353 unsigned short data_length; // length of the Data Packet
|
|
354 unsigned short cmd_length; // length of the Command Buffer
|
|
355 unsigned short flags; // flags
|
|
356 unsigned char command[16]; // Command Buffer for SCSI command
|
|
357
|
|
358 } OS2_ExecSCSICmd;
|
|
359
|
|
360 #pragma pack()
|
|
361
|
|
362 #endif
|