From: andr...@usa.net (Andrew Veliath)
Subject: DVD Progress and Information
Date: 1998/09/12
Message-ID: <199809121906.PAA07510@ztransform.velsoft.com>#1/1
X-Deja-AN: 390500136
Approved: ge...@greenie.muc.de
Sender: muc.de!l-linux-kernel-owner
Newsgroups: muc.lists.linux-kernel

Hello everyone,

Does anyone know if DVD-ioctls are standardized under Unix?  My
impression is that they aren't yet, but if so, any pointers would be
appreciated.  I've created a reasonable standard and implementation.
When I get a web page ready in a few days and clean stuff up a bit,
I'll put the patches and stuff there for the following stuff.

I've extended cdrom.h for 3 new DVD-related ioctls, and modified
cdrom.[ch] and ide-cd.[ch] for DVDs (note for ide-cd, if the drive
isn't a DVD device (CD) they will gracefully return EINVAL).  They
worked fine before as ATAPI CD devices, but you couldn't do DVD
specific things (naturally).

I've modifed cdrom and ide-cd to detect if the drive is a DVD-ROM or
DVD-RAM, and have implemented the following ioctls for DVDs, based on
the recent MMC-2 C/DVD packet command interface:

The DVD_READ_STRUCT lets you obtain info for the following items:

#define DVD_READ_STRUCT		0x5390  /* read DVD structures */
#define DVD_REPORT_KEY		0x5391  /* DVD CSS key reporting */
#define DVD_SEND_KEY		0x5392  /* DVD CSS key sending */

The related unions and structs are also included, and Ive implemented
them for ATAPI DVD devices.  Also, I've added the sensible error
messages if authentication fails or if you try to read scrambled
sectors.  Each of those ioctls have subfunctions, which are given in
the sent union structure.

Now, for Unix DVD players which need to do CSS related authentication
with the drive, I've provided the DVD_REPORT_KEY and DVD_SEND_KEY
ioctls, in addition to the DVD_READ_STRUCT with the
DVD_STRUCT_DISCKEY.  These together can be used to create the secure
channel in which a DVD decoding hardware can 1) unlock sectors, and 2)
decrypt the modified DES encrypted MPEG-2 Video streams inside the
system streams.  For those of you not familiar with the authentication
process, I'm going to try to work up a web page on Linux DVD soon.

CSS authentication involves a combination of asymmetric encryption to
transfer the symmetric modified DES key, for which the MPEG-2 Video
stream is encoded at manufacturing time in (modifed DES).  In this
way, the middle man doesn't have to know anything about encryption,
while the data remains protected.

