Discussion:
[libdvdcss-devel] [PATCH 1/4] ioctl: Drop single-use INIT_SPTD/SEND_SPTD macros
Diego Biurrun
2014-11-18 22:46:23 UTC
Permalink
---
src/ioctl.c | 13 +++++++++++--
src/ioctl.h | 14 --------------
test/dvd_region.c | 13 +++++++++++--
3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/ioctl.c b/src/ioctl.c
index 7219017..6e078d6 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -169,7 +169,13 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
*pi_copyright = dvdbs.copyrightProtectionSystemType;

#elif defined( WIN32 )
- INIT_SPTD( GPCMD_READ_DVD_STRUCTURE, 8 );
+ DWORD tmp;
+ SCSI_PASS_THROUGH_DIRECT sptd = { 0 };
+ uint8_t p_buffer[8];
+ sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT );
+ sptd.DataBuffer = p_buffer;
+ sptd.DataTransferLength = sizeof( p_buffer );
+ WinInitSPTD( &sptd, GPCMD_READ_DVD_STRUCTURE );

/* When using IOCTL_DVD_READ_STRUCTURE and
DVD_COPYRIGHT_DESCRIPTOR, CopyrightProtectionType
@@ -180,7 +186,10 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
sptd.Cdb[ 6 ] = i_layer;
sptd.Cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;

- i_ret = SEND_SPTD( i_fd, &sptd, &tmp );
+ i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_SCSI_PASS_THROUGH_DIRECT,
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &tmp, NULL ) ? 0 : -1;

if( i_ret == 0 )
{
diff --git a/src/ioctl.h b/src/ioctl.h
index ab8c42e..cc8ffac 100644
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -65,20 +65,6 @@ int ioctl_ReportRPC ( int, int *, int *, int * );
dvd.format = FORMAT; \
dvd.buffer = &dvdbs; \
dvd.bufferLength = sizeof(dvdbs);
-#elif defined( WIN32 )
-#define INIT_SPTD( TYPE, SIZE ) \
- DWORD tmp; \
- SCSI_PASS_THROUGH_DIRECT sptd = { 0 }; \
- uint8_t p_buffer[ (SIZE) ]; \
- sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT ); \
- sptd.DataBuffer = p_buffer; \
- sptd.DataTransferLength = (SIZE); \
- WinInitSPTD( &sptd, (TYPE) );
-#define SEND_SPTD( DEV, SPTD, TMP ) \
- (DeviceIoControl( (HANDLE)(DEV), IOCTL_SCSI_PASS_THROUGH_DIRECT, \
- (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
- (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
- (TMP), NULL ) ? 0 : -1)
#elif defined( __QNXNTO__ )
#define INIT_CPT( TYPE, SIZE ) \
CAM_PASS_THRU * p_cpt = { 0 }; \
diff --git a/test/dvd_region.c b/test/dvd_region.c
index a596fe7..f35b869 100644
--- a/test/dvd_region.c
+++ b/test/dvd_region.c
@@ -93,14 +93,23 @@ static int ioctl_SendRPC( int i_fd, int i_pdrc )
i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );

#elif defined( WIN32 )
- INIT_SPTD( GPCMD_SEND_KEY, 8 );
+ DWORD tmp;
+ SCSI_PASS_THROUGH_DIRECT sptd = { 0 };
+ uint8_t p_buffer[8];
+ sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT );
+ sptd.DataBuffer = p_buffer;
+ sptd.DataTransferLength = sizeof( p_buffer );
+ WinInitSPTD( &sptd, GPCMD_SEND_KEY );

sptd.Cdb[ 10 ] = DVD_SEND_RPC;

p_buffer[ 1 ] = 6;
p_buffer[ 4 ] = i_pdrc;

- i_ret = SEND_SPTD( i_fd, &sptd, &tmp );
+ i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_SCSI_PASS_THROUGH_DIRECT,
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &tmp, NULL ) ? 0 : -1;

#elif defined( __QNXNTO__ )
--
2.1.0
Diego Biurrun
2014-11-18 22:46:24 UTC
Permalink
---
src/libdvdcss.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libdvdcss.h b/src/libdvdcss.h
index 9447124..c824988 100644
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -77,7 +77,7 @@ struct dvdcss_s
#ifdef WIN32
HANDLE p_handle;
char * p_readv_buffer;
- int i_readv_buf_size;
+ size_t i_readv_buf_size;
#endif /* WIN32 */
};
--
2.1.0
Diego Biurrun
2014-11-18 22:47:34 UTC
Permalink
Post by Diego Biurrun
---
src/libdvdcss.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Ignore this one, it was sent by mistake.

