comparison libmpdvdkit2/ioctl.c @ 8637:0211de3039eb

update libdvdcss in libmpdvdkit to latest version (1.2.4) patch by Andreas Hess <jaska@gmx.net>
author arpi
date Sun, 29 Dec 2002 15:32:56 +0000
parents 1d15ca298dda
children c932c17042bf
comparison
equal deleted inserted replaced
8636:db4a1b1254cb 8637:0211de3039eb
9 * Jon Lech Johansen <jon-vl@nanocrew.net> 9 * Jon Lech Johansen <jon-vl@nanocrew.net>
10 * Håkan Hjort <d95hjort@dtek.chalmers.se> 10 * Håkan Hjort <d95hjort@dtek.chalmers.se>
11 * Eugenio Jarosiewicz <ej0@cise.ufl.edu> 11 * Eugenio Jarosiewicz <ej0@cise.ufl.edu>
12 * David Siebörger <drs-videolan@rucus.ru.ac.za> 12 * David Siebörger <drs-videolan@rucus.ru.ac.za>
13 * Alex Strelnikov <lelik@os2.ru> 13 * Alex Strelnikov <lelik@os2.ru>
14 * Gildas Bazin <gbazin@netcourrier.com>
14 * 15 *
15 * This program is free software; you can redistribute it and/or modify 16 * 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 * 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 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version. 19 * (at your option) any later version.
212 i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd ); 213 i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
213 214
214 *pi_copyright = dvdbs.copyrightProtectionSystemType; 215 *pi_copyright = dvdbs.copyrightProtectionSystemType;
215 216
216 #elif defined( WIN32 ) 217 #elif defined( WIN32 )
217 if( WIN2K ) /* NT/Win2000/Whistler */ 218 if( WIN2K ) /* NT/2k/XP */
218 { 219 {
219 DWORD tmp; 220 DWORD tmp;
220 u8 p_buffer[ 8 ]; 221 u8 p_buffer[ 8 ];
221 SCSI_PASS_THROUGH_DIRECT sptd; 222 SCSI_PASS_THROUGH_DIRECT sptd;
222 223
224 /* When using IOCTL_DVD_READ_STRUCTURE and
225 DVD_COPYRIGHT_DESCRIPTOR, CopyrightProtectionType
226 seems to be always 6 ???
227 To work around this M$ bug we try to send a raw scsi command
228 instead (if we've got enough privileges to do so). */
229
223 memset( &sptd, 0, sizeof( sptd ) ); 230 memset( &sptd, 0, sizeof( sptd ) );
224 memset( &p_buffer, 0, sizeof( p_buffer ) ); 231 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 232
230 sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT ); 233 sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT );
231 sptd.CdbLength = 12; 234 sptd.CdbLength = 12;
232 sptd.DataIn = SCSI_IOCTL_DATA_IN; 235 sptd.DataIn = SCSI_IOCTL_DATA_IN;
233 sptd.DataTransferLength = 8; 236 sptd.DataTransferLength = 8;
243 IOCTL_SCSI_PASS_THROUGH_DIRECT, 246 IOCTL_SCSI_PASS_THROUGH_DIRECT,
244 &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ), 247 &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
245 &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ), 248 &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
246 &tmp, NULL ) ? 0 : -1; 249 &tmp, NULL ) ? 0 : -1;
247 250
251 if( i_ret == 0 )
252 {
248 *pi_copyright = p_buffer[ 4 ]; 253 *pi_copyright = p_buffer[ 4 ];
254 }
249 } 255 }
250 else 256 else
251 { 257 {
252 INIT_SSC( GPCMD_READ_DVD_STRUCTURE, 8 ); 258 INIT_SSC( GPCMD_READ_DVD_STRUCTURE, 8 );
253 259
385 i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd ); 391 i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
386 392
387 memcpy( p_key, dvdbs.discKeyStructures, DVD_DISCKEY_SIZE ); 393 memcpy( p_key, dvdbs.discKeyStructures, DVD_DISCKEY_SIZE );
388 394
389 #elif defined( WIN32 ) 395 #elif defined( WIN32 )
390 if( WIN2K ) /* NT/Win2000/Whistler */ 396 if( WIN2K ) /* NT/2k/XP */
391 { 397 {
392 DWORD tmp; 398 DWORD tmp;
393 u8 buffer[DVD_DISK_KEY_LENGTH]; 399 u8 buffer[DVD_DISK_KEY_LENGTH];
394 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 400 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
395 401
553 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd ); 559 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
554 560
555 memcpy( p_key, dvdbs.titleKeyValue, DVD_KEY_SIZE ); 561 memcpy( p_key, dvdbs.titleKeyValue, DVD_KEY_SIZE );
556 562
557 #elif defined( WIN32 ) 563 #elif defined( WIN32 )
558 if( WIN2K ) /* NT/Win2000/Whistler */ 564 if( WIN2K ) /* NT/2k/XP */
559 { 565 {
560 DWORD tmp; 566 DWORD tmp;
561 u8 buffer[DVD_BUS_KEY_LENGTH]; 567 u8 buffer[DVD_BUS_KEY_LENGTH];
562 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 568 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
563 569
565 571
566 key->KeyLength = DVD_TITLE_KEY_LENGTH; 572 key->KeyLength = DVD_TITLE_KEY_LENGTH;
567 key->SessionId = *pi_agid; 573 key->SessionId = *pi_agid;
568 key->KeyType = DvdTitleKey; 574 key->KeyType = DvdTitleKey;
569 key->KeyFlags = 0; 575 key->KeyFlags = 0;
570 key->Parameters.TitleOffset.QuadPart = (LONGLONG) i_pos; 576 key->Parameters.TitleOffset.QuadPart = (LONGLONG) i_pos *
577 2048 /*DVDCSS_BLOCK_SIZE*/;
571 578
572 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key, 579 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_READ_KEY, key,
573 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1; 580 key->KeyLength, key, key->KeyLength, &tmp, NULL ) ? 0 : -1;
574 581
575 memcpy( p_key, key->KeyData, DVD_KEY_SIZE ); 582 memcpy( p_key, key->KeyData, DVD_KEY_SIZE );
698 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd ); 705 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
699 706
700 *pi_agid = dvdbs.grantID; 707 *pi_agid = dvdbs.grantID;
701 708
702 #elif defined( WIN32 ) 709 #elif defined( WIN32 )
703 if( WIN2K ) /* NT/Win2000/Whistler */ 710 if( WIN2K ) /* NT/2k/XP */
704 { 711 {
705 ULONG id; 712 ULONG id;
706 DWORD tmp; 713 DWORD tmp;
707 714
708 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_START_SESSION, 715 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_START_SESSION,
819 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd ); 826 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
820 827
821 memcpy( p_challenge, dvdbs.challengeKeyValue, DVD_CHALLENGE_SIZE ); 828 memcpy( p_challenge, dvdbs.challengeKeyValue, DVD_CHALLENGE_SIZE );
822 829
823 #elif defined( WIN32 ) 830 #elif defined( WIN32 )
824 if( WIN2K ) /* NT/Win2000/Whistler */ 831 if( WIN2K ) /* NT/2k/XP */
825 { 832 {
826 DWORD tmp; 833 DWORD tmp;
827 u8 buffer[DVD_CHALLENGE_KEY_LENGTH]; 834 u8 buffer[DVD_CHALLENGE_KEY_LENGTH];
828 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 835 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
829 836
951 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd ); 958 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
952 959
953 *pi_asf = dvdbs.successFlag; 960 *pi_asf = dvdbs.successFlag;
954 961
955 #elif defined( WIN32 ) 962 #elif defined( WIN32 )
956 if( WIN2K ) /* NT/Win2000/Whistler */ 963 if( WIN2K ) /* NT/2k/XP */
957 { 964 {
958 DWORD tmp; 965 DWORD tmp;
959 u8 buffer[DVD_ASF_LENGTH]; 966 u8 buffer[DVD_ASF_LENGTH];
960 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 967 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
961 968
1086 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd ); 1093 i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
1087 1094
1088 memcpy( p_key, dvdbs.key1Value, DVD_KEY_SIZE ); 1095 memcpy( p_key, dvdbs.key1Value, DVD_KEY_SIZE );
1089 1096
1090 #elif defined( WIN32 ) 1097 #elif defined( WIN32 )
1091 if( WIN2K ) /* NT/Win2000/Whistler */ 1098 if( WIN2K ) /* NT/2k/XP */
1092 { 1099 {
1093 DWORD tmp; 1100 DWORD tmp;
1094 u8 buffer[DVD_BUS_KEY_LENGTH]; 1101 u8 buffer[DVD_BUS_KEY_LENGTH];
1095 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 1102 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
1096 1103
1203 dvd.grantID = *pi_agid; 1210 dvd.grantID = *pi_agid;
1204 1211
1205 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd ); 1212 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
1206 1213
1207 #elif defined( WIN32 ) 1214 #elif defined( WIN32 )
1208 if( WIN2K ) /* NT/Win2000/Whistler */ 1215 if( WIN2K ) /* NT/2k/XP */
1209 { 1216 {
1210 DWORD tmp; 1217 DWORD tmp;
1211 1218
1212 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_END_SESSION, 1219 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_END_SESSION,
1213 pi_agid, sizeof( *pi_agid ), NULL, 0, &tmp, NULL ) ? 0 : -1; 1220 pi_agid, sizeof( *pi_agid ), NULL, 0, &tmp, NULL ) ? 0 : -1;
1331 memcpy( dvdbs.challengeKeyValue, p_challenge, DVD_CHALLENGE_SIZE ); 1338 memcpy( dvdbs.challengeKeyValue, p_challenge, DVD_CHALLENGE_SIZE );
1332 1339
1333 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd ); 1340 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
1334 1341
1335 #elif defined( WIN32 ) 1342 #elif defined( WIN32 )
1336 if( WIN2K ) /* NT/Win2000/Whistler */ 1343 if( WIN2K ) /* NT/2k/XP */
1337 { 1344 {
1338 DWORD tmp; 1345 DWORD tmp;
1339 u8 buffer[DVD_CHALLENGE_KEY_LENGTH]; 1346 u8 buffer[DVD_CHALLENGE_KEY_LENGTH];
1340 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 1347 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
1341 1348
1468 memcpy( dvdbs.key2Value, p_key, DVD_KEY_SIZE ); 1475 memcpy( dvdbs.key2Value, p_key, DVD_KEY_SIZE );
1469 1476
1470 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd ); 1477 i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
1471 1478
1472 #elif defined( WIN32 ) 1479 #elif defined( WIN32 )
1473 if( WIN2K ) /* NT/Win2000/Whistler */ 1480 if( WIN2K ) /* NT/2k/XP */
1474 { 1481 {
1475 DWORD tmp; 1482 DWORD tmp;
1476 u8 buffer[DVD_BUS_KEY_LENGTH]; 1483 u8 buffer[DVD_BUS_KEY_LENGTH];
1477 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer; 1484 PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
1478 1485
1614 *p_type = dvdbs.typeCode; 1621 *p_type = dvdbs.typeCode;
1615 *p_mask = dvdbs.driveRegion; 1622 *p_mask = dvdbs.driveRegion;
1616 *p_scheme = dvdbs.rpcScheme; 1623 *p_scheme = dvdbs.rpcScheme;
1617 1624
1618 #elif defined( WIN32 ) 1625 #elif defined( WIN32 )
1619 if( WIN2K ) /* NT/Win2000/Whistler */ 1626 if( WIN2K ) /* NT/2k/XP */
1620 { 1627 {
1621 DWORD tmp; 1628 DWORD tmp;
1622 u8 buffer[ DVD_REGION_LENGTH ]; 1629 u8 buffer[ DVD_REGION_LENGTH ];
1623 PDVD_REGION region = (PDVD_REGION) &buffer; 1630 PDVD_REGION region = (PDVD_REGION) &buffer;
1624 1631
1626 1633
1627 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_GET_REGION, NULL, 0, 1634 i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_DVD_GET_REGION, NULL, 0,
1628 region, DVD_REGION_LENGTH, &tmp, NULL ) ? 0 : -1; 1635 region, DVD_REGION_LENGTH, &tmp, NULL ) ? 0 : -1;
1629 1636
1630 /* Someone who has the headers should correct all this. */ 1637 /* Someone who has the headers should correct all this. */
1631 /* Use the IOCTL_SCSI_PASS_THROUGH_DIRECT so we get the real 1638 /* Use the IOCTL_SCSI_PASS_THROUGH_DIRECT so we get the real
1632 * values of theses entities? */ 1639 * values of theses entities? */
1633 if(region->SystemRegion != 0) { 1640 if(region->SystemRegion != 0) {
1634 *p_type = region->ResetCount > 1 ? 1 : 3 - region->ResetCount; 1641 *p_type = region->ResetCount > 1 ? 1 : 3 - region->ResetCount;
1635 *p_mask = 0xff ^ (1 << (region->SystemRegion - 1)); 1642 *p_mask = 0xff ^ (1 << (region->SystemRegion - 1));
1636 *p_scheme = 1; 1643 *p_scheme = 1;
1637 } 1644 }
1638 else 1645 else
1639 { 1646 {
1640 *p_type = 0; /* ?? */ 1647 *p_type = 0; /* ?? */
1641 *p_mask = 0xff; 1648 *p_mask = 0xff;
1642 *p_scheme = 1; /* ?? */ 1649 *p_scheme = 1; /* ?? */
1643 } 1650 }
1644 } 1651 }
1645 else 1652 else
1646 { 1653 {
1647 INIT_SSC( GPCMD_REPORT_KEY, 8 ); 1654 INIT_SSC( GPCMD_REPORT_KEY, 8 );
1648 1655
1903 } 1910 }
1904 #endif 1911 #endif
1905 1912
1906 #if defined( __QNXNTO__ ) 1913 #if defined( __QNXNTO__ )
1907 /***************************************************************************** 1914 /*****************************************************************************
1908 * QNXInitCPT: initialize a ssc structure for the win32 aspi layer 1915 * QNXInitCPT: initialize a CPT structure for QNX Neutrino
1909 ***************************************************************************** 1916 *****************************************************************************
1910 * This function initializes a ssc raw device command structure for future 1917 * This function initializes a cpt command structure for future use,
1911 * use, either a read command or a write command. 1918 * either a read command or a write command.
1912 *****************************************************************************/ 1919 *****************************************************************************/
1913 static void QNXInitCPT( CAM_PASS_THRU * p_cpt, int i_type ) 1920 static void QNXInitCPT( CAM_PASS_THRU * p_cpt, int i_type )
1914 { 1921 {
1915 switch( i_type ) 1922 switch( i_type )
1916 { 1923 {
1928 1935
1929 p_cpt->cam_cdb[ 8 ] = (p_cpt->cam_dxfer_len >> 8) & 0xff; 1936 p_cpt->cam_cdb[ 8 ] = (p_cpt->cam_dxfer_len >> 8) & 0xff;
1930 p_cpt->cam_cdb[ 9 ] = p_cpt->cam_dxfer_len & 0xff; 1937 p_cpt->cam_cdb[ 9 ] = p_cpt->cam_dxfer_len & 0xff;
1931 p_cpt->cam_cdb_len = 12; 1938 p_cpt->cam_cdb_len = 12;
1932 1939
1933 p_cpt->cam_timeout = CAM_TIME_DEFAULT; 1940 p_cpt->cam_timeout = CAM_TIME_DEFAULT;
1934 } 1941 }
1935 #endif 1942 #endif
1936 1943
1937 #if defined( SYS_OS2 ) 1944 #if defined( SYS_OS2 )
1938 /***************************************************************************** 1945 /*****************************************************************************