shithub: libdvdcss

Download patch

ref: d3e94a78bd73ebb34739c17d54290759aa0ae4d5
parent: 68b19d058bc17060167acf89a5650160aaf63610
author: Pascal Levesque <bigorneault@gmail.com>
date: Sun Jun 2 12:14:48 EDT 2002

* ./src/ioctl.c, ./src/ioctl.h: QNX port, 


--- a/AUTHORS
+++ b/AUTHORS
@@ -38,6 +38,10 @@
 E: ltlBeBoy@beosmail.com
 D: BeOS port of the DVD ioctls
 
+N: Pascal Levesque
+E: Pascal.Levesque@mindready.com
+D: QNX port
+
 N: Steven M. Schultz
 E: sms@TO.GD-ES.COM
 D: BSD/OS port
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 
 HEAD
 
+  * ./src/ioctl.c, ./src/ioctl.h: QNX port, courtesy of Pascal Levesque.
   * ./src/css.c: applied H�kan's fix for the failure on region mismatch.
   * ALL: switched to libtool 1.4.2a.
   * ./src/libdvdcss.c: fixed an uninitialized variable.
--- 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.8 2002/05/05 22:21:51 jlj Exp $
+ * $Id: ioctl.c,v 1.9 2002/06/02 16:14:48 sam Exp $
  *
  * Authors: Markus Kuespert <ltlBeBoy@beosmail.com>
  *          Samuel Hocevar <sam@zoy.org>
@@ -75,6 +75,10 @@
 #ifdef DARWIN_DVD_IOCTL
 #   include <IOKit/storage/IODVDMediaBSDClient.h>
 #endif
+#ifdef __QNXNTO__
+#   include <sys/mman.h>
+#   include <sys/dcmd_cam.h>
+#endif
 
 #include "common.h"
 
@@ -110,6 +114,13 @@
 #endif
 
 /*****************************************************************************
+ * Local prototypes, QNX specific
+ *****************************************************************************/
+#if defined( __QNXNTO__ )
+static void QNXInitCPT ( CAM_PASS_THRU *, int );
+#endif
+
+/*****************************************************************************
  * ioctl_ReadCopyright: check whether the disc is encrypted or not
  *****************************************************************************/
 int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
@@ -230,15 +241,16 @@
     }
 
 #elif defined( __QNXNTO__ )
-    /*
-        QNX RTOS currently doesn't have a CAM
-        interface (they're working on it though).
-        Assume DVD is not encrypted.
-    */
 
-    *pi_copyright = 0;
-    i_ret = 0;
+    INIT_CPT( GPCMD_READ_DVD_STRUCTURE, 8 );
 
+    p_cpt->cam_cdb[ 6 ] = i_layer;
+    p_cpt->cam_cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    *pi_copyright = p_buffer[4];
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -384,6 +396,17 @@
         memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_READ_DVD_STRUCTURE, DVD_DISCKEY_SIZE + 4 );
+
+    p_cpt->cam_cdb[ 7 ] = DVD_STRUCT_DISCKEY;
+    p_cpt->cam_cdb[ 10 ] = *pi_agid << 6;
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    memcpy( p_key, p_buffer + 4, DVD_DISCKEY_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -518,6 +541,20 @@
         memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 12 );
