1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2013-2013 Planets Communications B.V.
5    Copyright (C) 2013-2013 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, November 2013
25  */
26 
27 #ifndef BAREOS_LIB_SCSI_TAPEALERT_H_
28 #define BAREOS_LIB_SCSI_TAPEALERT_H_ 1
29 
30 /*
31  * Include the SCSI Low Level Interface functions and definitions.
32  */
33 #include "scsi_lli.h"
34 
35 #define MAX_TAPE_ALERTS 64
36 
37 /*
38  * SCSI CDB opcodes
39  */
40 enum
41 {
42   SCSI_LOG_OPCODE = 0x4d
43 };
44 
45 enum
46 {
47   SCSI_TAPE_ALERT_FLAGS = 0x2e
48 };
49 
50 /*
51  * SCSI Control Descriptor Block
52  */
53 typedef struct {
54   uint8_t opcode;               /* Operation Code See SCSI_*_OPCODE */
55   uint8_t res_bits_1[1];        /* Reserved, 1 byte */
56   uint8_t pagecode;             /* Page Code, 1 byte */
57   uint8_t res_bits_2[2];        /* Reserved, 2 bytes */
58   uint8_t parameter_pointer[2]; /* Parameter Pointer, 2 bytes, 1 bytes MSB and 1
59                                    bytes LSB */
60   uint8_t allocation_length[2]; /* Allocation Length, 2 bytes, 1 bytes MSB and 1
61                                    bytes LSB */
62   uint8_t control_byte;         /* Control Byte */
63 } LOG_SCSI_CDB;
64 
65 typedef struct {
66   uint8_t pagecode;      /* Page Code, 1 byte */
67   uint8_t res_bits_1[1]; /* Reserved, 1 byte */
68   uint8_t
69       page_length[2]; /* Page Length, 2 bytes, 1 bytes MSB and 1 bytes LSB */
70   uint8_t
71       log_parameters[2044]; /* Log parameters (2048 bytes - 4 bytes header) */
72 } TAPEALERT_PAGE_BUFFER;
73 
74 typedef struct {
75   uint8_t parameter_code[2]; /* Parameter Code, 2 bytes */
76 #if HAVE_BIG_ENDIAN
77   uint8_t parameter_length; /* Parameter Length, 1 byte */
78   uint8_t
79       disable_update : 1;   /* DU: Will be set to 0. The library will always
80                                update values reflected by the log parameters. */
81   uint8_t disable_save : 1; /* DS: Will be set to 1. The library does not
82                                support saving of log parameters. */
83   uint8_t target_save_disabled : 1; /* TSD: Will be set to 0. The library
84                                        provides a self-defined method for saving
85                                        log parameters. */
86   uint8_t
87       enable_threshold_comparison : 1; /* ETC: Will be set to 0. No comparison
88                                           to threshold values is made. */
89   uint8_t threshold_met_criteria : 2;  /* TMC: Will be set to 0. Comparison to
90                                           threshold values is not supported. */
91   uint8_t
92       list_parameter_binary : 1; /* LBIN: This field is only valid if LP is set
93                                   * to 1. When LBIN is set to 0, the list
94                                   * parameter is ASCII. When LBIN is set to 1,
95                                   * the list parameter is a binary value. */
96   uint8_t list_parameter : 1;    /* LP: This field will be set to 0 for data
97                                     counters and set to 1 for list parameters */
98 #else
99   uint8_t list_parameter : 1; /* LP: This field will be set to 0 for data
100                                  counters and set to 1 for list parameters */
101   uint8_t
102       list_parameter_binary : 1; /* LBIN: This field is only valid if LP is set
103                                   * to 1. When LBIN is set to 0, the list
104                                   * parameter is ASCII. When LBIN is set to 1,
105                                   * the list parameter is a binary value. */
106   uint8_t threshold_met_criteria : 2; /* TMC: Will be set to 0. Comparison to
107                                          threshold values is not supported. */
108   uint8_t
109       enable_threshold_comparison : 1; /* ETC: Will be set to 0. No comparison
110                                           to threshold values is made. */
111   uint8_t target_save_disabled : 1;    /* TSD: Will be set to 0. The library
112                                           provides a self-defined method for saving
113                                           log parameters. */
114   uint8_t disable_save : 1; /* DS: Will be set to 1. The library does not
115                                support saving of log parameters. */
116   uint8_t
117       disable_update : 1;   /* DU: Will be set to 0. The library will always
118                                update values reflected by the log parameters. */
119   uint8_t parameter_length; /* Parameter Length, 1 byte */
120 #endif
121   uint8_t parameter_value; /* Parameter Value, n bytes */
122 } TAPEALERT_PARAMETER;
123 
124 bool GetTapealertFlags(int fd, const char* device_name, uint64_t* flags);
125 
126 
127 #endif /* BAREOS_LIB_SCSI_TAPEALERT_H_ */
128