aboutsummaryrefslogtreecommitdiffhomepage
path: root/libmpdvdkit2/ioctl.h
blob: 519dfeb04a77cd00f7e20fedfac0f90a19366306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*****************************************************************************
 * ioctl.h: DVD ioctl replacement function
 *****************************************************************************
 * Copyright (C) 1999-2001 VideoLAN
 * $Id$
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

int ioctl_ReadCopyright     ( int, int, int * );
int ioctl_ReadDiscKey       ( int, int *, u8 * );
int ioctl_ReadTitleKey      ( int, int *, int, u8 * );
int ioctl_ReportAgid        ( int, int * );
int ioctl_ReportChallenge   ( int, int *, u8 * );
int ioctl_ReportKey1        ( int, int *, u8 * );
int ioctl_ReportASF         ( int, int *, int * );
int ioctl_InvalidateAgid    ( int, int * );
int ioctl_SendChallenge     ( int, int *, u8 * );
int ioctl_SendKey2          ( int, int *, u8 * );

#define DVD_KEY_SIZE 5
#define DVD_CHALLENGE_SIZE 10
#define DVD_DISCKEY_SIZE 2048

/*****************************************************************************
 * Common macro, BeOS specific
 *****************************************************************************/
#if defined( SYS_BEOS )
#define INIT_RDC( TYPE, SIZE ) \
    raw_device_command rdc; \
    u8 p_buffer[ (SIZE) ]; \
    memset( &rdc, 0, sizeof( raw_device_command ) ); \
    rdc.data = (char *)p_buffer; \
    rdc.data_length = (SIZE); \
    BeInitRDC( &rdc, (TYPE) );
#endif

/*****************************************************************************
 * Common macro, HP-UX specific
 *****************************************************************************/
#if defined( HPUX_SCTL_IO )
#define INIT_SCTL_IO( TYPE, SIZE ) \
    struct sctl_io sctl_io; \
    u8 p_buffer[ (SIZE) ]; \
    memset( &sctl_io, 0, sizeof( sctl_io ) ); \
    sctl_io.data = (void *)p_buffer; \
    sctl_io.data_length = (SIZE); \
    HPUXInitSCTL( &sctl_io, (TYPE) );
#endif

/*****************************************************************************
 * Common macro, Solaris specific
 *****************************************************************************/
#if defined( SOLARIS_USCSI )
#define USCSI_TIMEOUT( SC, TO ) ( (SC)->uscsi_timeout = (TO) )
#define USCSI_RESID( SC )       ( (SC)->uscsi_resid )
#define INIT_USCSI( TYPE, SIZE ) \
    struct uscsi_cmd sc; \
    union scsi_cdb rs_cdb; \
    u8 p_buffer[ (SIZE) ]; \
    memset( &sc, 0, sizeof( struct uscsi_cmd ) ); \
    sc.uscsi_cdb = (caddr_t)&rs_cdb; \
    sc.uscsi_bufaddr = p_buffer; \
    sc.uscsi_buflen = (SIZE); \
    SolarisInitUSCSI( &sc, (TYPE) );
#endif

/*****************************************************************************
 * Common macro, Darwin specific
 *****************************************************************************/
#if defined( DARWIN_DVD_IOCTL )
#define INIT_DVDIOCTL( DKDVD_TYPE, BUFFER_TYPE, FORMAT ) \
    DKDVD_TYPE dvd; \
    BUFFER_TYPE dvdbs; \
    memset( &dvd, 0, sizeof(dvd) ); \
    memset( &dvdbs, 0, sizeof(dvdbs) ); \
    dvd.format = FORMAT; \
    dvd.buffer = &dvdbs; \
    dvd.bufferLength = sizeof(dvdbs);
#endif

/*****************************************************************************
 * Common macro, win32 (ASPI) specific
 *****************************************************************************/
#if defined( WIN32 )
#define INIT_SSC( TYPE, SIZE ) \
    struct SRB_ExecSCSICmd ssc; \
    u8 p_buffer[ (SIZE) ]; \
    memset( &ssc, 0, sizeof( struct SRB_ExecSCSICmd ) ); \
    ssc.SRB_BufPointer = (char *)p_buffer; \
    ssc.SRB_BufLen = (SIZE); \
    WinInitSSC( &ssc, (TYPE) );
#endif

/*****************************************************************************
 * Common macro, QNX specific
 *****************************************************************************/
