7027
|
1 /*****************************************************************************
|
|
2 * ioctl.c: DVD ioctl replacement function
|
|
3 *****************************************************************************
|
|
4 * Copyright (C) 1999-2001 VideoLAN
|
|
5 * $Id$
|
|
6 *
|
|
7 * Authors: Markus Kuespert <ltlBeBoy@beosmail.com>
|
|
8 * Samuel Hocevar <sam@zoy.org>
|
|
9 * Jon Lech Johansen <jon-vl@nanocrew.net>
|
|
10 * Håkan Hjort <d95hjort@dtek.chalmers.se>
|
|
11 * Eugenio Jarosiewicz <ej0@cise.ufl.edu>
|
|
12 * David Siebörger <drs-videolan@rucus.ru.ac.za>
|
|
13 * Alex Strelnikov <lelik@os2.ru>
|
|
14 *
|
|
15 * This program is free software; you can redistribute it and/or modify
|
|
16 * it under the terms of the GNU General Public License as published by
|
|
17 * the Free Software Foundation; either version 2 of the License, or
|
|
18 * (at your option) any later version.
|
|
19 *
|
|
20 * This program is distributed in the hope that it will be useful,
|
|
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 * GNU General Public License for more details.
|
|
24 *
|
|
25 * You should have received a copy of the GNU General Public License
|
|
26 * along with this program; if not, write to the Free Software
|
|
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
|
28 *****************************************************************************/
|
|
29
|
|
30 /*****************************************************************************
|
|
31 * Preamble
|
|
32 *****************************************************************************/
|
|
33 #include "config.h"
|
|
34
|
|
35 #include <stdio.h>
|
|
36
|
|
37 #include <string.h> /* memcpy(), memset() */
|
|
38 #include <sys/types.h>
|
|
39
|
|
40 #if defined( WIN32 )
|
8142
|
41 # undef DATADIR /* clashes with /usr/include/w32api/objidl.h */
|
7027
|
42 # include <windows.h>
|
|
43 # include <winioctl.h>
|
|
44 #elif defined ( SYS_OS2 )
|
|
45 # define INCL_DOSFILEMGR
|
|
46 # define INCL_DOSDEVICES
|
|
47 # define INCL_DOSDEVIOCTL
|
|
48 # define INCL_DOSERRORS
|
|
49 # include <os2.h>
|
|
50 # include <sys/ioctl.h>
|
|
51 #else
|
|
52 # include <netinet/in.h>
|
|
53 # include <sys/ioctl.h>
|
|
54 #endif
|
|
55
|
|
56 #ifdef DVD_STRUCT_IN_SYS_CDIO_H
|
|
57 # include <sys/cdio.h>
|
|
58 #endif
|
|
59 #ifdef DVD_STRUCT_IN_SYS_DVDIO_H
|
|
60 # include <sys/dvdio.h>
|
|
61 #endif
|
|
62 #ifdef DVD_STRUCT_IN_LINUX_CDROM_H
|
|
63 # include <linux/cdrom.h>
|
|
64 #endif
|
|
65 #ifdef DVD_STRUCT_IN_DVD_H
|
|
66 # include <dvd.h>
|
|
67 #endif
|
|
68 #ifdef DVD_STRUCT_IN_BSDI_DVDIOCTL_DVD_H
|
|
69 # include "bsdi_dvd.h"
|
|
70 #endif
|
|
71 #ifdef SYS_BEOS
|
|
72 # include <malloc.h>
|
|
73 # include <scsi.h>
|
|
74 #endif
|
|
75 #ifdef HPUX_SCTL_IO
|
|
76 # include <sys/scsi.h>
|
|
77 #endif
|
|
78 #ifdef SOLARIS_USCSI
|
8575
|
79 # include <dlfcn.h>
|
7027
|
80 # include <unistd.h>
|
|
81 # include <stropts.h>
|
|
82 # include <sys/scsi/scsi_types.h>
|
|
83 # include <sys/scsi/impl/uscsi.h>
|
8575
|
84 # include <sys/smedia.h>
|
7027
|
85 #endif
|
|
86 #ifdef DARWIN_DVD_IOCTL
|
|
87 # include <IOKit/storage/IODVDMediaBSDClient.h>
|
|
88 #endif
|
|
89 #ifdef __QNXNTO__
|
|
90 # include <sys/mman.h>
|
|
91 # include <sys/dcmd_cam.h>
|
|
92 #endif
|
|
93
|
|
94 #include "common.h"
|
|
95
|
|
96 #include "ioctl.h"
|
|
97
|
|
98 /*****************************************************************************
|
|
99 * Local prototypes, BeOS specific
|
|
100 *****************************************************************************/
|
|
101 #if defined( SYS_BEOS )
|
|
102 static void BeInitRDC ( raw_device_command *, int );
|
|
103 #endif
|
|
104
|
|
105 /*****************************************************************************
|
|
106 * Local prototypes, HP-UX specific
|
|
107 *****************************************************************************/
|
|
108 #if defined( HPUX_SCTL_IO )
|
|
109 static void HPUXInitSCTL ( struct sctl_io *sctl_io, int i_type );
|
|
110 #endif
|
|
111
|
|
112 /*****************************************************************************
|
|
113 * Local prototypes, Solaris specific
|
|
114 *****************************************************************************/
|
|
115 #if defined( SOLARIS_USCSI )
|
|
116 static void SolarisInitUSCSI( struct uscsi_cmd *p_sc, int i_type );
|
8575
|
117 static int SolarisSendUSCSI( int fd, struct uscsi_cmd *p_sc );
|
7027
|
118 #endif
|
|
119
|
|
120 /*****************************************************************************
|
|
121 * Local prototypes, win32 (aspi) specific
|
|
122 *****************************************************************************/
|
|
123 #if defined( WIN32 )
|
|
124 static void WinInitSSC ( struct SRB_ExecSCSICmd *, int );
|
|
125 static int WinSendSSC ( int, struct SRB_ExecSCSICmd * );
|
|
126 #endif
|
|
127
|
|
128 /*****************************************************************************
|
|
129 * Local prototypes, QNX specific
|
|
130 *****************************************************************************/
|
|
131 #if defined( __QNXNTO__ )
|
|
132 static void QNXInitCPT ( CAM_PASS_THRU *, int );
|
|
133 #endif
|
|
134
|
|
135 /*****************************************************************************
|
|
136 * Local prototypes, OS2 specific
|
|
137 *****************************************************************************/
|
|
138 #if defined( SYS_OS2 )
|
|
139 static void OS2InitSDC( struct OS2_ExecSCSICmd *, int );
|
|
140 #endif
|
|
141
|
|
142 /*****************************************************************************
|
|
143 * ioctl_ReadCopyright: check whether the disc is encrypted or not
|
|
144 *****************************************************************************/
|
|
145 int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
|
|
146 {
|
|
147 int i_ret;
|
|
148
|
|
149 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
150 dvd_struct dvd;
|
|
151
|
|
152 memset( &dvd, 0, sizeof( dvd ) );
|
|
153 dvd.type = DVD_STRUCT_COPYRIGHT;
|
|
154 dvd.copyright.layer_num = i_layer;
|
|
155
|
|
156 i_ret = ioctl( i_fd, DVD_READ_STRUCT, &dvd );
|
|
157
|
|
158 *pi_copyright = dvd.copyright.cpst;
|
|
159
|
|
160 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
161 struct dvd_struct dvd;
|
|
162
|
|
163 memset( &dvd, 0, sizeof( dvd ) );
|
|
164 dvd.format = DVD_STRUCT_COPYRIGHT;
|
|
165 dvd.layer_num = i_layer;
|
|
166
|
|
167 i_ret = ioctl( i_fd, DVDIOCREADSTRUCTURE, &dvd );
|
|
168
|
|
169 *pi_copyright = dvd.cpst;
|
|
170
|
|
171 #elif defined( SYS_BEOS )
|
|
172 INIT_RDC( GPCMD_READ_DVD_STRUCTURE, 8 );
|
|
173
|
|
174 rdc.command[ 6 ] = i_layer;
|
|
175 rdc.command[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
176
|
|
177 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
178
|
|
179 *pi_copyright = p_buffer[ 4 ];
|
|
180
|
|
181 #elif defined( HPUX_SCTL_IO )
|
|
182 INIT_SCTL_IO( GPCMD_READ_DVD_STRUCTURE, 8 );
|
|
183
|
|
184 sctl_io.cdb[ 6 ] = i_layer;
|
|
185 sctl_io.cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
186
|
|
187 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
188
|
|
189 *pi_copyright = p_buffer[ 4 ];
|
|
190
|
|
191 #elif defined( SOLARIS_USCSI )
|
|
192 INIT_USCSI( GPCMD_READ_DVD_STRUCTURE, 8 );
|
|
193
|
|
194 rs_cdb.cdb_opaque[ 6 ] = i_layer;
|
|
195 rs_cdb.cdb_opaque[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
196
|
8575
|
197 i_ret = SolarisSendUSCSI(i_fd, &sc);
|
7027
|
198
|
|
199 if( i_ret < 0 || sc.uscsi_status ) {
|
|
200 i_ret = -1;
|
|
201 }
|
|
202
|
|
203 *pi_copyright = p_buffer[ 4 ];
|
|
204 /* s->copyright.rmi = p_buffer[ 5 ]; */
|
|
205
|
|
206 #elif defined( DARWIN_DVD_IOCTL )
|
|
207 INIT_DVDIOCTL( dk_dvd_read_structure_t, DVDCopyrightInfo,
|
|
208 kDVDStructureFormatCopyrightInfo );
|
|
209
|
|
210 dvd.layer = i_layer;
|
|
211
|
|
212 i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
|
|
213
|
|
214 *pi_copyright = dvdbs.copyrightProtectionSystemType;
|
|
215
|
|
216 #elif defined( WIN32 )
|
|
217 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
218 {
|
|
219 DWORD tmp;
|
|
220 u8 p_buffer[ 8 ];
|
|
221 SCSI_PASS_THROUGH_DIRECT sptd;
|
|
222
|
|
223 memset( &sptd, 0, sizeof( sptd ) );
|
|
224 memset( &p_buffer, 0, sizeof( p_buffer ) );
|
|
225
|
|
226 /* When using IOCTL_DVD_READ_STRUCTURE and
|
|
227 DVD_COPYRIGHT_DESCRIPTOR, CopyrightProtectionType
|
|
228 is always 6. So we send a raw scsi command instead. */
|
|
229
|
|
230 sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT );
|
|
231 sptd.CdbLength = 12;
|
|
232 sptd.DataIn = SCSI_IOCTL_DATA_IN;
|
|
233 sptd.DataTransferLength = 8;
|
|
234 sptd.TimeOutValue = 2;
|
|
235 sptd.DataBuffer = p_buffer;
|
|
236 sptd.Cdb[ 0 ] = GPCMD_READ_DVD_STRUCTURE;
|
|
237 sptd.Cdb[ 6 ] = i_layer;
|
|
238 sptd.Cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
239 sptd.Cdb[ 8 ] = (8 >> 8) & 0xff;
|
|
240 sptd.Cdb[ 9 ] = 8 & 0xff;
|
|
241
|
|
242 i_ret = DeviceIoControl( (HANDLE) i_fd,
|
|
243 IOCTL_SCSI_PASS_THROUGH_DIRECT,
|
|
244 &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
|
|
245 &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
|
|
246 &tmp, NULL ) ? 0 : -1;
|
|
247
|
|
248 *pi_copyright = p_buffer[ 4 ];
|
|
249 }
|
|
250 else
|
|
251 {
|
|
252 INIT_SSC( GPCMD_READ_DVD_STRUCTURE, 8 );
|
|
253
|
|
254 ssc.CDBByte[ 6 ] = i_layer;
|
|
255 ssc.CDBByte[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
256
|
|
257 i_ret = WinSendSSC( i_fd, &ssc );
|
|
258
|
|
259 *pi_copyright = p_buffer[ 4 ];
|
|
260 }
|
|
261
|
|
262 #elif defined( __QNXNTO__ )
|
|
263
|
|
264 INIT_CPT( GPCMD_READ_DVD_STRUCTURE, 8 );
|
|
265
|
|
266 p_cpt->cam_cdb[ 6 ] = i_layer;
|
|
267 p_cpt->cam_cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
268
|
|
269 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
270
|
|
271 *pi_copyright = p_buffer[4];
|
|
272
|
|
273 #elif defined( SYS_OS2 )
|
|
274 INIT_SSC( GPCMD_READ_DVD_STRUCTURE, 8 );
|
|
275
|
|
276 sdc.command[ 6 ] = i_layer;
|
|
277 sdc.command[ 7 ] = DVD_STRUCT_COPYRIGHT;
|
|
278
|
|
279 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
280 &sdc, sizeof(sdc), &ulParamLen,
|
|
281 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
282
|
|
283 *pi_copyright = p_buffer[ 4 ];
|
|
284
|
|
285 #else
|
|
286 # error "DVD ioctls are unavailable on this system"
|
|
287
|
|
288 #endif
|
|
289 return i_ret;
|
|
290 }
|
|
291
|
|
292 /*****************************************************************************
|
|
293 * ioctl_ReadDiscKey: get the disc key
|
|
294 *****************************************************************************/
|
|
295 int ioctl_ReadDiscKey( int i_fd, int *pi_agid, u8 *p_key )
|
|
296 {
|
|
297 int i_ret;
|
|
298
|
|
299 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
300 dvd_struct dvd;
|
|
301
|
|
302 memset( &dvd, 0, sizeof( dvd ) );
|
|
303 dvd.type = DVD_STRUCT_DISCKEY;
|
|
304 dvd.disckey.agid = *pi_agid;
|
|
305 memset( dvd.disckey.value, 0, DVD_DISCKEY_SIZE );
|
|
306
|
|
307 i_ret = ioctl( i_fd, DVD_READ_STRUCT, &dvd );
|
|
308
|
|
309 if( i_ret < 0 )
|
|
310 {
|
|
311 return i_ret;
|
|
312 }
|
|
313
|
|
314 memcpy( p_key, dvd.disckey.value, DVD_DISCKEY_SIZE );
|
|
315
|
|
316 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
317 struct dvd_struct dvd;
|
|
318
|
|
319 memset( &dvd, 0, sizeof( dvd ) );
|
|
320 dvd.format = DVD_STRUCT_DISCKEY;
|
|
321 dvd.agid = *pi_agid;
|
|
322 memset( dvd.data, 0, DVD_DISCKEY_SIZE );
|
|
323
|
|
324 i_ret = ioctl( i_fd, DVDIOCREADSTRUCTURE, &dvd );
|
|
325
|
|
326 if( i_ret < 0 )
|
|
327 {
|
|
328 return i_ret;
|
|
329 }
|
|
330
|
|
331 memcpy( p_key, dvd.data, DVD_DISCKEY_SIZE );
|
|
332
|
|
333 #elif defined( SYS_BEOS )
|
|
334 INIT_RDC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
|
|
335
|
|
336 rdc.command[ 7 ] = DVD_STRUCT_DISCKEY;
|
|
337 rdc.command[ 10 ] = *pi_agid << 6;
|
|
338
|
|
339 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
340
|
|
341 if( i_ret < 0 )
|
|
342 {
|
|
343 return i_ret;
|
|
344 }
|
|
345
|
|
346 memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
|
|
347
|
|
348 #elif defined( HPUX_SCTL_IO )
|
|
349 INIT_SCTL_IO( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
|
|
350
|
|
351 sctl_io.cdb[ 7 ] = DVD_STRUCT_DISCKEY;
|
|
352 sctl_io.cdb[ 10 ] = *pi_agid << 6;
|
|
353
|
|
354 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
355
|
|
356 if( i_ret < 0 )
|
|
357 {
|
|
358 return i_ret;
|
|
359 }
|
|
360
|
|
361 memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
|
|
362
|
|
363 #elif defined( SOLARIS_USCSI )
|
|
364 INIT_USCSI( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
|
|
365
|
|
366 rs_cdb.cdb_opaque[ 7 ] = DVD_STRUCT_DISCKEY;
|
|
367 rs_cdb.cdb_opaque[ 10 ] = *pi_agid << 6;
|
|
368
|
8575
|
369 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
370
|
|
371 if( i_ret < 0 || sc.uscsi_status )
|
|
372 {
|
|
373 i_ret = -1;
|
|
374 return i_ret;
|
|
375 }
|
|
376
|
|
377 memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
|
|
378
|
|
379 #elif defined( DARWIN_DVD_IOCTL )
|
|
380 INIT_DVDIOCTL( dk_dvd_read_structure_t, DVDDiscKeyInfo,
|
|
381 kDVDStructureFormatDiscKeyInfo );
|
|
382
|
|
383 dvd.grantID = *pi_agid;
|
|
384
|
|
385 i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
|
|
386
|
|
387 memcpy( p_key, dvdbs.discKeyStructures, DVD_DISCKEY_SIZE );
|
|
388
|
|
389 #elif defined( WIN32 )
|
|
390 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
391 {
|
|
392 DWORD tmp;
|
|
393 u8 buffer[DVD_DISK_KEY_LENGTH];
|
|
394 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
395
|
|
396 memset( &buffer, 0, sizeof( buffer ) );
|
|
397
|
|
398 key->KeyLength = DVD_DISK_KEY_LENGTH;
|
|
399 key->SessionId = *pi_agid;
|
|
400 key->KeyType = DvdDiskKey;
|
|
401 key->KeyFlags = 0;
|
|
402
|
|
403 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
|
|
404 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
405
|
|
406 if( i_ret < 0 )
|
|
407 {
|
|
408 return i_ret;
|
|
409 }
|
|
410
|
|
411 memcpy( p_key, key->KeyData, DVD_DISCKEY_SIZE );
|
|
412 }
|
|
413 else
|
|
414 {
|
|
415 INIT_SSC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
|
|
416
|
|
417 ssc.CDBByte[ 7 ] = DVD_STRUCT_DISCKEY;
|
|
418 ssc.CDBByte[ 10 ] = *pi_agid << 6;
|
|
419
|
|
420 i_ret = WinSendSSC( i_fd, &ssc );
|
|
421
|
|
422 if( i_ret < 0 )
|
|
423 {
|
|
424 return i_ret;
|
|
425 }
|
|
426
|
|
427 memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
|
|
428 }
|
|
429
|
|
430 #elif defined( __QNXNTO__ )
|
|
431
|
|
432 INIT_CPT( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
|
|
433
|
|
434 p_cpt->cam_cdb[ 7 ] = DVD_STRUCT_DISCKEY;
|
|
435 p_cpt->cam_cdb[ 10 ] = *pi_agid << 6;
|
|
436
|
|
437 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
438
|
|
439 memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
|
|
440
|
|
441 #elif defined ( SYS_OS2 )
|
|
442 INIT_SSC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
|
|
443
|
|
444 sdc.command[ 7 ] = DVD_STRUCT_DISCKEY;
|
|
445 sdc.command[ 10 ] = *pi_agid << 6;
|
|
446
|
|
447 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
448 &sdc, sizeof(sdc), &ulParamLen,
|
|
449 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
450
|
|
451 if( i_ret < 0 )
|
|
452 {
|
|
453 return i_ret;
|
|
454 }
|
|
455
|
|
456 memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
|
|
457
|
|
458 #else
|
|
459 # error "DVD ioctls are unavailable on this system"
|
|
460
|
|
461 #endif
|
|
462 return i_ret;
|
|
463 }
|
|
464
|
|
465 /*****************************************************************************
|
|
466 * ioctl_ReadTitleKey: get the title key
|
|
467 *****************************************************************************/
|
|
468 int ioctl_ReadTitleKey( int i_fd, int *pi_agid, int i_pos, u8 *p_key )
|
|
469 {
|
|
470 int i_ret;
|
|
471
|
|
472 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
473 dvd_authinfo auth_info;
|
|
474
|
|
475 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
476 auth_info.type = DVD_LU_SEND_TITLE_KEY;
|
|
477 auth_info.lstk.agid = *pi_agid;
|
|
478 auth_info.lstk.lba = i_pos;
|
|
479
|
|
480 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
481
|
|
482 memcpy( p_key, auth_info.lstk.title_key, DVD_KEY_SIZE );
|
|
483
|
|
484 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
485 struct dvd_authinfo auth_info;
|
|
486
|
|
487 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
488 auth_info.format = DVD_REPORT_TITLE_KEY;
|
|
489 auth_info.agid = *pi_agid;
|
|
490 auth_info.lba = i_pos;
|
|
491
|
|
492 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
493
|
|
494 memcpy( p_key, auth_info.keychal, DVD_KEY_SIZE );
|
|
495
|
|
496 #elif defined( SYS_BEOS )
|
|
497 INIT_RDC( GPCMD_REPORT_KEY, 12 );
|
|
498
|
|
499 rdc.command[ 2 ] = ( i_pos >> 24 ) & 0xff;
|
|
500 rdc.command[ 3 ] = ( i_pos >> 16 ) & 0xff;
|
|
501 rdc.command[ 4 ] = ( i_pos >> 8 ) & 0xff;
|
|
502 rdc.command[ 5 ] = ( i_pos ) & 0xff;
|
|
503 rdc.command[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
|
|
504
|
|
505 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
506
|
|
507 memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
|
|
508
|
|
509 #elif defined( HPUX_SCTL_IO )
|
|
510 INIT_SCTL_IO( GPCMD_REPORT_KEY, 12 );
|
|
511
|
|
512 sctl_io.cdb[ 2 ] = ( i_pos >> 24 ) & 0xff;
|
|
513 sctl_io.cdb[ 3 ] = ( i_pos >> 16 ) & 0xff;
|
|
514 sctl_io.cdb[ 4 ] = ( i_pos >> 8 ) & 0xff;
|
|
515 sctl_io.cdb[ 5 ] = ( i_pos ) & 0xff;
|
|
516 sctl_io.cdb[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
|
|
517
|
|
518 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
519
|
|
520 memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
|
|
521
|
|
522 #elif defined( SOLARIS_USCSI )
|
|
523 INIT_USCSI( GPCMD_REPORT_KEY, 12 );
|
|
524
|
|
525 rs_cdb.cdb_opaque[ 2 ] = ( i_pos >> 24 ) & 0xff;
|
|
526 rs_cdb.cdb_opaque[ 3 ] = ( i_pos >> 16 ) & 0xff;
|
|
527 rs_cdb.cdb_opaque[ 4 ] = ( i_pos >> 8 ) & 0xff;
|
|
528 rs_cdb.cdb_opaque[ 5 ] = ( i_pos ) & 0xff;
|
|
529 rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
|
|
530
|
8575
|
531 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
532
|
|
533 if( i_ret < 0 || sc.uscsi_status )
|
|
534 {
|
|
535 i_ret = -1;
|
|
536 }
|
|
537
|
|
538 /* Do we want to return the cp_sec flag perhaps? */
|
|
539 /* a->lstk.cpm = (buf[ 4 ] >> 7) & 1; */
|
|
540 /* a->lstk.cp_sec = (buf[ 4 ] >> 6) & 1; */
|
|
541 /* a->lstk.cgms = (buf[ 4 ] >> 4) & 3; */
|
|
542
|
|
543 memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
|
|
544
|
|
545 #elif defined( DARWIN_DVD_IOCTL )
|
|
546 INIT_DVDIOCTL( dk_dvd_report_key_t, DVDTitleKeyInfo,
|
|
547 kDVDKeyFormatTitleKey );
|
|
548
|
|
549 dvd.address = i_pos;
|
|
550 dvd.grantID = *pi_agid;
|
|
551 dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
|
|
552
|
|
553 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
|
|
554
|
|
555 memcpy( p_key, dvdbs.titleKeyValue, DVD_KEY_SIZE );
|
|
556
|
|
557 #elif defined( WIN32 )
|
|
558 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
559 {
|
|
560 DWORD tmp;
|
|
561 u8 buffer[DVD_BUS_KEY_LENGTH];
|
|
562 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
563
|
|
564 memset( &buffer, 0, sizeof( buffer ) );
|
|
565
|
|
566 key->KeyLength = DVD_TITLE_KEY_LENGTH;
|
|
567 key->SessionId = *pi_agid;
|
|
568 key->KeyType = DvdTitleKey;
|
|
569 key->KeyFlags = 0;
|
|
570 key->Parameters.TitleOffset.QuadPart = (LONGLONG) i_pos;
|
|
571
|
|
572 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
|
|
573 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
574
|
|
575 memcpy( p_key, key->KeyData, DVD_KEY_SIZE );
|
|
576 }
|
|
577 else
|
|
578 {
|
|
579 INIT_SSC( GPCMD_REPORT_KEY, 12 );
|
|
580
|
|
581 ssc.CDBByte[ 2 ] = ( i_pos >> 24 ) & 0xff;
|
|
582 ssc.CDBByte[ 3 ] = ( i_pos >> 16 ) & 0xff;
|
|
583 ssc.CDBByte[ 4 ] = ( i_pos >> 8 ) & 0xff;
|
|
584 ssc.CDBByte[ 5 ] = ( i_pos ) & 0xff;
|
|
585 ssc.CDBByte[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
|
|
586
|
|
587 i_ret = WinSendSSC( i_fd, &ssc );
|
|
588
|
|
589 memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
|
|
590 }
|
|
591
|
|
592 #elif defined( __QNXNTO__ )
|
|
593
|
|
594 INIT_CPT( GPCMD_REPORT_KEY, 12 );
|
|
595
|
|
596 p_cpt->cam_cdb[ 2 ] = ( i_pos >> 24 ) & 0xff;
|
|
597 p_cpt->cam_cdb[ 3 ] = ( i_pos >> 16 ) & 0xff;
|
|
598 p_cpt->cam_cdb[ 4 ] = ( i_pos >> 8 ) & 0xff;
|
|
599 p_cpt->cam_cdb[ 5 ] = ( i_pos ) & 0xff;
|
|
600 p_cpt->cam_cdb[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
|
|
601
|
|
602 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
603
|
|
604 memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
|
|
605
|
|
606 #elif defined( SYS_OS2 )
|
|
607 INIT_SSC( GPCMD_REPORT_KEY, 12 );
|
|
608
|
|
609 sdc.command[ 2 ] = ( i_pos >> 24 ) & 0xff;
|
|
610 sdc.command[ 3 ] = ( i_pos >> 16 ) & 0xff;
|
|
611 sdc.command[ 4 ] = ( i_pos >> 8 ) & 0xff;
|
|
612 sdc.command[ 5 ] = ( i_pos ) & 0xff;
|
|
613 sdc.command[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
|
|
614
|
|
615 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
616 &sdc, sizeof(sdc), &ulParamLen,
|
|
617 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
618
|
|
619 memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
|
|
620
|
|
621 #else
|
|
622 # error "DVD ioctls are unavailable on this system"
|
|
623
|
|
624 #endif
|
|
625
|
|
626 return i_ret;
|
|
627 }
|
|
628
|
|
629
|
|
630 /*****************************************************************************
|
|
631 * ioctl_ReportAgid: get AGID from the drive
|
|
632 *****************************************************************************/
|
|
633 int ioctl_ReportAgid( int i_fd, int *pi_agid )
|
|
634 {
|
|
635 int i_ret;
|
|
636
|
|
637 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
638 dvd_authinfo auth_info;
|
|
639
|
|
640 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
641 auth_info.type = DVD_LU_SEND_AGID;
|
|
642 auth_info.lsa.agid = *pi_agid;
|
|
643
|
|
644 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
645
|
|
646 *pi_agid = auth_info.lsa.agid;
|
|
647
|
|
648 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
649 struct dvd_authinfo auth_info;
|
|
650
|
|
651 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
652 auth_info.format = DVD_REPORT_AGID;
|
|
653 auth_info.agid = *pi_agid;
|
|
654
|
|
655 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
656
|
|
657 *pi_agid = auth_info.agid;
|
|
658
|
|
659 #elif defined( SYS_BEOS )
|
|
660 INIT_RDC( GPCMD_REPORT_KEY, 8 );
|
|
661
|
|
662 rdc.command[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
|
|
663
|
|
664 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
665
|
|
666 *pi_agid = p_buffer[ 7 ] >> 6;
|
|
667
|
|
668 #elif defined( HPUX_SCTL_IO )
|
|
669 INIT_SCTL_IO( GPCMD_REPORT_KEY, 8 );
|
|
670
|
|
671 sctl_io.cdb[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
|
|
672
|
|
673 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
674
|
|
675 *pi_agid = p_buffer[ 7 ] >> 6;
|
|
676
|
|
677 #elif defined( SOLARIS_USCSI )
|
|
678 INIT_USCSI( GPCMD_REPORT_KEY, 8 );
|
|
679
|
|
680 rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
|
|
681
|
8575
|
682 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
683
|
|
684 if( i_ret < 0 || sc.uscsi_status )
|
|
685 {
|
|
686 i_ret = -1;
|
|
687 }
|
|
688
|
|
689 *pi_agid = p_buffer[ 7 ] >> 6;
|
|
690
|
|
691 #elif defined( DARWIN_DVD_IOCTL )
|
|
692 INIT_DVDIOCTL( dk_dvd_report_key_t, DVDAuthenticationGrantIDInfo,
|
|
693 kDVDKeyFormatAGID_CSS );
|
|
694
|
|
695 dvd.grantID = *pi_agid;
|
|
696 dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
|
|
697
|
|
698 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
|
|
699
|
|
700 *pi_agid = dvdbs.grantID;
|
|
701
|
|
702 #elif defined( WIN32 )
|
|
703 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
704 {
|
|
705 ULONG id;
|
|
706 DWORD tmp;
|
|
707
|
|
708 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_START_SESSION,
|
|
709 &tmp, 4, &id, sizeof( id ), &tmp, NULL ) ? 0 : -1;
|
|
710
|
|
711 *pi_agid = id;
|
|
712 }
|
|
713 else
|
|
714 {
|
|
715 INIT_SSC( GPCMD_REPORT_KEY, 8 );
|
|
716
|
|
717 ssc.CDBByte[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
|
|
718
|
|
719 i_ret = WinSendSSC( i_fd, &ssc );
|
|
720
|
|
721 *pi_agid = p_buffer[ 7 ] >> 6;
|
|
722 }
|
|
723
|
|
724 #elif defined( __QNXNTO__ )
|
|
725
|
|
726 INIT_CPT( GPCMD_REPORT_KEY, 8 );
|
|
727
|
|
728 p_cpt->cam_cdb[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
|
|
729
|
|
730 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
731
|
|
732 *pi_agid = p_buffer[ 7 ] >> 6;
|
|
733
|
|
734 #elif defined( SYS_OS2 )
|
|
735 INIT_SSC( GPCMD_REPORT_KEY, 8 );
|
|
736
|
|
737 sdc.command[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
|
|
738
|
|
739 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
740 &sdc, sizeof(sdc), &ulParamLen,
|
|
741 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
742
|
|
743 *pi_agid = p_buffer[ 7 ] >> 6;
|
|
744
|
|
745 #else
|
|
746 # error "DVD ioctls are unavailable on this system"
|
|
747
|
|
748 #endif
|
|
749 return i_ret;
|
|
750 }
|
|
751
|
|
752 /*****************************************************************************
|
|
753 * ioctl_ReportChallenge: get challenge from the drive
|
|
754 *****************************************************************************/
|
|
755 int ioctl_ReportChallenge( int i_fd, int *pi_agid, u8 *p_challenge )
|
|
756 {
|
|
757 int i_ret;
|
|
758
|
|
759 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
760 dvd_authinfo auth_info;
|
|
761
|
|
762 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
763 auth_info.type = DVD_LU_SEND_CHALLENGE;
|
|
764 auth_info.lsc.agid = *pi_agid;
|
|
765
|
|
766 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
767
|
|
768 memcpy( p_challenge, auth_info.lsc.chal, DVD_CHALLENGE_SIZE );
|
|
769
|
|
770 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
771 struct dvd_authinfo auth_info;
|
|
772
|
|
773 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
774 auth_info.format = DVD_REPORT_CHALLENGE;
|
|
775 auth_info.agid = *pi_agid;
|
|
776
|
|
777 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
778
|
|
779 memcpy( p_challenge, auth_info.keychal, DVD_CHALLENGE_SIZE );
|
|
780
|
|
781 #elif defined( SYS_BEOS )
|
|
782 INIT_RDC( GPCMD_REPORT_KEY, 16 );
|
|
783
|
|
784 rdc.command[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
|
|
785
|
|
786 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
787
|
|
788 memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
|
|
789
|
|
790 #elif defined( HPUX_SCTL_IO )
|
|
791 INIT_SCTL_IO( GPCMD_REPORT_KEY, 16 );
|
|
792
|
|
793 sctl_io.cdb[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
|
|
794
|
|
795 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
796
|
|
797 memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
|
|
798
|
|
799 #elif defined( SOLARIS_USCSI )
|
|
800 INIT_USCSI( GPCMD_REPORT_KEY, 16 );
|
|
801
|
|
802 rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
|
|
803
|
8575
|
804 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
805
|
|
806 if( i_ret < 0 || sc.uscsi_status )
|
|
807 {
|
|
808 i_ret = -1;
|
|
809 }
|
|
810
|
|
811 memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
|
|
812
|
|
813 #elif defined( DARWIN_DVD_IOCTL )
|
|
814 INIT_DVDIOCTL( dk_dvd_report_key_t, DVDChallengeKeyInfo,
|
|
815 kDVDKeyFormatChallengeKey );
|
|
816
|
|
817 dvd.grantID = *pi_agid;
|
|
818
|
|
819 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
|
|
820
|
|
821 memcpy( p_challenge, dvdbs.challengeKeyValue, DVD_CHALLENGE_SIZE );
|
|
822
|
|
823 #elif defined( WIN32 )
|
|
824 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
825 {
|
|
826 DWORD tmp;
|
|
827 u8 buffer[DVD_CHALLENGE_KEY_LENGTH];
|
|
828 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
829
|
|
830 memset( &buffer, 0, sizeof( buffer ) );
|
|
831
|
|
832 key->KeyLength = DVD_CHALLENGE_KEY_LENGTH;
|
|
833 key->SessionId = *pi_agid;
|
|
834 key->KeyType = DvdChallengeKey;
|
|
835 key->KeyFlags = 0;
|
|
836
|
|
837 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
|
|
838 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
839
|
|
840 if( i_ret < 0 )
|
|
841 {
|
|
842 return i_ret;
|
|
843 }
|
|
844
|
|
845 memcpy( p_challenge, key->KeyData, DVD_CHALLENGE_SIZE );
|
|
846 }
|
|
847 else
|
|
848 {
|
|
849 INIT_SSC( GPCMD_REPORT_KEY, 16 );
|
|
850
|
|
851 ssc.CDBByte[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
|
|
852
|
|
853 i_ret = WinSendSSC( i_fd, &ssc );
|
|
854
|
|
855 memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
|
|
856 }
|
|
857
|
|
858 #elif defined( __QNXNTO__ )
|
|
859
|
|
860 INIT_CPT( GPCMD_REPORT_KEY, 16 );
|
|
861
|
|
862 p_cpt->cam_cdb[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
|
|
863
|
|
864 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
865
|
|
866 memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
|
|
867
|
|
868 #elif defined( SYS_OS2 )
|
|
869 INIT_SSC( GPCMD_REPORT_KEY, 16 );
|
|
870
|
|
871 sdc.command[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
|
|
872
|
|
873 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
874 &sdc, sizeof(sdc), &ulParamLen,
|
|
875 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
876
|
|
877 memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
|
|
878
|
|
879 #else
|
|
880 # error "DVD ioctls are unavailable on this system"
|
|
881
|
|
882 #endif
|
|
883 return i_ret;
|
|
884 }
|
|
885
|
|
886 /*****************************************************************************
|
|
887 * ioctl_ReportASF: get ASF from the drive
|
|
888 *****************************************************************************/
|
|
889 int ioctl_ReportASF( int i_fd, int *pi_remove_me, int *pi_asf )
|
|
890 {
|
|
891 int i_ret;
|
|
892
|
|
893 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
894 dvd_authinfo auth_info;
|
|
895
|
|
896 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
897 auth_info.type = DVD_LU_SEND_ASF;
|
|
898 auth_info.lsasf.asf = *pi_asf;
|
|
899
|
|
900 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
901
|
|
902 *pi_asf = auth_info.lsasf.asf;
|
|
903
|
|
904 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
905 struct dvd_authinfo auth_info;
|
|
906
|
|
907 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
908 auth_info.format = DVD_REPORT_ASF;
|
|
909 auth_info.asf = *pi_asf;
|
|
910
|
|
911 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
912
|
|
913 *pi_asf = auth_info.asf;
|
|
914
|
|
915 #elif defined( SYS_BEOS )
|
|
916 INIT_RDC( GPCMD_REPORT_KEY, 8 );
|
|
917
|
|
918 rdc.command[ 10 ] = DVD_REPORT_ASF;
|
|
919
|
|
920 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
921
|
|
922 *pi_asf = p_buffer[ 7 ] & 1;
|
|
923
|
|
924 #elif defined( HPUX_SCTL_IO )
|
|
925 INIT_SCTL_IO( GPCMD_REPORT_KEY, 8 );
|
|
926
|
|
927 sctl_io.cdb[ 10 ] = DVD_REPORT_ASF;
|
|
928
|
|
929 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
930
|
|
931 *pi_asf = p_buffer[ 7 ] & 1;
|
|
932
|
|
933 #elif defined( SOLARIS_USCSI )
|
|
934 INIT_USCSI( GPCMD_REPORT_KEY, 8 );
|
|
935
|
|
936 rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_ASF;
|
|
937
|
8575
|
938 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
939
|
|
940 if( i_ret < 0 || sc.uscsi_status )
|
|
941 {
|
|
942 i_ret = -1;
|
|
943 }
|
|
944
|
|
945 *pi_asf = p_buffer[ 7 ] & 1;
|
|
946
|
|
947 #elif defined( DARWIN_DVD_IOCTL )
|
|
948 INIT_DVDIOCTL( dk_dvd_report_key_t, DVDAuthenticationSuccessFlagInfo,
|
|
949 kDVDKeyFormatASF );
|
|
950
|
|
951 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
|
|
952
|
|
953 *pi_asf = dvdbs.successFlag;
|
|
954
|
|
955 #elif defined( WIN32 )
|
|
956 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
957 {
|
|
958 DWORD tmp;
|
|
959 u8 buffer[DVD_ASF_LENGTH];
|
|
960 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
961
|
|
962 memset( &buffer, 0, sizeof( buffer ) );
|
|
963
|
|
964 key->KeyLength = DVD_ASF_LENGTH;
|
|
965 key->KeyType = DvdAsf;
|
|
966 key->KeyFlags = 0;
|
|
967
|
|
968 ((PDVD_ASF)key->KeyData)->SuccessFlag = *pi_asf;
|
|
969
|
|
970 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
|
|
971 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
972
|
|
973 if( i_ret < 0 )
|
|
974 {
|
|
975 return i_ret;
|
|
976 }
|
|
977
|
|
978 *pi_asf = ((PDVD_ASF)key->KeyData)->SuccessFlag;
|
|
979 }
|
|
980 else
|
|
981 {
|
|
982 INIT_SSC( GPCMD_REPORT_KEY, 8 );
|
|
983
|
|
984 ssc.CDBByte[ 10 ] = DVD_REPORT_ASF;
|
|
985
|
|
986 i_ret = WinSendSSC( i_fd, &ssc );
|
|
987
|
|
988 *pi_asf = p_buffer[ 7 ] & 1;
|
|
989 }
|
|
990
|
|
991 #elif defined( __QNXNTO__ )
|
|
992
|
|
993 INIT_CPT( GPCMD_REPORT_KEY, 8 );
|
|
994
|
|
995 p_cpt->cam_cdb[ 10 ] = DVD_REPORT_ASF;
|
|
996
|
|
997 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
998
|
|
999 *pi_asf = p_buffer[ 7 ] & 1;
|
|
1000
|
|
1001 #elif defined( SYS_OS2 )
|
|
1002 INIT_SSC( GPCMD_REPORT_KEY, 8 );
|
|
1003
|
|
1004 sdc.command[ 10 ] = DVD_REPORT_ASF;
|
|
1005
|
|
1006 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
1007 &sdc, sizeof(sdc), &ulParamLen,
|
|
1008 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
1009
|
|
1010 *pi_asf = p_buffer[ 7 ] & 1;
|
|
1011
|
|
1012 #else
|
|
1013 # error "DVD ioctls are unavailable on this system"
|
|
1014
|
|
1015 #endif
|
|
1016 return i_ret;
|
|
1017 }
|
|
1018
|
|
1019 /*****************************************************************************
|
|
1020 * ioctl_ReportKey1: get the first key from the drive
|
|
1021 *****************************************************************************/
|
|
1022 int ioctl_ReportKey1( int i_fd, int *pi_agid, u8 *p_key )
|
|
1023 {
|
|
1024 int i_ret;
|
|
1025
|
|
1026 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
1027 dvd_authinfo auth_info;
|
|
1028
|
|
1029 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1030 auth_info.type = DVD_LU_SEND_KEY1;
|
|
1031 auth_info.lsk.agid = *pi_agid;
|
|
1032
|
|
1033 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
1034
|
|
1035 memcpy( p_key, auth_info.lsk.key, DVD_KEY_SIZE );
|
|
1036
|
|
1037 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
1038 struct dvd_authinfo auth_info;
|
|
1039
|
|
1040 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1041 auth_info.format = DVD_REPORT_KEY1;
|
|
1042 auth_info.agid = *pi_agid;
|
|
1043
|
|
1044 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
1045
|
|
1046 memcpy( p_key, auth_info.keychal, DVD_KEY_SIZE );
|
|
1047
|
|
1048 #elif defined( SYS_BEOS )
|
|
1049 INIT_RDC( GPCMD_REPORT_KEY, 12 );
|
|
1050
|
|
1051 rdc.command[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
|
|
1052
|
|
1053 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
1054
|
|
1055 memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
|
|
1056
|
|
1057 #elif defined( HPUX_SCTL_IO )
|
|
1058 INIT_SCTL_IO( GPCMD_REPORT_KEY, 12 );
|
|
1059
|
|
1060 sctl_io.cdb[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
|
|
1061
|
|
1062 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
1063
|
|
1064 memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
|
|
1065
|
|
1066 #elif defined( SOLARIS_USCSI )
|
|
1067 INIT_USCSI( GPCMD_REPORT_KEY, 12 );
|
|
1068
|
|
1069 rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
|
|
1070
|
8575
|
1071 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
1072
|
|
1073 if( i_ret < 0 || sc.uscsi_status )
|
|
1074 {
|
|
1075 i_ret = -1;
|
|
1076 }
|
|
1077
|
|
1078 memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
|
|
1079
|
|
1080 #elif defined( DARWIN_DVD_IOCTL )
|
|
1081 INIT_DVDIOCTL( dk_dvd_report_key_t, DVDKey1Info,
|
|
1082 kDVDKeyFormatKey1 );
|
|
1083
|
|
1084 dvd.grantID = *pi_agid;
|
|
1085
|
|
1086 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
|
|
1087
|
|
1088 memcpy( p_key, dvdbs.key1Value, DVD_KEY_SIZE );
|
|
1089
|
|
1090 #elif defined( WIN32 )
|
|
1091 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
1092 {
|
|
1093 DWORD tmp;
|
|
1094 u8 buffer[DVD_BUS_KEY_LENGTH];
|
|
1095 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
1096
|
|
1097 memset( &buffer, 0, sizeof( buffer ) );
|
|
1098
|
|
1099 key->KeyLength = DVD_BUS_KEY_LENGTH;
|
|
1100 key->SessionId = *pi_agid;
|
|
1101 key->KeyType = DvdBusKey1;
|
|
1102 key->KeyFlags = 0;
|
|
1103
|
|
1104 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
|
|
1105 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
1106
|
|
1107 memcpy( p_key, key->KeyData, DVD_KEY_SIZE );
|
|
1108 }
|
|
1109 else
|
|
1110 {
|
|
1111 INIT_SSC( GPCMD_REPORT_KEY, 12 );
|
|
1112
|
|
1113 ssc.CDBByte[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
|
|
1114
|
|
1115 i_ret = WinSendSSC( i_fd, &ssc );
|
|
1116
|
|
1117 memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
|
|
1118 }
|
|
1119
|
|
1120 #elif defined( __QNXNTO__ )
|
|
1121
|
|
1122 INIT_CPT( GPCMD_REPORT_KEY, 12 );
|
|
1123
|
|
1124 p_cpt->cam_cdb[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
|
|
1125
|
|
1126 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
1127
|
|
1128 memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
|
|
1129
|
|
1130 #elif defined( SYS_OS2 )
|
|
1131 INIT_SSC( GPCMD_REPORT_KEY, 12 );
|
|
1132
|
|
1133 sdc.command[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
|
|
1134
|
|
1135 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
1136 &sdc, sizeof(sdc), &ulParamLen,
|
|
1137 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
1138
|
|
1139 memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
|
|
1140
|
|
1141 #else
|
|
1142 # error "DVD ioctls are unavailable on this system"
|
|
1143
|
|
1144 #endif
|
|
1145 return i_ret;
|
|
1146 }
|
|
1147
|
|
1148 /*****************************************************************************
|
|
1149 * ioctl_InvalidateAgid: invalidate the current AGID
|
|
1150 *****************************************************************************/
|
|
1151 int ioctl_InvalidateAgid( int i_fd, int *pi_agid )
|
|
1152 {
|
|
1153 int i_ret;
|
|
1154
|
|
1155 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
1156 dvd_authinfo auth_info;
|
|
1157
|
|
1158 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1159 auth_info.type = DVD_INVALIDATE_AGID;
|
|
1160 auth_info.lsa.agid = *pi_agid;
|
|
1161
|
|
1162 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
1163
|
|
1164 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
1165 struct dvd_authinfo auth_info;
|
|
1166
|
|
1167 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1168 auth_info.format = DVD_INVALIDATE_AGID;
|
|
1169 auth_info.agid = *pi_agid;
|
|
1170
|
|
1171 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
1172
|
|
1173 #elif defined( SYS_BEOS )
|
|
1174 INIT_RDC( GPCMD_REPORT_KEY, 0 );
|
|
1175
|
|
1176 rdc.command[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
|
|
1177
|
|
1178 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
1179
|
|
1180 #elif defined( HPUX_SCTL_IO )
|
|
1181 INIT_SCTL_IO( GPCMD_REPORT_KEY, 0 );
|
|
1182
|
|
1183 sctl_io.cdb[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
|
|
1184
|
|
1185 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
1186
|
|
1187 #elif defined( SOLARIS_USCSI )
|
|
1188 INIT_USCSI( GPCMD_REPORT_KEY, 0 );
|
|
1189
|
|
1190 rs_cdb.cdb_opaque[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
|
|
1191
|
8575
|
1192 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
1193
|
|
1194 if( i_ret < 0 || sc.uscsi_status )
|
|
1195 {
|
|
1196 i_ret = -1;
|
|
1197 }
|
|
1198
|
|
1199 #elif defined( DARWIN_DVD_IOCTL )
|
|
1200 INIT_DVDIOCTL( dk_dvd_send_key_t, DVDAuthenticationGrantIDInfo,
|
|
1201 kDVDKeyFormatAGID_Invalidate );
|
|
1202
|
|
1203 dvd.grantID = *pi_agid;
|
|
1204
|
|
1205 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
|
|
1206
|
|
1207 #elif defined( WIN32 )
|
|
1208 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
1209 {
|
|
1210 DWORD tmp;
|
|
1211
|
|
1212 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_END_SESSION,
|
|
1213 pi_agid, sizeof( *pi_agid ), NULL, 0, &tmp, NULL ) ? 0 : -1;
|
|
1214 }
|
|
1215 else
|
|
1216 {
|
|
1217 #if defined( __MINGW32__ )
|
|
1218 INIT_SSC( GPCMD_REPORT_KEY, 0 );
|
|
1219 #else
|
|
1220 INIT_SSC( GPCMD_REPORT_KEY, 1 );
|
|
1221
|
|
1222 ssc.SRB_BufLen = 0;
|
|
1223 ssc.CDBByte[ 8 ] = 0;
|
|
1224 ssc.CDBByte[ 9 ] = 0;
|
|
1225 #endif
|
|
1226
|
|
1227 ssc.CDBByte[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
|
|
1228
|
|
1229 i_ret = WinSendSSC( i_fd, &ssc );
|
|
1230 }
|
|
1231
|
|
1232 #elif defined( __QNXNTO__ )
|
|
1233
|
|
1234 INIT_CPT( GPCMD_REPORT_KEY, 0 );
|
|
1235
|
|
1236 p_cpt->cam_cdb[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
|
|
1237
|
|
1238 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
1239
|
|
1240 #elif defined( SYS_OS2 )
|
|
1241 INIT_SSC( GPCMD_REPORT_KEY, 1 );
|
|
1242
|
|
1243 sdc.data_length = 0;
|
|
1244 sdc.command[ 8 ] = 0;
|
|
1245 sdc.command[ 9 ] = 0;
|
|
1246
|
|
1247 sdc.command[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
|
|
1248
|
|
1249 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
1250 &sdc, sizeof(sdc), &ulParamLen,
|
|
1251 NULL, 0, &ulDataLen);
|
|
1252 #else
|
|
1253 # error "DVD ioctls are unavailable on this system"
|
|
1254
|
|
1255 #endif
|
|
1256 return i_ret;
|
|
1257 }
|
|
1258
|
|
1259 /*****************************************************************************
|
|
1260 * ioctl_SendChallenge: send challenge to the drive
|
|
1261 *****************************************************************************/
|
|
1262 int ioctl_SendChallenge( int i_fd, int *pi_agid, u8 *p_challenge )
|
|
1263 {
|
|
1264 int i_ret;
|
|
1265
|
|
1266 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
1267 dvd_authinfo auth_info;
|
|
1268
|
|
1269 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1270 auth_info.type = DVD_HOST_SEND_CHALLENGE;
|
|
1271 auth_info.hsc.agid = *pi_agid;
|
|
1272
|
|
1273 memcpy( auth_info.hsc.chal, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1274
|
|
1275 return ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
1276
|
|
1277 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
1278 struct dvd_authinfo auth_info;
|
|
1279
|
|
1280 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1281 auth_info.format = DVD_SEND_CHALLENGE;
|
|
1282 auth_info.agid = *pi_agid;
|
|
1283
|
|
1284 memcpy( auth_info.keychal, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1285
|
|
1286 return ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
|
|
1287
|
|
1288 #elif defined( SYS_BEOS )
|
|
1289 INIT_RDC( GPCMD_SEND_KEY, 16 );
|
|
1290
|
|
1291 rdc.command[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
|
|
1292
|
|
1293 p_buffer[ 1 ] = 0xe;
|
|
1294 memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1295
|
|
1296 return ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
1297
|
|
1298 #elif defined( HPUX_SCTL_IO )
|
|
1299 INIT_SCTL_IO( GPCMD_SEND_KEY, 16 );
|
|
1300
|
|
1301 sctl_io.cdb[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
|
|
1302
|
|
1303 p_buffer[ 1 ] = 0xe;
|
|
1304 memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1305
|
|
1306 return ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
1307
|
|
1308 #elif defined( SOLARIS_USCSI )
|
|
1309 INIT_USCSI( GPCMD_SEND_KEY, 16 );
|
|
1310
|
|
1311 rs_cdb.cdb_opaque[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
|
|
1312
|
|
1313 p_buffer[ 1 ] = 0xe;
|
|
1314 memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1315
|
8575
|
1316 if( SolarisSendUSCSI( i_fd, &sc ) < 0 || sc.uscsi_status )
|
7027
|
1317 {
|
|
1318 return -1;
|
|
1319 }
|
|
1320
|
|
1321 return 0;
|
|
1322
|
|
1323 #elif defined( DARWIN_DVD_IOCTL )
|
|
1324 INIT_DVDIOCTL( dk_dvd_send_key_t, DVDChallengeKeyInfo,
|
|
1325 kDVDKeyFormatChallengeKey );
|
|
1326
|
|
1327 dvd.grantID = *pi_agid;
|
|
1328 dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
|
|
1329
|
|
1330 dvdbs.dataLength[ 1 ] = 0xe;
|
|
1331 memcpy( dvdbs.challengeKeyValue, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1332
|
|
1333 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
|
|
1334
|
|
1335 #elif defined( WIN32 )
|
|
1336 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
1337 {
|
|
1338 DWORD tmp;
|
|
1339 u8 buffer[DVD_CHALLENGE_KEY_LENGTH];
|
|
1340 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
1341
|
|
1342 memset( &buffer, 0, sizeof( buffer ) );
|
|
1343
|
|
1344 key->KeyLength = DVD_CHALLENGE_KEY_LENGTH;
|
|
1345 key->SessionId = *pi_agid;
|
|
1346 key->KeyType = DvdChallengeKey;
|
|
1347 key->KeyFlags = 0;
|
|
1348
|
|
1349 memcpy( key->KeyData, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1350
|
|
1351 return DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_SEND_KEY, key,
|
|
1352 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
1353 }
|
|
1354 else
|
|
1355 {
|
|
1356 INIT_SSC( GPCMD_SEND_KEY, 16 );
|
|
1357
|
|
1358 ssc.CDBByte[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
|
|
1359
|
|
1360 p_buffer[ 1 ] = 0xe;
|
|
1361 memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1362
|
|
1363 return WinSendSSC( i_fd, &ssc );
|
|
1364 }
|
|
1365
|
|
1366 #elif defined( __QNXNTO__ )
|
|
1367
|
|
1368 INIT_CPT( GPCMD_SEND_KEY, 16 );
|
|
1369
|
|
1370 p_cpt->cam_cdb[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
|
|
1371
|
|
1372 p_buffer[ 1 ] = 0xe;
|
|
1373 memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1374
|
|
1375 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
1376
|
|
1377 #elif defined( SYS_OS2 )
|
|
1378 INIT_SSC( GPCMD_SEND_KEY, 16 );
|
|
1379
|
|
1380 sdc.command[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
|
|
1381
|
|
1382 p_buffer[ 1 ] = 0xe;
|
|
1383 memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
|
|
1384
|
|
1385 return DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
1386 &sdc, sizeof(sdc), &ulParamLen,
|
|
1387 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
1388
|
|
1389 #else
|
|
1390 # error "DVD ioctls are unavailable on this system"
|
|
1391
|
|
1392 #endif
|
|
1393 return i_ret;
|
|
1394 }
|
|
1395
|
|
1396 /*****************************************************************************
|
|
1397 * ioctl_SendKey2: send the second key to the drive
|
|
1398 *****************************************************************************/
|
|
1399 int ioctl_SendKey2( int i_fd, int *pi_agid, u8 *p_key )
|
|
1400 {
|
|
1401 int i_ret;
|
|
1402
|
|
1403 #if defined( HAVE_LINUX_DVD_STRUCT )
|
|
1404 dvd_authinfo auth_info;
|
|
1405
|
|
1406 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1407 auth_info.type = DVD_HOST_SEND_KEY2;
|
|
1408 auth_info.hsk.agid = *pi_agid;
|
|
1409
|
|
1410 memcpy( auth_info.hsk.key, p_key, DVD_KEY_SIZE );
|
|
1411
|
|
1412 return ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
1413
|
|
1414 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
1415 struct dvd_authinfo auth_info;
|
|
1416
|
|
1417 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1418 auth_info.format = DVD_SEND_KEY2;
|
|
1419 auth_info.agid = *pi_agid;
|
|
1420
|
|
1421 memcpy( auth_info.keychal, p_key, DVD_KEY_SIZE );
|
|
1422
|
|
1423 return ioctl( i_fd, DVDIOCSENDKEY, &auth_info );
|
|
1424
|
|
1425 #elif defined( SYS_BEOS )
|
|
1426 INIT_RDC( GPCMD_SEND_KEY, 12 );
|
|
1427
|
|
1428 rdc.command[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
|
|
1429
|
|
1430 p_buffer[ 1 ] = 0xa;
|
|
1431 memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
|
|
1432
|
|
1433 return ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
1434
|
|
1435 #elif defined( HPUX_SCTL_IO )
|
|
1436 INIT_SCTL_IO( GPCMD_SEND_KEY, 12 );
|
|
1437
|
|
1438 sctl_io.cdb[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
|
|
1439
|
|
1440 p_buffer[ 1 ] = 0xa;
|
|
1441 memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
|
|
1442
|
|
1443 return ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
1444
|
|
1445 #elif defined( SOLARIS_USCSI )
|
|
1446 INIT_USCSI( GPCMD_SEND_KEY, 12 );
|
|
1447
|
|
1448 rs_cdb.cdb_opaque[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
|
|
1449
|
|
1450 p_buffer[ 1 ] = 0xa;
|
|
1451 memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
|
|
1452
|
8575
|
1453 if( SolarisSendUSCSI( i_fd, &sc ) < 0 || sc.uscsi_status )
|
7027
|
1454 {
|
|
1455 return -1;
|
|
1456 }
|
|
1457
|
|
1458 return 0;
|
|
1459
|
|
1460 #elif defined( DARWIN_DVD_IOCTL )
|
|
1461 INIT_DVDIOCTL( dk_dvd_send_key_t, DVDKey2Info,
|
|
1462 kDVDKeyFormatKey2 );
|
|
1463
|
|
1464 dvd.grantID = *pi_agid;
|
|
1465 dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
|
|
1466
|
|
1467 dvdbs.dataLength[ 1 ] = 0xa;
|
|
1468 memcpy( dvdbs.key2Value, p_key, DVD_KEY_SIZE );
|
|
1469
|
|
1470 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
|
|
1471
|
|
1472 #elif defined( WIN32 )
|
|
1473 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
1474 {
|
|
1475 DWORD tmp;
|
|
1476 u8 buffer[DVD_BUS_KEY_LENGTH];
|
|
1477 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
|
|
1478
|
|
1479 memset( &buffer, 0, sizeof( buffer ) );
|
|
1480
|
|
1481 key->KeyLength = DVD_BUS_KEY_LENGTH;
|
|
1482 key->SessionId = *pi_agid;
|
|
1483 key->KeyType = DvdBusKey2;
|
|
1484 key->KeyFlags = 0;
|
|
1485
|
|
1486 memcpy( key->KeyData, p_key, DVD_KEY_SIZE );
|
|
1487
|
|
1488 return DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_SEND_KEY, key,
|
|
1489 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
|
|
1490 }
|
|
1491 else
|
|
1492 {
|
|
1493 INIT_SSC( GPCMD_SEND_KEY, 12 );
|
|
1494
|
|
1495 ssc.CDBByte[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
|
|
1496
|
|
1497 p_buffer[ 1 ] = 0xa;
|
|
1498 memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
|
|
1499
|
|
1500 return WinSendSSC( i_fd, &ssc );
|
|
1501 }
|
|
1502
|
|
1503 #elif defined( __QNXNTO__ )
|
|
1504
|
|
1505 INIT_CPT( GPCMD_SEND_KEY, 12 );
|
|
1506
|
|
1507 p_cpt->cam_cdb[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
|
|
1508
|
|
1509 p_buffer[ 1 ] = 0xa;
|
|
1510 memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
|
|
1511
|
|
1512 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
1513
|
|
1514 #elif defined( SYS_OS2 )
|
|
1515 INIT_SSC( GPCMD_SEND_KEY, 12 );
|
|
1516
|
|
1517 sdc.command[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
|
|
1518
|
|
1519 p_buffer[ 1 ] = 0xa;
|
|
1520 memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
|
|
1521
|
|
1522 return DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
1523 &sdc, sizeof(sdc), &ulParamLen,
|
|
1524 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
1525
|
|
1526 #else
|
|
1527 # error "DVD ioctls are unavailable on this system"
|
|
1528
|
|
1529 #endif
|
|
1530 return i_ret;
|
|
1531 }
|
|
1532
|
|
1533 /*****************************************************************************
|
|
1534 * ioctl_ReportRPC: get RPC status for the drive
|
|
1535 *****************************************************************************/
|
|
1536 int ioctl_ReportRPC( int i_fd, int *p_type, int *p_mask, int *p_scheme )
|
|
1537 {
|
|
1538 int i_ret;
|
|
1539
|
|
1540 #if defined( HAVE_LINUX_DVD_STRUCT ) && defined( DVD_LU_SEND_RPC_STATE )
|
|
1541 dvd_authinfo auth_info;
|
|
1542
|
|
1543 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1544 auth_info.type = DVD_LU_SEND_RPC_STATE;
|
|
1545
|
|
1546 i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
|
|
1547
|
|
1548 *p_type = auth_info.lrpcs.type;
|
|
1549 *p_mask = auth_info.lrpcs.region_mask;
|
|
1550 *p_scheme = auth_info.lrpcs.rpc_scheme;
|
|
1551
|
|
1552 #elif defined( HAVE_LINUX_DVD_STRUCT )
|
|
1553 /* FIXME: OpenBSD doesn't know this */
|
|
1554 i_ret = -1;
|
|
1555
|
|
1556 #elif defined( HAVE_BSD_DVD_STRUCT )
|
|
1557 struct dvd_authinfo auth_info;
|
|
1558
|
|
1559 memset( &auth_info, 0, sizeof( auth_info ) );
|
|
1560 auth_info.format = DVD_REPORT_RPC;
|
|
1561
|
|
1562 i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
|
|
1563
|
|
1564 *p_type = auth_info.reg_type;
|
|
1565 *p_mask = auth_info.region; // ??
|
|
1566 *p_scheme = auth_info.rpc_scheme;
|
|
1567
|
|
1568 #elif defined( SYS_BEOS )
|
|
1569 INIT_RDC( GPCMD_REPORT_KEY, 8 );
|
|
1570
|
|
1571 rdc.command[ 10 ] = DVD_REPORT_RPC;
|
|
1572
|
|
1573 i_ret = ioctl( i_fd, B_RAW_DEVICE_COMMAND, &rdc, sizeof(rdc) );
|
|
1574
|
|
1575 *p_type = p_buffer[ 4 ] >> 6;
|
|
1576 *p_mask = p_buffer[ 5 ];
|
|
1577 *p_scheme = p_buffer[ 6 ];
|
|
1578
|
|
1579 #elif defined( HPUX_SCTL_IO )
|
|
1580 INIT_SCTL_IO( GPCMD_REPORT_KEY, 8 );
|
|
1581
|
|
1582 sctl_io.cdb[ 10 ] = DVD_REPORT_RPC;
|
|
1583
|
|
1584 i_ret = ioctl( i_fd, SIOC_IO, &sctl_io );
|
|
1585
|
|
1586 *p_type = p_buffer[ 4 ] >> 6;
|
|
1587 *p_mask = p_buffer[ 5 ];
|
|
1588 *p_scheme = p_buffer[ 6 ];
|
|
1589
|
|
1590 #elif defined( SOLARIS_USCSI )
|
|
1591 INIT_USCSI( GPCMD_REPORT_KEY, 8 );
|
|
1592
|
|
1593 rs_cdb.cdb_opaque[ 10 ] = DVD_REPORT_RPC;
|
|
1594
|
8575
|
1595 i_ret = SolarisSendUSCSI( i_fd, &sc );
|
7027
|
1596
|
|
1597 if( i_ret < 0 || sc.uscsi_status )
|
|
1598 {
|
|
1599 i_ret = -1;
|
|
1600 }
|
|
1601
|
|
1602 *p_type = p_buffer[ 4 ] >> 6;
|
|
1603 *p_mask = p_buffer[ 5 ];
|
|
1604 *p_scheme = p_buffer[ 6 ];
|
|
1605
|
|
1606 #elif defined( DARWIN_DVD_IOCTL )
|
|
1607 INIT_DVDIOCTL( dk_dvd_report_key_t, DVDRegionPlaybackControlInfo,
|
|
1608 kDVDKeyFormatRegionState );
|
|
1609
|
|
1610 dvd.keyClass = kDVDKeyClassCSS_CPPM_CPRM;
|
|
1611
|
|
1612 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
|
|
1613
|
|
1614 *p_type = dvdbs.typeCode;
|
|
1615 *p_mask = dvdbs.driveRegion;
|
|
1616 *p_scheme = dvdbs.rpcScheme;
|
|
1617
|
|
1618 #elif defined( WIN32 )
|
|
1619 if( WIN2K ) /* NT/Win2000/Whistler */
|
|
1620 {
|
|
1621 DWORD tmp;
|
|
1622 u8 buffer[ DVD_REGION_LENGTH ];
|
|
1623 PDVD_REGION region = (PDVD_REGION) &buffer;
|
|
1624
|
|
1625 memset( &buffer, 0, sizeof( buffer ) );
|
|
1626
|
|
1627 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_GET_REGION, NULL, 0,
|
|
1628 region, DVD_REGION_LENGTH, &tmp, NULL ) ? 0 : -1;
|
|
1629
|
|
1630 /* Someone who has the headers should correct all this. */
|
|
1631 /* Use the IOCTL_SCSI_PASS_THROUGH_DIRECT so we get the real
|
|
1632 * values of theses entities? */
|
|
1633 if(region->SystemRegion != 0) {
|
|
1634 *p_type = region->ResetCount > 1 ? 1 : 3 - region->ResetCount;
|
|
1635 *p_mask = 0xff ^ (1 << (region->SystemRegion - 1));
|
|
1636 *p_scheme = 1;
|
|
1637 }
|
|
1638 else
|
|
1639 {
|
|
1640 *p_type = 0; /* ?? */
|
|
1641 *p_mask = 0xff;
|
|
1642 *p_scheme = 1; /* ?? */
|
|
1643 }
|
|
1644 }
|
|
1645 else
|
|
1646 {
|
|
1647 INIT_SSC( GPCMD_REPORT_KEY, 8 );
|
|
1648
|
|
1649 ssc.CDBByte[ 10 ] = DVD_REPORT_RPC;
|
|
1650
|
|
1651 i_ret = WinSendSSC( i_fd, &ssc );
|
|
1652
|
|
1653 *p_type = p_buffer[ 4 ] >> 6;
|
|
1654 *p_mask = p_buffer[ 5 ];
|
|
1655 *p_scheme = p_buffer[ 6 ];
|
|
1656 }
|
|
1657
|
|
1658 #elif defined( __QNXNTO__ )
|
|
1659
|
|
1660 INIT_CPT( GPCMD_REPORT_KEY, 8 );
|
|
1661
|
|
1662 p_cpt->cam_cdb[ 10 ] = DVD_REPORT_RPC;
|
|
1663
|
|
1664 i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
|
|
1665
|
|
1666 *p_type = p_buffer[ 4 ] >> 6;
|
|
1667 *p_mask = p_buffer[ 5 ];
|
|
1668 *p_scheme = p_buffer[ 6 ];
|
|
1669
|
|
1670 #elif defined( SYS_OS2 )
|
|
1671 INIT_SSC( GPCMD_REPORT_KEY, 8 );
|
|
1672
|
|
1673 sdc.command[ 10 ] = DVD_REPORT_RPC;
|
|
1674
|
|
1675 i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
|
|
1676 &sdc, sizeof(sdc), &ulParamLen,
|
|
1677 p_buffer, sizeof(p_buffer), &ulDataLen);
|
|
1678
|
|
1679 *p_type = p_buffer[ 4 ] >> 6;
|
|
1680 *p_mask = p_buffer[ 5 ];
|
|
1681 *p_scheme = p_buffer[ 6 ];
|
|
1682
|
|
1683 #else
|
|
1684 # error "DVD ioctls are unavailable on this system"
|
|
1685
|
|
1686 #endif
|
|
1687 return i_ret;
|
|
1688 }
|
|
1689
|
|
1690 /* Local prototypes */
|
|
1691
|
|
1692 #if defined( SYS_BEOS )
|
|
1693 /*****************************************************************************
|
|
1694 * BeInitRDC: initialize a RDC structure for the BeOS kernel
|
|
1695 *****************************************************************************
|
|
1696 * This function initializes a BeOS raw device command structure for future
|
|
1697 * use, either a read command or a write command.
|
|
1698 *****************************************************************************/
|
|
1699 static void BeInitRDC( raw_device_command *p_rdc, int i_type )
|
|
1700 {
|
|
1701 memset( p_rdc->data, 0, p_rdc->data_length );
|
|
1702
|
|
1703 switch( i_type )
|
|
1704 {
|
|
1705 case GPCMD_SEND_KEY:
|
|
1706 /* leave the flags to 0 */
|
|
1707 break;
|
|
1708
|
|
1709 case GPCMD_READ_DVD_STRUCTURE: case GPCMD_REPORT_KEY:
|
|
1710 p_rdc->flags = B_RAW_DEVICE_DATA_IN; break; }
|
|
1711
|
|
1712 p_rdc->command[ 0 ] = i_type;
|
|
1713
|
|
1714 p_rdc->command[ 8 ] = (p_rdc->data_length >> 8) & 0xff;
|
|
1715 p_rdc->command[ 9 ] = p_rdc->data_length & 0xff;
|
|
1716 p_rdc->command_length = 12;
|
|
1717
|
|
1718 p_rdc->sense_data = NULL;
|
|
1719 p_rdc->sense_data_length = 0;
|
|
1720
|
|
1721 p_rdc->timeout = 1000000;
|
|
1722 }
|
|
1723 #endif
|
|
1724
|
|
1725 #if defined( HPUX_SCTL_IO )
|
|
1726 /*****************************************************************************
|
|
1727 * HPUXInitSCTL: initialize a sctl_io structure for the HP-UX kernel
|
|
1728 *****************************************************************************
|
|
1729 * This function initializes a HP-UX command structure for future
|
|
1730 * use, either a read command or a write command.
|
|
1731 *****************************************************************************/
|
|
1732 static void HPUXInitSCTL( struct sctl_io *sctl_io, int i_type )
|
|
1733 {
|
|
1734 memset( sctl_io->data, 0, sctl_io->data_length );
|
|
1735
|
|
1736 switch( i_type )
|
|
1737 {
|
|
1738 case GPCMD_SEND_KEY:
|
|
1739 /* leave the flags to 0 */
|
|
1740 break;
|
|
1741
|
|
1742 case GPCMD_READ_DVD_STRUCTURE:
|
|
1743 case GPCMD_REPORT_KEY:
|
|
1744 sctl_io->flags = SCTL_READ;
|
|
1745 break;
|
|
1746 }
|
|
1747
|
|
1748 sctl_io->cdb[ 0 ] = i_type;
|
|
1749
|
|
1750 sctl_io->cdb[ 8 ] = (sctl_io->data_length >> 8) & 0xff;
|
|
1751 sctl_io->cdb[ 9 ] = sctl_io->data_length & 0xff;
|
|
1752 sctl_io->cdb_length = 12;
|
|
1753
|
|
1754 sctl_io->max_msecs = 1000000;
|
|
1755 }
|
|
1756 #endif
|
|
1757
|
|
1758 #if defined( SOLARIS_USCSI )
|
|
1759 /*****************************************************************************
|
|
1760 * SolarisInitUSCSI: initialize a USCSICMD structure for the Solaris kernel
|
|
1761 *****************************************************************************
|
|
1762 * This function initializes a Solaris userspace scsi command structure for
|
|
1763 * future use, either a read command or a write command.
|
|
1764 *****************************************************************************/
|
|
1765 static void SolarisInitUSCSI( struct uscsi_cmd *p_sc, int i_type )
|
|
1766 {
|
|
1767 union scsi_cdb *rs_cdb;
|
|
1768 memset( p_sc->uscsi_cdb, 0, sizeof( union scsi_cdb ) );
|
|
1769 memset( p_sc->uscsi_bufaddr, 0, p_sc->uscsi_buflen );
|
|
1770
|
|
1771 switch( i_type )
|
|
1772 {
|
|
1773 case GPCMD_SEND_KEY:
|
|
1774 p_sc->uscsi_flags = USCSI_ISOLATE | USCSI_WRITE;
|
|
1775 break;
|
|
1776
|
|
1777 case GPCMD_READ_DVD_STRUCTURE:
|
|
1778 case GPCMD_REPORT_KEY:
|
|
1779 p_sc->uscsi_flags = USCSI_ISOLATE | USCSI_READ;
|
|
1780 break;
|
|
1781 }
|
|
1782
|
|
1783 rs_cdb = (union scsi_cdb *)p_sc->uscsi_cdb;
|
|
1784
|
|
1785 rs_cdb->scc_cmd = i_type;
|
|
1786
|
|
1787 rs_cdb->cdb_opaque[ 8 ] = (p_sc->uscsi_buflen >> 8) & 0xff;
|
|
1788 rs_cdb->cdb_opaque[ 9 ] = p_sc->uscsi_buflen & 0xff;
|
|
1789 p_sc->uscsi_cdblen = 12;
|
|
1790
|
|
1791 USCSI_TIMEOUT( p_sc, 15 );
|
|
1792 }
|
8575
|
1793
|
|
1794 /*****************************************************************************
|
|
1795 * SolarisSendUSCSI: send a USCSICMD structure to the Solaris kernel
|
|
1796 * for execution
|
|
1797 *****************************************************************************
|
|
1798 * When available, this function uses the function smedia_uscsi_cmd()
|
|
1799 * from solaris' libsmedia library (solaris 9 or newer) to execute the
|
|
1800 * USCSI command. smedia_uscsi_cmd() allows USCSI commands for
|
|
1801 * non-root users on removable media devices on solaris 9; sending the
|
|
1802 * USCSI command directly to the device using the USCSICMD ioctl fails
|
|
1803 * with an EPERM error on solaris 9.
|
|
1804 *
|
|
1805 * The code will fall back to the USCSICMD ioctl method, when
|
|
1806 * libsmedia.so is not available or does not export the
|
|
1807 * smedia_uscsi_cmd() function (on solaris releases upto and including
|
|
1808 * solaris 8). Fortunatelly, on these old releases non-root users are
|
|
1809 * allowed to perform USCSICMD ioctls on removable media devices.
|
|
1810 *****************************************************************************/
|
|
1811 static int SolarisSendUSCSI( int i_fd, struct uscsi_cmd *p_sc ) {
|
|
1812 void *sm_hdl;
|
|
1813 static int initialized;
|
|
1814 static void* (*sm_get_handle)(int32_t);
|
|
1815 static int (*sm_release_handle)(void*);
|
|
1816 static int (*sm_uscsi_cmd)(void*, struct uscsi_cmd *);
|
|
1817
|
|
1818 if (!initialized)
|
|
1819 {
|
|
1820 void *smedia_lib;
|
|
1821
|
|
1822 smedia_lib = dlopen("libsmedia.so", RTLD_NOW);
|
|
1823 if (smedia_lib) {
|
|
1824 sm_get_handle = dlsym(smedia_lib, "smedia_get_handle");
|
|
1825 sm_release_handle = dlsym(smedia_lib, "smedia_release_handle");
|
|
1826 sm_uscsi_cmd = dlsym(smedia_lib, "smedia_uscsi_cmd");
|
|
1827 }
|
|
1828 initialized = 1;
|
|
1829 }
|
|
1830
|
|
1831 if (sm_get_handle && sm_uscsi_cmd && sm_release_handle
|
|
1832 && (sm_hdl = sm_get_handle(i_fd)))
|
|
1833 {
|
|
1834 int i_ret = sm_uscsi_cmd(sm_hdl, p_sc);
|
|
1835 sm_release_handle(sm_hdl);
|
|
1836 return i_ret;
|
|
1837 }
|
|
1838
|
|
1839 return ioctl( i_fd, USCSICMD, p_sc );
|
|
1840 }
|
7027
|
1841 #endif
|
|
1842
|
|
1843 #if defined( WIN32 )
|
|
1844 /*****************************************************************************
|
|
1845 * WinInitSSC: initialize a ssc structure for the win32 aspi layer
|
|
1846 *****************************************************************************
|
|
1847 * This function initializes a ssc raw device command structure for future
|
|
1848 * use, either a read command or a write command.
|
|
1849 *****************************************************************************/
|
|
1850 static void WinInitSSC( struct SRB_ExecSCSICmd *p_ssc, int i_type )
|
|
1851 {
|
|
1852 memset( p_ssc->SRB_BufPointer, 0, p_ssc->SRB_BufLen );
|
|
1853
|
|
1854 switch( i_type )
|
|
1855 {
|
|
1856 case GPCMD_SEND_KEY:
|
|
1857 p_ssc->SRB_Flags = SRB_DIR_OUT;
|
|
1858 break;
|
|
1859
|
|
1860 case GPCMD_READ_DVD_STRUCTURE:
|
|
1861 case GPCMD_REPORT_KEY:
|
|
1862 p_ssc->SRB_Flags = SRB_DIR_IN;
|
|
1863 break;
|
|
1864 }
|
|
1865
|
|
1866 p_ssc->SRB_Cmd = SC_EXEC_SCSI_CMD;
|
|
1867 p_ssc->SRB_Flags |= SRB_EVENT_NOTIFY;
|
|
1868
|
|
1869 p_ssc->CDBByte[ 0 ] = i_type;
|
|
1870
|
|
1871 p_ssc->CDBByte[ 8 ] = (u8)(p_ssc->SRB_BufLen >> 8) & 0xff;
|
|
1872 p_ssc->CDBByte[ 9 ] = (u8) p_ssc->SRB_BufLen & 0xff;
|
|
1873 p_ssc->SRB_CDBLen = 12;
|
|
1874
|
|
1875 p_ssc->SRB_SenseLen = SENSE_LEN;
|
|
1876 }
|
|
1877
|
|
1878 /*****************************************************************************
|
|
1879 * WinSendSSC: send a ssc structure to the aspi layer
|
|
1880 *****************************************************************************/
|
|
1881 static int WinSendSSC( int i_fd, struct SRB_ExecSCSICmd *p_ssc )
|
|
1882 {
|
|
1883 HANDLE hEvent = NULL;
|
|
1884 struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
|
|
1885
|
|
1886 hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
|
|
1887 if( hEvent == NULL )
|
|
1888 {
|
|
1889 return -1;
|
|
1890 }
|
|
1891
|
|
1892 p_ssc->SRB_PostProc = hEvent;
|
|
1893 p_ssc->SRB_HaId = LOBYTE( fd->i_sid );
|
|
1894 p_ssc->SRB_Target = HIBYTE( fd->i_sid );
|
|
1895
|
|
1896 ResetEvent( hEvent );
|
|
1897 if( fd->lpSendCommand( (void*) p_ssc ) == SS_PENDING )
|
|
1898 WaitForSingleObject( hEvent, INFINITE );
|
|
1899
|
|
1900 CloseHandle( hEvent );
|
|
1901
|
|
1902 return p_ssc->SRB_Status == SS_COMP ? 0 : -1;
|
|
1903 }
|
|
1904 #endif
|
|
1905
|
|
1906 #if defined( __QNXNTO__ )
|
|
1907 /*****************************************************************************
|
|
1908 * QNXInitCPT: initialize a ssc structure for the win32 aspi layer
|
|
1909 *****************************************************************************
|
|
1910 * This function initializes a ssc raw device command structure for future
|
|
1911 * use, either a read command or a write command.
|
|
1912 *****************************************************************************/
|
|
1913 static void QNXInitCPT( CAM_PASS_THRU * p_cpt, int i_type )
|
|
1914 {
|
|
1915 switch( i_type )
|
|
1916 {
|
|
1917 case GPCMD_SEND_KEY:
|
|
1918 p_cpt->cam_flags = CAM_DIR_OUT;
|
|
1919 break;
|
|
1920
|
|
1921 case GPCMD_READ_DVD_STRUCTURE:
|
|
1922 case GPCMD_REPORT_KEY:
|
|
1923 p_cpt->cam_flags = CAM_DIR_IN;
|
|
1924 break;
|
|
1925 }
|
|
1926
|
|
1927 p_cpt->cam_cdb[0] = i_type;
|
|
1928
|
|
1929 p_cpt->cam_cdb[ 8 ] = (p_cpt->cam_dxfer_len >> 8) & 0xff;
|
|
1930 p_cpt->cam_cdb[ 9 ] = p_cpt->cam_dxfer_len & 0xff;
|
|
1931 p_cpt->cam_cdb_len = 12;
|
|
1932
|
|
1933 p_cpt->cam_timeout = CAM_TIME_DEFAULT;
|
|
1934 }
|
|
1935 #endif
|
|
1936
|
|
1937 #if defined( SYS_OS2 )
|
|
1938 /*****************************************************************************
|
|
1939 * OS2InitSDC: initialize a SDC structure for the Execute SCSI-command
|
|
1940 *****************************************************************************
|
|
1941 * This function initializes a OS2 'execute SCSI command' structure for
|
|
1942 * future use, either a read command or a write command.
|
|
1943 *****************************************************************************/
|
|
1944 static void OS2InitSDC( struct OS2_ExecSCSICmd *p_sdc, int i_type )
|
|
1945 {
|
|
1946 switch( i_type )
|
|
1947 {
|
|
1948 case GPCMD_SEND_KEY:
|
|
1949 p_sdc->flags = 0;
|
|
1950 break;
|
|
1951
|
|
1952 case GPCMD_READ_DVD_STRUCTURE:
|
|
1953 case GPCMD_REPORT_KEY:
|
|
1954 p_sdc->flags = EX_DIRECTION_IN;
|
|
1955 break;
|
|
1956 }
|
|
1957
|
|
1958 p_sdc->command[ 0 ] = i_type;
|
|
1959 p_sdc->command[ 8 ] = (p_sdc->data_length >> 8) & 0xff;
|
|
1960 p_sdc->command[ 9 ] = p_sdc->data_length & 0xff;
|
|
1961 p_sdc->id_code = 0x31304443; // 'CD01'
|
|
1962 p_sdc->cmd_length = 12;
|
|
1963 }
|
|
1964 #endif
|