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