annotate libmpdvdkit2/bsdi_ioctl.c @ 7800:1dd34db6cb92

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