Mercurial > mplayer.hg
annotate libmpdvdkit2/libdvdcss.c @ 16789:def7bbb898a3
synced with 1.1139 + Reimar's patch
author | gpoirier |
---|---|
date | Mon, 17 Oct 2005 20:44:17 +0000 |
parents | 2ab52c9b72b9 |
children | 279cd50f2ba0 |
rev | line source |
---|---|
7027 | 1 /* libdvdcss.c: DVD reading library. |
2 * | |
3 * Authors: Stéphane Borel <stef@via.ecp.fr> | |
4 * Samuel Hocevar <sam@zoy.org> | |
5 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
6 * | |
7 * Copyright (C) 1998-2002 VideoLAN | |
16631 | 8 * |
9 * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff. | |
10 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ | |
7027 | 11 * $Id$ |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
17 * |
7027 | 18 * This program is distributed in the hope that it will be useful, |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 * GNU General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. | |
26 */ | |
27 | |
16630 | 28 /** |
7027 | 29 * \mainpage libdvdcss developer documentation |
30 * | |
31 * \section intro Introduction | |
32 * | |
33 * \e libdvdcss is a simple library designed for accessing DVDs like a block | |
34 * device without having to bother about the decryption. The important features | |
35 * are: | |
36 * \li portability: currently supported platforms are GNU/Linux, FreeBSD, | |
37 * NetBSD, OpenBSD, BSD/OS, BeOS, Windows 95/98, Windows NT/2000, MacOS X, | |
38 * Solaris, HP-UX and OS/2. | |
39 * \li adaptability: unlike most similar projects, libdvdcss doesn't require | |
40 * the region of your drive to be set and will try its best to read from | |
41 * the disc even in the case of a region mismatch. | |
42 * \li simplicity: a DVD player can be built around the \e libdvdcss API using | |
43 * no more than 4 or 5 library calls. | |
44 * | |
45 * \e libdvdcss is free software, released under the General Public License. | |
46 * This ensures that \e libdvdcss remains free and used only with free | |
47 * software. | |
48 * | |
49 * \section api The libdvdcss API | |
50 * | |
51 * The complete \e libdvdcss programming interface is documented in the | |
52 * dvdcss.h file. | |
53 * | |
54 * \section env Environment variables | |
55 * | |
56 * Some environment variables can be used to change the behaviour of | |
57 * \e libdvdcss without having to modify the program which uses it. These | |
58 * variables are: | |
59 * | |
60 * \li \b DVDCSS_VERBOSE: sets the verbosity level. | |
61 * - \c 0 outputs no messages at all. | |
62 * - \c 1 outputs error messages to stderr. | |
63 * - \c 2 outputs error messages and debug messages to stderr. | |
64 * | |
65 * \li \b DVDCSS_METHOD: sets the authentication and decryption method | |
66 * that \e libdvdcss will use to read scrambled discs. Can be one | |
67 * of \c title, \c key or \c disc. | |
68 * - \c key is the default method. \e libdvdcss will use a set of | |
69 * calculated player keys to try and get the disc key. This can fail | |
70 * if the drive does not recognize any of the player keys. | |
71 * - \c disc is a fallback method when \c key has failed. Instead of | |
72 * using player keys, \e libdvdcss will crack the disc key using | |
73 * a brute force algorithm. This process is CPU intensive and requires | |
74 * 64 MB of memory to store temporary data. | |
75 * - \c title is the fallback when all other methods have failed. It does | |
76 * not rely on a key exchange with the DVD drive, but rather uses a | |
77 * crypto attack to guess the title key. On rare cases this may fail | |
78 * because there is not enough encrypted data on the disc to perform | |
79 * a statistical attack, but in the other hand it is the only way to | |
80 * decrypt a DVD stored on a hard disc, or a DVD with the wrong region | |
81 * on an RPC2 drive. | |
82 * | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
83 * \li \b DVDCSS_RAW_DEVICE: specify the raw device to use. Exact usage will |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
84 * depend on your operating system, the Linux utility to set up raw devices |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
85 * is \c raw(8) for instance. Please note that on most operating systems, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
86 * using a raw device requires highly aligned buffers: Linux requires a |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
87 * 2048 bytes alignment (which is the size of a DVD sector). |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
88 * |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
89 * \li \b DVDCSS_CACHE: specify a directory in which to store title key |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
90 * values. This will speed up descrambling of DVDs which are in the |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
91 * cache. The DVDCSS_CACHE directory is created if it does not exist, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
92 * and a subdirectory is created named after the DVD's title or |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
93 * manufacturing date. |
7027 | 94 */ |
95 | |
96 /* | |
97 * Preamble | |
98 */ | |
99 #include "config.h" | |
100 | |
101 #include <stdio.h> | |
102 #include <stdlib.h> | |
103 #include <string.h> | |
104 #include <sys/types.h> | |
105 #include <sys/stat.h> | |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
106 #ifdef HAVE_SYS_PARAM_H |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
107 # include <sys/param.h> |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
108 #endif |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
109 #ifdef HAVE_PWD_H |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
110 # include <pwd.h> |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
111 #endif |
7027 | 112 #include <fcntl.h> |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
113 #include <errno.h> |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
114 |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
115 #ifdef HAVE_UNISTD_H |
16630 | 116 # include <unistd.h> |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
117 #endif |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
118 |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
119 #ifdef HAVE_LIMITS_H |
16630 | 120 # include <limits.h> |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
121 #endif |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
122 |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
123 #ifdef HAVE_DIRECT_H |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
124 # include <direct.h> |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
125 #endif |
7027 | 126 |
7033 | 127 #include "dvdcss.h" |
7027 | 128 |
129 #include "common.h" | |
130 #include "css.h" | |
131 #include "libdvdcss.h" | |
132 #include "ioctl.h" | |
133 #include "device.h" | |
134 | |
9882 | 135 #ifndef HAVE_MPLAYER |
136 #include "get_path.c" | |
137 #else | |
138 extern char * get_path( char * filename ); | |
139 #endif | |
140 | |
7027 | 141 /** |
142 * \brief Symbol for version checks. | |
143 * | |
144 * The name of this symbol contains the library major number, which makes it | |
145 * easy to check which \e libdvdcss development headers are installed on the | |
146 * system with tools such as autoconf. | |
147 * | |
148 * The variable itself contains the exact version number of the library, | |
149 * which can be useful for specific feature needs. | |
150 */ | |
151 char * dvdcss_interface_2 = VERSION; | |
152 | |
153 /** | |
154 * \brief Open a DVD device or directory and return a dvdcss instance. | |
155 * | |
156 * \param psz_target a string containing the target name, for instance | |
157 * "/dev/hdc" or "E:". | |
158 * \return a handle to a dvdcss instance or NULL on error. | |
159 * | |
160 * Initialize the \e libdvdcss library and open the requested DVD device or | |
161 * directory. \e libdvdcss checks whether ioctls can be performed on the disc, | |
162 * and when possible, the disc key is retrieved. | |
163 * | |
164 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss | |
165 * calls. If an error occured, NULL is returned. | |
166 */ | |
167 extern dvdcss_t dvdcss_open ( char *psz_target ) | |
168 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
169 char psz_buffer[PATH_MAX]; |
7027 | 170 int i_ret; |
171 | |
172 char *psz_method = getenv( "DVDCSS_METHOD" ); | |
173 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
174 char *psz_cache = getenv( "DVDCSS_CACHE" ); |
7027 | 175 #ifndef WIN32 |
176 char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" ); | |
177 #endif | |
178 | |
179 dvdcss_t dvdcss; | |
180 | |
181 /* | |
182 * Allocate the library structure | |
183 */ | |
184 dvdcss = malloc( sizeof( struct dvdcss_s ) ); | |
185 if( dvdcss == NULL ) | |
186 { | |
187 return NULL; | |
188 } | |
189 | |
190 /* | |
191 * Initialize structure with default values | |
192 */ | |
193 #ifndef WIN32 | |
194 dvdcss->i_raw_fd = -1; | |
195 #endif | |
196 dvdcss->p_titles = NULL; | |
197 dvdcss->psz_device = (char *)strdup( psz_target ); | |
198 dvdcss->psz_error = "no error"; | |
199 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
200 dvdcss->psz_cachefile[0] = '\0'; |
7027 | 201 dvdcss->b_debug = 0; |
202 dvdcss->b_errors = 0; | |
203 | |
204 /* | |
205 * Find verbosity from DVDCSS_VERBOSE environment variable | |
206 */ | |
207 if( psz_verbose != NULL ) | |
208 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
209 int i = atoi( psz_verbose ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
210 |
16630 | 211 if( i >= 2 ) dvdcss->b_debug = i; |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
212 if( i >= 1 ) dvdcss->b_errors = 1; |
7027 | 213 } |
214 | |
215 /* | |
216 * Find method from DVDCSS_METHOD environment variable | |
217 */ | |
218 if( psz_method != NULL ) | |
219 { | |
220 if( !strncmp( psz_method, "key", 4 ) ) | |
221 { | |
222 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
223 } | |
224 else if( !strncmp( psz_method, "disc", 5 ) ) | |
225 { | |
226 dvdcss->i_method = DVDCSS_METHOD_DISC; | |
227 } | |
228 else if( !strncmp( psz_method, "title", 5 ) ) | |
229 { | |
230 dvdcss->i_method = DVDCSS_METHOD_TITLE; | |
231 } | |
232 else | |
233 { | |
16630 | 234 print_error( dvdcss, "unknown decrypt method, please choose " |
235 "from 'title', 'key' or 'disc'" ); | |
7027 | 236 free( dvdcss->psz_device ); |
237 free( dvdcss ); | |
238 return NULL; | |
239 } | |
240 } | |
241 | |
16630 | 242 #if 0 /* MPlayer caches keys in its own configuration directory */ |
243 | |
244 /* | |
245 * If DVDCSS_CACHE was not set, try to guess a default value | |
246 */ | |
247 if( psz_cache == NULL || psz_cache[0] == '\0' ) | |
248 { | |
249 #ifdef HAVE_DIRECT_H | |
250 typedef HRESULT( WINAPI *SHGETFOLDERPATH ) | |
251 ( HWND, int, HANDLE, DWORD, LPTSTR ); | |
252 | |
253 # define CSIDL_FLAG_CREATE 0x8000 | |
254 # define CSIDL_APPDATA 0x1A | |
255 # define SHGFP_TYPE_CURRENT 0 | |
256 | |
257 char psz_home[MAX_PATH]; | |
258 HINSTANCE p_dll; | |
259 SHGETFOLDERPATH p_getpath; | |
260 | |
261 *psz_home = '\0'; | |
262 | |
263 /* Load the shfolder dll to retrieve SHGetFolderPath */ | |
264 p_dll = LoadLibrary( "shfolder.dll" ); | |
265 if( p_dll ) | |
266 { | |
267 p_getpath = (void*)GetProcAddress( p_dll, "SHGetFolderPathA" ); | |
268 if( p_getpath ) | |
269 { | |
270 /* Get the "Application Data" folder for the current user */ | |
271 if( p_getpath( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, | |
272 NULL, SHGFP_TYPE_CURRENT, psz_home ) == S_OK ) | |
273 { | |
274 FreeLibrary( p_dll ); | |
275 } | |
276 else | |
277 { | |
278 *psz_home = '\0'; | |
279 } | |
280 } | |
281 FreeLibrary( p_dll ); | |
282 } | |
283 | |
284 /* Cache our keys in | |
285 * C:\Documents and Settings\$USER\Application Data\dvdcss\ */ | |
286 if( *psz_home ) | |
287 { | |
288 snprintf( psz_buffer, PATH_MAX, "%s/dvdcss", psz_home ); | |
289 psz_buffer[PATH_MAX-1] = '\0'; | |
290 psz_cache = psz_buffer; | |
291 } | |
292 #else | |
293 char *psz_home = NULL; | |
294 # ifdef HAVE_PWD_H | |
295 struct passwd *p_pwd; | |
296 | |
297 /* Try looking in password file for home dir. */ | |
298 p_pwd = getpwuid(getuid()); | |
299 if( p_pwd ) | |
300 { | |
301 psz_home = p_pwd->pw_dir; | |
302 } | |
303 # endif | |
304 | |
305 if( psz_home == NULL ) | |
306 { | |
307 psz_home = getenv( "HOME" ); | |
308 } | |
309 | |
310 /* Cache our keys in ${HOME}/.dvdcss/ */ | |
311 if( psz_home ) | |
312 { | |
313 snprintf( psz_buffer, PATH_MAX, "%s/.dvdcss", psz_home ); | |
314 psz_buffer[PATH_MAX-1] = '\0'; | |
315 psz_cache = psz_buffer; | |
316 } | |
317 #endif | |
318 } | |
319 | |
320 #endif /* 0 */ | |
321 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
322 /* |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
323 * Find cache dir from the DVDCSS_CACHE environment variable |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
324 */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
325 if( psz_cache != NULL ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
326 { |
16630 | 327 if( psz_cache[0] == '\0' || !strcmp( psz_cache, "off" ) ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
328 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
329 psz_cache = NULL; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
330 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
331 /* Check that we can add the ID directory and the block filename */ |
16630 | 332 else if( strlen( psz_cache ) + 1 + 32 + 1 + (KEY_SIZE * 2) + 10 + 1 |
333 > PATH_MAX ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
334 { |
16630 | 335 print_error( dvdcss, "cache directory name is too long" ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
336 psz_cache = NULL; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
337 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
338 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
339 else psz_cache = get_path( "DVDKeys" ); |
7032 | 340 |
7027 | 341 /* |
342 * Open device | |
343 */ | |
344 i_ret = _dvdcss_open( dvdcss ); | |
345 if( i_ret < 0 ) | |
346 { | |
347 free( dvdcss->psz_device ); | |
348 free( dvdcss ); | |
349 return NULL; | |
350 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
351 |
7027 | 352 dvdcss->b_scrambled = 1; /* Assume the worst */ |
353 dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss ); | |
354 | |
355 if( dvdcss->b_ioctls ) | |
356 { | |
357 i_ret = _dvdcss_test( dvdcss ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
358 if( i_ret < 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
359 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
360 /* Disable the CSS ioctls and hope that it works? */ |
16630 | 361 print_debug( dvdcss, |
362 "could not check whether the disc was scrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
363 dvdcss->b_ioctls = 0; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
364 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
365 else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
366 { |
16630 | 367 print_debug( dvdcss, i_ret ? "disc is scrambled" |
368 : "disc is unscrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
369 dvdcss->b_scrambled = i_ret; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
370 } |
7027 | 371 } |
372 | |
373 /* If disc is CSS protected and the ioctls work, authenticate the drive */ | |
374 if( dvdcss->b_scrambled && dvdcss->b_ioctls ) | |
375 { | |
376 i_ret = _dvdcss_disckey( dvdcss ); | |
377 | |
378 if( i_ret < 0 ) | |
379 { | |
380 _dvdcss_close( dvdcss ); | |
381 free( dvdcss->psz_device ); | |
382 free( dvdcss ); | |
383 return NULL; | |
384 } | |
385 } | |
386 | |
16630 | 387 /* If the cache is enabled, write the cache directory tag */ |
388 if( psz_cache ) | |
389 { | |
390 char *psz_tag = "Signature: 8a477f597d28d172789f06886806bc55\r\n" | |
391 "# This file is a cache directory tag created by libdvdcss.\r\n" | |
392 "# For information about cache directory tags, see:\r\n" | |
393 "# http://www.brynosaurus.com/cachedir/\r\n"; | |
394 unsigned char psz_tagfile[PATH_MAX+1+12+1]; | |
395 int i_fd; | |
396 | |
397 sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache ); | |
398 i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 ); | |
399 if( i_fd >= 0 ) | |
400 { | |
401 write( i_fd, psz_tag, strlen(psz_tag) ); | |
402 close( i_fd ); | |
403 } | |
404 } | |
405 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
406 /* If the cache is enabled, extract a unique disc ID */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
407 if( psz_cache ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
408 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
409 uint8_t p_sector[DVDCSS_BLOCK_SIZE]; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
410 unsigned char psz_debug[PATH_MAX+30]; |
16630 | 411 unsigned char psz_key[1 + KEY_SIZE * 2 + 1]; |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
412 unsigned char * psz_title, * psz_serial; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
413 int i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
414 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
415 /* We read sector 0. If it starts with 0x000001ba (BE), we are |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
416 * reading a VOB file, and we should not cache anything. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
417 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
418 i_ret = dvdcss->pf_seek( dvdcss, 0 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
419 if( i_ret != 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
420 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
421 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
422 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
423 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
424 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
425 if( i_ret != 1 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
426 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
427 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
428 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
429 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
430 if( p_sector[0] == 0x00 && p_sector[1] == 0x00 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
431 && p_sector[2] == 0x01 && p_sector[3] == 0xba ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
432 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
433 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
434 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
435 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
436 /* The data we are looking for is at sector 16 (32768 bytes): |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
437 * - offset 40: disc title (32 uppercase chars) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
438 * - offset 813: manufacturing date + serial no (16 digits) */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
439 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
440 i_ret = dvdcss->pf_seek( dvdcss, 16 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
441 if( i_ret != 16 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
442 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
443 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
444 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
445 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
446 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
447 if( i_ret != 1 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
448 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
449 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
450 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
451 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
452 /* Get the disc title */ |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
453 psz_title = p_sector + 40; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
454 psz_title[32] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
455 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
456 for( i = 0 ; i < 32 ; i++ ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
457 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
458 if( psz_title[i] <= ' ' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
459 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
460 psz_title[i] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
461 break; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
462 } |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
463 else if( psz_title[i] == '/' || psz_title[i] == '\\' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
464 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
465 psz_title[i] = '-'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
466 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
467 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
468 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
469 /* Get the date + serial */ |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
470 psz_serial = p_sector + 813; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
471 psz_serial[16] = '\0'; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
472 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
473 /* Check that all characters are digits, otherwise convert. */ |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
474 for( i = 0 ; i < 16 ; i++ ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
475 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
476 if( psz_serial[i] < '0' || psz_serial[i] > '9' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
477 { |
16630 | 478 unsigned char psz_tmp[16 + 1]; |
479 sprintf( psz_tmp, | |
480 "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
481 psz_serial[0], psz_serial[1], psz_serial[2], |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
482 psz_serial[3], psz_serial[4], psz_serial[5], |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
483 psz_serial[6], psz_serial[7] ); |
16630 | 484 memcpy( psz_serial, psz_tmp, 16 ); |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
485 break; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
486 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
487 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
488 |
16630 | 489 /* Get disk key, since some discs have got same title, manufacturing |
490 * date and serial number, but different keys */ | |
491 if( dvdcss->b_scrambled ) | |
492 { | |
493 psz_key[0] = '-'; | |
494 for( i = 0; i < KEY_SIZE; i++ ) | |
495 { | |
496 sprintf( &psz_key[1+i*2], "%.2x", dvdcss->css.p_disc_key[i] ); | |
497 } | |
498 psz_key[1 + KEY_SIZE * 2] = '\0'; | |
499 } | |
500 else | |
501 { | |
502 psz_key[0] = 0; | |
503 } | |
504 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
505 /* We have a disc name or ID, we can create the cache dir */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
506 i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
507 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
508 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
509 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
510 i_ret = mkdir( dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
511 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
512 if( i_ret < 0 && errno != EEXIST ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
513 { |
16630 | 514 print_error( dvdcss, "failed creating cache directory" ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
515 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
516 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
517 } |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
518 i += sprintf( dvdcss->psz_cachefile + i, "/"); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
519 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
520 // i += sprintf( dvdcss->psz_cachefile + i, "/%s", psz_data ); |
16630 | 521 i += sprintf( dvdcss->psz_cachefile + i, "/%s#%s", psz_title, psz_serial ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
522 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
523 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
524 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
525 i_ret = mkdir( dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
526 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
527 if( i_ret < 0 && errno != EEXIST ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
528 { |
16630 | 529 print_error( dvdcss, "failed creating cache subdirectory" ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
530 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
531 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
532 } |
9882 | 533 i += sprintf( dvdcss->psz_cachefile + i, "/"); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
534 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
535 /* Pointer to the filename we will use. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
536 dvdcss->psz_block = dvdcss->psz_cachefile + i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
537 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
538 sprintf( psz_debug, "using CSS key cache dir: %s", |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
539 dvdcss->psz_cachefile ); |
16630 | 540 print_debug( dvdcss, psz_debug ); |
7032 | 541 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
542 nocache: |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
543 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
544 #ifndef WIN32 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
545 if( psz_raw_device != NULL ) |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
546 { |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
547 _dvdcss_raw_open( dvdcss, psz_raw_device ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
548 } |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
549 #endif |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
550 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
551 /* Seek at the beginning, just for safety. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
552 dvdcss->pf_seek( dvdcss, 0 ); |
7032 | 553 |
7027 | 554 return dvdcss; |
555 } | |
556 | |
557 /** | |
558 * \brief Return a string containing the latest error that occured in the | |
559 * given \e libdvdcss instance. | |
560 * | |
561 * \param dvdcss a \e libdvdcss instance. | |
562 * \return a null-terminated string containing the latest error message. | |
563 * | |
564 * This function returns a constant string containing the latest error that | |
565 * occured in \e libdvdcss. It can be used to format error messages at your | |
566 * convenience in your application. | |
567 */ | |
568 extern char * dvdcss_error ( dvdcss_t dvdcss ) | |
569 { | |
570 return dvdcss->psz_error; | |
571 } | |
572 | |
573 /** | |
574 * \brief Seek in the disc and change the current key if requested. | |
575 * | |
576 * \param dvdcss a \e libdvdcss instance. | |
577 * \param i_blocks an absolute block offset to seek to. | |
578 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with one of #DVDCSS_SEEK_KEY | |
579 * or #DVDCSS_SEEK_MPEG. | |
580 * \return the new position in blocks, or a negative value in case an error | |
581 * happened. | |
582 * | |
583 * This function seeks to the requested position, in logical blocks. | |
584 * | |
585 * You typically set \p i_flags to #DVDCSS_NOFLAGS when seeking in a .IFO. | |
586 * | |
587 * If #DVDCSS_SEEK_MPEG is specified in \p i_flags and if \e libdvdcss finds it | |
588 * reasonable to do so (ie, if the dvdcss method is not "title"), the current | |
589 * title key will be checked and a new one will be calculated if necessary. | |
590 * This flag is typically used when reading data from a VOB. | |
591 * | |
592 * If #DVDCSS_SEEK_KEY is specified, the title key will be always checked, | |
593 * even with the "title" method. This is equivalent to using the now | |
594 * deprecated dvdcss_title() call. This flag is typically used when seeking | |
595 * in a new title. | |
596 */ | |
597 extern int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) | |
598 { | |
599 /* title cracking method is too slow to be used at each seek */ | |
600 if( ( ( i_flags & DVDCSS_SEEK_MPEG ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
601 && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) ) |
7027 | 602 || ( i_flags & DVDCSS_SEEK_KEY ) ) |
603 { | |
604 /* check the title key */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
605 if( _dvdcss_title( dvdcss, i_blocks ) ) |
7027 | 606 { |
607 return -1; | |
608 } | |
609 } | |
610 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
611 return dvdcss->pf_seek( dvdcss, i_blocks ); |
7027 | 612 } |
613 | |
614 /** | |
615 * \brief Read from the disc and decrypt data if requested. | |
616 * | |
617 * \param dvdcss a \e libdvdcss instance. | |
618 * \param p_buffer a buffer that will contain the data read from the disc. | |
619 * \param i_blocks the amount of blocks to read. | |
620 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
621 * \return the amount of blocks read, or a negative value in case an | |
622 * error happened. | |
623 * | |
624 * This function reads \p i_blocks logical blocks from the DVD. | |
625 * | |
626 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
627 * .IFO file on the DVD. | |
628 * | |
629 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_read() will | |
630 * automatically decrypt scrambled sectors. This flag is typically used when | |
631 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
632 * discs or unscrambled sectors, and can be safely used on those. | |
633 * | |
634 * \warning dvdcss_read() expects to be able to write \p i_blocks * | |
635 * #DVDCSS_BLOCK_SIZE bytes in \p p_buffer. | |
636 */ | |
637 extern int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, | |
638 int i_blocks, | |
639 int i_flags ) | |
640 { | |
641 int i_ret, i_index; | |
642 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
643 i_ret = dvdcss->pf_read( dvdcss, p_buffer, i_blocks ); |
7027 | 644 |
645 if( i_ret <= 0 | |
646 || !dvdcss->b_scrambled | |
647 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
648 { | |
649 return i_ret; | |
650 } | |
651 | |
652 if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) ) | |
653 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
654 /* For what we believe is an unencrypted title, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
655 * check that there are no encrypted blocks */ |
7027 | 656 for( i_index = i_ret; i_index; i_index-- ) |
657 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
658 if( ((uint8_t*)p_buffer)[0x14] & 0x30 ) |
7027 | 659 { |
16630 | 660 print_error( dvdcss, "no key but found encrypted block" ); |
7027 | 661 /* Only return the initial range of unscrambled blocks? */ |
662 /* or fail completely? return 0; */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
663 break; |
7027 | 664 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
665 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
7027 | 666 } |
667 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
668 else |
7027 | 669 { |
670 /* Decrypt the blocks we managed to read */ | |
671 for( i_index = i_ret; i_index; i_index-- ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
672 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
673 _dvdcss_unscramble( dvdcss->css.p_title_key, p_buffer ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
674 ((uint8_t*)p_buffer)[0x14] &= 0x8f; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
675 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
676 } |
7027 | 677 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
678 |
7027 | 679 return i_ret; |
680 } | |
681 | |
682 /** | |
683 * \brief Read from the disc into multiple buffers and decrypt data if | |
684 * requested. | |
685 * | |
686 * \param dvdcss a \e libdvdcss instance. | |
687 * \param p_iovec a pointer to an array of iovec structures that will contain | |
688 * the data read from the disc. | |
689 * \param i_blocks the amount of blocks to read. | |
690 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
691 * \return the amount of blocks read, or a negative value in case an | |
692 * error happened. | |
693 * | |
694 * This function reads \p i_blocks logical blocks from the DVD and writes them | |
695 * to an array of iovec structures. | |
696 * | |
697 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
698 * .IFO file on the DVD. | |
699 * | |
700 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_readv() will | |
701 * automatically decrypt scrambled sectors. This flag is typically used when | |
702 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
703 * discs or unscrambled sectors, and can be safely used on those. | |
704 * | |
705 * \warning dvdcss_readv() expects to be able to write \p i_blocks * | |
706 * #DVDCSS_BLOCK_SIZE bytes in the buffers pointed by \p p_iovec. | |
707 * Moreover, all iov_len members of the iovec structures should be | |
708 * multiples of #DVDCSS_BLOCK_SIZE. | |
709 */ | |
710 extern int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, | |
711 int i_blocks, | |
712 int i_flags ) | |
713 { | |
714 struct iovec *_p_iovec = (struct iovec *)p_iovec; | |
715 int i_ret, i_index; | |
716 void *iov_base; | |
717 size_t iov_len; | |
718 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
719 i_ret = dvdcss->pf_readv( dvdcss, _p_iovec, i_blocks ); |
7027 | 720 |
721 if( i_ret <= 0 | |
722 || !dvdcss->b_scrambled | |
723 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
724 { | |
725 return i_ret; | |
726 } | |
727 | |
728 /* Initialize loop for decryption */ | |
729 iov_base = _p_iovec->iov_base; | |
730 iov_len = _p_iovec->iov_len; | |
731 | |
732 /* Decrypt the blocks we managed to read */ | |
733 for( i_index = i_ret; i_index; i_index-- ) | |
734 { | |
735 /* Check that iov_len is a multiple of 2048 */ | |
736 if( iov_len & 0x7ff ) | |
737 { | |
738 return -1; | |
739 } | |
740 | |
741 while( iov_len == 0 ) | |
742 { | |
743 _p_iovec++; | |
744 iov_base = _p_iovec->iov_base; | |
745 iov_len = _p_iovec->iov_len; | |
746 } | |
747 | |
748 _dvdcss_unscramble( dvdcss->css.p_title_key, iov_base ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
749 ((uint8_t*)iov_base)[0x14] &= 0x8f; |
7027 | 750 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
751 iov_base = (void *) ((uint8_t*)iov_base + DVDCSS_BLOCK_SIZE); |
7027 | 752 iov_len -= DVDCSS_BLOCK_SIZE; |
753 } | |
754 | |
755 return i_ret; | |
756 } | |
757 | |
758 /** | |
759 * \brief Close the DVD and clean up the library. | |
760 * | |
761 * \param dvdcss a \e libdvdcss instance. | |
762 * \return zero in case of success, a negative value otherwise. | |
763 * | |
764 * This function closes the DVD device and frees all the memory allocated | |
765 * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be | |
766 * used again. | |
767 */ | |
768 extern int dvdcss_close ( dvdcss_t dvdcss ) | |
769 { | |
770 dvd_title_t *p_title; | |
771 int i_ret; | |
772 | |
773 /* Free our list of keys */ | |
774 p_title = dvdcss->p_titles; | |
775 while( p_title ) | |
776 { | |
777 dvd_title_t *p_tmptitle = p_title->p_next; | |
778 free( p_title ); | |
779 p_title = p_tmptitle; | |
780 } | |
781 | |
782 i_ret = _dvdcss_close( dvdcss ); | |
783 | |
784 if( i_ret < 0 ) | |
785 { | |
786 return i_ret; | |
787 } | |
788 | |
789 free( dvdcss->psz_device ); | |
790 free( dvdcss ); | |
791 | |
792 return 0; | |
793 } | |
794 | |
795 /* | |
796 * Deprecated. See dvdcss_seek(). | |
797 */ | |
798 #undef dvdcss_title | |
799 extern int dvdcss_title ( dvdcss_t dvdcss, int i_block ) | |
800 { | |
801 return _dvdcss_title( dvdcss, i_block ); | |
802 } | |
803 |