1 /*****************************************************************************
2 * dummy_dvdcss.c: Dummy libdvdcss with minimal DVD access.
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: dummy_dvdcss.c,v 1.3 2001/11/12 20:16:33 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include <sys/types.h>
36 #include <sys/uio.h> /* struct iovec */
37 #include <sys/ioctl.h>
39 #ifdef DVD_STRUCT_IN_LINUX_CDROM_H
40 # include <netinet/in.h>
41 # include <linux/cdrom.h>
43 # error "building dummy libdvdcss on this system does not make sense !"
49 #include "dummy_dvdcss.h"
51 /*****************************************************************************
53 *****************************************************************************/
60 /*****************************************************************************
61 * dvdcss_open: initialize library, open a DVD device, crack CSS key
62 *****************************************************************************/
63 extern dvdcss_handle dummy_dvdcss_open ( char *psz_target )
68 /* Allocate the library structure */
69 dvdcss = malloc( sizeof( struct dvdcss_s ) );
72 fprintf( stderr, "dvd error: "
73 "dummy libdvdcss could not allocate memory\n" );
78 dvdcss->i_fd = open( psz_target, 0 );
79 if( dvdcss->i_fd < 0 )
81 fprintf( stderr, "dvd error: "
82 "dummy libdvdcss could not open device\n" );
87 /* Check for encryption or ioctl failure */
88 dvd.type = DVD_STRUCT_COPYRIGHT;
89 dvd.copyright.layer_num = 0;
90 if( ioctl( dvdcss->i_fd, DVD_READ_STRUCT, &dvd ) != 0
91 || dvd.copyright.cpst )
93 fprintf( stderr, "dvd error: "
94 "dummy libdvdcss could not decrypt disc\n" );
95 close( dvdcss->i_fd );
103 /*****************************************************************************
104 * dvdcss_error: return the last libdvdcss error message
105 *****************************************************************************/
106 extern char * dummy_dvdcss_error ( dvdcss_handle dvdcss )
108 return "unknown error";
111 /*****************************************************************************
112 * dvdcss_seek: seek into the device
113 *****************************************************************************/
114 extern int dummy_dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks,
119 i_read = lseek( dvdcss->i_fd,
120 (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
122 return i_read / DVDCSS_BLOCK_SIZE;
125 /*****************************************************************************
126 * dvdcss_title: crack the current title key if needed
127 *****************************************************************************/
128 extern int dummy_dvdcss_title ( dvdcss_handle dvdcss, int i_block )
133 /*****************************************************************************
134 * dvdcss_read: read data from the device, decrypt if requested
135 *****************************************************************************/
136 extern int dummy_dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
142 i_bytes = read( dvdcss->i_fd, p_buffer,
143 (size_t)i_blocks * DVDCSS_BLOCK_SIZE );
145 return i_bytes / DVDCSS_BLOCK_SIZE;
148 /*****************************************************************************
149 * dvdcss_readv: read data to an iovec structure, decrypt if reaquested
150 *****************************************************************************/
151 extern int dummy_dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
157 i_read = readv( dvdcss->i_fd, (struct iovec*)p_iovec, i_blocks );
159 return i_read / DVDCSS_BLOCK_SIZE;
162 /*****************************************************************************
163 * dvdcss_close: close the DVD device and clean up the library
164 *****************************************************************************/
165 extern int dummy_dvdcss_close ( dvdcss_handle dvdcss )
169 i_ret = close( dvdcss->i_fd );