xref: /onnv-gate/usr/src/cmd/cfgadm/cfgadm.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1998-1999 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_CFGADM_H
28*0Sstevel@tonic-gate #define	_CFGADM_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * Command line options
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate #define	OPTIONS		"ac:fhlno:s:tx:vy"
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate /*
42*0Sstevel@tonic-gate  * Configuration operations
43*0Sstevel@tonic-gate  */
44*0Sstevel@tonic-gate typedef enum {
45*0Sstevel@tonic-gate 	CFGA_OP_NONE = 0,
46*0Sstevel@tonic-gate 	CFGA_OP_CHANGE_STATE,
47*0Sstevel@tonic-gate 	CFGA_OP_TEST,
48*0Sstevel@tonic-gate 	CFGA_OP_LIST,
49*0Sstevel@tonic-gate 	CFGA_OP_PRIVATE,
50*0Sstevel@tonic-gate 	CFGA_OP_HELP
51*0Sstevel@tonic-gate } cfga_op_t;
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate /*
54*0Sstevel@tonic-gate  * Names for -c functions
55*0Sstevel@tonic-gate  */
56*0Sstevel@tonic-gate static char *state_opts[] = {
57*0Sstevel@tonic-gate 	"",
58*0Sstevel@tonic-gate 	"insert",
59*0Sstevel@tonic-gate 	"remove",
60*0Sstevel@tonic-gate 	"connect",
61*0Sstevel@tonic-gate 	"disconnect",
62*0Sstevel@tonic-gate 	"configure",
63*0Sstevel@tonic-gate 	"unconfigure",
64*0Sstevel@tonic-gate 	NULL
65*0Sstevel@tonic-gate };
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate /*
68*0Sstevel@tonic-gate  * Attachment point specifier types.
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate typedef enum {
71*0Sstevel@tonic-gate 	UNKNOWN_AP,
72*0Sstevel@tonic-gate 	LOGICAL_AP_ID,
73*0Sstevel@tonic-gate 	PHYSICAL_AP_ID,
74*0Sstevel@tonic-gate 	AP_TYPE
75*0Sstevel@tonic-gate } cfga_ap_types_t;
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate /*
78*0Sstevel@tonic-gate  * Confirm values.
79*0Sstevel@tonic-gate  */
80*0Sstevel@tonic-gate enum confirm { CONFIRM_DEFAULT, CONFIRM_NO, CONFIRM_YES };
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate /* Limit size of sysinfo return */
83*0Sstevel@tonic-gate #define	SYSINFO_LENGTH	256
84*0Sstevel@tonic-gate #define	YESNO_STR_MAX	127
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate /* exit codes */
87*0Sstevel@tonic-gate #define	EXIT_OK		0
88*0Sstevel@tonic-gate #define	EXIT_OPFAILED	1
89*0Sstevel@tonic-gate #define	EXIT_NOTSUPP	2
90*0Sstevel@tonic-gate #define	EXIT_ARGERROR	3
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate /* Macro to figure size of cfga_list_data items */
93*0Sstevel@tonic-gate #define	SZ_EL(EL)	(sizeof ((struct cfga_list_data *)NULL)->EL)
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate /* Maximum number of fields in cfgadm output */
96*0Sstevel@tonic-gate #define	N_FIELDS	(sizeof (all_fields)/sizeof (all_fields[0]))
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate /* printing format controls */
99*0Sstevel@tonic-gate #define	DEF_SORT_FIELDS		"ap_id"
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate #define	DEF_COLS		"ap_id:type:r_state:o_state:condition"
102*0Sstevel@tonic-gate #define	DEF_COLS2		NULL
103*0Sstevel@tonic-gate #define	DEF_COLS_VERBOSE	"ap_id:r_state:o_state:condition:info"
104*0Sstevel@tonic-gate #define	DEF_COLS2_VERBOSE	"status_time:type:busy:physid"
105*0Sstevel@tonic-gate #define	DEF_DELIM		" "
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate /* listing field delimiter */
108*0Sstevel@tonic-gate #define	FDELIM		':'
109*0Sstevel@tonic-gate #define	ARG_DELIM	' '
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /* listing lengths for various fields */
112*0Sstevel@tonic-gate #define	STATE_WIDTH	12	/* longest - "disconnected" */
113*0Sstevel@tonic-gate #define	COND_WIDTH	10	/* longest is the heading - "condition" */
114*0Sstevel@tonic-gate #define	TIME_WIDTH	12
115*0Sstevel@tonic-gate #define	TIME_P_WIDTH	14	/* YYYYMMDDhhmmss */
116*0Sstevel@tonic-gate /*	Date and time	formats	*/
117*0Sstevel@tonic-gate /*
118*0Sstevel@tonic-gate  * b --- abbreviated month name
119*0Sstevel@tonic-gate  * e --- day number
120*0Sstevel@tonic-gate  * Y --- year in the form ccyy
121*0Sstevel@tonic-gate  * H --- hour(24-hour version)
122*0Sstevel@tonic-gate  * M --- minute
123*0Sstevel@tonic-gate  */
124*0Sstevel@tonic-gate #define	FORMAT1	 "%b %e  %Y"
125*0Sstevel@tonic-gate #define	FORMAT2  "%b %e %H:%M"
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate /* listing control data */
128*0Sstevel@tonic-gate struct sort_el {
129*0Sstevel@tonic-gate 	int reverse;
130*0Sstevel@tonic-gate 	struct field_info *fld;
131*0Sstevel@tonic-gate };
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate struct print_col {
134*0Sstevel@tonic-gate 	int width;
135*0Sstevel@tonic-gate 	struct field_info *line1;
136*0Sstevel@tonic-gate 	struct field_info *line2;
137*0Sstevel@tonic-gate };
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate /*
140*0Sstevel@tonic-gate  * The first three types are used for filtering and the last for sorting.
141*0Sstevel@tonic-gate  */
142*0Sstevel@tonic-gate typedef enum {
143*0Sstevel@tonic-gate 	CFGA_MATCH_PARTIAL,	/* pass if a partial match */
144*0Sstevel@tonic-gate 	CFGA_MATCH_EXACT,	/* pass only if an exact match */
145*0Sstevel@tonic-gate 	CFGA_MATCH_NOFILTER,	/* pass all. Not valid user input */
146*0Sstevel@tonic-gate 	CFGA_MATCH_ORDER	/* compare and return relative order */
147*0Sstevel@tonic-gate } match_type_t;
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate struct field_info {
150*0Sstevel@tonic-gate 	char *name;
151*0Sstevel@tonic-gate 	char *heading;
152*0Sstevel@tonic-gate 	int width;
153*0Sstevel@tonic-gate 	int (*compare)(struct cfga_list_data *, struct cfga_list_data *,
154*0Sstevel@tonic-gate 	    match_type_t);
155*0Sstevel@tonic-gate 	void (*printfn)(struct cfga_list_data *, int, char *);
156*0Sstevel@tonic-gate 	cfga_err_t (*set_filter)(struct cfga_list_data *, const char *);
157*0Sstevel@tonic-gate };
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate /* list option strings */
160*0Sstevel@tonic-gate static char *list_options[] = {
161*0Sstevel@tonic-gate #define	LIST_SORT	0
162*0Sstevel@tonic-gate 	"sort",
163*0Sstevel@tonic-gate #define	LIST_COLS	1
164*0Sstevel@tonic-gate 	"cols",
165*0Sstevel@tonic-gate #define	LIST_COLS2	2
166*0Sstevel@tonic-gate 	"cols2",
167*0Sstevel@tonic-gate #define	LIST_DELIM	3
168*0Sstevel@tonic-gate 	"delim",
169*0Sstevel@tonic-gate #define	LIST_NOHEADINGS	4
170*0Sstevel@tonic-gate 	"noheadings",
171*0Sstevel@tonic-gate #define	LIST_SELECT	5
172*0Sstevel@tonic-gate 	"select",
173*0Sstevel@tonic-gate #define	LIST_MATCH	6
174*0Sstevel@tonic-gate 	"match",
175*0Sstevel@tonic-gate 	NULL
176*0Sstevel@tonic-gate };
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate /* Selection related */
179*0Sstevel@tonic-gate typedef struct {
180*0Sstevel@tonic-gate 	char *arg;
181*0Sstevel@tonic-gate 	int resp; /* If set, this cmd arg received a response */
182*0Sstevel@tonic-gate } ap_arg_t;
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate typedef struct {
185*0Sstevel@tonic-gate 	cfga_list_data_t *ldatap;
186*0Sstevel@tonic-gate 	int req; /* If set, this list_data was requested by user */
187*0Sstevel@tonic-gate } ap_out_t;
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate /* Filtering related */
190*0Sstevel@tonic-gate #define	CFGA_DEFAULT_MATCH	CFGA_MATCH_EXACT
191*0Sstevel@tonic-gate #define	LEFT_PAREN	'('
192*0Sstevel@tonic-gate #define	RIGHT_PAREN	')'
193*0Sstevel@tonic-gate #define	CFGA_DEV_DIR	"/dev/cfg"
194*0Sstevel@tonic-gate #define	SLASH		"/"
195*0Sstevel@tonic-gate #define	EQUALS		"="
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate typedef enum {
198*0Sstevel@tonic-gate 	CFGA_PSTATE_INIT,
199*0Sstevel@tonic-gate 	CFGA_PSTATE_ATTR_DONE,
200*0Sstevel@tonic-gate 	CFGA_PSTATE_VAL_DONE,
201*0Sstevel@tonic-gate 	CFGA_PSTATE_ERR
202*0Sstevel@tonic-gate } parse_state_t;
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate typedef struct match_cvt {
205*0Sstevel@tonic-gate 	char *str;
206*0Sstevel@tonic-gate 	match_type_t type;
207*0Sstevel@tonic-gate } match_cvt_t;
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate #ifdef	__cplusplus
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate #endif
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate #endif	/* _CFGADM_H */
214