]> git.sesse.net Git - vlc/blob - extras/libdvdcss/ioctl.h
* Added vlc-arts to the debian package generation.
[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.10 2001/12/11 14:43:38 sam 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_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 /*****************************************************************************
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, HP-UX specific
50  *****************************************************************************/
51 #if defined( HPUX_SCTL_IO )
52 #define INIT_SCTL_IO( TYPE, SIZE ) \
53     struct sctl_io sctl_io; \
54     u8 p_buffer[ (SIZE) ]; \
55     memset( &sctl_io, 0, sizeof( sctl_io ) ); \
56     sctl_io.data = (void *)p_buffer; \
57     sctl_io.data_length = (SIZE); \
58     HPUXInitSCTL( &sctl_io, (TYPE) );
59 #endif
60
61 /*****************************************************************************
62  * Common macro, Solaris specific
63  *****************************************************************************/
64 #if defined( SOLARIS_USCSI )
65 #define USCSI_TIMEOUT( SC, TO ) ( (SC)->uscsi_timeout = (TO) )
66 #define USCSI_RESID( SC )       ( (SC)->uscsi_resid )
67 #define INIT_USCSI( TYPE, SIZE ) \
68     struct uscsi_cmd sc; \
69     union scsi_cdb rs_cdb; \
70     u8 p_buffer[ (SIZE) ]; \
71     memset( &sc, 0, sizeof( struct uscsi_cmd ) ); \
72     sc.uscsi_cdb = (caddr_t)&rs_cdb; \
73     sc.uscsi_bufaddr = p_buffer; \
74     sc.uscsi_buflen = (SIZE); \
75     SolarisInitUSCSI( &sc, (TYPE) );
76 #endif
77
78 /*****************************************************************************
79  * Common macro, Darwin specific
80  *****************************************************************************/
81 #if defined( SYS_DARWIN )
82 #define INIT_DVDIOCTL( SIZE ) \
83     dvdioctl_data_t dvdioctl; \
84     u8 p_buffer[ (SIZE) ]; \
85     dvdioctl.p_buffer = p_buffer; \
86     dvdioctl.i_size = (SIZE); \
87     dvdioctl.i_keyclass = kCSS_CSS2_CPRM; \
88     memset( p_buffer, 0, (SIZE) );
89 #endif
90
91 /*****************************************************************************
92  * Common macro, win32 (ASPI) specific
93  *****************************************************************************/
94 #if defined( WIN32 )
95 #define INIT_SSC( TYPE, SIZE ) \
96     struct SRB_ExecSCSICmd ssc; \
97     u8 p_buffer[ (SIZE) ]; \
98     memset( &ssc, 0, sizeof( struct SRB_ExecSCSICmd ) ); \
99     ssc.SRB_BufPointer = (char *)p_buffer; \
100     ssc.SRB_BufLen = (SIZE); \
101     WinInitSSC( &ssc, (TYPE) );
102 #endif
103
104 /*****************************************************************************
105  * Various DVD I/O tables
106  *****************************************************************************/
107
108 #if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO )
109     /* The generic packet command opcodes for CD/DVD Logical Units,
110      * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
111 #   define GPCMD_READ_DVD_STRUCTURE 0xad
112 #   define GPCMD_REPORT_KEY         0xa4
113 #   define GPCMD_SEND_KEY           0xa3
114     /* DVD struct types */
115 #   define DVD_STRUCT_PHYSICAL      0x00
116 #   define DVD_STRUCT_COPYRIGHT     0x01
117 #   define DVD_STRUCT_DISCKEY       0x02
118 #   define DVD_STRUCT_BCA           0x03
119 #   define DVD_STRUCT_MANUFACT      0x04
120     /* Key formats */
121 #   define DVD_REPORT_AGID          0x00
122 #   define DVD_REPORT_CHALLENGE     0x01
123 #   define DVD_SEND_CHALLENGE       0x01
124 #   define DVD_REPORT_KEY1          0x02
125 #   define DVD_SEND_KEY2            0x03
126 #   define DVD_REPORT_ASF           0x05
127 #   define DVD_INVALIDATE_AGID      0x3f
128 #endif
129
130 #if defined( HAVE_OPENBSD_DVD_STRUCT )
131
132 /*****************************************************************************
133  * OpenBSD ioctl specific
134  *****************************************************************************/
135 typedef union dvd_struct dvd_struct;
136 typedef union dvd_authinfo dvd_authinfo;
137 typedef u_int8_t dvd_key[5];
138 typedef u_int8_t dvd_challenge[10];
139 #endif
140
141
142 #if defined( WIN32 )
143
144 #define WIN32_LEAN_AND_MEAN
145 #include <windows.h>
146
147 /*****************************************************************************
148  * win32 ioctl specific
149  *****************************************************************************/
150
151 #define IOCTL_DVD_START_SESSION         CTL_CODE(FILE_DEVICE_DVD, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
152 #define IOCTL_DVD_READ_KEY              CTL_CODE(FILE_DEVICE_DVD, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
153 #define IOCTL_DVD_SEND_KEY              CTL_CODE(FILE_DEVICE_DVD, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
154 #define IOCTL_DVD_END_SESSION           CTL_CODE(FILE_DEVICE_DVD, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
155
156 #define IOCTL_SCSI_PASS_THROUGH_DIRECT  CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
157
158 #define DVD_CHALLENGE_KEY_LENGTH        (12 + sizeof(DVD_COPY_PROTECT_KEY))
159 #define DVD_BUS_KEY_LENGTH              (8 + sizeof(DVD_COPY_PROTECT_KEY))
160 #define DVD_DISK_KEY_LENGTH             (2048 + sizeof(DVD_COPY_PROTECT_KEY))
161 #define DVD_ASF_LENGTH                  (sizeof(DVD_ASF) + sizeof(DVD_COPY_PROTECT_KEY))
162
163 #define SCSI_IOCTL_DATA_OUT             0
164 #define SCSI_IOCTL_DATA_IN              1
165
166 typedef ULONG DVD_SESSION_ID, *PDVD_SESSION_ID;
167
168 typedef enum
169 {
170     DvdChallengeKey = 0x01,
171     DvdBusKey1,
172     DvdBusKey2,
173     DvdTitleKey,
174     DvdAsf,
175     DvdSetRpcKey = 0x6,
176     DvdGetRpcKey = 0x8,
177     DvdDiskKey = 0x80,
178     DvdInvalidateAGID = 0x3f
179 } DVD_KEY_TYPE;
180
181 typedef struct _DVD_COPY_PROTECT_KEY
182 {
183     ULONG KeyLength;
184     DVD_SESSION_ID SessionId;
185     DVD_KEY_TYPE KeyType;
186     ULONG KeyFlags;
187     union
188     {
189         struct
190         {
191             ULONG FileHandle;
192             ULONG Reserved;   // used for NT alignment
193         };
194         LARGE_INTEGER TitleOffset;
195     } Parameters;
196     UCHAR KeyData[0];
197 } DVD_COPY_PROTECT_KEY, *PDVD_COPY_PROTECT_KEY;
198
199 typedef struct _DVD_ASF
200 {
201     UCHAR Reserved0[3];
202     UCHAR SuccessFlag:1;
203     UCHAR Reserved1:7;
204 } DVD_ASF, * PDVD_ASF;
205
206 typedef struct _SCSI_PASS_THROUGH_DIRECT
207 {
208     USHORT Length;
209     UCHAR ScsiStatus;
210     UCHAR PathId;
211     UCHAR TargetId;
212     UCHAR Lun;
213     UCHAR CdbLength;
214     UCHAR SenseInfoLength;
215     UCHAR DataIn;
216     ULONG DataTransferLength;
217     ULONG TimeOutValue;
218     PVOID DataBuffer;
219     ULONG SenseInfoOffset;
220     UCHAR Cdb[16];
221 } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
222
223 /*****************************************************************************
224  * win32 aspi specific
225  *****************************************************************************/
226
227 #define WIN2K               ( GetVersion() < 0x80000000 )
228 #define ASPI_HAID           0
229 #define ASPI_TARGET         0
230
231 #define SENSE_LEN           0x0E
232 #define SC_EXEC_SCSI_CMD    0x02
233 #define SC_GET_DISK_INFO    0x06
234 #define SS_COMP             0x01
235 #define SS_PENDING          0x00
236 #define SS_NO_ADAPTERS      0xE8
237 #define SRB_DIR_IN          0x08
238 #define SRB_DIR_OUT         0x10
239 #define SRB_EVENT_NOTIFY    0x40
240
241 struct w32_aspidev
242 {
243     long  hASPI;
244     short i_sid;
245     int   i_blocks;
246     long  (*lpSendCommand)( void* );
247 };
248
249 #pragma pack(1)
250
251 struct SRB_GetDiskInfo
252 {
253     unsigned char   SRB_Cmd;
254     unsigned char   SRB_Status;
255     unsigned char   SRB_HaId;
256     unsigned char   SRB_Flags;
257     unsigned long   SRB_Hdr_Rsvd;
258     unsigned char   SRB_Target;
259     unsigned char   SRB_Lun;
260     unsigned char   SRB_DriveFlags;
261     unsigned char   SRB_Int13HDriveInfo;
262     unsigned char   SRB_Heads;
263     unsigned char   SRB_Sectors;
264     unsigned char   SRB_Rsvd1[22];
265 };
266
267 struct SRB_ExecSCSICmd
268 {
269     unsigned char   SRB_Cmd;
270     unsigned char   SRB_Status;
271     unsigned char   SRB_HaId;
272     unsigned char   SRB_Flags;
273     unsigned long   SRB_Hdr_Rsvd;
274     unsigned char   SRB_Target;
275     unsigned char   SRB_Lun;
276     unsigned short  SRB_Rsvd1;
277     unsigned long   SRB_BufLen;
278     unsigned char   *SRB_BufPointer;
279     unsigned char   SRB_SenseLen;
280     unsigned char   SRB_CDBLen;
281     unsigned char   SRB_HaStat;
282     unsigned char   SRB_TargStat;
283     unsigned long   *SRB_PostProc;
284     unsigned char   SRB_Rsvd2[20];
285     unsigned char   CDBByte[16];
286     unsigned char   SenseArea[SENSE_LEN+2];
287 };
288
289 #pragma pack()
290
291 #endif
292