xref: /titanic_52/usr/src/cmd/smserverd/smserver.h (revision 6a1af1a67532df169a657cce07140be64bdea084)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SMSERVER_H_
27 #define	_SMSERVER_H_
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <door.h>
34 #include <thread.h>
35 #include <synch.h>
36 #include <sys/dkio.h>
37 #include <bsm/audit.h>
38 
39 #define	RQ_LEN 18
40 #define	MAX_RQ_LEN 32
41 #define	MAX_CDB_LEN 32
42 
43 #define	smedia_service	"/var/run/smedia_svc"
44 #define	DEFAULT_SMEDIAD_DEVDIR	"/usr/lib/smedia"
45 
46 #define	INIT_NOT_DONE		0
47 #define	INIT_DONE		1
48 #define	INIT_IN_PROGRESS	2
49 
50 /* SCSI FORMAT UNIT cdb[1] #defines */
51 #define	FMTDATA			0x10
52 #define	CMPLIST			0x08
53 
54 /* Defect list header data[1] #defines */
55 
56 #define	VS			0x1
57 #define	IMMED			0x2
58 #define	DSP			0x4
59 #define	IP			0x8
60 #define	STPF			0x10
61 #define	DCRT			0x20
62 #define	DPRY			0x40
63 #define	FOV			0x80
64 
65 #define	DEFERRED_ERROR		0x71
66 #define	AWRE			0x80
67 
68 #define	MODE_SENSE_PARAM_HDR_LEN		4
69 #define	MODE_PARAM_BLOCK_LEN			8
70 #define	AWRE_OFFSET	(MODE_SENSE_PARAM_HDR_LEN + MODE_PARAM_BLOCK_LEN + 2)
71 #define	BLOCK_LEN_OFFSET			(MODE_SENSE_PARAM_HDR_LEN + 5)
72 #define	SKSV_FIELD				0x80
73 #define	SKSV_OFFSET				15
74 #define	FORMAT_PROGRESS_INDICATOR_OFFSET_0	16
75 #define	FORMAT_PROGRESS_INDICATOR_OFFSET_1	17
76 
77 /* #defines for protect medode field */
78 
79 #define	UNLOCK_MODE			0x0
80 #define	WRITE_PROTECT_MODE		0x2
81 #define	PASSWD_WRITE_PROTECT_MODE	0x3
82 #define	READ_WRITE_PROTECT_MODE		0x5
83 #define	TEMP_UNLOCK_MODE		0x8
84 
85 /* #defines for CARTRIDGE STATUS PAGE */
86 
87 #define	CARTRIDGE_STATUS_PAGE		2
88 #define	NON_SENSE_HDR_LEN		0x2
89 #define	PROTECT_MODE_OFFSET		19
90 #define	DISK_STATUS_OFFSET		1
91 
92 
93 /* error reporting mechanism */
94 void	fatal(const char *, ...);
95 void	info(const char *, ...);
96 void	warning(const char *, ...);
97 void	debug(uint_t, const char *, ...);
98 void	setlog(const char *);
99 void	flushlog();
100 void	quit(const char *, ...);
101 void	noise(const char *, ...);
102 
103 typedef struct server_data {
104 	char	sd_init_state;
105 	mutex_t	sd_init_lock;
106 	cond_t	sd_init_cv;
107 	int	sd_door;
108 	int	sd_fd;
109 } server_data_t;
110 
111 typedef	enum {
112 	SMEDIA_SUCCESS = 0x0,
113 	SMEDIA_FAILURE			/* general failure */
114 } smedia_errno_t;
115 
116 typedef struct door_data {
117 	mutex_t		dd_lock;	/* lock to protect entire structure */
118 	mutex_t		dd_threadlock;	/* lock to protect dd_thread field */
119 	sigset_t	dd_newset;	/* signal set handled by the server */
120 	cond_t		dd_cv;		/* client_door_descriptor cv */
121 	cond_t		dd_cv_bind;	/* client door descriptor bind cv */
122 	int32_t		dd_id;		/* for future use. To store unique id */
123 	door_desc_t	dd_desc[2];	/* [0] : Client Door descriptor */
124 					/* [1] : Death Door decriptor */
125 	thread_t	dd_thread;	/* thread bound to the client door */
126 	door_cred_t	dd_cred;	/* credentials of client */
127 	int32_t		dd_fd;		/* device file descriptor */
128 	void		*dd_buf;	/* mmapped buffer of client */
129 	int32_t		dd_buf_len;	/* size of the mmapped buffer */
130 	int32_t		dd_buffd;	/* mmapped file descriptor */
131 	int32_t		dd_sector_size;	/* sector size of the device */
132 	struct stat	dd_stat;	/* stat of the dd_fd */
133 	struct dk_cinfo	dd_dkinfo;
134 
135 	au_id_t		audit_auid;	/* auid of user writing audit record */
136 	uid_t		audit_uid;	/* uid of user writing audit record */
137 	uid_t		audit_euid;	/* euid of user writing audit record */
138 	gid_t		audit_gid;	/* gid of user writing audit record */
139 	gid_t		audit_egid;	/* euid of user writing audit record */
140 	pid_t		audit_pid;	/* pid of user writing audit record */
141 	au_tid_addr_t	audit_tid;	/* tid of user writing audit record */
142 	int		audit_na;	/* 0 if event is attributable */
143 	au_mask_t	audit_namask;	/* not attributable flags */
144 	au_event_t	audit_event;	/* id of event being audited */
145 	int 		audit_sorf;	/* success or failure of audit_event */
146 	char 		*audit_user;	/* text version of audit_uid */
147 	au_asid_t	audit_asid;	/* asid of process writing record */
148 	char 		*audit_path;	/* path token */
149 	uint32_t	audit_policy;	/* kernel audit policy */
150 	struct auditpinfo_addr audit_ap;
151 	char		audit_text[128];
152 	char		audit_text1[128];
153 } door_data_t;
154 
155 /* Symbols to simplify access of door_data_t */
156 #define	dd_cdoor	dd_desc[0]	/* Client Door descriptor */
157 #define	dd_ddoor	dd_desc[1]	/* Death Door descriptor */
158 #define	dd_cdoor_descriptor	dd_cdoor.d_data.d_desc.d_descriptor
159 #define	dd_ddoor_descriptor	dd_ddoor.d_data.d_desc.d_descriptor
160 
161 typedef enum {
162 	SMEDIA_CNUM_OPEN_FD = 0x1,
163 	SMEDIA_CNUM_GET_DEVICE_INFO,
164 	SMEDIA_CNUM_GET_MEDIUM_PROPERTY,
165 	SMEDIA_CNUM_GET_PROTECTION_STATUS,
166 	SMEDIA_CNUM_SET_PROTECTION_STATUS,
167 	SMEDIA_CNUM_RAW_READ,
168 	SMEDIA_CNUM_RAW_WRITE,
169 	SMEDIA_CNUM_FORMAT,
170 	SMEDIA_CNUM_CHECK_FORMAT_STATUS,
171 	SMEDIA_CNUM_EJECT,
172 	SMEDIA_CNUM_REASSIGN_BLOCK,
173 	SMEDIA_CNUM_ERROR,
174 	SMEDIA_CNUM_CLOSE,
175 	SMEDIA_CNUM_SET_SHFD,
176 	SMEDIA_CNUM_PING,
177 	SMEDIA_CNUM_USCSI_CMD
178 } smedia_callnumber_t;
179 
180 typedef struct {
181 	smedia_callnumber_t	cnum;	/* service call number */
182 	char			buf[1];	/* buffer containing input arguments */
183 } smedia_req_t;
184 
185 typedef struct {
186 	smedia_callnumber_t	cnum;	/* service call number */
187 	char			buf[1];	/* buffer containing the results */
188 } smedia_ret_t;
189 
190 typedef struct smedia_reqping {
191 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_PING */
192 } smedia_reqping_t;
193 
194 typedef struct smedia_retping {
195 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_PING */
196 } smedia_retping_t;
197 
198 	/*
199 	 * SMEDIA open device
200 	 */
201 typedef	struct	smedia_reqopen {
202 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_OPEN */
203 	int	oflag;
204 	int	omode;
205 } smedia_reqopen_t;
206 
207 typedef	struct	smedia_retopen {
208 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_OPEN */
209 } smedia_retopen_t;
210 
211 typedef struct smedia_requscsi_cmd {
212 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_USCSI_CMD */
213 	int32_t			uscsi_flags;
214 	short			uscsi_timeout;
215 	char			uscsi_cdb[MAX_CDB_LEN];
216 	int32_t			uscsi_buflen;
217 	uchar_t			uscsi_cdblen;
218 	uchar_t			uscsi_rqlen;
219 } smedia_requscsi_cmd_t;
220 
221 typedef struct smedia_retuscsi_cmd {
222 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_USCSI_CMD */
223 	int32_t			uscsi_retval;
224 	int32_t			uscsi_errno;
225 	short			uscsi_status;
226 	int32_t			uscsi_resid;
227 	uchar_t			uscsi_rqstatus;
228 	uchar_t			uscsi_rqresid;
229 	char			uscsi_rqbuf[MAX_RQ_LEN];
230 } smedia_retuscsi_cmd_t;
231 
232 typedef struct	smedia_reqget_device_info {
233 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_GET_DEVICE_INFO */
234 } smedia_reqget_device_info_t;
235 
236 typedef struct	smedia_reqset_shfd {
237 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_SET_SHFD */
238 	int32_t	fdbuf_len;
239 } smedia_reqset_shfd_t;
240 
241 typedef struct	smedia_retget_device_info {
242 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_GET_DEVICE_INFO */
243 	smdevice_info_t		smdevinfo;
244 	uchar_t			sm_version;
245 	int32_t			sm_interface_type;
246 	char			sm_vendor_name[32];
247 	char			sm_product_name[32];
248 	char			sm_firmware_version[32];
249 } smedia_retget_device_info_t;
250 
251 typedef struct	smedia_reqget_medium_property {
252 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_GET_MEDIUM_PROPERTY */
253 } smedia_reqget_medium_property_t;
254 
255 typedef struct	smedia_retget_medium_property {
256 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_GET_MEDIUM_PROPERTY */
257 	smmedium_prop_t		smprop;
258 } smedia_retget_medium_property_t;
259 
260 typedef struct	smedia_reqget_protection_status {
261 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_GET_PROTECTION_STATUS */
262 } smedia_reqget_protection_status_t;
263 
264 typedef struct	smedia_retget_protection_status {
265 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_GET_PROTECTION_STATUS */
266 	smwp_state_t		prot_state;
267 } smedia_retget_protection_status_t;
268 
269 typedef struct	smedia_reqset_protection_status {
270 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_SET_PROTECTION_STATUS */
271 	smwp_state_t		prot_state;
272 } smedia_reqset_protection_status_t;
273 
274 typedef struct	smedia_retset_protection_status {
275 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_SET_PROTECTION_STATUS */
276 } smedia_retset_protection_status_t;
277 
278 typedef struct	smedia_reqraw_read {
279 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_RAW_READ */
280 	diskaddr_t		blockno;
281 	int32_t			nbytes;
282 } smedia_reqraw_read_t;
283 
284 typedef struct	smedia_retraw_read {
285 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_RAW_READ */
286 	int32_t			nbytes;	/* bytes read */
287 	char			buf[1];	/* buffer size is nbytes long */
288 } smedia_retraw_read_t;
289 
290 typedef struct	smedia_reqraw_write {
291 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_RAW_WRITE */
292 	diskaddr_t		blockno;
293 	int32_t			nbytes;
294 	char			buf[1];	/* buffer size is nbytes long */
295 } smedia_reqraw_write_t;
296 
297 typedef struct	smedia_retraw_write {
298 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_RAW_WRITE */
299 	int32_t			nbytes;	/* bytes written */
300 } smedia_retraw_write_t;
301 
302 typedef struct	smedia_reqformat {
303 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_FORMAT */
304 	uint_t			flavor;
305 	uint_t			mode;
306 } smedia_reqformat_t;
307 
308 typedef struct	smedia_retformat {
309 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_FORMAT */
310 } smedia_retformat_t;
311 
312 typedef struct	smedia_reqcheck_format_status {
313 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_CHECK_FORMAT_STATUS */
314 } smedia_reqcheck_format_status_t;
315 
316 typedef struct	smedia_retcheck_format_status {
317 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_CHECK_FORMAT_STATUS */
318 	int			percent_complete;
319 } smedia_retcheck_format_status_t;
320 
321 typedef struct smedia_reqreassign_block {
322 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_REASSIGN_BLOCK */
323 	diskaddr_t		blockno;
324 } smedia_reqreassign_block_t;
325 
326 typedef struct smedia_retreassign_block {
327 	smedia_callnumber_t	cnum;	/* SMEDIA_CNUM_REASSIGN_BLOCK */
328 } smedia_retreassign_block_t;
329 
330 typedef struct	{
331 	smedia_callnumber_t	cnum;		/* SMEDIA_CNUM_ERROR */
332 	smedia_callnumber_t	in_cnum;	/* requested service number */
333 	smedia_errno_t		errnum;
334 } smedia_reterror_t;
335 
336 typedef union	{
337 	smedia_req_t			in;		/* req arguments */
338 	smedia_ret_t			out;		/* out results */
339 	smedia_reqping_t		reqping;
340 	smedia_retping_t		retping;
341 	smedia_reqopen_t		reqopen;
342 	smedia_retopen_t		retopen;
343 	smedia_reqget_device_info_t	reqget_device_info;
344 	smedia_retget_device_info_t	retget_device_info;
345 	smedia_reqget_medium_property_t	reqget_medium_property;
346 	smedia_retget_medium_property_t	retget_medium_property;
347 	smedia_reqget_protection_status_t	reqget_protection_status;
348 	smedia_retget_protection_status_t	retget_protection_status;
349 	smedia_reqset_protection_status_t	reqset_protection_status;
350 	smedia_retset_protection_status_t	retset_protection_status;
351 	smedia_reqraw_read_t		reqraw_read;
352 	smedia_retraw_read_t		retraw_read;
353 	smedia_reqraw_write_t		reqraw_write;
354 	smedia_retraw_write_t		retraw_write;
355 	smedia_reqformat_t		reqformat;
356 	smedia_retformat_t		retformat;
357 	smedia_reqcheck_format_status_t		reqcheck_format_status;
358 	smedia_retcheck_format_status_t		retcheck_format_status;
359 	smedia_reqreassign_block_t	reqreassign_block;
360 	smedia_retreassign_block_t	retreassign_block;
361 	smedia_reterror_t		reterror;
362 	smedia_reqset_shfd_t			reqset_shfd;
363 	smedia_requscsi_cmd_t		requscsi_cmd;
364 	smedia_retuscsi_cmd_t		retuscsi_cmd;
365 } smedia_services_t;
366 
367 #define	SCSI_GENERIC	1
368 #define	SCSI_IOMEGA	2
369 #define	SCSI_FLOPPY	3
370 
371 /*
372  * Crude algorithm for calculating format timeout.
373  * 30min + 5min/100MB =>
374  * 35min for 100MB ZIP
375  * 42.5 min for 250MB ZIP
376  * 127 min for 2GB Jaz
377  * It is OK for now as this is just an upper limit by which the
378  * format should complete.
379  */
380 
381 #define	FORMAT_TIMEOUT(n) (1800 + ((n)/682))
382 
383 #define	WA_BIT	0x10	/* The word align bit for ATAPI devices */
384 /*
385  * Non sense data length for catridge status page.
386  * Should be 63, but IDE driver panics with a non-aligned
387  * data transfer.
388  */
389 
390 #define	ND_LENGTH 64
391 
392 /*
393  * Vendor specific commands from Iomega
394  */
395 
396 #define	IOMEGA_NONSENSE_CMD 	0x6
397 #define	IOMEGA_CATRIDGE_PROTECT	0xC
398 
399 #ifdef __cplusplus
400 }
401 #endif
402 
403 #endif	/* _SMSERVER_H_ */
404