Mercurial > mplayer.hg
comparison dvdauth.c @ 492:888a85621f50
preliminary DVD support using libcss
author | lgb |
---|---|
date | Tue, 17 Apr 2001 22:04:44 +0000 |
parents | |
children | 22ed5f5821e2 |
comparison
equal
deleted
inserted
replaced
491:2313c6ea006f | 492:888a85621f50 |
---|---|
1 /* (C)2001 by LGB (Gabor Lenart), based on example programs in libcss | |
2 Some TODO: root privilegies really needed?? */ | |
3 | |
4 /* don't do anything with this source if css support was not requested */ | |
5 #include "config.h" | |
6 #ifdef HAVE_LIBCSS | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <linux/cdrom.h> | |
11 // FIXME #include <string.h> conflicts with #include <linux/fs.h> (below) | |
12 //#include <string.h> // FIXME this conflicts with #include <linux/fs.h> | |
13 #include <unistd.h> | |
14 #include <fcntl.h> | |
15 #include <sys/types.h> | |
16 #include <sys/ioctl.h> | |
17 #include <sys/stat.h> | |
18 | |
19 #include <css.h> | |
20 | |
21 #include "dvdauth.h" | |
22 | |
23 char *dvd_device=NULL; | |
24 unsigned char key_disc[2048]; | |
25 unsigned char key_title[5]; | |
26 | |
27 | |
28 #include <linux/fs.h> | |
29 | |
30 #ifndef FIBMAP | |
31 #define FIBMAP 1 | |
32 #endif | |
33 | |
34 | |
35 static int path_to_lba ( int fd ) | |
36 { | |
37 int lba = 0; | |
38 if (ioctl(fd, FIBMAP, &lba) < 0) { | |
39 perror ("ioctl FIBMAP"); | |
40 fprintf(stderr,"Hint: run mplayer as root!\n"); | |
41 // close(fd); | |
42 return -1; | |
43 } | |
44 return lba; | |
45 } | |
46 | |
47 | |
48 | |
49 static void reset_agids ( int fd ) | |
50 { | |
51 dvd_authinfo ai; | |
52 int i; | |
53 for (i = 0; i < 4; i++) { | |
54 memset(&ai, 0, sizeof(ai)); | |
55 ai.type = DVD_INVALIDATE_AGID; | |
56 ai.lsa.agid = i; | |
57 ioctl(fd, DVD_AUTH, &ai); | |
58 } | |
59 } | |
60 | |
61 | |
62 | |
63 int dvd_auth ( char *dev , int fd ) | |
64 { | |
65 int devfd; /* FD of DVD device */ | |
66 int lba; | |
67 | |
68 // printf("DVD: auth fd=%d on %s.\n",fd,dev); | |
69 | |
70 if ((devfd=open(dev,O_RDONLY))<0) { | |
71 fprintf(stderr,"DVD: cannot open DVD device \"%s\".\n",dev); | |
72 return 1; | |
73 } | |
74 | |
75 /* reset AGIDs */ | |
76 reset_agids(devfd); | |
77 | |
78 /* authenticate disc */ | |
79 if (CSSAuthDisc(devfd,key_disc)) { | |
80 fprintf(stderr,"DVD: CSSAuthDisc() failed.\n"); | |
81 return 1; | |
82 } | |
83 | |
84 /* authenticate title */ | |
85 lba=path_to_lba(fd); | |
86 if (lba==-1) { | |
87 fprintf(stderr,"DVD: path_to_lba() failed.\n"); | |
88 return 1; | |
89 } | |
90 if (CSSAuthTitle(devfd,key_title,lba)) { | |
91 fprintf(stderr,"DVD: CSSAuthTitle() failed.\n"); | |
92 return 1; | |
93 } | |
94 | |
95 /* decrypting title */ | |
96 if (CSSDecryptTitleKey (key_title, key_disc) < 0) { | |
97 fprintf(stderr,"DVD: CSSDecryptTitleKey() failed.\n"); | |
98 return 1; | |
99 } | |
100 | |
101 close(devfd); | |
102 return 0; | |
103 } | |
104 | |
105 | |
106 #endif |