#if defined( __QNXNTO__ )
#define INIT_CPT( TYPE, SIZE ) \
    CAM_PASS_THRU * p_cpt; \
    uint8_t * p_buffer; \
    int structSize = sizeof( CAM_PASS_THRU ) + (SIZE); \
    p_cpt = (CAM_PASS_THRU *) malloc ( structSize ); \
    p_buffer = (uint8_t *) p_cpt + sizeof( CAM_PASS_THRU ); \
    memset( p_cpt, 0, structSize ); \
      p_cpt->cam_data_ptr = sizeof( CAM_PASS_THRU ); \
      p_cpt->cam_dxfer_len = (SIZE); \
    QNXInitCPT( p_cpt, (TYPE) );
#endif

/*****************************************************************************
 * Common macro, OS2 specific
 *****************************************************************************/
#if defined( SYS_OS2 )
#define INIT_SSC( TYPE, SIZE ) \
    struct OS2_ExecSCSICmd sdc; \
    u8 p_buffer[ (SIZE) ]; \
    unsigned long ulParamLen; \
    unsigned long ulDataLen; \
    memset( &sdc, 0, sizeof( OS2_ExecSCSICmd ) ); \
    memset( &p_buffer, 0, SIZE ); \
    sdc.data_length = (SIZE); \
    ulParamLen = sizeof(sdc); \
    OS2InitSDC( &sdc, (TYPE) )
#endif

/*****************************************************************************
 * Additional types, OpenBSD specific
 *****************************************************************************/
#if defined( HAVE_OPENBSD_DVD_STRUCT )
typedef union dvd_struct dvd_struct;
typedef union dvd_authinfo dvd_authinfo;
#endif

/*****************************************************************************
 * Various DVD I/O tables
 *****************************************************************************/
#if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO ) || defined ( __QNXNTO__ ) || defined ( SYS_OS2 )
    /* The generic packet command opcodes for CD/DVD Logical Units,
     * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
#   define GPCMD_READ_DVD_STRUCTURE 0xad
#   define GPCMD_REPORT_KEY         0xa4
#   define GPCMD_SEND_KEY           0xa3
    /* DVD struct types */
#   define DVD_STRUCT_PHYSICAL      0x00
#   define DVD_STRUCT_COPYRIGHT     0x01
#   define DVD_STRUCT_DISCKEY       0x02
#   define DVD_STRUCT_BCA           0x03
#   define DVD_STRUCT_MANUFACT      0x04
    /* Key formats */
#   define DVD_REPORT_AGID          0x00
#   define DVD_REPORT_CHALLENGE     0x01
#   define DVD_SEND_CHALLENGE       0x01
#   define DVD_REPORT_KEY1          0x02
#   define DVD_SEND_KEY2            0x03
#   define DVD_REPORT_TITLE_KEY     0x04
#   define DVD_REPORT_ASF           0x05
#   define DVD_SEND_RPC             0x06
#   define DVD_REPORT_RPC           0x08
#   define DVD_INVALIDATE_AGID      0x3f
#endif

/*****************************************************************************
 * win32 ioctl specific
 *****************************************************************************/
