1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2011-2012 Planets Communications B.V.
5    Copyright (C) 2013-2018 Bareos GmbH & Co. KG
6 
7    This program is Free Software; you can redistribute it and/or
8    modify it under the terms of version three of the GNU Affero General Public
9    License as published by the Free Software Foundation and included
10    in the file LICENSE.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15    Affero General Public License for more details.
16 
17    You should have received a copy of the GNU Affero General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21 */
22 
23 /*
24  * Marco van Wieringen, March 2012
25  */
26 
27 #ifndef BAREOS_LIB_SCSI_LLI_H_
28 #define BAREOS_LIB_SCSI_LLI_H_ 1
29 
30 /*
31  * Device Inquiry Response
32  */
33 typedef struct {
34 #if HAVE_BIG_ENDIAN
35    uint8_t peripheralQualifier:3;
36    uint8_t periphrealDeviceType:5;
37    uint8_t RMB:1;
38    uint8_t res_bits_1:7;
39 #else
40    uint8_t periphrealDeviceType:5;
41    uint8_t peripheralQualifier:3;
42    uint8_t res_bits_1:7;
43    uint8_t RMB:1;
44 #endif
45    uint8_t Version[1];
46 #if HAVE_BIG_ENDIAN
47    uint8_t obs_bits_1:2;
48    uint8_t NORMACA:1;
49    uint8_t HISUP:1;
50    uint8_t responseDataFormat:4;
51 #else
52    uint8_t responseDataFormat:4;
53    uint8_t HISUP:1;
54    uint8_t NORMACA:1;
55    uint8_t obs_bits_1:2;
56 #endif
57    uint8_t additionalLength[1];
58 #if HAVE_BIG_ENDIAN
59    uint8_t SCCS:1;
60    uint8_t ACC:1;
61    uint8_t TPGS:2;
62    uint8_t threePC:1;
63    uint8_t res_bits_2:2;
64    uint8_t protect:1;
65    uint8_t obs_bits_2:1;
66    uint8_t ENCSERV:1;
67    uint8_t VS:1;
68    uint8_t MULTIP:1;
69    uint8_t MCHNGR:1;
70    uint8_t obs_bits_3:2;
71    uint8_t ADDR16:1;
72    uint8_t obs_bits_4:2;
73    uint8_t WBUS16:1;
74    uint8_t SYNC:1;
75    uint8_t obs_bits_5:2;
76    uint8_t CMDQUE:1;
77    uint8_t VS2:1;
78 #else
79    uint8_t protect:1;
80    uint8_t res_bits_2:2;
81    uint8_t threePC:1;
82    uint8_t TPGS:2;
83    uint8_t ACC:1;
84    uint8_t SCCS:1;
85    uint8_t ADDR16:1;
86    uint8_t obs_bits_3:2;
87    uint8_t MCHNGR:1;
88    uint8_t MULTIP:1;
89    uint8_t VS:1;
90    uint8_t ENCSERV:1;
91    uint8_t obs_bits_2:1;
92    uint8_t VS2:1;
93    uint8_t CMDQUE:1;
94    uint8_t obs_bits_5:2;
95    uint8_t SYNC:1;
96    uint8_t WBUS16:1;
97    uint8_t obs_bits_4:2;
98 #endif
99    uint8_t vendor[8];
100    uint8_t productID[16];
101    uint8_t productRev[4];
102    uint8_t SN[7];
103    uint8_t venderUnique[12];
104 #if HAVE_BIG_ENDIAN
105    uint8_t res_bits_3:4;
106    uint8_t CLOCKING:2;
107    uint8_t QAS:1;
108    uint8_t IUS:1;
109 #else
110    uint8_t IUS:1;
111    uint8_t QAS:1;
112    uint8_t CLOCKING:2;
113    uint8_t res_bits_3:4;
114 #endif
115    uint8_t res_bits_4[1];
116    uint8_t versionDescriptor[16];
117    uint8_t res_bits_5[22];
118    uint8_t copyright[1];
119 } SCSI_PAGE_INQ;
120 
121 /*
122  * Sense Data Response
123  */
124 typedef struct {
125 #if HAVE_BIG_ENDIAN
126    uint8_t valid:1;
127    uint8_t responseCode:7;
128 #else
129    uint8_t responseCode:7;
130    uint8_t valid:1;
131 #endif
132    uint8_t res_bits_1;
133 #if HAVE_BIG_ENDIAN
134    uint8_t filemark:1;
135    uint8_t EOM:1;
136    uint8_t ILI:1;
137    uint8_t res_bits_2:1;
138    uint8_t senseKey:4;
139 #else
140    uint8_t senseKey:4;
141    uint8_t res_bits_2:1;
142    uint8_t ILI:1;
143    uint8_t EOM:1;
144    uint8_t filemark:1;
145 #endif
146    uint8_t information[4];
147    uint8_t addSenseLen;
148    uint8_t cmdSpecificInfo[4];
149    uint8_t addSenseCode;
150    uint8_t addSenseCodeQual;
151    uint8_t fieldRepUnitCode;
152 #if HAVE_BIG_ENDIAN
153    uint8_t sim:3;                              /* system information message */
154    uint8_t bpv:1;                              /* bit pointer valid */
155    uint8_t resvd2:2;
156    uint8_t cd:1;                               /* control/data */
157    uint8_t SKSV:1;
158 #else
159    uint8_t SKSV:1;
160    uint8_t cd:1;                               /* control/data */
161    uint8_t resvd2:2;
162    uint8_t bpv:1;                              /* bit pointer valid */
163    uint8_t sim:3;                              /* system information message */
164 #endif
165    uint8_t field[2];                           /* field pointer */
166    uint8_t addSenseData[109];
167 } SCSI_PAGE_SENSE;
168 
169 bool RecvScsiCmdPage(int fd, const char *device_name,
170                         void *cdb, unsigned int cdb_len,
171                         void *cmd_page, unsigned int cmd_page_len);
172 bool send_scsi_cmd_page(int fd, const char *device_name,
173                         void *cdb, unsigned int cdb_len,
174                         void *cmd_page, unsigned int cmd_page_len);
175 bool CheckScsiAtEod(int fd);
176 #endif /* BAREOS_LIB_SCSI_LLI_H_ */
177