annotate libdvdcss/bsdi_ioctl.c @ 22783:96f0c2cd4538

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