Note these ioctls have absolutely nothing to do with the actual CSS
algorithm, which is something you can only get under NDA (and btw, I
have _no_ interest in seeing CSS `broken' at all).  This is just
related to the authentication process, and is somewhat similar to how
Windows does it with the new DirectShow stuff.  Basically, a secure
channel is created in which to transfer the disc key (which itself is
secured through encryption).  So, with DVD hardware which has a CSS
chip and the DVD drive, you can perform proper authentication.  Here
is an example of a failed CSS authentication with a program which uses
these ioctls (of course, I still do not have docs for my C-Cube Ziva
DS on my Creative Encore, so if anyone wants to send me some or a
contant at C-Cube that would be great.  I would be willing to go under
NDA if it is the only way):

Authentication ID 3 granted
Sending random 80-bit challenge: 675266e0fed440629450
Received 40-bit authentication key: 22d1a8240d
Recieved 80-bit challenge: 1bd14b85c06b58773576
Create 40-bit key 2 (?)
Sending key 2: 0000000000
ioctl send key 2: Input/output error

Which results in a log message from ide-cd of:
kernel: ATAPI device hdc:
kernel:   Error: Illegal request -- (Sense key=0x05)
kernel:   Copy protection key exchange failure (authentication failure) -- 
(asc=0x6f, ascq=0x00)

Reading of a scramble in this case would yield something like:
kernel: ATAPI device hdc:
kernel:   Error: Illegal request -- (Sense key=0x05)
kernel:   Read of scrambled sector without authentication -- (asc=0x6f, ascq=0x03)

These ioctls could be implmemented easily for SCSI DVD-ROMs, I'm sure.

Any comments or suggestions or help are gracefully accepted.

Andrew

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html

From: schi...@fokus.gmd.de (Joerg Schilling)
Subject: Re: (fwd) DVD Progress and Information
Date: 1998/09/15
Message-ID: <199809152150.XAA11080@fokus.gmd.de>#1/1
X-Deja-AN: 391523675
Approved: ge...@greenie.muc.de
Sender: muc.de!l-linux-kernel-owner
Newsgroups: muc.lists.linux-kernel


>Does anyone know if DVD-ioctls are standardized under Unix?  My
>impression is that they aren't yet, but if so, any pointers would be
>appreciated.  I've created a reasonable standard and implementation.
>When I get a web page ready in a few days and clean stuff up a bit,
>I'll put the patches and stuff there for the following stuff.

Solaris 2.7 does not have (will not have DVD support ;-) but 2.8 will do.
Unfortunaetly 2.7 is currently in beta so I expect the 2.8 beta 
to be available ~ april 1999.

>I've extended cdrom.h for 3 new DVD-related ioctls, and modified
>cdrom.[ch] and ide-cd.[ch] for DVDs (note for ide-cd, if the drive
>isn't a DVD device (CD) they will gracefully return EINVAL).  They
>worked fine before as ATAPI CD devices, but you couldn't do DVD
>specific things (naturally).

>I've modifed cdrom and ide-cd to detect if the drive is a DVD-ROM or
>DVD-RAM, and have implemented the following ioctls for DVDs, based on
>the recent MMC-2 C/DVD packet command interface:

>The DVD_READ_STRUCT lets you obtain info for the following items:

>#define DVD_READ_STRUCT		0x5390  /* read DVD structures */

How do you define the interface to set the structure # ? 
Which structure #'s do you support ?

J�rg

 EMail...@schily.isdn.cs.tu-berlin.de (home) J�rg Schilling D-13353 Berlin
       j...@cs.tu-berlin.de		(uni)  If you don't have iso-8859-1
       schi...@fokus.gmd.de		(work) chars I am J"org Schilling
 URL:  http://www.fokus.gmd.de/usr/schilling   ftp://ftp.fokus.gmd.de/pub/unix

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

From: andr...@usa.net (Andrew Veliath)
Subject: Re: (fwd) DVD Progress and Information
Date: 1998/09/20
Message-ID: <199809201625.MAA03126@ztransform.velsoft.com>
X-Deja-AN: 393036452
Approved: ge...@greenie.muc.de
Sender: muc.de!l-linux-kernel-owner
References: <199809152150.XAA11080@fokus.gmd.de>
Newsgroups: muc.lists.linux-kernel

 .........----------------==================----
..--==-  Tue, 15 Sep 1998 23:50:08 +0200 (MET DST),
..--==-  Joerg Schilling (JS) discussed:

 )) Does anyone know if DVD-ioctls are standardized under Unix?  My
 )) impression is that they aren't yet, but if so, any pointers would
 )) be appreciated.  I've created a reasonable standard and
 )) implementation.  When I get a web page ready in a few days and
 )) clean stuff up a bit, I'll put the patches and stuff there for the
 )) following stuff.

 JS)  Solaris 2.7 does not have (will not have DVD support ;-) but 2.8
 JS)  will do.  Unfortunaetly 2.7 is currently in beta so I expect the
 JS)  2.8 beta to be available ~ april 1999.

 )) I've extended cdrom.h for 3 new DVD-related ioctls, and modified
 )) cdrom.[ch] and ide-cd.[ch] for DVDs (note for ide-cd, if the drive
 )) isn't a DVD device (CD) they will gracefully return EINVAL).  They
 )) worked fine before as ATAPI CD devices, but you couldn't do DVD
 )) specific things (naturally).

 )) I've modifed cdrom and ide-cd to detect if the drive is a DVD-ROM
 )) or DVD-RAM, and have implemented the following ioctls for DVDs,
 )) based on the recent MMC-2 C/DVD packet command interface:

 )) The DVD_READ_STRUCT lets you obtain info for the following items:

 )) #define DVD_READ_STRUCT 0x5390 /* read DVD structures */

 JS)  How do you define the interface to set the structure # ?  Which
 JS)  structure #'s do you support ?

I created the following interface which I've implemented for the Linux
IDE CD-ROM driver.  I have no idea what the future Solaris interface
is, but using the same interface is a good idea.  Pertinent
information and my latest patch with the Linux IDE driver
implementation for 2.1.121 is here,
http://www.rpi.edu/~veliaa/linux-dvd.

At the moment I'm still trying to get info on the C-Cube Ziva DS
chipset on the Creative card on how to initialize the MPEG decoder,
upload the microcode and get/send the CSS keys, since the DVD decoder
driver can just use the same or similar interface to the following to
do authentication and key transfer (so it will act as an independent
arbiter).

/*
 * DVD-ROM specific ioctls
 */
#define DVD_READ_STRUCT		0x5390  /* read DVD structures */
#define DVD_REPORT_KEY		0x5391  /* DVD CSS key reporting */
#define DVD_SEND_KEY		0x5392  /* DVD CSS key sending */

.....

/*******************************************************
 * DVD-ROM IOCTL structures
 *******************************************************/

/* This is used with the DVD_READ_STRUCT ioctl */
#define DVD_STRUCT_PHYSICAL	0x00
#define DVD_STRUCT_COPYRIGHT	0x01
#define DVD_STRUCT_DISCKEY	0x02
#define DVD_STRUCT_BCA		0x03
#define DVD_STRUCT_MANUFACT	0x04
union dvd_read_struct {
	u_char type;
	struct {
		u_char type;
		u_char layer_num;
		struct dvd_layer {
			unsigned book_version	: 4;
			unsigned book_type	: 4;
			unsigned min_rate	: 4;
			unsigned disc_size	: 4;
			unsigned layer_type	: 4;
			unsigned track_path	: 1;
			unsigned nlayers	: 2;
			unsigned track_density	: 4;
			unsigned linear_density	: 4;
			unsigned bca		: 1;
			unsigned start_sector;
			unsigned end_sector;
			unsigned end_sector_l0;
		} layer[4];
	} physical;
	struct {
		u_char type;
		u_char layer_num;
		u_char cpst;
		u_char rmi;
	} copyright;
	struct {
		u_char type;
		unsigned agid			: 2;
		u_char value[2048];
	} disckey;
	struct {
		u_char type;
		int len;
		u_char value[188];
	} bca;
	struct {
		u_char type;
		u_char layer_num;
		int len;
		u_char value[2048];
	} manufact;
};

/* Key invalidation for DVD_REPORT_KEY and DVD_SEND_KEY ioctls.  Must
   be used to reset authentication process. */
#define DVD_KEY_INVAL_AGID	0x7f

/* This is used by the DVD_REPORT_KEY ioctl */
#define DVD_REPORT_KEY_AGID	0x00
#define DVD_REPORT_KEY_CHAL	0x01
#define DVD_REPORT_KEY_KEY1	0x02
#define DVD_REPORT_KEY_TITLE	0x04
#define DVD_REPORT_KEY_ASF	0x05
union dvd_report_key {
	u_char type;
	struct {
		u_char type;
		unsigned value		: 2;
	} agid;
	struct {
		u_char type;
		unsigned agid		: 2;
		u_char value[10];
	} chal;
	struct {
		u_char type;
		unsigned agid		: 2;
		u_char value[5];
	} key1;
	struct {
		u_char type;
		unsigned agid		: 2;
		u_char value[5];
		unsigned cpm		: 1;
		unsigned cp_sec		: 1;
		unsigned cgms		: 2;
	} title_key;
	struct {
		u_char type;
		unsigned agid		: 2;
		unsigned value		: 1;
	} asf;
};

/* This is used by the DVD_SEND_KEY ioctl */
#define DVD_SEND_KEY_CHAL	0x01
#define DVD_SEND_KEY_KEY2	0x03
union dvd_send_key {
	u_char type;
	struct {
		u_char type;
		unsigned value		: 2;
	} agid;
	struct {
		u_char type;
		unsigned agid		: 2;
		u_char value[10];
	} chal;
	struct {
		u_char type;
		unsigned agid		: 2;
		u_char value[5];
	} key2;
};

..
 ~~~~~~~~~================-------------......---
--

        Andrew Veliath
	andr...@usa.net, vel...@rpi.edu

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/