Diego
Diego Biurrun
2014-11-18 22:46:26 UTC
Permalink
Avoid checking an impossible condition, skip the check instead.
This fixes CID 82126.
---
src/css.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/css.c b/src/css.c
index 4043efe..fef2ae5 100644
--- a/src/css.c
+++ b/src/css.c
@@ -107,30 +107,29 @@ int dvdcss_test( dvdcss_t dvdcss )

i_ret = ioctl_ReadCopyright( dvdcss->i_fd, 0 /* i_layer */, &i_copyright );

-#ifdef WIN32
if( i_ret < 0 )
{
+#ifdef WIN32
/* Maybe we didn't have enough privileges to read the copyright
* (see ioctl_ReadCopyright comments).
* Apparently, on unencrypted DVDs dvdcss_disckey() always fails, so
* we can check this as a workaround. */
- i_ret = 0;
- i_copyright = 1;
if( dvdcss_disckey( dvdcss ) < 0 )
{
i_copyright = 0;
}
- }
-#endif /* WIN32 */
-
- if( i_ret < 0 )
- {
+ else
+ {
+ i_copyright = 1;
+ }
+#else
/* Since it's the first ioctl we try to issue, we add a notice */
print_error( dvdcss, "CSS error: could not get \"copyright\""
" information, make sure there is a DVD in the drive,"
" and that you have used the correct device node." );

return -1;
+#endif /* WIN32 */
}

print_debug( dvdcss, "disc reports copyright information 0x%x",
--
2.1.0
Jean-Baptiste Kempf
2014-11-18 22:56:05 UTC
Permalink
Seems good.
Post by Diego Biurrun
Avoid checking an impossible condition, skip the check instead.
This fixes CID 82126.
---
src/css.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/css.c b/src/css.c
index 4043efe..fef2ae5 100644
--- a/src/css.c
+++ b/src/css.c
@@ -107,30 +107,29 @@ int dvdcss_test( dvdcss_t dvdcss )
i_ret = ioctl_ReadCopyright( dvdcss->i_fd, 0 /* i_layer */, &i_copyright );
-#ifdef WIN32
if( i_ret < 0 )
{
+#ifdef WIN32
/* Maybe we didn't have enough privileges to read the copyright
* (see ioctl_ReadCopyright comments).
* Apparently, on unencrypted DVDs dvdcss_disckey() always fails, so
* we can check this as a workaround. */
- i_ret = 0;
- i_copyright = 1;
if( dvdcss_disckey( dvdcss ) < 0 )
{
i_copyright = 0;
}
- }
-#endif /* WIN32 */
-
- if( i_ret < 0 )
- {
+ else
+ {
+ i_copyright = 1;
+ }
+#else
/* Since it's the first ioctl we try to issue, we add a notice */
print_error( dvdcss, "CSS error: could not get \"copyright\""
" information, make sure there is a DVD in the drive,"
" and that you have used the correct device node." );
return -1;
+#endif /* WIN32 */
}
print_debug( dvdcss, "disc reports copyright information 0x%x",
--
2.1.0
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Diego Biurrun
2014-11-18 22:46:25 UTC
Permalink
---
src/css.c | 14 +++-----------
test/dvd_region.c | 2 --
2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/css.c b/src/css.c
index 3d18372..4043efe 100644
--- a/src/css.c
+++ b/src/css.c
@@ -72,7 +72,7 @@ static void DecryptKey ( uint8_t,
const uint8_t *, const uint8_t *, uint8_t * );

static int DecryptDiscKey ( dvdcss_t, const uint8_t *, dvd_key );
-static int CrackDiscKey ( dvdcss_t, uint8_t * );
+static int CrackDiscKey ( uint8_t * );

static void DecryptTitleKey ( dvd_key, dvd_key );
static int RecoverTitleKey ( int, const uint8_t *,
@@ -403,7 +403,7 @@ int dvdcss_disckey( dvdcss_t dvdcss )
/* Crack Disc key to be able to use it */
memcpy( p_disc_key, p_buffer, DVD_KEY_SIZE );
PrintKey( dvdcss, "cracking disc key ", p_disc_key );
- if( ! CrackDiscKey( dvdcss, p_disc_key ) )
+ if( ! CrackDiscKey( p_disc_key ) )
{
PrintKey( dvdcss, "cracked disc key is ", p_disc_key );
break;
@@ -1164,7 +1164,7 @@ static int investigate( unsigned char *hash, unsigned char *ckey )
return memcmp( key, ckey, DVD_KEY_SIZE );
}

-static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )
+static int CrackDiscKey( uint8_t *p_disc_key )
{
unsigned char B[5] = { 0,0,0,0,0 }; /* Second Stage of mangle cipher */
unsigned char C[5] = { 0,0,0,0,0 }; /* Output Stage of mangle cipher
@@ -1206,12 +1206,6 @@ static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )
tmp3 = j ^ tmp2 ^ i; /* C[1] */
tmp4 = K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) ]; /* count of entries here */
tmp4++;
-/*
- if( tmp4 == K1TABLEWIDTH )
- {
- print_debug( dvdcss, "Table disaster %d", tmp4 );
- }
-*/
if( tmp4 < K1TABLEWIDTH )
{
K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) + tmp4 ] = i;
@@ -1230,8 +1224,6 @@ static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )

