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