#if defined( WIN32 )

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define IOCTL_DVD_START_SESSION         CTL_CODE(FILE_DEVICE_DVD, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_DVD_READ_KEY              CTL_CODE(FILE_DEVICE_DVD, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_DVD_SEND_KEY              CTL_CODE(FILE_DEVICE_DVD, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_DVD_END_SESSION           CTL_CODE(FILE_DEVICE_DVD, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_DVD_GET_REGION            CTL_CODE(FILE_DEVICE_DVD, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_DVD_SEND_KEY2             CTL_CODE(FILE_DEVICE_DVD, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define IOCTL_SCSI_PASS_THROUGH_DIRECT  CTL_CODE(FILE_DEVICE_CONTROLLER, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define DVD_CHALLENGE_KEY_LENGTH        (12 + sizeof(DVD_COPY_PROTECT_KEY))
#define DVD_BUS_KEY_LENGTH              (8 + sizeof(DVD_COPY_PROTECT_KEY))
#define DVD_TITLE_KEY_LENGTH            (8 + sizeof(DVD_COPY_PROTECT_KEY))
#define DVD_DISK_KEY_LENGTH             (2048 + sizeof(DVD_COPY_PROTECT_KEY))
#define DVD_ASF_LENGTH                  (sizeof(DVD_ASF) + sizeof(DVD_COPY_PROTECT_KEY))
#define DVD_REGION_LENGTH               (sizeof(DVD_REGION))

#define SCSI_IOCTL_DATA_OUT             0
#define SCSI_IOCTL_DATA_IN              1

typedef ULONG DVD_SESSION_ID, *PDVD_SESSION_ID;

typedef enum
{
    DvdChallengeKey = 0x01,
    DvdBusKey1,
    DvdBusKey2,
    DvdTitleKey,
    DvdAsf,
    DvdSetRpcKey = 0x6,
    DvdGetRpcKey = 0x8,
    DvdDiskKey = 0x80,
    DvdInvalidateAGID = 0x3f
} DVD_KEY_TYPE;

typedef struct _DVD_COPY_PROTECT_KEY
{
    ULONG KeyLength;
    DVD_SESSION_ID SessionId;
    DVD_KEY_TYPE KeyType;
    ULONG KeyFlags;
    union
    {
        struct
        {
            ULONG FileHandle;
            ULONG Reserved;   // used for NT alignment
        };
        LARGE_INTEGER TitleOffset;
    } Parameters;
    UCHAR KeyData[0];
} DVD_COPY_PROTECT_KEY, *PDVD_COPY_PROTECT_KEY;

typedef struct _DVD_ASF
{
    UCHAR Reserved0[3];
    UCHAR SuccessFlag:1;
    UCHAR Reserved1:7;
} DVD_ASF, * PDVD_ASF;

typedef struct _DVD_REGION {
  UCHAR  CopySystem;
  UCHAR  RegionData;
  UCHAR  SystemRegion;
  UCHAR  ResetCount;
} DVD_REGION, *PDVD_REGION;

typedef struct _SCSI_PASS_THROUGH_DIRECT
{
    USHORT Length;
    UCHAR ScsiStatus;
    UCHAR PathId;
    UCHAR TargetId;
    UCHAR Lun;
    UCHAR CdbLength;
    UCHAR SenseInfoLength;
    UCHAR DataIn;
    ULONG DataTransferLength;
    ULONG TimeOutValue;
    PVOID DataBuffer;
    ULONG SenseInfoOffset;
    UCHAR Cdb[16];
} SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;

/*****************************************************************************
 * win32 aspi specific
 *****************************************************************************/

#define WIN2K               ( GetVersion() < 0x80000000 )
#define ASPI_HAID           0
#define ASPI_TARGET         0

#define SENSE_LEN           0x0E
#define SC_EXEC_SCSI_CMD    0x02
#define SC_GET_DISK_INFO    0x06
#define SS_COMP             0x01
#define SS_PENDING          0x00
#define SS_NO_ADAPTERS      0xE8
#define SRB_DIR_IN          0x08
#define SRB_DIR_OUT         0x10
#define SRB_EVENT_NOTIFY    0x40

struct w32_aspidev
{
    long  hASPI;
    short i_sid;
    int   i_blocks;
    long  (*lpSendCommand)( void* );
};

#pragma pack(1)

struct SRB_GetDiskInfo
{
    unsigned char   SRB_Cmd;
    unsigned char   SRB_Status;
    unsigned char   SRB_HaId;
    unsigned char   SRB_Flags;
    unsigned long   SRB_Hdr_Rsvd;
    unsigned char   SRB_Target;
    unsigned char   SRB_Lun;
    unsigned char   SRB_DriveFlags;
    unsigned char   SRB_Int13HDriveInfo;
    unsigned char   SRB_Heads;
    unsigned char   SRB_Sectors;
    unsigned char   SRB_Rsvd1[22];
};

struct SRB_ExecSCSICmd
{
    unsigned char   SRB_Cmd;
    unsigned char   SRB_Status;
    unsigned char   SRB_HaId;
    unsigned char   SRB_Flags;
    unsigned long   SRB_Hdr_Rsvd;
    unsigned char   SRB_Target;
    unsigned char   SRB_Lun;
    unsigned short  SRB_Rsvd1;
    unsigned long   SRB_BufLen;
    unsigned char   *SRB_BufPointer;
    unsigned char   SRB_SenseLen;
    unsigned char   SRB_CDBLen;
    unsigned char   SRB_HaStat;
    unsigned char   SRB_TargStat;
    unsigned long   *SRB_PostProc;
    unsigned char   SRB_Rsvd2[20];
    unsigned char   CDBByte[16];
    unsigned char   SenseArea[SENSE_LEN+2];
};

#pragma pack()

#endif

/*****************************************************************************
 * OS2 ioctl specific
 *****************************************************************************/
#if defined( SYS_OS2 )

#define CDROMDISK_EXECMD      0x7A

#define EX_DIRECTION_IN       0x01
#define EX_PLAYING_CHK        0x02

#pragma pack(1)

struct OS2_ExecSCSICmd
{
    unsigned long   id_code;      // 'CD01'
    unsigned short  data_length;  // length of the Data Packet
    unsigned short  cmd_length;   // length of the Command Buffer
    unsigned short  flags;        // flags
    unsigned char   command[16];  // Command Buffer for SCSI command

} OS2_ExecSCSICmd;

#pragma pack()

#endif