annotate libmpdvdkit2/bsdi_ioctl.c @ 16168:99c188fbdba4

libavutil compile fix (working also with old libavcodec)
author reimar
date Mon, 01 Aug 2005 22:09:17 +0000
parents c2ddedd0619e
children 954cdf2171f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1 #include "config.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
2
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
3 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
4 * Hacked version of the linux cdrom.c kernel module - everything except the
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
5 * DVD handling ripped out and the rest rewritten to use raw SCSI commands
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
6 * on BSD/OS 4.2 (but should work with earlier versions as well).
14860
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14643
diff changeset
7 *
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14643
diff changeset
8 * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14643
diff changeset
9 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14643
diff changeset
10 * $Id$
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
11 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
12
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
13 #include <sys/types.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
14 #include <stdlib.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
15 #include <stdio.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
16 #include <errno.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
17 #include <unistd.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
18 #include <sys/ioctl.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
19 #include </sys/dev/scsi/scsi.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
20 #include </sys/dev/scsi/scsi_ioctl.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
21
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
22 #include "bsdi_dvd.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
23
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
24 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
25 * Now get rid of the override/intercept macro so we can call the real ioctl()
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
26 * routine!
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
27 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
28 #undef ioctl
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
29
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
30 #define CMD_READ_10 0x28
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
31 #define CMD_READ_TOC_PMA_ATIP 0x43
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
32 #define CMD_READ_CD 0xbe
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
33 #define CMD_START_STOP_UNIT 0x1b
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
34
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
35 #define CMD_SEND_KEY 0xa3
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
36 #define CMD_REPORT_KEY 0xa4
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
37 #define CMD_READ_DVD_STRUCTURE 0xad
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
38
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
39 #define copy_key(dest,src) memcpy((dest), (src), sizeof(dvd_key))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
40 #define copy_chal(dest,src) memcpy((dest), (src), sizeof(dvd_challenge))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
41
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
42 /* Define the Cdrom Generic Command structure */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
43 typedef struct cgc
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
44 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
45 u_char cdb[12];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
46 u_char *buf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
47 int buflen;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
48 int rw;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
49 int timeout;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
50 scsi_user_sense_t *sus;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
51 } cgc_t;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
52
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
53 static int scsi_cmd(int, cgc_t *);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
54 static int cdrom_ioctl(int, u_long, void *);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
55 static int cdrom_tray_move(int, int);
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
56 static void cdrom_count_tracks(int, tracktype *);
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
57 static int dvd_ioctl(int, u_long, void *);
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
58 static int debug = 0;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
59
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
60 void dvd_cdrom_debug(int flag)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
61 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
62 debug = flag;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
63 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
64
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
65 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
66 * This is the published entry point. Actually applications should simply
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
67 * include <dvd.h> and not refer to this at all.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
68 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
69 int dvd_cdrom_ioctl(int fd, unsigned long cmd, void *arg)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
70 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
71 switch (cmd)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
72 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
73 case DVD_AUTH:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
74 case DVD_READ_STRUCT:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
75 return(dvd_ioctl(fd, cmd, arg));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
76 case CDROMREADTOCHDR:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
77 case CDROMREADTOCENTRY:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
78 case CDROMEJECT:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
79 case CDROMREADRAW:
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
80 case CDROMREADMODE1:
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
81 case CDROMREADMODE2:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
82 case CDROMCLOSETRAY:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
83 case CDROM_DRIVE_STATUS:
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
84 case CDROM_DISC_STATUS:
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
85 return(cdrom_ioctl(fd, cmd, arg));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
86 default:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
87 return(ioctl(fd, cmd, arg));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
88 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
89 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
90
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
91 static void setup_report_key(cgc_t *cgc, u_int agid, u_int type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
92 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
93
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
94 cgc->cdb[0] = CMD_REPORT_KEY;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
95 cgc->cdb[10] = type | (agid << 6);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
96 switch (type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
97 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
98 case 0:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
99 case 5:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
100 case 8:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
101 cgc->buflen = 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
102 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
103 case 1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
104 cgc->buflen = 16;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
105 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
106 case 2:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
107 case 4:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
108 cgc->buflen = 12;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
109 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
110 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
111 cgc->cdb[9] = cgc->buflen;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
112 cgc->rw = SUC_READ;;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
113 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
114
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
115 static void setup_send_key(cgc_t *cgc, u_int agid, u_int type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
116 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
117
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
118 cgc->cdb[0] = CMD_SEND_KEY;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
119 cgc->cdb[10] = type | (agid << 6);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
120 switch (type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
121 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
122 case 1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
123 cgc->buflen = 16;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
124 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
125 case 3:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
126 cgc->buflen = 12;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
127 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
128 case 6:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
129 cgc->buflen = 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
130 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
131 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
132 cgc->cdb[9] = cgc->buflen;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
133 cgc->rw = SUC_WRITE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
134 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
135
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
136 static void cgc_init(cgc_t *cgc, void *buf, int len, int type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
137 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
138
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
139 memset(cgc, 0, sizeof (*cgc));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
140 if (buf)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
141 memset(buf, 0, len);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
142 cgc->buf = (u_char *)buf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
143 cgc->buflen = len;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
144 cgc->rw = type;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
145 cgc->timeout = 5; /* 5 second timeout */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
146 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
147
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
148 static int dvd_do_auth(int fd, dvd_authinfo *ai)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
149 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
150 int ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
151 u_char buf[20];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
152 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
153 rpc_state_t rpc_state;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
154
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
155 memset(buf, 0, sizeof(buf));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
156 cgc_init(&cgc, buf, 0, SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
157
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
158 switch (ai->type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
159 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
160 case DVD_LU_SEND_AGID: /* LU data send */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
161 setup_report_key(&cgc, ai->lsa.agid, 0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
162 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
163 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
164 ai->lsa.agid = buf[7] >> 6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
165 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
166 case DVD_LU_SEND_KEY1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
167 setup_report_key(&cgc, ai->lsk.agid, 2);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
168 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
169 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
170 copy_key(ai->lsk.key, &buf[4]);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
171 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
172 case DVD_LU_SEND_CHALLENGE:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
173 setup_report_key(&cgc, ai->lsc.agid, 1);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
174 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
175 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
176 copy_chal(ai->lsc.chal, &buf[4]);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
177 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
178 case DVD_LU_SEND_TITLE_KEY: /* Post-auth key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
179 setup_report_key(&cgc, ai->lstk.agid, 4);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
180 cgc.cdb[5] = ai->lstk.lba;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
181 cgc.cdb[4] = ai->lstk.lba >> 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
182 cgc.cdb[3] = ai->lstk.lba >> 16;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
183 cgc.cdb[2] = ai->lstk.lba >> 24;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
184 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
185 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
186 ai->lstk.cpm = (buf[4] >> 7) & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
187 ai->lstk.cp_sec = (buf[4] >> 6) & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
188 ai->lstk.cgms = (buf[4] >> 4) & 3;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
189 copy_key(ai->lstk.title_key, &buf[5]);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
190 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
191 case DVD_LU_SEND_ASF:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
192 setup_report_key(&cgc, ai->lsasf.agid, 5);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
193 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
194 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
195 ai->lsasf.asf = buf[7] & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
196 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
197 case DVD_HOST_SEND_CHALLENGE: /* LU data receive (LU changes state) */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
198 setup_send_key(&cgc, ai->hsc.agid, 1);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
199 buf[1] = 0xe;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
200 copy_chal(&buf[4], ai->hsc.chal);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
201 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
202 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
203 ai->type = DVD_LU_SEND_KEY1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
204 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
205 case DVD_HOST_SEND_KEY2:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
206 setup_send_key(&cgc, ai->hsk.agid, 3);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
207 buf[1] = 0xa;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
208 copy_key(&buf[4], ai->hsk.key);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
209 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
210 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
211 ai->type = DVD_AUTH_FAILURE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
212 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
213 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
214 ai->type = DVD_AUTH_ESTABLISHED;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
215 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
216 case DVD_INVALIDATE_AGID:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
217 setup_report_key(&cgc, ai->lsa.agid, 0x3f);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
218 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
219 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
220 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
221 case DVD_LU_SEND_RPC_STATE: /* Get region settings */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
222 setup_report_key(&cgc, 0, 8);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
223 memset(&rpc_state, 0, sizeof(rpc_state_t));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
224 cgc.buf = (char *) &rpc_state;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
225 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
226 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
227 ai->lrpcs.type = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
228 ai->lrpcs.rpc_scheme = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
229 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
230 else
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
231 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
232 ai->lrpcs.type = rpc_state.type_code;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
233 ai->lrpcs.vra = rpc_state.vra;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
234 ai->lrpcs.ucca = rpc_state.ucca;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
235 ai->lrpcs.region_mask = rpc_state.region_mask;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
236 ai->lrpcs.rpc_scheme = rpc_state.rpc_scheme;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
237 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
238 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
239 case DVD_HOST_SEND_RPC_STATE: /* Set region settings */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
240 setup_send_key(&cgc, 0, 6);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
241 buf[1] = 6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
242 buf[4] = ai->hrpcs.pdrc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
243 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
244 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
245 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
246 default:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
247 return EINVAL;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
248 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
249 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
250 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
251
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
252 static int dvd_read_physical(int fd, dvd_struct *s)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
253 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
254 int ret, i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
255 u_char buf[4 + 4 * 20], *base;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
256 struct dvd_layer *layer;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
257 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
258
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
259 cgc_init(&cgc, buf, sizeof(buf), SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
260 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
261 cgc.cdb[6] = s->physical.layer_num;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
262 cgc.cdb[7] = s->type;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
263 cgc.cdb[9] = cgc.buflen & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
264
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
265 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
266 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
267
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
268 base = &buf[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
269 layer = &s->physical.layer[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
270
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
271 /* place the data... really ugly, but at least we won't have to
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
272 worry about endianess in userspace or here. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
273 for (i = 0; i < 4; ++i, base += 20, ++layer)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
274 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
275 memset(layer, 0, sizeof(*layer));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
276 layer->book_version = base[0] & 0xf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
277 layer->book_type = base[0] >> 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
278 layer->min_rate = base[1] & 0xf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
279 layer->disc_size = base[1] >> 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
280 layer->layer_type = base[2] & 0xf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
281 layer->track_path = (base[2] >> 4) & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
282 layer->nlayers = (base[2] >> 5) & 3;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
283 layer->track_density = base[3] & 0xf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
284 layer->linear_density = base[3] >> 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
285 layer->start_sector = base[5] << 16 | base[6] << 8 | base[7];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
286 layer->end_sector = base[9] << 16 | base[10] << 8 | base[11];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
287 layer->end_sector_l0 = base[13] << 16 | base[14] << 8 | base[15];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
288 layer->bca = base[16] >> 7;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
289 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
290 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
291 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
292
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
293 static int dvd_read_copyright(int fd, dvd_struct *s)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
294 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
295 int ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
296 u_char buf[8];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
297 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
298
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
299 cgc_init(&cgc, buf, sizeof(buf), SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
300 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
301 cgc.cdb[6] = s->copyright.layer_num;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
302 cgc.cdb[7] = s->type;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
303 cgc.cdb[8] = cgc.buflen >> 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
304 cgc.cdb[9] = cgc.buflen & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
305
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
306 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
307 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
308 s->copyright.cpst = buf[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
309 s->copyright.rmi = buf[5];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
310 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
311 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
312
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
313 static int dvd_read_disckey(int fd, dvd_struct *s)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
314 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
315 int ret, size;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
316 u_char *buf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
317 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
318
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
319 size = sizeof(s->disckey.value) + 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
320
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
321 if ((buf = (u_char *) malloc(size)) == NULL)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
322 return ENOMEM;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
323
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
324 cgc_init(&cgc, buf, size, SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
325 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
326 cgc.cdb[7] = s->type;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
327 cgc.cdb[8] = size >> 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
328 cgc.cdb[9] = size & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
329 cgc.cdb[10] = s->disckey.agid << 6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
330
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
331 if (!(ret = scsi_cmd(fd, &cgc)))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
332 memcpy(s->disckey.value, &buf[4], sizeof(s->disckey.value));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
333 free(buf);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
334 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
335 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
336
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
337 static int dvd_read_bca(int fd, dvd_struct *s)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
338 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
339 int ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
340 u_char buf[4 + 188];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
341 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
342
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
343 cgc_init(&cgc, buf, sizeof(buf), SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
344 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
345 cgc.cdb[7] = s->type;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
346 cgc.cdb[9] = cgc.buflen = 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
347
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
348 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
349 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
350 s->bca.len = buf[0] << 8 | buf[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
351 if (s->bca.len < 12 || s->bca.len > 188)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
352 return EIO;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
353 memcpy(s->bca.value, &buf[4], s->bca.len);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
354 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
355 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
356
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
357 static int dvd_read_manufact(int fd, dvd_struct *s)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
358 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
359 int ret = 0, size;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
360 u_char *buf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
361 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
362
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
363 size = sizeof(s->manufact.value) + 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
364
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
365 if ((buf = (u_char *) malloc(size)) == NULL)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
366 return ENOMEM;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
367
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
368 cgc_init(&cgc, buf, size, SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
369 cgc.cdb[0] = CMD_READ_DVD_STRUCTURE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
370 cgc.cdb[7] = s->type;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
371 cgc.cdb[8] = size >> 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
372 cgc.cdb[9] = size & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
373
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
374 if (ret = scsi_cmd(fd, &cgc))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
375 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
376 free(buf);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
377 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
378 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
379 s->manufact.len = buf[0] << 8 | buf[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
380 if (s->manufact.len < 0 || s->manufact.len > 2048)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
381 ret = -EIO;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
382 else
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
383 memcpy(s->manufact.value, &buf[4], s->manufact.len);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
384 free(buf);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
385 return ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
386 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
387
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
388 static int dvd_read_struct(int fd, dvd_struct *s)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
389 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
390 switch (s->type)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
391 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
392 case DVD_STRUCT_PHYSICAL:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
393 return dvd_read_physical(fd, s);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
394 case DVD_STRUCT_COPYRIGHT:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
395 return dvd_read_copyright(fd, s);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
396 case DVD_STRUCT_DISCKEY:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
397 return dvd_read_disckey(fd, s);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
398 case DVD_STRUCT_BCA:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
399 return dvd_read_bca(fd, s);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
400 case DVD_STRUCT_MANUFACT:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
401 return dvd_read_manufact(fd, s);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
402 default:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
403 return EINVAL;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
404 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
405 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
406
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
407 static u_char scsi_cdblen[8] = {6, 10, 10, 12, 12, 12, 10, 10};
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
408
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
409 static int scsi_cmd(int fd, cgc_t *cgc)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
410 {
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
411 int i, scsistatus, cdblen;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
412 unsigned char *cp;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
413 struct scsi_user_cdb suc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
414
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
415 /* safety checks */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
416 if (cgc->rw != SUC_READ && cgc->rw != SUC_WRITE)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
417 return(EINVAL);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
418
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
419 suc.suc_flags = cgc->rw;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
420 cdblen = scsi_cdblen[(cgc->cdb[0] >> 5) & 7];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
421 suc.suc_cdblen = cdblen;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
422 bcopy(cgc->cdb, suc.suc_cdb, cdblen);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
423 suc.suc_data = cgc->buf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
424 suc.suc_datalen = cgc->buflen;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
425 suc.suc_timeout = cgc->timeout;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
426 if (ioctl(fd, SCSIRAWCDB, &suc) == -1)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
427 return(errno);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
428 scsistatus = suc.suc_sus.sus_status;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
429
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
430 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
431 * If the device returns a scsi sense error and debugging is enabled print
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
432 * some hopefully useful information on stderr.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
433 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
434 if (scsistatus && debug)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
435 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
436 cp = suc.suc_sus.sus_sense;
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
437 fprintf(stderr,"scsistatus = %x cdb =",
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
438 scsistatus);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
439 for (i = 0; i < cdblen; i++)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
440 fprintf(stderr, " %x", cgc->cdb[i]);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
441 fprintf(stderr, "\nsense =");
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
442 for (i = 0; i < 16; i++)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
443 fprintf(stderr, " %x", cp[i]);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
444 fprintf(stderr, "\n");
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
445 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
446 if (cgc->sus)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
447 bcopy(&suc.suc_sus, cgc->sus, sizeof (struct scsi_user_sense));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
448 if (scsistatus)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
449 return(EIO); /* generic i/o error for unsuccessful status */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
450 return(0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
451 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
452
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
453 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
454 * The entry point for the DVDioctls for BSD/OS.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
455 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
456 static int dvd_ioctl(int fd, u_long cmd, void *arg)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
457 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
458 int ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
459
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
460 switch (cmd)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
461 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
462 case DVD_READ_STRUCT:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
463 ret = dvd_read_struct(fd, (dvd_struct *)arg);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
464 if (ret)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
465 errno = ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
466 return(ret ? -1 : 0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
467 case DVD_AUTH:
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
468 ret = dvd_do_auth(fd, (dvd_authinfo *)arg);
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
469 if (ret)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
470 errno = ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
471 return(ret ? -1 : 0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
472 default:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
473 errno = EINVAL;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
474 return(-1);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
475 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
476 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
477
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
478 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
479 * The entry point for the CDROMioctls for BSD/OS
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
480 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
481 static int cdrom_read_block(int, cgc_t *, int, int, int, int);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
482 static int cdrom_read_cd(int, cgc_t *, int, int, int );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
483 int cdrom_blocksize(int, int );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
484
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
485 static inline
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
486 int msf_to_lba(char m, char s, char f)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
487 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
488 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
489 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
490
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
491 cdrom_ioctl(int fd, u_long cmd, void *arg)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
492 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
493 int ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
494 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
495
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
496 switch (cmd)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
497 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
498 case CDROMREADRAW:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
499 case CDROMREADMODE1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
500 case CDROMREADMODE2:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
501 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
502 struct cdrom_msf *msf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
503 int blocksize = 0, format = 0, lba;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
504
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
505 switch (cmd)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
506 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
507 case CDROMREADRAW:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
508 blocksize = CD_FRAMESIZE_RAW;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
509 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
510 case CDROMREADMODE1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
511 blocksize = CD_FRAMESIZE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
512 format = 2;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
513 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
514 case CDROMREADMODE2:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
515 blocksize = CD_FRAMESIZE_RAW0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
516 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
517 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
518 msf = (struct cdrom_msf *)arg;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
519 lba = msf_to_lba(msf->cdmsf_min0,msf->cdmsf_sec0,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
520 msf->cdmsf_frame0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
521 ret = EINVAL;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
522 if (lba < 0)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
523 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
524
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
525 cgc_init(&cgc, arg, blocksize, SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
526 ret = cdrom_read_block(fd, &cgc, lba, 1, format, blocksize);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
527 if (ret)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
528 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
529 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
530 * SCSI-II devices are not required to support CMD_READ_CD (which specifies
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
531 * the blocksize to read) so try switching the block size with a mode select,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
532 * doing the normal read sector command and then changing the sector size back
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
533 * to 2048.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
534 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
535 * If the program dies before changing the blocksize back sdopen()
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
536 * in the kernel will fail opens with a message that looks something like:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
537 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
538 * "sr1: blksize 2336 not multiple of 512: cannot use"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
539 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
540 * At that point the drive has to be power cycled (or reset in some other way).
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
541 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
542 if (ret = cdrom_blocksize(fd, blocksize))
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
543 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
544 ret = cdrom_read_cd(fd, &cgc, lba, blocksize, 1);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
545 ret |= cdrom_blocksize(fd, 2048);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
546 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
547 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
548 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
549 case CDROMREADTOCHDR:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
550 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
551 struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
552 u_char buffer[12];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
553
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
554 cgc_init(&cgc, buffer, sizeof (buffer), SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
555 cgc.cdb[0] = CMD_READ_TOC_PMA_ATIP;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
556 cgc.cdb[1] = 0x2; /* MSF */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
557 cgc.cdb[8] = 12; /* LSB of length */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
558
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
559 ret = scsi_cmd(fd, &cgc);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
560 if (!ret)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
561 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
562 tochdr->cdth_trk0 = buffer[2];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
563 tochdr->cdth_trk1 = buffer[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
564 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
565 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
566 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
567 case CDROMREADTOCENTRY:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
568 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
569 struct cdrom_tocentry *tocentry = (struct cdrom_tocentry *) arg;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
570 u_char buffer[12];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
571
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
572 cgc_init(&cgc, buffer, sizeof (buffer), SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
573 cgc.cdb[0] = CMD_READ_TOC_PMA_ATIP;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
574 cgc.cdb[1] = (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
575 cgc.cdb[6] = tocentry->cdte_track;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
576 cgc.cdb[8] = 12; /* LSB of length */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
577
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
578 ret = scsi_cmd(fd, &cgc);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
579 if (ret)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
580 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
581
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
582 tocentry->cdte_ctrl = buffer[5] & 0xf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
583 tocentry->cdte_adr = buffer[5] >> 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
584 tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
585 if (tocentry->cdte_format == CDROM_MSF)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
586 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
587 tocentry->cdte_addr.msf.minute = buffer[9];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
588 tocentry->cdte_addr.msf.second = buffer[10];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
589 tocentry->cdte_addr.msf.frame = buffer[11];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
590 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
591 else
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
592 tocentry->cdte_addr.lba = (((((buffer[8] << 8)
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
593 + buffer[9]) << 8)
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
594 + buffer[10]) << 8)
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
595 + buffer[11];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
596 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
597 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
598 case CDROMEJECT: /* NO-OP for now */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
599 ret = cdrom_tray_move(fd, 1);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
600 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
601 case CDROMCLOSETRAY:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
602 ret = cdrom_tray_move(fd, 0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
603 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
604 /*
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
605 * This sucks but emulates the expected behaviour. Instead of the return
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
606 * value being the actual status a success/fail indicator should have been
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
607 * returned and the 3rd arg to the ioctl should have been an 'int *' to update
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
608 * with the actual status. Both the drive and disc status ioctl calls are
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
609 * similarily braindamaged.
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
610 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
611 case CDROM_DRIVE_STATUS:
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
612 return(CDS_NO_INFO); /* XXX */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
613 case CDROM_DISC_STATUS:
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
614 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
615 tracktype tracks;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
616 int cnt;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
617
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
618 cdrom_count_tracks(fd, &tracks);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
619 if (tracks.error)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
620 return(tracks.error);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
621 if (tracks.audio > 0)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
622 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
623 cnt = tracks.data + tracks.cdi + tracks.xa;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
624 if (cnt == 0)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
625 return(CDS_AUDIO);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
626 else
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
627 return(CDS_MIXED);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
628 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
629 if (tracks.cdi)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
630 return(CDS_XA_2_2);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
631 if (tracks.xa)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
632 return(CDS_XA_2_1);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
633 if (tracks.data)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
634 return(CDS_DATA_1);
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
635 return(CDS_NO_INFO);
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
636 }
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
637 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
638 errno = ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
639 return(ret ? -1 : 0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
640 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
641
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
642 static int cdrom_read_cd(int fd, cgc_t *cgc, int lba, int blocksize, int nblocks)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
643 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
644
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
645 memset(&cgc->cdb, 0, sizeof(cgc->cdb));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
646 cgc->cdb[0] = CMD_READ_10;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
647 cgc->cdb[2] = (lba >> 24) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
648 cgc->cdb[3] = (lba >> 16) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
649 cgc->cdb[4] = (lba >> 8) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
650 cgc->cdb[5] = lba & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
651 cgc->cdb[6] = (nblocks >> 16) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
652 cgc->cdb[7] = (nblocks >> 8) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
653 cgc->cdb[8] = nblocks & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
654 cgc->buflen = blocksize * nblocks;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
655 return(scsi_cmd(fd, cgc));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
656 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
657
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
658 static int cdrom_read_block(int fd, cgc_t *cgc,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
659 int lba, int nblocks, int format, int blksize)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
660 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
661
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
662 memset(&cgc->cdb, 0, sizeof(cgc->cdb));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
663 cgc->cdb[0] = CMD_READ_CD;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
664 /* expected sector size - cdda,mode1,etc. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
665 cgc->cdb[1] = format << 2;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
666 /* starting address */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
667 cgc->cdb[2] = (lba >> 24) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
668 cgc->cdb[3] = (lba >> 16) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
669 cgc->cdb[4] = (lba >> 8) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
670 cgc->cdb[5] = lba & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
671 /* number of blocks */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
672 cgc->cdb[6] = (nblocks >> 16) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
673 cgc->cdb[7] = (nblocks >> 8) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
674 cgc->cdb[8] = nblocks & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
675 cgc->buflen = blksize * nblocks;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
676
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
677 /* set the header info returned */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
678 switch (blksize)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
679 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
680 case CD_FRAMESIZE_RAW0:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
681 cgc->cdb[9] = 0x58;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
682 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
683 case CD_FRAMESIZE_RAW1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
684 cgc->cdb[9] = 0x78;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
685 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
686 case CD_FRAMESIZE_RAW:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
687 cgc->cdb[9] = 0xf8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
688 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
689 default:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
690 cgc->cdb[9] = 0x10;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
691 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
692 return(scsi_cmd(fd, cgc));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
693 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
694
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
695 static void cdrom_count_tracks(int fd, tracktype *tracks)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
696 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
697 struct cdrom_tochdr header;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
698 struct cdrom_tocentry entry;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
699 int ret, i;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
700
14643
d59cc68ba13b bzero is deprecated patch by ?Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents: 9333
diff changeset
701 memset(tracks, 0, sizeof (*tracks));
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
702 ret = cdrom_ioctl(fd, CDROMREADTOCHDR, &header);
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
703 /*
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
704 * This whole business is a crock anyhow so we don't bother distinguishing
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
705 * between no media, drive not ready, etc and on any error just say we have
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
706 * no info.
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
707 */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
708 if (ret)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
709 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
710 tracks->error = CDS_NO_INFO;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
711 return;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
712 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
713
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
714 entry.cdte_format = CDROM_MSF;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
715 for (i = header.cdth_trk0; i <= header.cdth_trk1; i++)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
716 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
717 entry.cdte_track = i;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
718 if (cdrom_ioctl(fd, CDROMREADTOCENTRY, &entry))
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
719 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
720 tracks->error = CDS_NO_INFO;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
721 return;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
722 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
723 if (entry.cdte_ctrl & CDROM_DATA_TRACK)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
724 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
725 if (entry.cdte_format == 0x10)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
726 tracks->cdi++;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
727 else if (entry.cdte_format == 0x20)
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
728 tracks->xa++;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
729 else
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
730 tracks->data++;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
731 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
732 else
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
733 tracks->audio++;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
734 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
735 return;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
736 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 7027
diff changeset
737
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
738 static int cdrom_tray_move(int fd, int flag)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
739 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
740 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
741
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
742 cgc_init(&cgc, NULL, 0, SUC_READ);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
743 cgc.cdb[0] = CMD_START_STOP_UNIT;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
744 cgc.cdb[1] = 1; /* immediate */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
745 cgc.cdb[4] = flag ? 0x2 : 0x3; /* eject : close */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
746 return(scsi_cmd(fd, &cgc));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
747 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
748
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
749 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
750 * Required when we need to use READ_10 to issue other than 2048 block
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
751 * reads
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
752 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
753 int cdrom_blocksize(int fd, int size)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
754 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
755 cgc_t cgc;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
756 struct modesel_head mh;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
757
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
758 memset(&mh, 0, sizeof(mh));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
759 mh.block_desc_length = 0x08;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
760 mh.block_length_med = (size >> 8) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
761 mh.block_length_lo = size & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
762
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
763 memset(&cgc, 0, sizeof(cgc));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
764 cgc.cdb[0] = 0x15;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
765 cgc.cdb[1] = 1 << 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
766 cgc.cdb[4] = 12;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
767 cgc.buflen = sizeof(mh);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
768 cgc.buf = (u_char *) &mh;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
769 cgc.rw = SUC_WRITE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
770 mh.block_desc_length = 0x08;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
771 mh.block_length_med = (size >> 8) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
772 mh.block_length_lo = size & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
773 return(scsi_cmd(fd, &cgc));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
774 }