xref: /titanic_44/usr/src/lib/libnwam/common/libnwam_impl.h (revision cb8a054b1ab30d5caa746e6c44f29d4c9d3071c1)
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 /*
27  * This file contains hidden implementation structures and APIs of libnwam,
28  * and is not installed in the proto area.  Implementation is MT safe.
29  */
30 
31 
32 #ifndef _LIBNWAM_IMPL_H
33 #define	_LIBNWAM_IMPL_H
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <libnwam_priv.h>
40 #include <libnwam.h>
41 
42 /*
43  * We separate global flags (which are applicable to all object types) from
44  * local flags (which only apply to specific object types).  These definitions
45  * mask off the global vs. local portions of the flags value, with the former
46  * being the low-order 32 bits and the latter the high-order 32 bits.
47  */
48 #define	NWAM_FLAG_GLOBAL_MASK		0xFFFFFFFF
49 #define	NWAM_FLAG_LOCAL_MASK		0xFFFFFFFFULL << 32
50 #define	NWAM_WALK_FILTER_MASK		NWAM_FLAG_LOCAL_MASK
51 
52 /*
53  * Maximum object size is the size of a maximally-sized name/values property
54  * multiplied by the maximum number of properties.  The maximum object size
55  * and the maximum number of objects are used to determine how much space
56  * needs to be allocated for door calls to retrieve objects from the
57  * backend.
58  */
59 #define	NWAM_MAX_OBJECT_LEN 		\
60 	((NWAM_MAX_NAME_LEN +		\
61 	(NWAM_MAX_VALUE_LEN * NWAM_MAX_NUM_VALUES)) * \
62 	NWAM_MAX_NUM_PROPERTIES)
63 
64 #define	NWAM_MAX_NUM_OBJECTS		4192
65 
66 #define	NWAM_MAX_OBJECT_LIST_LEN	\
67 	(NWAM_MAX_NUM_OBJECTS * NWAM_MAX_NAME_LEN)
68 
69 #define	NWAM_BACKEND_DOOR_ARG_SIZE      \
70 	(sizeof (nwam_backend_door_arg_t) + \
71 	(NWAM_MAX_OBJECT_LEN > NWAM_MAX_OBJECT_LIST_LEN ? \
72 	NWAM_MAX_OBJECT_LEN : NWAM_MAX_OBJECT_LIST_LEN))
73 
74 
75 #define	NWAMD_DOOR_ARG_SIZE		\
76 	(sizeof (nwamd_door_arg_t) + \
77 	(NWAMD_MAX_NUM_WLANS * sizeof (nwam_wlan_t));
78 
79 #define	NWAM_CONF_DIR			"/etc/nwam/"
80 
81 #define	NWAM_LOC_OBJECT_STRING	"loc"
82 #define	NWAM_LOC_CONF_FILE	NWAM_CONF_DIR "loc.conf"
83 
84 struct nwam_handle {
85 	nwam_object_type_t nwh_object_type;
86 	char nwh_name[NWAM_MAX_NAME_LEN];
87 	boolean_t nwh_committed;
88 	void *nwh_data;
89 };
90 
91 #define	NWAM_OBJECT_NAMES_STRING	"object-names"
92 #define	NWAM_NCP_OBJECT_STRING		"ncp"
93 #define	NWAM_NCP_CONF_FILE_PRE		"ncp-"
94 #define	NWAM_NCP_CONF_FILE_SUF		".conf"
95 #define	NWAM_NCU_LINK_NAME_PRE		"link:"
96 #define	NWAM_NCU_INTERFACE_NAME_PRE	"interface:"
97 
98 struct nwam_value {
99 	nwam_value_type_t nwv_value_type;
100 	uint_t nwv_value_numvalues;
101 	union {
102 		boolean_t *nwv_boolean;
103 		int64_t *nwv_int64;
104 		uint64_t *nwv_uint64;
105 		char **nwv_string;
106 	} nwv_values;
107 };
108 
109 /* Used in property table retrieval of property attributes */
110 #define	NWAM_TYPE_ANY		1
111 #define	NWAM_CLASS_ANY		1
112 
113 typedef nwam_error_t (*nwam_prop_validate_func_t)(nwam_value_t);
114 
115 /* Used to hold validation/description data for properties */
116 struct nwam_prop_table_entry {
117 	const char *prop_name;
118 	nwam_value_type_t prop_type;
119 	boolean_t prop_is_readonly;
120 	uint_t prop_min_numvalues;
121 	uint_t prop_max_numvalues;
122 	nwam_prop_validate_func_t prop_validate;
123 	const char *prop_description;
124 	uint64_t prop_type_membership;
125 	uint64_t prop_class_membership;
126 };
127 
128 struct nwam_prop_table {
129 	uint_t num_entries;
130 	struct nwam_prop_table_entry *entries;
131 };
132 
133 #define	NWAM_ENM_OBJECT_STRING	"enm"
134 #define	NWAM_ENM_CONF_FILE	NWAM_CONF_DIR "enm.conf"
135 
136 #define	NWAM_KNOWN_WLAN_OBJECT_STRING	"known-wlan"
137 #define	NWAM_KNOWN_WLAN_CONF_FILE	NWAM_CONF_DIR "known-wlan.conf"
138 
139 /* Definitions that are used to map uint64 property values to strings */
140 #define	NWAM_ACTIVATION_MODE_MANUAL_STRING		"manual"
141 #define	NWAM_ACTIVATION_MODE_SYSTEM_STRING		"system"
142 #define	NWAM_ACTIVATION_MODE_PRIORITIZED_STRING		"prioritized"
143 #define	NWAM_ACTIVATION_MODE_CONDITIONAL_ANY_STRING	"conditional-any"
144 #define	NWAM_ACTIVATION_MODE_CONDITIONAL_ALL_STRING	"conditional-all"
145 
146 #define	NWAM_CONDITION_IS_STRING			"is"
147 #define	NWAM_CONDITION_IS_NOT_STRING			"is-not"
148 #define	NWAM_CONDITION_IS_IN_RANGE_STRING		"is-in-range"
149 #define	NWAM_CONDITION_IS_NOT_IN_RANGE_STRING		"is-not-in-range"
150 #define	NWAM_CONDITION_CONTAINS_STRING			"contains"
151 #define	NWAM_CONDITION_DOES_NOT_CONTAIN_STRING		"does-not-contain"
152 
153 #define	NWAM_CONDITION_OBJECT_TYPE_NCP_STRING		"ncp"
154 #define	NWAM_CONDITION_OBJECT_TYPE_NCU_STRING		"ncu"
155 #define	NWAM_CONDITION_OBJECT_TYPE_ENM_STRING		"enm"
156 #define	NWAM_CONDITION_OBJECT_TYPE_LOC_STRING		"loc"
157 #define	NWAM_CONDITION_OBJECT_TYPE_IP_ADDRESS_STRING	"ip-address"
158 #define	NWAM_CONDITION_OBJECT_TYPE_ADV_DOMAIN_STRING	"advertised-domain"
159 #define	NWAM_CONDITION_OBJECT_TYPE_SYS_DOMAIN_STRING	"system-domain"
160 #define	NWAM_CONDITION_OBJECT_TYPE_ESSID_STRING		"essid"
161 #define	NWAM_CONDITION_OBJECT_TYPE_BSSID_STRING		"bssid"
162 
163 #define	NWAM_CONDITION_ACTIVE_STRING			"active"
164 
165 #define	NWAM_NAMESERVICES_DNS_STRING			"dns"
166 #define	NWAM_NAMESERVICES_FILES_STRING			"files"
167 #define	NWAM_NAMESERVICES_NIS_STRING			"nis"
168 #define	NWAM_NAMESERVICES_LDAP_STRING			"ldap"
169 
170 #define	NWAM_CONFIGSRC_MANUAL_STRING		"manual"
171 #define	NWAM_CONFIGSRC_DHCP_STRING		"dhcp"
172 
173 #define	NWAM_NCU_TYPE_LINK_STRING			"link"
174 #define	NWAM_NCU_TYPE_INTERFACE_STRING			"interface"
175 
176 #define	NWAM_NCU_CLASS_PHYS_STRING			"phys"
177 #define	NWAM_NCU_CLASS_IP_STRING			"ip"
178 
179 #define	NWAM_IP_VERSION_IPV4_STRING			"ipv4"
180 #define	NWAM_IP_VERSION_IPV6_STRING			"ipv6"
181 
182 #define	NWAM_ADDRSRC_DHCP_STRING			"dhcp"
183 #define	NWAM_ADDRSRC_AUTOCONF_STRING			"autoconf"
184 #define	NWAM_ADDRSRC_STATIC_STRING			"static"
185 
186 #define	NWAM_PRIORITY_MODE_EXCLUSIVE_STRING		"exclusive"
187 #define	NWAM_PRIORITY_MODE_SHARED_STRING		"shared"
188 #define	NWAM_PRIORITY_MODE_ALL_STRING			"all"
189 
190 /*
191  * Functions that interact with nwamd's door server to request
192  * object actions, states or to register for receipt of events from nwamd.
193  * See libnwam_door.c.
194  */
195 extern nwam_error_t nwam_request_register_unregister(nwam_request_type_t,
196 	const char *);
197 extern nwam_error_t nwam_request_action(nwam_object_type_t, const char *,
198 	const char *, nwam_action_t);
199 extern nwam_error_t nwam_request_state(nwam_object_type_t, const char *,
200 	const char *, nwam_state_t *, nwam_aux_state_t *);
201 extern nwam_error_t nwam_request_wlan(nwam_request_type_t, const char *,
202 	const char *, const char *, uint32_t, uint_t, const char *, boolean_t);
203 extern nwam_error_t nwam_request_wlan_scan_results(const char *name,
204 	uint_t *, nwam_wlan_t **);
205 extern nwam_error_t nwam_request_active_priority_group(int64_t *);
206 
207 /*
208  * Functions that access and manipulate backend representation of data -
209  * see libnwam_backend.c.
210  */
211 extern nwam_error_t nwam_read_object_from_backend(char *, char *,
212 	uint64_t, void *);
213 extern nwam_error_t nwam_update_object_in_backend(char *, char *,
214 	uint64_t, void *);
215 extern nwam_error_t nwam_remove_object_from_backend(char *, char *,
216 	uint64_t);
217 
218 /*
219  * Functions that handle files-specific backend persistent representation
220  * of data - see libnwam_files.c.
221  */
222 extern nwam_error_t nwam_read_object_from_files_backend(char *,
223 	char *, uint64_t, void *);
224 extern nwam_error_t nwam_update_object_in_files_backend(char *,
225 	char *, uint64_t, void *);
226 extern nwam_error_t nwam_remove_object_from_files_backend(char *,
227 	char *, uint64_t);
228 
229 /*
230  * Utility functions for nwam data (values and lists of values) associated
231  * with objects - see libnwam_values.c.
232  */
233 nwam_error_t nwam_alloc_object_list(void *);
234 void nwam_free_object_list(void *);
235 nwam_error_t nwam_object_list_add_object_list(void *, char *, void *);
236 nwam_error_t nwam_object_list_remove_object_list(void *, char *);
237 nwam_error_t nwam_dup_object_list(void *, void *);
238 nwam_error_t nwam_next_object_list(void *, char *, char **, void *);
239 nwam_error_t nwam_next_object_prop(void *, char *, char **, nwam_value_t *);
240 extern nwam_error_t nwam_pack_object_list(void *, char **, size_t *);
241 extern nwam_error_t nwam_unpack_object_list(char *, size_t, void *);
242 
243 extern const char *nwam_value_type_to_string(nwam_value_type_t);
244 extern nwam_value_type_t nwam_string_to_value_type(const char *);
245 extern nwam_error_t nwam_delete_prop(void *, const char *);
246 extern nwam_error_t nwam_set_prop_value(void *, const char *, nwam_value_t);
247 extern nwam_error_t nwam_get_prop_value(void *, const char *, nwam_value_t *);
248 
249 /*
250  * Utility functions for nwam objects (NCUs, ENMs, locations and known WLANs).
251  * See libnwam_object.c.
252  */
253 nwam_error_t nwam_handle_create(nwam_object_type_t, const char *,
254 	struct nwam_handle **);
255 nwam_error_t nwam_read(nwam_object_type_t, const char *, const char *,
256 	uint64_t, struct nwam_handle **);
257 nwam_error_t nwam_create(nwam_object_type_t, const char *, const char *,
258 	struct nwam_handle **);
259 nwam_error_t nwam_get_name(struct nwam_handle *, char **);
260 nwam_error_t nwam_set_name(struct nwam_handle *, const char *);
261 nwam_error_t nwam_walk(nwam_object_type_t, const char *,
262 	int(*)(struct nwam_handle *, void *), void *, uint64_t, int *,
263 	int(*)(struct nwam_handle *, uint64_t, void *));
264 void nwam_free(struct nwam_handle *);
265 nwam_error_t nwam_copy(const char *, struct nwam_handle *, const char *,
266 	struct nwam_handle **);
267 nwam_error_t nwam_walk_props(struct nwam_handle *,
268 	int(*)(const char *, nwam_value_t, void *), void *, uint64_t, int *);
269 nwam_error_t nwam_commit(const char *, struct nwam_handle *, uint64_t);
270 nwam_error_t nwam_destroy(const char *, struct nwam_handle *, uint64_t);
271 nwam_error_t nwam_enable(const char *, struct nwam_handle *);
272 nwam_error_t nwam_disable(const char *, struct nwam_handle *);
273 struct nwam_prop_table_entry *nwam_get_prop_table_entry(struct nwam_prop_table,
274 	const char *);
275 nwam_error_t nwam_get_prop_description(struct nwam_prop_table, const char *,
276 	const char **);
277 nwam_error_t nwam_get_prop_type(struct nwam_prop_table, const char *,
278 	nwam_value_type_t *);
279 nwam_error_t nwam_prop_multivalued(struct nwam_prop_table, const char *,
280 	boolean_t *);
281 nwam_error_t nwam_prop_read_only(struct nwam_prop_table, const char *,
282 	boolean_t *);
283 nwam_error_t nwam_validate_prop(struct nwam_prop_table, struct nwam_handle *,
284 	const char *, nwam_value_t);
285 nwam_error_t nwam_validate(struct nwam_prop_table, struct nwam_handle *,
286 	const char **);
287 nwam_error_t nwam_get_default_proplist(struct nwam_prop_table, uint64_t,
288 	uint64_t, const char ***, uint_t *);
289 nwam_error_t nwam_get_state(const char *, struct nwam_handle *, nwam_state_t *,
290 	nwam_aux_state_t *);
291 
292 /*
293  * Generic validation functions - see libnwam_util.c.
294  */
295 extern nwam_error_t nwam_valid_flags(uint64_t, uint64_t);
296 extern nwam_error_t nwam_valid_condition(nwam_value_t);
297 extern nwam_error_t nwam_valid_boolean(nwam_value_t);
298 extern nwam_error_t nwam_valid_uint64(nwam_value_t);
299 extern nwam_error_t nwam_valid_domain(nwam_value_t);
300 extern nwam_error_t nwam_valid_host_any(nwam_value_t);
301 extern nwam_error_t nwam_valid_host_v4(nwam_value_t);
302 extern nwam_error_t nwam_valid_route_v4(nwam_value_t);
303 extern nwam_error_t nwam_valid_host_v6(nwam_value_t);
304 extern nwam_error_t nwam_valid_route_v6(nwam_value_t);
305 extern nwam_error_t nwam_valid_host_or_domain(nwam_value_t);
306 extern nwam_error_t nwam_valid_file(nwam_value_t);
307 extern nwam_error_t nwam_valid_fmri(nwam_value_t);
308 extern nwam_error_t nwam_valid_mac_addr(nwam_value_t);
309 
310 /* Misc. util functions */
311 extern boolean_t nwam_uid_is_special(void);
312 extern nwam_error_t nwam_set_smf_string_property(const char *, const char *,
313 	const char *, const char *);
314 extern nwam_error_t nwam_get_smf_string_property(const char *, const char *,
315 	const char *, char **);
316 extern int nwam_make_door_call(const char *, int *, void *, size_t);
317 extern nwam_error_t nwam_errno_to_nwam_error(int);
318 
319 /* Needed in libnwam_files.c to check if NCP filename is valid */
320 extern nwam_error_t nwam_ncp_file_to_name(const char *path, char **name);
321 
322 #ifdef	__cplusplus
323 }
324 #endif
325 
326 #endif	/* _LIBNWAM_IMPL_H */
327