+
+    p_cpt->cam_cdb[ 2 ] = ( i_pos >> 24 ) & 0xff;
+    p_cpt->cam_cdb[ 3 ] = ( i_pos >> 16 ) & 0xff;
+    p_cpt->cam_cdb[ 4 ] = ( i_pos >>  8 ) & 0xff;
+    p_cpt->cam_cdb[ 5 ] = ( i_pos       ) & 0xff;
+    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_TITLE_KEY | (*pi_agid << 6);
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    memcpy( p_key, p_buffer + 5, DVD_KEY_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -621,6 +658,16 @@
         *pi_agid = p_buffer[ 7 ] >> 6;
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 8 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_AGID | (*pi_agid << 6);
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    *pi_agid = p_buffer[ 7 ] >> 6;
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -734,6 +781,16 @@
         memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 16 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_CHALLENGE | (*pi_agid << 6);
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    memcpy( p_challenge, p_buffer + 4, DVD_CHALLENGE_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -846,6 +903,16 @@
         *pi_asf = p_buffer[ 7 ] & 1;
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 8 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_ASF;
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    *pi_asf = p_buffer[ 7 ] & 1;
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -954,6 +1021,16 @@
         memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 12 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_KEY1 | (*pi_agid << 6);
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    memcpy( p_key, p_buffer + 4, DVD_KEY_SIZE );
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1045,6 +1122,14 @@
         i_ret = WinSendSSC( i_fd, &ssc );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 0 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_INVALIDATE_AGID | (*pi_agid << 6);
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1159,6 +1244,17 @@
         return WinSendSSC( i_fd, &ssc );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_SEND_KEY, 16 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_SEND_CHALLENGE | (*pi_agid << 6);
+
+    p_buffer[ 1 ] = 0xe;
+    memcpy( p_buffer + 4, p_challenge, DVD_CHALLENGE_SIZE );
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1273,6 +1369,17 @@
         return WinSendSSC( i_fd, &ssc );
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_SEND_KEY, 12 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_SEND_KEY2 | (*pi_agid << 6);
+
+    p_buffer[ 1 ] = 0xa;
+    memcpy( p_buffer + 4, p_key, DVD_KEY_SIZE );
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
 #else
 #   error "DVD ioctls are unavailable on this system"
 
@@ -1394,6 +1501,18 @@
         *p_scheme = p_buffer[ 6 ];
     }
 
+#elif defined( __QNXNTO__ )
+
+    INIT_CPT( GPCMD_REPORT_KEY, 8 );
+
+    p_cpt->cam_cdb[ 10 ] = DVD_REPORT_RPC;
+
+    i_ret = devctl(i_fd, DCMD_CAM_PASS_THRU, p_cpt, structSize, NULL);
+
+    *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"
 
@@ -1569,6 +1688,37 @@
     CloseHandle( hEvent );
 
     return p_ssc->SRB_Status == SS_COMP ? 0 : -1;
+}
+#endif
+
+#if defined( __QNXNTO__ )
+/*****************************************************************************
+ * QNXInitCPT: initialize a ssc structure for the win32 aspi layer
+ *****************************************************************************
+ * This function initializes a ssc raw device command structure for future
+ * use, either a read command or a write command.
+ *****************************************************************************/
+static void QNXInitCPT( CAM_PASS_THRU * p_cpt, int i_type )
+{
+    switch( i_type )
+    {
+        case GPCMD_SEND_KEY:
+            p_cpt->cam_flags = CAM_DIR_OUT;
+            break;
+
+        case GPCMD_READ_DVD_STRUCTURE:
+        case GPCMD_REPORT_KEY:
+            p_cpt->cam_flags = CAM_DIR_IN;
+            break;
+    }
+
+    p_cpt->cam_cdb[0] = i_type;
+
+    p_cpt->cam_cdb[ 8 ] = (p_cpt->cam_dxfer_len >> 8) & 0xff;
+    p_cpt->cam_cdb[ 9 ] =  p_cpt->cam_dxfer_len       & 0xff;
+    p_cpt->cam_cdb_len = 12;
+
+	p_cpt->cam_timeout = CAM_TIME_DEFAULT;
 }
 #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.3 2002/05/05 22:21:51 jlj Exp $
+ * $Id: ioctl.h,v 1.4 2002/06/02 16:14:48 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -107,6 +107,22 @@
 #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
+
+/*****************************************************************************
  * Additional types, OpenBSD specific
  *****************************************************************************/
 #if defined( HAVE_OPENBSD_DVD_STRUCT )
@@ -117,7 +133,7 @@
 /*****************************************************************************
  * Various DVD I/O tables
  *****************************************************************************/
-#if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO )
+#if defined( SYS_BEOS ) || defined( WIN32 ) || defined ( SOLARIS_USCSI ) || defined ( HPUX_SCTL_IO ) || defined ( __QNXNTO__ )
     /* 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