shithub: libdvdcss

Download patch

ref: 35589cea2e9e39e5d65d2a2b146ea11bd0e65da6
parent: 71f84cb0068cdb7da5576c51fccc68039f2d217f
author: Alex Strelnikov <lelik@os2.ru>
date: Mon Jul 1 06:36:37 EDT 2002

Patch for OS/2.


--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -2,7 +2,7 @@
  * ioctl.c: DVD ioctl replacement function
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: ioctl.c,v 1.11 2002/07/01 09:02:25 hjort Exp $
+ * $Id: ioctl.c,v 1.12 2002/07/01 10:36:37 hjort Exp $
  *
  * Authors: Markus Kuespert <ltlBeBoy@beosmail.com>
  *          Samuel Hocevar <sam@zoy.org>
@@ -10,6 +10,7 @@
  *          H�kan Hjort <d95hjort@dtek.chalmers.se>
  *          Eugenio Jarosiewicz <ej0@cise.ufl.edu>
  *          David Sieb�rger <drs-videolan@rucus.ru.ac.za>
+ *          Alex Strelnikov <lelik@os2.ru>
  *
  * 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
@@ -39,6 +40,13 @@
 #if defined( WIN32 )
 #   include <windows.h>
 #   include <winioctl.h>
+#elif defined ( SYS_OS2 )
+#   define INCL_DOSFILEMGR
+#   define INCL_DOSDEVICES
+#   define INCL_DOSDEVIOCTL
+#   define INCL_DOSERRORS
+#   include <os2.h>
+#   include <sys/ioctl.h>
 #else
 #   include <netinet/in.h>
 #   include <sys/ioctl.h>
@@ -121,6 +129,13 @@
 #endif
 
 /*****************************************************************************
+ * Local prototypes, OS2 specific
+ *****************************************************************************/
+#if defined( SYS_OS2 )
+static void OS2InitSDC( struct OS2_ExecSCSICmd *, int );
+#endif
+
+/*****************************************************************************
  * ioctl_ReadCopyright: check whether the disc is encrypted or not
  *****************************************************************************/
 int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
@@ -251,6 +266,18 @@
 
     *pi_copyright = p_buffer[4];
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_READ_DVD_STRUCTURE, 8 );
+
+    sdc.command[ 6 ] = i_layer;
+    sdc.command[ 7 ] = DVD_STRUCT_COPYRIGHT;
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    *pi_copyright = p_buffer[ 4 ];
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -407,6 +434,23 @@
 
     memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
 
+#elif defined ( SYS_OS2 )
+    INIT_SSC( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
+
+    sdc.command[ 7 ]  = DVD_STRUCT_DISCKEY;
+    sdc.command[ 10 ] = *pi_agid << 6;
+    
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    if( i_ret < 0 )
+    {
+        return i_ret;
+    }
+
+    memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -555,6 +599,21 @@
 
     memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 12 );
+
+    sdc.command[ 2 ] = ( i_pos >> 24 ) & 0xff;
+    sdc.command[ 3 ] = ( i_pos >> 16 ) & 0xff;
+    sdc.command[ 4 ] = ( i_pos >>  8 ) & 0xff;
+    sdc.command[ 5 ] = ( i_pos       ) & 0xff;
+    sdc.command[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -668,6 +727,17 @@
 
     *pi_agid = p_buffer[ 7 ] >> 6;
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 8 );
+
+    sdc.command[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    *pi_agid = p_buffer[ 7 ] >> 6;
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -791,6 +861,17 @@
 
     memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 16 );
+
+    sdc.command[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -913,6 +994,17 @@
 
     *pi_asf = p_buffer[ 7 ] & 1;
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 8 );
+
+    sdc.command[ 10 ] = DVD_REPORT_ASF;
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    *pi_asf = p_buffer[ 7 ] & 1;
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1031,6 +1123,17 @@
 
     memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 12 );
+
+    sdc.command[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1130,6 +1233,18 @@
 
     i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 1 );
+
+    sdc.data_length = 0;
+    sdc.command[ 8 ] = 0;
+    sdc.command[ 9 ] = 0;
+
+    sdc.command[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        NULL, 0, &ulDataLen);
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1255,6 +1370,18 @@
 
     i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_SEND_KEY, 16 );
+
+    sdc.command[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
+
+    p_buffer[ 1 ] = 0xe;
+    memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
+
+    return DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                       &sdc, sizeof(sdc), &ulParamLen,
+                       p_buffer, sizeof(p_buffer), &ulDataLen);
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1380,6 +1507,18 @@
 
     i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_SEND_KEY, 12 );
+
+    sdc.command[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
+
+    p_buffer[ 1 ] = 0xa;
+    memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
+
+    return DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                       &sdc, sizeof(sdc), &ulParamLen,
+                       p_buffer, sizeof(p_buffer), &ulDataLen);
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1527,6 +1666,19 @@
     *p_mask = p_buffer[ 5 ];
     *p_scheme = p_buffer[ 6 ];
 
+#elif defined( SYS_OS2 )
+    INIT_SSC( GPCMD_REPORT_KEY, 8 );
+
+    sdc.command[ 10 ] = DVD_REPORT_RPC;
+
+    i_ret = DosDevIOCtl(i_fd, IOCTL_CDROMDISK, CDROMDISK_EXECMD,
+                        &sdc, sizeof(sdc), &ulParamLen,
+                        p_buffer, sizeof(p_buffer), &ulDataLen);
+
+    *p_type = p_buffer[ 4 ] >> 6;
+    *p_mask = p_buffer[ 5 ];
+    *p_scheme = p_buffer[ 6 ];
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1736,3 +1888,31 @@
 }
 #endif
 
+#if defined( SYS_OS2 )
+/*****************************************************************************
+ * OS2InitSDC: initialize a SDC structure for the Execute SCSI-command
+ *****************************************************************************
+ * This function initializes a OS2 'execute SCSI command' structure for 
+ * future use, either a read command or a write command.
+ *****************************************************************************/
+static void OS2InitSDC( struct OS2_ExecSCSICmd *p_sdc, int i_type )
+{
+    switch( i_type )
+    {
+        case GPCMD_SEND_KEY:
+            p_sdc->flags = 0;
+            break;
+
+        case GPCMD_READ_DVD_STRUCTURE:
+        case GPCMD_REPORT_KEY:
+            p_sdc->flags = EX_DIRECTION_IN;
+            break;
+    }
+
+    p_sdc->command[ 0 ] = i_type;
+    p_sdc->command[ 8 ] = (p_sdc->data_length >> 8) & 0xff;
+    p_sdc->command[ 9 ] = p_sdc->data_length        & 0xff;
+    p_sdc->id_code      = 0x31304443;    // 'CD01'
+    p_sdc->cmd_length   = 12;
+}
+#endif
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -2,7 +2,7 @@
  * ioctl.h: DVD ioctl replacement function
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: ioctl.h,v 1.5 2002/07/01 09:02:25 hjort Exp $
+ * $Id: ioctl.h,v 1.6 2002/07/01 10:36:37 hjort Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -123,6 +123,22 @@
 #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 )
@@ -133,7 +149,7 @@
 /*****************************************************************************
  * Various DVD I/O tables
  *****************************************************************************/
-#if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO ) || defined ( __QNXNTO__ )
+#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
@@ -317,3 +333,28 @@
 
 #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