LimHD:DVDCSS
Unfortunately, libdvdcss's csstest program claim all the disks I've tried are not scrambled:
uclibc[/tmp]# ./csstest /dev/scsi/host0/bus0/target0/lun0/cd cool, I found libdvdcss version 1.2.9 examples: ./csstest /dev/hdc 1024 ./csstest D: 1024 ./csstest scrambledfile.vob 1024 uclibc[/tmp]# ./csstest /dev/scsi/host0/bus0/target0/lun0/cd 1024 cool, I found libdvdcss version 1.2.9 requested sector: 00 00 01 2u... 2{ 1i 0� 2e 2� 17 1n 1} 2� 0d 05 1} 2� 09 1� 1� 2s 3g 2� 0l 03 2�... sector is not scrambled uclibc[/tmp]# ./csstest /mnt/USB1/video_ts/vts_01_2.vob 1024 cool, I found libdvdcss version 1.2.9 zS@j>-�301�}�<O2NR���BV1�cn����-�pC>݃�"��?���?��E?��v?��?���?�̂?��E?���?��?���?@j>zS@j>-�30�...<O2NR���BV1�cn����-��?���?��E?��v?��?���?�̂?��E?���?��?���?��"Q sector is not scrambled
Ah just a misunderstanding of how csstest works. That's the block I want to unscramble, and only video streams are scrambled.
uclibc[/tmp]# ./csstest /dev/scsi/host0/bus0/target0/lun0/cd 1000001 cool, I found libdvdcss version 1.2.9 requested sector: 00 00 01 2c... 0� 0� 2� 18 1� 2~ 2� 2� 0� 0} 1w 0� 2� 1p 0g 2 2� 0� 2e 2g 0� 0d 0�... unscrambled sector: 00 00 01 2c... 2� 1� 1s 1z 1� 2 2� 1� 0� 1f 1u 0| 2p 0� 0� 1� 0� 0� 27 0� 13 1l...
So, I remain positive that this can be done. However, since Fuse does not want to run easily, I thought I would attempt to get CSS internal to em8xxx.o to work. All the code is in there, but curacao does not call it, or set it up.
The EM8xxx.PDF file claim to enable DVD-CSS you need but to load the title key with set_CSStitlekey() before demuxing begins.
I thought I would dlopen('em8xxx.o') from my program and call said function, but unfortunately you can not use dlopen in uClinux. (or at least not the version I have / LimHD runs).
So, the proper way is actually to open /dev/em8xxx0 device, and use ioctl to communicate with it. This is what curacao does after all. I have not done much ioctl programming lately, so I am rusty. This is the next thing I shall try however.
My pseudo-code for the daemon would be:
$cd_dev=/dev/scsi/host0/target0/lun0/cd loop forver if $cd_dev has changed (how can we detect a new CD? research) call libdvdread and obtain disckey and titlekey call em8xxx.o via ioctl to hand over both. hope to hell that that just magically works.
Right, so the ioctl looks like:
#define EM8XXX_IOCTL_MAGIC 'E' #define EM8XXX_IOCTL_SET_PROPERTY _IOWR( EM8XXX_IOCTL_MAGIC, 1, struct em8xxx_property) struct em8xxx_property { RMuint32 moduleId; RMuint32 propId; void *propInVal; RMuint32 propInSize; void *propOutVal; RMuint32 propOutSize; RMstatus status; }; RMVideoDecoderPropertyID_CSSdisckey = 6123 0x17eb RMVideoDecoderPropertyID_CSStitlekey = 6124
I am not sure what ModuleId is of yet. It is used when the kernel code calls em8xxx library (private.o).
The documentation on the matter say:
The DVD decryption unit is controlled by 5 registers. The controller register indicates the number of bytes to process, typically 2048 for a DVD sector. If the count is programmed to 4095 (reset value), then the DVD decryption block is transparent. The start indicates how many bytes must be transferred before the decryption begins, typically 128 for a DVD sector. In a 2048-byte encrypted sector, the first 128-byte are clear and the last 1920- byte are encrypted. Before starting the decryption, the 40-bit title key must be pro- grammed in the key registers. The two state registers allow a backup of the decryption block internal state. This is required when a context switch occurs while a DVD sector is only partially processed.
I grabbed a disc and title key from a known disk, wrote a program to issue the ioctl to set the keys, setting moduleId to 0 (what should it be I wonder?) but unfortunately:
uclibc[/tmp]# ./2dvd_em8xxx /dev/em8xxx0 1 ./2dvd_em8xxx: Patch Disc and Title keys into em8xxx.o 1' ... set_CSStitlekey says 0
and then it hangs. Quite peculiar. ioctl actually returns, and successfully at that. And yet the machine dies before the program can exit.
Minor success. Using moduleId of 9 make it do "something". It loads both disckey and titlekey without crashing. Then when I try to play that vts_02_1.vob file it actually starts to play. First frame is perfect. However, play is very jerky (stop/start) and have a lot of macroblocks / corruption. I am used to the video being all "green" when it's encrypted so I am not sure what to think.
My current train of thought is that the DVDRom that I have will not let me read the data without first authenticating with the drive. With all my hacks, I must have eventually done so, which enabled LimHD to attempt to play the DVD. The jerks and corruption could be failure to descramble the blocks, but not all blocks are scrambled.
I am thinking I should call all the ewhlib functions to authenticate the drive now.
But ultimately, if a title changes key in the middle, we have no way to succeed.
Ok, what it comes down to is me authenticating the drive, which lets me play the files. They are not unscrambled so that is why they appear blocky. My loading of CSStitlekey is failing, 99% sure it is due to me not knowing what moduleId to use.