1 /* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
2 
3 /* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens
4    Copyright (c) 2006 - 2019 Thomas Schmitt <scdbackup@gmx.net>
5    Provided under GPL version 2 or later.
6 */
7 
8 
9 #ifndef __SPC
10 #define __SPC
11 
12 #include "libburn.h"
13 
14 void spc_inquiry(struct burn_drive *);
15 void spc_prevent(struct burn_drive *);
16 void spc_allow(struct burn_drive *);
17 void spc_sense_caps(struct burn_drive *);
18 void spc_sense_error_params(struct burn_drive *);
19 void spc_select_error_params(struct burn_drive *,
20 			     const struct burn_read_opts *);
21 void spc_getcaps(struct burn_drive *d);
22 void spc_sense_write_params(struct burn_drive *);
23 void spc_select_write_params(struct burn_drive *,
24 			     struct burn_session *, int,
25 			     const struct burn_write_opts *);
26 
27 #ifdef Libburn_enable_scsi_cmd_ABh
28 int spc_read_media_serial_number(struct burn_drive *d);
29 #endif
30 
31 void spc_probe_write_modes(struct burn_drive *);
32 void spc_request_sense(struct burn_drive *d, struct buffer *buf);
33 int spc_block_type(enum burn_block_types b);
34 int spc_get_erase_progress(struct burn_drive *d);
35 
36 /* ts A70315 : test_unit_ready with result parameters */
37 int spc_test_unit_ready_r(struct burn_drive *d, int *key, int *asc, int *ascq,
38 				int *progress);
39 
40 int spc_test_unit_ready(struct burn_drive *d);
41 
42 /* ts A70315 */
43 /** Wait until the drive state becomes clear in or until max_sec elapsed */
44 int spc_wait_unit_attention(struct burn_drive *d, int max_sec, char *cmd_text,
45 				int flag);
46 
47 /* ts A61021 : the spc specific part of sg.c:enumerate_common()
48 */
49 int spc_setup_drive(struct burn_drive *d);
50 
51 /* ts A61021 : the general SCSI specific part of sg.c:enumerate_common()
52    @param flag Bitfield for control purposes
53                bit0= do not setup spc/sbc/mmc
54 */
55 int burn_scsi_setup_drive(struct burn_drive *d, int bus_no, int host_no,
56 			int channel_no, int target_no, int lun_no, int flag);
57 
58 /* ts A61115 moved from sg-*.h */
59 enum response { RETRY, FAIL, GO_ON };
60 enum response scsi_error(struct burn_drive *, unsigned char *, int);
61 
62 /* ts A61122 */
63 enum response scsi_error_msg(struct burn_drive *d, unsigned char *sense,
64                              int senselen, char msg[161],
65                              int *key, int *asc, int *ascq);
66 
67 /* ts A61030 */
68 /* @param flag bit0=do report conditions which are considered not an error */
69 int scsi_notify_error(struct burn_drive *, struct command *c,
70 			unsigned char *sense, int senselen, int flag);
71 
72 /* ts A70519 */
73 int scsi_init_command(struct command *c, unsigned char *opcode, int oplen);
74 
75 /* ts A91106 */
76 int scsi_show_cmd_text(struct command *c, void *fp, int flag);
77 
78 /* ts B11110 */
79 /** Logs command (before execution). */
80 int scsi_log_command(unsigned char *opcode, int oplen, int data_dir,
81                      unsigned char *data, int bytes,
82                      void *fp_in, int flag);
83 
84 /* ts B40731 */
85 /* Arbitrary SCSI log message */
86 int scsi_log_text(char *text, void *fp_in, int flag);
87 
88 /* ts A91218 (former sg_log_cmd ts A70518) */
89 /** Legacy frontend to scsi_log_command() */
90 int scsi_log_cmd(struct command *c, void *fp, int flag);
91 
92 /* ts B11110 */
93 /** Logs outcome of a sg command.
94     @param flag  bit0 causes an error message
95                  bit1 do not print duration
96 */
97 int scsi_log_reply(unsigned char *opcode, int data_dir, unsigned char *data,
98                    int dxfer_len, void *fp_in, unsigned char sense[18],
99                    int sense_len, double duration, int flag);
100 
101 /* ts A91221 (former sg_log_err ts A91108) */
102 /** Legacy frontend to scsi_log_reply().
103     @param flag  bit0 causes an error message
104                  bit1 do not print duration
105 */
106 int scsi_log_err(struct burn_drive *d, struct command *c,
107                  void *fp, unsigned char sense[18],
108                  int sense_len, int flag);
109 
110 /* ts B31112 */
111 int scsi_log_message(struct burn_drive *d, void *fp, char * msg, int flag);
112 
113 /* ts B00728 */
114 int spc_decode_sense(unsigned char *sense, int senselen,
115                      int *key, int *asc, int *ascq);
116 
117 /* ts B90206 */
118 char *spc_command_name(unsigned int c, int flag);
119 
120 /* ts B90511 */
121 int spc_human_readable_cmd(struct command *c, char *msg, int msg_max,
122                            int flag);
123 
124 /* ts B90616 */
125 void spc_register_retry(struct command *c);
126 
127 /* ts B00808 */
128 /** Evaluates outcome of a single SCSI command, eventually logs sense data,
129     and issues DEBUG error message in case the command is evaluated as done.
130     @param flag   bit1 = do not print duration
131     @return 0 = not yet done , 1 = done , -1 = error
132 */
133 int scsi_eval_cmd_outcome(struct burn_drive *d, struct command *c, void *fp_in,
134                         unsigned char *sense, int sense_len,
135                         time_t start_time, int timeout_ms,
136 			int loop_count, int flag);
137 
138 /* ts B40204 */
139 /* Verify by INQUIRY that the drive is indeed a MMC device.
140 */
141 int spc_confirm_cd_drive(struct burn_drive *d, int flag);
142 
143 
144 /* The waiting time before eventually retrying a failed SCSI command.
145    Before each retry wait Libburn_scsi_retry_incR longer than with
146    the previous one. At most wait for Libburn_scsi_retry_umaX microseconds.
147 */
148 #define Libburn_scsi_retry_usleeP 100000
149 #define Libburn_scsi_retry_incR   100000
150 #define Libburn_scsi_retry_umaX   500000
151 
152 /* The retry waiting time for commands WRITE(10) and WRITE(12).
153 */
154 #define Libburn_scsi_write_retry_usleeP     0
155 #define Libburn_scsi_write_retry_incR    2000
156 #define Libburn_scsi_write_retry_umaX   25000
157 
158 
159 /* ts B11124 */
160 /* Millisecond timeout for quickly responding SPC, SBC, and MMC commands */
161 #define Libburn_scsi_default_timeouT          30000
162 
163 /* WRITE(10) and WRITE(12) */
164 #define Libburn_scsi_write_timeouT           200000
165 
166 /* RESERVE TRACK */
167 #define Libburn_mmc_reserve_timeouT          200000
168 
169 /* CLOSE TRACK/SESSION with Immed bit */
170 #define Libburn_mmc_close_timeouT            200000
171 /* CLOSE TRACK/SESSION without Immed bit */
172 #define Libburn_mmc_close_noim_timeouT      3600000
173 
174 /* BLANK , FORMAT UNIT with Immed bit */
175 #define Libburn_mmc_blank_timeouT            200000
176 /* BLANK , FORMAT UNIT without Immed bit */
177 #define Libburn_mmc_blank_noim_timeouT     18000000
178 
179 /* SEND OPC INFORMATION */
180 #define Libburn_mmc_opc_timeouT              200000
181 
182 /* MMC_SYNC_CACHE with Immed bit */
183 #define Libburn_mmc_sync_timeouT             200000
184 /* MMC_SYNC_CACHE without Immed bit */
185 #define Libburn_mmc_sync_noim_timeouT       3600000
186 
187 /* START STOP UNIT with Start bit and Load bit set */
188 #define Libburn_mmc_load_timeouT             300000
189 
190 #endif /*__SPC*/
191