ad_speex: improve timestamp handling
[mplayer.git] / libdvdcss / ioctl.h
blobebc972eb7c92d8cac2e8d1ac86ab32e7c035f768
1 /*****************************************************************************
2 * ioctl.h: DVD ioctl replacement function
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id$
7 * Authors: Sam Hocevar <sam@zoy.org>
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.
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.
19 * You should have received a copy of the GNU General Public License along
20 * with libdvdcss; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *****************************************************************************/
24 #ifndef DVDCSS_IOCTL_H
25 #define DVDCSS_IOCTL_H
27 int ioctl_ReadCopyright ( int, int, int * );
28 int ioctl_ReadDiscKey ( int, int *, uint8_t * );
29 int ioctl_ReadTitleKey ( int, int *, int, uint8_t * );
30 int ioctl_ReportAgid ( int, int * );
31 int ioctl_ReportChallenge ( int, int *, uint8_t * );
32 int ioctl_ReportKey1 ( int, int *, uint8_t * );
33 int ioctl_ReportASF ( int, int *, int * );
34 int ioctl_InvalidateAgid ( int, int * );
35 int ioctl_SendChallenge ( int, int *, uint8_t * );
36 int ioctl_SendKey2 ( int, int *, uint8_t * );
37 int ioctl_ReportRPC ( int, int *, int *, int * );
38 int ioctl_SendRPC ( int, int );
40 #define DVD_KEY_SIZE 5
41 #define DVD_CHALLENGE_SIZE 10
42 #define DVD_DISCKEY_SIZE 2048
44 /*****************************************************************************
45 * Common macro, BeOS specific
46 *****************************************************************************/
47 #if defined( SYS_BEOS )
48 #define INIT_RDC( TYPE, SIZE ) \
49 raw_device_command rdc; \
50 uint8_t p_buffer[ (SIZE)+1 ]; \
51 memset( &rdc, 0, sizeof( raw_device_command ) ); \
52 rdc.data = (char *)p_buffer; \
53 rdc.data_length = (SIZE); \
54 BeInitRDC( &rdc, (TYPE) );
55 #endif
57 /*****************************************************************************
58 * Common macro, HP-UX specific
59 *****************************************************************************/
60 #if defined( HPUX_SCTL_IO )
61 #define INIT_SCTL_IO( TYPE, SIZE ) \
62 struct sctl_io sctl_io; \
63 uint8_t p_buffer[ (SIZE)+1 ]; \
64 memset( &sctl_io, 0, sizeof( sctl_io ) ); \
65 sctl_io.data = (void *)p_buffer; \
66 sctl_io.data_length = (SIZE); \
67 HPUXInitSCTL( &sctl_io, (TYPE) );
68 #endif
70 /*****************************************************************************
71 * Common macro, Solaris specific
72 *****************************************************************************/
73 #if defined( SOLARIS_USCSI )
74 #define USCSI_TIMEOUT( SC, TO ) ( (SC)->uscsi_timeout = (TO) )
75 #define USCSI_RESID( SC ) ( (SC)->uscsi_resid )
76 #define INIT_USCSI( TYPE, SIZE ) \
77 struct uscsi_cmd sc; \
78 union scsi_cdb rs_cdb; \
79 uint8_t p_buffer[ (SIZE)+1 ]; \
80 memset( &sc, 0, sizeof( struct uscsi_cmd ) ); \
81 sc.uscsi_cdb = (caddr_t)&rs_cdb; \
82 sc.uscsi_bufaddr = (caddr_t)p_buffer; \
83 sc.uscsi_buflen = (SIZE); \
84 SolarisInitUSCSI( &sc, (TYPE) );
85 #endif
87 /*****************************************************************************
88 * Common macro, Darwin specific
89 *****************************************************************************/
90 #if defined( DARWIN_DVD_IOCTL )
91 #define INIT_DVDIOCTL( DKDVD_TYPE, BUFFER_TYPE, FORMAT ) \
92 DKDVD_TYPE dvd; \
93 BUFFER_TYPE dvdbs; \
94 memset( &dvd, 0, sizeof(dvd) ); \
95 memset( &dvdbs, 0, sizeof(dvdbs) ); \
96 dvd.format = FORMAT; \
97 dvd.buffer = &dvdbs; \
98 dvd.bufferLength = sizeof(dvdbs);
99 #endif
101 /*****************************************************************************
102 * Common macro, win32 specific
103 *****************************************************************************/
104 #if defined( WIN32 )
105 #define INIT_SPTD( TYPE, SIZE ) \
106 DWORD tmp; \
107 SCSI_PASS_THROUGH_DIRECT sptd; \
108 uint8_t p_buffer[ (SIZE) ]; \
109 memset( &sptd, 0, sizeof( SCSI_PASS_THROUGH_DIRECT ) ); \
110 sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT ); \
111 sptd.DataBuffer = p_buffer; \
112 sptd.DataTransferLength = (SIZE); \
113 WinInitSPTD( &sptd, (TYPE) );
114 #define SEND_SPTD( DEV, SPTD, TMP ) \
115 (DeviceIoControl( (HANDLE)(DEV), IOCTL_SCSI_PASS_THROUGH_DIRECT, \
116 (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
117 (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
118 (TMP), NULL ) ? 0 : -1)
119 #define INIT_SSC( TYPE, SIZE ) \
120 struct SRB_ExecSCSICmd ssc; \
121 uint8_t p_buffer[ (SIZE)+1 ]; \
122 memset( &ssc, 0, sizeof( struct SRB_ExecSCSICmd ) ); \
123 ssc.SRB_BufPointer = (char *)p_buffer; \
124 ssc.SRB_BufLen = (SIZE); \
125 WinInitSSC( &ssc, (TYPE) );
126 #endif
128 /*****************************************************************************
129 * Common macro, QNX specific
130 *****************************************************************************/
131 #if defined( __QNXNTO__ )
132 #define INIT_CPT( TYPE, SIZE ) \
133 CAM_PASS_THRU * p_cpt; \
134 uint8_t * p_buffer; \
135 int structSize = sizeof( CAM_PASS_THRU ) + (SIZE); \
136 p_cpt = (CAM_PASS_THRU *) malloc ( structSize ); \
137 p_buffer = (uint8_t *) p_cpt + sizeof( CAM_PASS_THRU ); \
138 memset( p_cpt, 0, structSize ); \
139 p_cpt->cam_data_ptr = sizeof( CAM_PASS_THRU ); \
140 p_cpt->cam_dxfer_len = (SIZE); \
141 QNXInitCPT( p_cpt, (TYPE) );
142 #endif
144 /*****************************************************************************
145 * Common macro, OS2 specific
146 *****************************************************************************/
147 #if defined( SYS_OS2 )
148 #define INIT_SSC( TYPE, SIZE ) \
149 struct OS2_ExecSCSICmd sdc; \
150 uint8_t p_buffer[ (SIZE)+1 ]; \
151 unsigned long ulParamLen; \
152 unsigned long ulDataLen; \
153 memset( &sdc, 0, sizeof( OS2_ExecSCSICmd ) ); \
154 memset( &p_buffer, 0, SIZE ); \
155 sdc.data_length = (SIZE); \
156 ulParamLen = sizeof(sdc); \
157 OS2InitSDC( &sdc, (TYPE) )
158 #endif
160 /*****************************************************************************
161 * Additional types, OpenBSD specific
162 *****************************************************************************/
163 #if defined( HAVE_OPENBSD_DVD_STRUCT )
164 typedef union dvd_struct dvd_struct;
165 typedef union dvd_authinfo dvd_authinfo;
166 #endif
168 /*****************************************************************************
169 * Various DVD I/O tables
170 *****************************************************************************/
171 #if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO ) || defined ( __QNXNTO__ ) || defined ( SYS_OS2 )
172 /* The generic packet command opcodes for CD/DVD Logical Units,
173 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
174 # define GPCMD_READ_DVD_STRUCTURE 0xad
175 # define GPCMD_REPORT_KEY 0xa4
176 # define GPCMD_SEND_KEY 0xa3
177 /* DVD struct types */
178 # define DVD_STRUCT_PHYSICAL 0x00
179 # define DVD_STRUCT_COPYRIGHT 0x01
180 # define DVD_STRUCT_DISCKEY 0x02
181 # define DVD_STRUCT_BCA 0x03
182 # define DVD_STRUCT_MANUFACT 0x04
183 /* Key formats */
184 # define DVD_REPORT_AGID 0x00
185 # define DVD_REPORT_CHALLENGE 0x01
186 # define DVD_SEND_CHALLENGE 0x01
187 # define DVD_REPORT_KEY1 0x02
188 # define DVD_SEND_KEY2 0x03
189 # define DVD_REPORT_TITLE_KEY 0x04
190 # define DVD_REPORT_ASF 0x05
191 # define DVD_SEND_RPC 0x06
192 # define DVD_REPORT_RPC 0x08
193 # define DVD_INVALIDATE_AGID 0x3f
194 #endif
196 /*****************************************************************************
197 * win32 ioctl specific
198 *****************************************************************************/
199 #if defined( WIN32 )
201 #define WIN32_LEAN_AND_MEAN
202 #include <windows.h>
204 #define IOCTL_DVD_START_SESSION CTL_CODE(FILE_DEVICE_DVD, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
205 #define IOCTL_DVD_READ_KEY CTL_CODE(FILE_DEVICE_DVD, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
206 #define IOCTL_DVD_SEND_KEY CTL_CODE(FILE_DEVICE_DVD, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
207 #define IOCTL_DVD_END_SESSION CTL_CODE(FILE_DEVICE_DVD, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
208 #define IOCTL_DVD_GET_REGION CTL_CODE(FILE_DEVICE_DVD, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
209 #define IOCTL_DVD_SEND_KEY2 CTL_CODE(FILE_DEVICE_DVD, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
210 #define IOCTL_DVD_READ_STRUCTURE CTL_CODE(FILE_DEVICE_DVD, 0x0450, METHOD_BUFFERED, FILE_READ_ACCESS)
211 #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
213 #define DVD_CHALLENGE_KEY_LENGTH (12 + sizeof(DVD_COPY_PROTECT_KEY))
214 #define DVD_BUS_KEY_LENGTH (8 + sizeof(DVD_COPY_PROTECT_KEY))
215 #define DVD_TITLE_KEY_LENGTH (8 + sizeof(DVD_COPY_PROTECT_KEY))
216 #define DVD_DISK_KEY_LENGTH (2048 + sizeof(DVD_COPY_PROTECT_KEY))
217 #define DVD_RPC_KEY_LENGTH (sizeof(DVD_RPC_KEY) + sizeof(DVD_COPY_PROTECT_KEY))
218 #define DVD_ASF_LENGTH (sizeof(DVD_ASF) + sizeof(DVD_COPY_PROTECT_KEY))
220 #define DVD_COPYRIGHT_MASK 0x00000040
221 #define DVD_NOT_COPYRIGHTED 0x00000000
222 #define DVD_COPYRIGHTED 0x00000040
224 #define DVD_SECTOR_PROTECT_MASK 0x00000020
225 #define DVD_SECTOR_NOT_PROTECTED 0x00000000
226 #define DVD_SECTOR_PROTECTED 0x00000020
228 #define SCSI_IOCTL_DATA_OUT 0
229 #define SCSI_IOCTL_DATA_IN 1
231 typedef ULONG DVD_SESSION_ID, *PDVD_SESSION_ID;
233 typedef enum DVD_STRUCTURE_FORMAT {
234 DvdPhysicalDescriptor,
235 DvdCopyrightDescriptor,
236 DvdDiskKeyDescriptor,
237 DvdBCADescriptor,
238 DvdManufacturerDescriptor,
239 DvdMaxDescriptor
240 } DVD_STRUCTURE_FORMAT, *PDVD_STRUCTURE_FORMAT;
242 typedef struct DVD_READ_STRUCTURE {
243 LARGE_INTEGER BlockByteOffset;
244 DVD_STRUCTURE_FORMAT Format;
245 DVD_SESSION_ID SessionId;
246 UCHAR LayerNumber;
247 } DVD_READ_STRUCTURE, *PDVD_READ_STRUCTURE;
249 typedef struct DVD_COPYRIGHT_DESCRIPTOR {
250 UCHAR CopyrightProtectionType;
251 UCHAR RegionManagementInformation;
252 USHORT Reserved;
253 } DVD_COPYRIGHT_DESCRIPTOR, *PDVD_COPYRIGHT_DESCRIPTOR;
255 typedef enum
257 DvdChallengeKey = 0x01,
258 DvdBusKey1,
259 DvdBusKey2,
260 DvdTitleKey,
261 DvdAsf,
262 DvdSetRpcKey = 0x6,
263 DvdGetRpcKey = 0x8,
264 DvdDiskKey = 0x80,
265 DvdInvalidateAGID = 0x3f
266 } DVD_KEY_TYPE;
268 typedef struct DVD_COPY_PROTECT_KEY
270 ULONG KeyLength;
271 DVD_SESSION_ID SessionId;
272 DVD_KEY_TYPE KeyType;
273 ULONG KeyFlags;
274 union
276 struct
278 ULONG FileHandle;
279 ULONG Reserved; // used for NT alignment
281 LARGE_INTEGER TitleOffset;
282 } Parameters;
283 UCHAR KeyData[0];
284 } DVD_COPY_PROTECT_KEY, *PDVD_COPY_PROTECT_KEY;
286 typedef struct DVD_ASF
288 UCHAR Reserved0[3];
289 UCHAR SuccessFlag:1;
290 UCHAR Reserved1:7;
291 } DVD_ASF, * PDVD_ASF;
293 typedef struct DVD_RPC_KEY
295 UCHAR UserResetsAvailable:3;
296 UCHAR ManufacturerResetsAvailable:3;
297 UCHAR TypeCode:2;
298 UCHAR RegionMask;
299 UCHAR RpcScheme;
300 UCHAR Reserved2[1];
301 } DVD_RPC_KEY, * PDVD_RPC_KEY;
303 typedef struct SCSI_PASS_THROUGH_DIRECT
305 USHORT Length;
306 UCHAR ScsiStatus;
307 UCHAR PathId;
308 UCHAR TargetId;
309 UCHAR Lun;
310 UCHAR CdbLength;
311 UCHAR SenseInfoLength;
312 UCHAR DataIn;
313 ULONG DataTransferLength;
314 ULONG TimeOutValue;
315 PVOID DataBuffer;
316 ULONG SenseInfoOffset;
317 UCHAR Cdb[16];
318 } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
320 /*****************************************************************************
321 * win32 aspi specific
322 *****************************************************************************/
324 typedef DWORD (CALLBACK *GETASPI32SUPPORTINFO)(VOID);
325 typedef DWORD (CALLBACK *SENDASPI32COMMAND)(LPVOID);
327 #define WIN2K ( GetVersion() < 0x80000000 )
328 #define ASPI_HAID 0
329 #define ASPI_TARGET 0
330 #define DTYPE_CDROM 0x05
332 #define SENSE_LEN 0x0E
333 #define SC_GET_DEV_TYPE 0x01
334 #define SC_EXEC_SCSI_CMD 0x02
335 #define SC_GET_DISK_INFO 0x06
336 #define SS_COMP 0x01
337 #define SS_PENDING 0x00
338 #define SS_NO_ADAPTERS 0xE8
339 #define SRB_DIR_IN 0x08
340 #define SRB_DIR_OUT 0x10
341 #define SRB_EVENT_NOTIFY 0x40
343 struct w32_aspidev
345 long hASPI;
346 short i_sid;
347 int i_blocks;
348 SENDASPI32COMMAND lpSendCommand;
351 #pragma pack(1)
353 struct SRB_GetDiskInfo
355 unsigned char SRB_Cmd;
356 unsigned char SRB_Status;
357 unsigned char SRB_HaId;
358 unsigned char SRB_Flags;
359 unsigned long SRB_Hdr_Rsvd;
360 unsigned char SRB_Target;
361 unsigned char SRB_Lun;
362 unsigned char SRB_DriveFlags;
363 unsigned char SRB_Int13HDriveInfo;
364 unsigned char SRB_Heads;
365 unsigned char SRB_Sectors;
366 unsigned char SRB_Rsvd1[22];
369 struct SRB_GDEVBlock
371 unsigned char SRB_Cmd;
372 unsigned char SRB_Status;
373 unsigned char SRB_HaId;
374 unsigned char SRB_Flags;
375 unsigned long SRB_Hdr_Rsvd;
376 unsigned char SRB_Target;
377 unsigned char SRB_Lun;
378 unsigned char SRB_DeviceType;
379 unsigned char SRB_Rsvd1;
382 struct SRB_ExecSCSICmd
384 unsigned char SRB_Cmd;
385 unsigned char SRB_Status;
386 unsigned char SRB_HaId;
387 unsigned char SRB_Flags;
388 unsigned long SRB_Hdr_Rsvd;
389 unsigned char SRB_Target;
390 unsigned char SRB_Lun;
391 unsigned short SRB_Rsvd1;
392 unsigned long SRB_BufLen;
393 unsigned char *SRB_BufPointer;
394 unsigned char SRB_SenseLen;
395 unsigned char SRB_CDBLen;
396 unsigned char SRB_HaStat;
397 unsigned char SRB_TargStat;
398 unsigned long *SRB_PostProc;
399 unsigned char SRB_Rsvd2[20];
400 unsigned char CDBByte[16];
401 unsigned char SenseArea[SENSE_LEN+2];
404 #pragma pack()
406 #endif
408 /*****************************************************************************
409 * OS2 ioctl specific
410 *****************************************************************************/
411 #if defined( SYS_OS2 )
413 #define CDROMDISK_EXECMD 0x7A
415 #define EX_DIRECTION_IN 0x01
416 #define EX_PLAYING_CHK 0x02
418 #pragma pack(1)
420 struct OS2_ExecSCSICmd
422 unsigned long id_code; // 'CD01'
423 unsigned short data_length; // length of the Data Packet
424 unsigned short cmd_length; // length of the Command Buffer
425 unsigned short flags; // flags
426 unsigned char command[16]; // Command Buffer for SCSI command
428 } OS2_ExecSCSICmd;
430 #pragma pack()
432 #endif
434 #endif /* DVDCSS_IOCTL_H */