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