1 /*
2  * scsicmds.h
3  *
4  * Home page of code is: https://www.smartmontools.org
5  *
6  * Copyright (C) 2002-8 Bruce Allen
7  * Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
8  * Copyright (C) 2003-18 Douglas Gilbert <dgilbert@interlog.com>
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  *
12  *
13  * N.B. What was formerly known as "SMART" are now called "informational
14  * exceptions" in recent t10.org drafts (i.e. recent SCSI).
15  *
16  */
17 
18 
19 #ifndef SCSICMDS_H_
20 #define SCSICMDS_H_
21 
22 #define SCSICMDS_H_CVSID "$Id: scsicmds.h 5131 2020-12-15 21:30:33Z dpgilbert $\n"
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <string.h>
28 
29 /* #define SCSI_DEBUG 1 */ /* Comment out to disable command debugging */
30 
31 /* Following conditional defines just in case OS already has them defined.
32  * If they are defined we hope they are defined correctly (for SCSI). */
33 #ifndef TEST_UNIT_READY
34 #define TEST_UNIT_READY 0x0
35 #endif
36 #ifndef LOG_SELECT
37 #define LOG_SELECT 0x4c
38 #endif
39 #ifndef LOG_SENSE
40 #define LOG_SENSE 0x4d
41 #endif
42 #ifndef MODE_SENSE
43 #define MODE_SENSE 0x1a
44 #endif
45 #ifndef MODE_SENSE_10
46 #define MODE_SENSE_10 0x5a
47 #endif
48 #ifndef MODE_SELECT
49 #define MODE_SELECT 0x15
50 #endif
51 #ifndef MODE_SELECT_10
52 #define MODE_SELECT_10 0x55
53 #endif
54 #ifndef INQUIRY
55 #define INQUIRY 0x12
56 #endif
57 #ifndef REQUEST_SENSE
58 #define REQUEST_SENSE  0x03
59 #endif
60 #ifndef RECEIVE_DIAGNOSTIC
61 #define RECEIVE_DIAGNOSTIC  0x1c
62 #endif
63 #ifndef SEND_DIAGNOSTIC
64 #define SEND_DIAGNOSTIC  0x1d
65 #endif
66 #ifndef READ_DEFECT_10
67 #define READ_DEFECT_10  0x37
68 #endif
69 #ifndef READ_DEFECT_12
70 #define READ_DEFECT_12  0xb7
71 #endif
72 #ifndef START_STOP_UNIT		/* SSU */
73 #define START_STOP_UNIT  0x1b
74 #endif
75 #ifndef REPORT_LUNS
76 #define REPORT_LUNS  0xa0
77 #endif
78 #ifndef READ_CAPACITY_10
79 #define READ_CAPACITY_10  0x25
80 #endif
81 #ifndef READ_CAPACITY_16
82 #define READ_CAPACITY_16  0x9e
83 #endif
84 #ifndef SAI_READ_CAPACITY_16    /* service action for READ_CAPACITY_16 */
85 #define SAI_READ_CAPACITY_16  0x10
86 #endif
87 
88 #ifndef SAT_ATA_PASSTHROUGH_12
89 #define SAT_ATA_PASSTHROUGH_12 0xa1
90 #endif
91 #ifndef SAT_ATA_PASSTHROUGH_16
92 #define SAT_ATA_PASSTHROUGH_16 0x85
93 #endif
94 
95 
96 #define DXFER_NONE        0
97 #define DXFER_FROM_DEVICE 1
98 #define DXFER_TO_DEVICE   2
99 
100 struct scsi_cmnd_io
101 {
102     uint8_t * cmnd;     /* [in]: ptr to SCSI command block (cdb) */
103     size_t  cmnd_len;   /* [in]: number of bytes in SCSI command */
104     int dxfer_dir;      /* [in]: DXFER_NONE, DXFER_FROM_DEVICE, or
105                                  DXFER_TO_DEVICE */
106     uint8_t * dxferp;   /* [in]: ptr to outgoing or incoming data buffer */
107     size_t dxfer_len;   /* [in]: bytes to be transferred to/from dxferp */
108     uint8_t * sensep;   /* [in]: ptr to sense buffer, filled when
109                                  CHECK CONDITION status occurs */
110     size_t max_sense_len; /* [in]: max number of bytes to write to sensep */
111     unsigned timeout;   /* [in]: seconds, 0-> default timeout (60 seconds?) */
112     size_t resp_sense_len;  /* [out]: sense buffer length written */
113     uint8_t scsi_status;  /* [out]: 0->ok, 2->CHECK CONDITION, etc ... */
114     int resid;          /* [out]: Number of bytes requested to be transferred
115                                   less actual number transferred (0 if not
116                                    supported) */
117 };
118 
119 struct scsi_sense_disect {
120     uint8_t resp_code;
121     uint8_t sense_key;
122     uint8_t asc;
123     uint8_t ascq;
124     int progress; /* -1 -> N/A, 0-65535 -> available */
125 };
126 
127 /* Useful data from Informational Exception Control mode page (0x1c) */
128 #define SCSI_IECMP_RAW_LEN 64
129 struct scsi_iec_mode_page {
130     uint8_t requestedCurrent;
131     uint8_t gotCurrent;
132     uint8_t requestedChangeable;
133     uint8_t gotChangeable;
134     uint8_t modese_len;   /* 0 (don't know), 6 or 10 */
135     uint8_t raw_curr[SCSI_IECMP_RAW_LEN];
136     uint8_t raw_chg[SCSI_IECMP_RAW_LEN];
137 };
138 
139 /* Carrier for Error counter log pages (e.g. read, write, verify ...) */
140 struct scsiErrorCounter {
141     uint8_t gotPC[7];
142     uint8_t gotExtraPC;
143     uint64_t counter[8];
144 };
145 
146 /* Carrier for Non-medium error log page */
147 struct scsiNonMediumError {
148     uint8_t gotPC0;
149     uint8_t gotExtraPC;
150     uint64_t counterPC0;
151     uint8_t gotTFE_H;
152     uint64_t counterTFE_H; /* Track following errors [Hitachi] */
153     uint8_t gotPE_H;
154     uint64_t counterPE_H;  /* Positioning errors [Hitachi] */
155 };
156 
157 struct scsi_readcap_resp {
158     uint64_t num_lblocks;       /* Number of Logical Blocks on device */
159     uint32_t lb_size;   /* should be available in all non-error cases */
160     /* following fields from READ CAPACITY(16) or set to 0 */
161     uint8_t prot_type;  /* 0, 1, 2 or 3 protection type, deduced from
162                          * READ CAPACITY(16) P_TYPE and PROT_EN fields */
163     uint8_t p_i_exp;    /* Protection information Intervals Exponent */
164     uint8_t lb_p_pb_exp;/* Logical Blocks per Physical Block Exponent */
165     bool lbpme;         /* Logical Block Provisioning Management Enabled */
166     bool lbprz;         /* Logical Block Provisioning Read Zeros */
167     uint16_t l_a_lba;   /* Lowest Aligned Logical Block Address */
168 };
169 
170 /* SCSI Peripheral types (of interest) */
171 #define SCSI_PT_DIRECT_ACCESS           0x0
172 #define SCSI_PT_SEQUENTIAL_ACCESS       0x1
173 #define SCSI_PT_CDROM                   0x5
174 #define SCSI_PT_MEDIUM_CHANGER          0x8
175 #define SCSI_PT_ENCLOSURE               0xd
176 #define SCSI_PT_HOST_MANAGED            0x14
177 
178 /* Transport protocol identifiers or just Protocol identifiers */
179 #define SCSI_TPROTO_FCP 0
180 #define SCSI_TPROTO_SPI 1
181 #define SCSI_TPROTO_SSA 2
182 #define SCSI_TPROTO_1394 3
183 #define SCSI_TPROTO_SRP 4            /* SCSI over RDMA */
184 #define SCSI_TPROTO_ISCSI 5
185 #define SCSI_TPROTO_SAS 6
186 #define SCSI_TPROTO_ADT 7
187 #define SCSI_TPROTO_ATA 8
188 #define SCSI_TPROTO_UAS 9            /* USB attached SCSI */
189 #define SCSI_TPROTO_SOP 0xa          /* SCSI over PCIe */
190 #define SCSI_TPROTO_PCIE 0xb         /* includes NVMe */
191 #define SCSI_TPROTO_NONE 0xf
192 
193 
194 /* SCSI Log Pages retrieved by LOG SENSE. 0x0 to 0x3f, 0x30 to 0x3e vendor */
195 #define SUPPORTED_LPAGES                    0x00
196 #define BUFFER_OVERRUN_LPAGE                0x01
197 #define WRITE_ERROR_COUNTER_LPAGE           0x02
198 #define READ_ERROR_COUNTER_LPAGE            0x03
199 #define READ_REVERSE_ERROR_COUNTER_LPAGE    0x04
200 #define VERIFY_ERROR_COUNTER_LPAGE          0x05
201 #define NON_MEDIUM_ERROR_LPAGE              0x06
202 #define LAST_N_ERROR_EVENTS_LPAGE           0x07
203 #define FORMAT_STATUS_LPAGE                 0x08
204 #define LAST_N_DEFERRED_LPAGE               0x0b   /* or async events */
205 #define LB_PROV_LPAGE                       0x0c   /* SBC-3 */
206 #define TEMPERATURE_LPAGE                   0x0d
207 #define STARTSTOP_CYCLE_COUNTER_LPAGE       0x0e
208 #define APPLICATION_CLIENT_LPAGE            0x0f
209 #define SELFTEST_RESULTS_LPAGE              0x10
210 #define SS_MEDIA_LPAGE                      0x11   /* SBC-3 */
211 #define BACKGROUND_RESULTS_LPAGE            0x15   /* SBC-3 */
212 #define ATA_PT_RESULTS_LPAGE                0x16   /* SAT */
213 #define NONVOL_CACHE_LPAGE                  0x17   /* SBC-3 */
214 #define PROTOCOL_SPECIFIC_LPAGE             0x18
215 #define GEN_STATS_PERF_LPAGE                0x19
216 #define POWER_COND_TRANS_LPAGE              0x1a
217 #define IE_LPAGE                            0x2f
218 
219 /* SCSI Log subpages (8 bits), added spc4r05 2006, standardized SPC-4 2015 */
220 #define NO_SUBPAGE_L_SPAGE              0x0     /* 0x0-0x3f,0x0 */
221 #define LAST_N_INQ_DAT_L_SPAGE          0x1     /* 0xb,0x1 */
222 #define LAST_N_MODE_PG_L_SPAGE          0x2     /* 0xb,0x2 */
223 #define ENVIRO_REP_L_SPAGE              0x1     /* 0xd,0x1 */
224 #define ENVIRO_LIMITS_L_SPAGE           0x2     /* 0xd,0x2 */
225 #define UTILIZATION_L_SPAGE             0x1     /* 0xe,0x1 */
226 #define ZB_DEV_STATS_L_SPAGE            0x1     /* 0x14,0x1 */
227 #define PEND_DEFECTS_L_SPAGE            0x1     /* 0x15,0x1 */
228 #define BACKGROUND_OP_L_SPAGE           0x2     /* 0x15,0x2 */
229 #define LPS_MISALIGN_L_SPAGE            0x3     /* 0x15,0x3 */
230 #define SUPP_SPAGE_L_SPAGE              0xff    /* 0x0,0xff pages+subpages */
231 
232 /* Seagate vendor specific log pages. */
233 #define SEAGATE_CACHE_LPAGE                 0x37
234 #define SEAGATE_FACTORY_LPAGE               0x3e
235 
236 /* Log page response lengths */
237 #define LOG_RESP_SELF_TEST_LEN 0x194
238 
239 /* See the SSC-2 document at www.t10.org . Earlier note: From IBM
240 Documentation, see http://www.storage.ibm.com/techsup/hddtech/prodspecs.htm */
241 #define TAPE_ALERTS_LPAGE                        0x2e
242 
243 /* ANSI SCSI-3 Mode Pages */
244 #define VENDOR_UNIQUE_PAGE                       0x00
245 #define READ_WRITE_ERROR_RECOVERY_PAGE           0x01
246 #define DISCONNECT_RECONNECT_PAGE                0x02
247 #define FORMAT_DEVICE_PAGE                       0x03
248 #define RIGID_DISK_DRIVE_GEOMETRY_PAGE           0x04
249 #define FLEXIBLE_DISK_PAGE                       0x05
250 #define VERIFY_ERROR_RECOVERY_PAGE               0x07
251 #define CACHING_PAGE                             0x08
252 #define PERIPHERAL_DEVICE_PAGE                   0x09
253 #define XOR_CONTROL_MODE_PAGE                    0x10
254 #define CONTROL_MODE_PAGE                        0x0a
255 #define MEDIUM_TYPES_SUPPORTED_PAGE              0x0b
256 #define NOTCH_PAGE                               0x0c
257 #define CD_DEVICE_PAGE                           0x0d
258 #define CD_AUDIO_CONTROL_PAGE                    0x0e
259 #define DATA_COMPRESSION_PAGE                    0x0f
260 #define ENCLOSURE_SERVICES_MANAGEMENT_PAGE       0x14
261 #define PROTOCOL_SPECIFIC_LUN_PAGE               0x18
262 #define PROTOCOL_SPECIFIC_PORT_PAGE              0x19
263 #define POWER_CONDITION_PAGE                     0x1a
264 #define INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE    0x1c
265 #define FAULT_FAILURE_REPORTING_PAGE             0x1c
266 
267 /* Background control mode subpage is [0x1c,0x1] */
268 #define BACKGROUND_CONTROL_M_SUBPAGE             0x1   /* SBC-2 */
269 
270 #define ALL_MODE_PAGES                           0x3f
271 
272 /* Mode page control field */
273 #define MPAGE_CONTROL_CURRENT               0
274 #define MPAGE_CONTROL_CHANGEABLE            1
275 #define MPAGE_CONTROL_DEFAULT               2
276 #define MPAGE_CONTROL_SAVED                 3
277 
278 /* SCSI Vital Product Data (VPD) pages */
279 #define SCSI_VPD_SUPPORTED_VPD_PAGES    0x0
280 #define SCSI_VPD_UNIT_SERIAL_NUMBER     0x80
281 #define SCSI_VPD_DEVICE_IDENTIFICATION  0x83
282 #define SCSI_VPD_EXTENDED_INQUIRY_DATA  0x86
283 #define SCSI_VPD_ATA_INFORMATION        0x89
284 #define SCSI_VPD_POWER_CONDITION        0x8a
285 #define SCSI_VPD_POWER_CONSUMPTION      0x8d
286 #define SCSI_VPD_BLOCK_LIMITS           0xb0
287 #define SCSI_VPD_BLOCK_DEVICE_CHARACTERISTICS   0xb1
288 #define SCSI_VPD_LOGICAL_BLOCK_PROVISIONING     0xb2
289 
290 /* defines for useful SCSI Status codes */
291 #define SCSI_STATUS_CHECK_CONDITION     0x2
292 
293 /* defines for useful Sense Key codes */
294 #define SCSI_SK_NO_SENSE                0x0
295 #define SCSI_SK_RECOVERED_ERR           0x1
296 #define SCSI_SK_NOT_READY               0x2
297 #define SCSI_SK_MEDIUM_ERROR            0x3
298 #define SCSI_SK_HARDWARE_ERROR          0x4
299 #define SCSI_SK_ILLEGAL_REQUEST         0x5
300 #define SCSI_SK_UNIT_ATTENTION          0x6
301 #define SCSI_SK_ABORTED_COMMAND         0xb
302 
303 /* defines for useful Additional Sense Codes (ASCs) */
304 #define SCSI_ASC_NOT_READY              0x4     /* more info in ASCQ code */
305 #define SCSI_ASC_NO_MEDIUM              0x3a    /* more info in ASCQ code */
306 #define SCSI_ASC_UNKNOWN_OPCODE         0x20
307 #define SCSI_ASC_INVALID_FIELD          0x24
308 #define SCSI_ASC_UNKNOWN_PARAM          0x26
309 #define SCSI_ASC_WARNING                0xb
310 #define SCSI_ASC_IMPENDING_FAILURE      0x5d
311 
312 #define SCSI_ASCQ_ATA_PASS_THROUGH      0x1d
313 
314 /* Simplified error code (negative values as per errno) */
315 #define SIMPLE_NO_ERROR                 0
316 #define SIMPLE_ERR_NOT_READY            1
317 #define SIMPLE_ERR_BAD_OPCODE           2
318 #define SIMPLE_ERR_BAD_FIELD            3       /* in cbd */
319 #define SIMPLE_ERR_BAD_PARAM            4       /* in data */
320 #define SIMPLE_ERR_BAD_RESP             5       /* response fails sanity */
321 #define SIMPLE_ERR_NO_MEDIUM            6       /* no medium present */
322 #define SIMPLE_ERR_BECOMING_READY       7       /* device will be ready soon */
323 #define SIMPLE_ERR_TRY_AGAIN            8       /* some warning, try again */
324 #define SIMPLE_ERR_MEDIUM_HARDWARE      9       /* medium or hardware error */
325 #define SIMPLE_ERR_UNKNOWN              10      /* unknown sense value */
326 #define SIMPLE_ERR_ABORTED_COMMAND      11      /* probably transport error */
327 
328 
329 /* defines for functioncode parameter in SENDDIAGNOSTIC function */
330 #define SCSI_DIAG_NO_SELF_TEST          0x00
331 #define SCSI_DIAG_DEF_SELF_TEST         0xff
332 #define SCSI_DIAG_BG_SHORT_SELF_TEST    0x01
333 #define SCSI_DIAG_BG_EXTENDED_SELF_TEST 0x02
334 #define SCSI_DIAG_FG_SHORT_SELF_TEST    0x05
335 #define SCSI_DIAG_FG_EXTENDED_SELF_TEST 0x06
336 #define SCSI_DIAG_ABORT_SELF_TEST       0x04
337 
338 /* Defines for power_cond in scsiSetPowerCondition() (SSU command) */
339 #define SCSI_POW_COND_ACTIVE            0x1
340 #define SCSI_POW_COND_IDLE              0x2
341 #define SCSI_POW_COND_STANDBY           0x3
342 
343 
344 /* SCSI command timeout values (units are seconds) */
345 #define SCSI_TIMEOUT_DEFAULT    60  // should be longer than the spin up time
346                                     // of a disk in JBOD.
347 
348 #define SCSI_TIMEOUT_SELF_TEST  (5 * 60 * 60)   /* allow max 5 hours for */
349                                             /* extended foreground self test */
350 
351 
352 
353 #define LOGPAGEHDRSIZE  4
354 
355 class scsi_device;
356 
357 // Set of supported SCSI VPD pages. Constructor fetches Supported VPD pages
358 // VPD page and remembers the response for later queries.
359 class supported_vpd_pages
360 {
361 public:
362     explicit supported_vpd_pages(scsi_device * device);
363 
364     bool is_supported(int vpd_page_num) const;
365 
366 private:
367     int num_valid;      /* 0 or less for invalid */
368     unsigned char pages[256];
369 };
370 
371 extern supported_vpd_pages * supported_vpd_pages_p;
372 
373 /* This is a heuristic that takes into account the command bytes and length
374  * to decide whether the presented unstructured sequence of bytes could be
375  * a SCSI command. If so it returns true otherwise false. Vendor specific
376  * SCSI commands (i.e. opcodes from 0xc0 to 0xff), if presented, are assumed
377  * to follow SCSI conventions (i.e. length of 6, 10, 12 or 16 bytes). The
378  * only SCSI commands considered above 16 bytes of length are the Variable
379  * Length Commands (opcode 0x7f) and the XCDB wrapped commands (opcode 0x7e).
380  * Both have an inbuilt length field which can be cross checked with clen.
381  * No NVMe commands (64 bytes long plus some extra added by some OSes) have
382  * opcodes 0x7e or 0x7f yet. ATA is register based but SATA has FIS
383  * structures that are sent across the wire. The FIS register structure is
384  * used to move a command from a SATA host to device, but the ATA 'command'
385  * is not the first byte. So it is harder to say what will happen if a
386  * FIS structure is presented as a SCSI command, hopefully there is a low
387  * probability this function will yield true in that case. */
388 bool is_scsi_cdb(const uint8_t * cdbp, int clen);
389 
390 // Print SCSI debug messages?
391 extern unsigned char scsi_debugmode;
392 
393 void scsi_do_sense_disect(const struct scsi_cmnd_io * in,
394                           struct scsi_sense_disect * out);
395 
396 int scsiSimpleSenseFilter(const struct scsi_sense_disect * sinfo);
397 
398 const char * scsiErrString(int scsiErr);
399 
400 int scsi_vpd_dev_id_iter(const unsigned char * initial_desig_desc,
401                          int page_len, int * off, int m_assoc,
402                          int m_desig_type, int m_code_set);
403 
404 int scsi_decode_lu_dev_id(const unsigned char * b, int blen, char * s,
405                           int slen, int * transport);
406 
407 
408 /* STANDARD SCSI Commands  */
409 int scsiTestUnitReady(scsi_device * device);
410 
411 int scsiStdInquiry(scsi_device * device, uint8_t *pBuf, int bufLen);
412 
413 int scsiInquiryVpd(scsi_device * device, int vpd_page, uint8_t *pBuf,
414                    int bufLen);
415 
416 int scsiLogSense(scsi_device * device, int pagenum, int subpagenum,
417                  uint8_t *pBuf, int bufLen, int known_resp_len);
418 
419 int scsiLogSelect(scsi_device * device, int pcr, int sp, int pc, int pagenum,
420                   int subpagenum, uint8_t *pBuf, int bufLen);
421 
422 int scsiModeSense(scsi_device * device, int pagenum, int subpagenum, int pc,
423                   uint8_t *pBuf, int bufLen);
424 
425 int scsiModeSelect(scsi_device * device, int sp, uint8_t *pBuf, int bufLen);
426 
427 int scsiModeSense10(scsi_device * device, int pagenum, int subpagenum, int pc,
428                     uint8_t *pBuf, int bufLen);
429 
430 int scsiModeSelect10(scsi_device * device, int sp, uint8_t *pBuf, int bufLen);
431 
432 int scsiModePageOffset(const uint8_t * resp, int len, int modese_len);
433 
434 int scsiRequestSense(scsi_device * device,
435                      struct scsi_sense_disect * sense_info);
436 
437 int scsiSetPowerCondition(scsi_device * device, int power_cond,
438                           int pcond_modifier = 0);
439 
440 int scsiSendDiagnostic(scsi_device * device, int functioncode, uint8_t *pBuf,
441                        int bufLen);
442 
443 int scsiReadDefect10(scsi_device * device, int req_plist, int req_glist,
444                      int dl_format, uint8_t *pBuf, int bufLen);
445 
446 int scsiReadDefect12(scsi_device * device, int req_plist, int req_glist,
447                      int dl_format, int addrDescIndex, uint8_t *pBuf,
448                      int bufLen);
449 
450 int scsiReadCapacity10(scsi_device * device, unsigned int * last_lbp,
451                        unsigned int * lb_sizep);
452 
453 int scsiReadCapacity16(scsi_device * device, uint8_t *pBuf, int bufLen);
454 
455 /* SMART specific commands */
456 int scsiCheckIE(scsi_device * device, int hasIELogPage, int hasTempLogPage,
457                 uint8_t *asc, uint8_t *ascq, uint8_t *currenttemp,
458                 uint8_t *triptemp);
459 
460 int scsiFetchIECmpage(scsi_device * device, struct scsi_iec_mode_page *iecp,
461                       int modese_len);
462 int scsi_IsExceptionControlEnabled(const struct scsi_iec_mode_page *iecp);
463 int scsi_IsWarningEnabled(const struct scsi_iec_mode_page *iecp);
464 int scsiSetExceptionControlAndWarning(scsi_device * device, int enabled,
465                             const struct scsi_iec_mode_page *iecp);
466 void scsiDecodeErrCounterPage(unsigned char * resp,
467                               struct scsiErrorCounter *ecp);
468 void scsiDecodeNonMediumErrPage(unsigned char * resp,
469                                 struct scsiNonMediumError *nmep);
470 int scsiFetchExtendedSelfTestTime(scsi_device * device, int * durationSec,
471                                   int modese_len);
472 int scsiCountFailedSelfTests(scsi_device * device, int noisy);
473 int scsiSelfTestInProgress(scsi_device * device, int * inProgress);
474 int scsiFetchControlGLTSD(scsi_device * device, int modese_len, int current);
475 int scsiSetControlGLTSD(scsi_device * device, int enabled, int modese_len);
476 int scsiFetchTransportProtocol(scsi_device * device, int modese_len);
477 int scsiGetRPM(scsi_device * device, int modese_len, int * form_factorp,
478                int * haw_zbcp);
479 int scsiGetSetCache(scsi_device * device,  int modese_len, short int * wce,
480                     short int * rcd);
481 uint64_t scsiGetSize(scsi_device * device, bool avoid_rcap16,
482                      struct scsi_readcap_resp * srrp);
483 
484 /* T10 Standard IE Additional Sense Code strings taken from t10.org */
485 const char* scsiGetIEString(uint8_t asc, uint8_t ascq);
486 int scsiGetTemp(scsi_device * device, uint8_t *currenttemp, uint8_t *triptemp);
487 
488 
489 int scsiSmartDefaultSelfTest(scsi_device * device);
490 int scsiSmartShortSelfTest(scsi_device * device);
491 int scsiSmartExtendSelfTest(scsi_device * device);
492 int scsiSmartShortCapSelfTest(scsi_device * device);
493 int scsiSmartExtendCapSelfTest(scsi_device * device);
494 int scsiSmartSelfTestAbort(scsi_device * device);
495 
496 const char * scsiTapeAlertsTapeDevice(unsigned short code);
497 const char * scsiTapeAlertsChangerDevice(unsigned short code);
498 
499 const char * scsi_get_opcode_name(uint8_t opcode);
500 void scsi_format_id_string(char * out, const uint8_t * in, int n);
501 
502 void dStrHex(const uint8_t * up, int len, int no_ascii);
503 
504 /* Attempt to find the first SCSI sense data descriptor that matches the
505    given 'desc_type'. If found return pointer to start of sense data
506    descriptor; otherwise (including fixed format sense data) returns NULL. */
507 const unsigned char * sg_scsi_sense_desc_find(const unsigned char * sensep,
508                                               int sense_len, int desc_type);
509 
510 
511 /* SCSI command transmission interface function declaration. Its
512  * definition is target OS specific (see os_<OS>.c file).
513  * Returns 0 if SCSI command successfully launched and response
514  * received. Even when 0 is returned the caller should check
515  * scsi_cmnd_io::scsi_status for SCSI defined errors and warnings
516  * (e.g. CHECK CONDITION). If the SCSI command could not be issued
517  * (e.g. device not present or not a SCSI device) or some other problem
518  * arises (e.g. timeout) then returns a negative errno value. */
519 // Moved to C++ interface
520 //int do_scsi_cmnd_io(int dev_fd, struct scsi_cmnd_io * iop, int report);
521 
522 
523 
524 #endif
525