tmp3 = 0;

- print_debug( dvdcss, "initializing the big table" );
-
for( i = 0 ; i < BIGTABLESIZE ; i++ )
{
tmp = (( i + i ) & 0x1fffff0 ) | 0x8 | ( i & 0x7 );
diff --git a/test/dvd_region.c b/test/dvd_region.c
index f35b869..2ab5db3 100644
--- a/test/dvd_region.c
+++ b/test/dvd_region.c
@@ -198,8 +198,6 @@ static int print_region(int fd)
break;
}

- // printf("%d vendor resets available\n", ai->lrpcs.vra);
- // printf("%d user controlled changes available\n", ai->lrpcs.ucca);
printf("Region: ");
if( region_mask)
while(region_mask) {
--
2.1.0
Jean-Baptiste Kempf
2014-11-18 22:55:44 UTC
Permalink
OK.
Post by Diego Biurrun
---
src/css.c | 14 +++-----------
test/dvd_region.c | 2 --
2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/src/css.c b/src/css.c
index 3d18372..4043efe 100644
--- a/src/css.c
+++ b/src/css.c
@@ -72,7 +72,7 @@ static void DecryptKey ( uint8_t,
const uint8_t *, const uint8_t *, uint8_t * );
static int DecryptDiscKey ( dvdcss_t, const uint8_t *, dvd_key );
-static int CrackDiscKey ( dvdcss_t, uint8_t * );
+static int CrackDiscKey ( uint8_t * );
static void DecryptTitleKey ( dvd_key, dvd_key );
static int RecoverTitleKey ( int, const uint8_t *,
@@ -403,7 +403,7 @@ int dvdcss_disckey( dvdcss_t dvdcss )
/* Crack Disc key to be able to use it */
memcpy( p_disc_key, p_buffer, DVD_KEY_SIZE );
PrintKey( dvdcss, "cracking disc key ", p_disc_key );
- if( ! CrackDiscKey( dvdcss, p_disc_key ) )
+ if( ! CrackDiscKey( p_disc_key ) )
{
PrintKey( dvdcss, "cracked disc key is ", p_disc_key );
break;
@@ -1164,7 +1164,7 @@ static int investigate( unsigned char *hash, unsigned char *ckey )
return memcmp( key, ckey, DVD_KEY_SIZE );
}
-static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )
+static int CrackDiscKey( uint8_t *p_disc_key )
{
unsigned char B[5] = { 0,0,0,0,0 }; /* Second Stage of mangle cipher */
unsigned char C[5] = { 0,0,0,0,0 }; /* Output Stage of mangle cipher
@@ -1206,12 +1206,6 @@ static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )
tmp3 = j ^ tmp2 ^ i; /* C[1] */
tmp4 = K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) ]; /* count of entries here */
tmp4++;
-/*
- if( tmp4 == K1TABLEWIDTH )
- {
- print_debug( dvdcss, "Table disaster %d", tmp4 );
- }
-*/
if( tmp4 < K1TABLEWIDTH )
{
K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) + tmp4 ] = i;
@@ -1230,8 +1224,6 @@ static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )
tmp3 = 0;
- print_debug( dvdcss, "initializing the big table" );
-
for( i = 0 ; i < BIGTABLESIZE ; i++ )
{
tmp = (( i + i ) & 0x1fffff0 ) | 0x8 | ( i & 0x7 );
diff --git a/test/dvd_region.c b/test/dvd_region.c
index f35b869..2ab5db3 100644
--- a/test/dvd_region.c
+++ b/test/dvd_region.c
@@ -198,8 +198,6 @@ static int print_region(int fd)
break;
}
- // printf("%d vendor resets available\n", ai->lrpcs.vra);
- // printf("%d user controlled changes available\n", ai->lrpcs.ucca);
printf("Region: ");
if( region_mask)
while(region_mask) {
--
2.1.0
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Jean-Baptiste Kempf
2014-11-18 22:55:39 UTC
Permalink
OK.
Post by Diego Biurrun
---
src/ioctl.c | 13 +++++++++++--
src/ioctl.h | 14 --------------
test/dvd_region.c | 13 +++++++++++--
3 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/src/ioctl.c b/src/ioctl.c
index 7219017..6e078d6 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -169,7 +169,13 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
*pi_copyright = dvdbs.copyrightProtectionSystemType;
#elif defined( WIN32 )
- INIT_SPTD( GPCMD_READ_DVD_STRUCTURE, 8 );
+ DWORD tmp;
+ SCSI_PASS_THROUGH_DIRECT sptd = { 0 };
+ uint8_t p_buffer[8];
+ sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT );
+ sptd.DataBuffer = p_buffer;
+ sptd.DataTransferLength = sizeof( p_buffer );
+ WinInitSPTD( &sptd, GPCMD_READ_DVD_STRUCTURE );
/* When using IOCTL_DVD_READ_STRUCTURE and
DVD_COPYRIGHT_DESCRIPTOR, CopyrightProtectionType
@@ -180,7 +186,10 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
sptd.Cdb[ 6 ] = i_layer;
sptd.Cdb[ 7 ] = DVD_STRUCT_COPYRIGHT;
- i_ret = SEND_SPTD( i_fd, &sptd, &tmp );
+ i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_SCSI_PASS_THROUGH_DIRECT,
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &tmp, NULL ) ? 0 : -1;
if( i_ret == 0 )
{
diff --git a/src/ioctl.h b/src/ioctl.h
index ab8c42e..cc8ffac 100644
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -65,20 +65,6 @@ int ioctl_ReportRPC ( int, int *, int *, int * );
dvd.format = FORMAT; \
dvd.buffer = &dvdbs; \
dvd.bufferLength = sizeof(dvdbs);
-#elif defined( WIN32 )
-#define INIT_SPTD( TYPE, SIZE ) \
- DWORD tmp; \
- SCSI_PASS_THROUGH_DIRECT sptd = { 0 }; \
- uint8_t p_buffer[ (SIZE) ]; \
- sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT ); \
- sptd.DataBuffer = p_buffer; \
- sptd.DataTransferLength = (SIZE); \
- WinInitSPTD( &sptd, (TYPE) );
-#define SEND_SPTD( DEV, SPTD, TMP ) \
- (DeviceIoControl( (HANDLE)(DEV), IOCTL_SCSI_PASS_THROUGH_DIRECT, \
- (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
- (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
- (TMP), NULL ) ? 0 : -1)
#elif defined( __QNXNTO__ )
#define INIT_CPT( TYPE, SIZE ) \
CAM_PASS_THRU * p_cpt = { 0 }; \
diff --git a/test/dvd_region.c b/test/dvd_region.c
index a596fe7..f35b869 100644
--- a/test/dvd_region.c
+++ b/test/dvd_region.c
@@ -93,14 +93,23 @@ static int ioctl_SendRPC( int i_fd, int i_pdrc )
i_ret = ioctl( i_fd, DKIOCDVDSENDKEY, &dvd );
#elif defined( WIN32 )
- INIT_SPTD( GPCMD_SEND_KEY, 8 );
+ DWORD tmp;
+ SCSI_PASS_THROUGH_DIRECT sptd = { 0 };
+ uint8_t p_buffer[8];
+ sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT );
+ sptd.DataBuffer = p_buffer;
+ sptd.DataTransferLength = sizeof( p_buffer );
+ WinInitSPTD( &sptd, GPCMD_SEND_KEY );
sptd.Cdb[ 10 ] = DVD_SEND_RPC;
p_buffer[ 1 ] = 6;
p_buffer[ 4 ] = i_pdrc;
- i_ret = SEND_SPTD( i_fd, &sptd, &tmp );
+ i_ret = DeviceIoControl( (HANDLE) i_fd, IOCTL_SCSI_PASS_THROUGH_DIRECT,
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &sptd, sizeof( SCSI_PASS_THROUGH_DIRECT ),
+ &tmp, NULL ) ? 0 : -1;
#elif defined( __QNXNTO__ )
--
2.1.0
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Loading...