xref: /illumos-gate/usr/src/lib/libnwam/common/libnwam.h (revision 7ab4e62e3b5c454f248a38bec0d489e8f5543324)
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 /*
26  * This file contains data structures and APIs of libnwam.
27  * Implementation is MT safe.
28  */
29 #ifndef _LIBNWAM_H
30 #define	_LIBNWAM_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <bsm/adt.h>
37 #include <net/if.h>
38 #include <inet/ip.h>
39 #include <inet/ip6.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 
43 /*
44  * Note - several interface functions below are not utilized in ON, but are
45  * used by the GNOME nwam-manager.  One example is nwam_enm_get_name().
46  */
47 
48 /*
49  * Common definitions
50  */
51 
52 /* nwam FMRI and properties */
53 #define	NWAM_FMRI		"svc:/network/physical:nwam"
54 #define	NWAM_PG			"nwamd"
55 #define	NWAM_PROP_ACTIVE_NCP	"active_ncp"
56 
57 /* nwam flags used for read/commit */
58 /* Block waiting for commit if necessary */
59 #define	NWAM_FLAG_BLOCKING		0x00000001
60 /* Committed object must be new */
61 #define	NWAM_FLAG_CREATE		0x00000002
62 /* Tell destroy functions not to free handle */
63 #define	NWAM_FLAG_DO_NOT_FREE		0x00000004
64 /* Object is being enabled/disabled */
65 #define	NWAM_FLAG_ENTITY_ENABLE		0x00000008
66 /* Known WLAN being read, committed or destroyed */
67 #define	NWAM_FLAG_ENTITY_KNOWN_WLAN	0x00000010
68 
69 /* nwam flags used for selecting ncu type for walk */
70 #define	NWAM_FLAG_NCU_TYPE_LINK		0x00000001ULL << 32
71 #define	NWAM_FLAG_NCU_TYPE_INTERFACE	0x00000002ULL << 32
72 #define	NWAM_FLAG_NCU_TYPE_ALL		(NWAM_FLAG_NCU_TYPE_LINK | \
73 					NWAM_FLAG_NCU_TYPE_INTERFACE)
74 
75 /* nwam flags used for selecting ncu class for walk */
76 #define	NWAM_FLAG_NCU_CLASS_PHYS		0x00000100ULL << 32
77 #define	NWAM_FLAG_NCU_CLASS_IP			0x00010000ULL << 32
78 #define	NWAM_FLAG_NCU_CLASS_ALL_LINK		NWAM_FLAG_NCU_CLASS_PHYS
79 #define	NWAM_FLAG_NCU_CLASS_ALL_INTERFACE	NWAM_FLAG_NCU_CLASS_IP
80 #define	NWAM_FLAG_NCU_CLASS_ALL		(NWAM_FLAG_NCU_CLASS_ALL_INTERFACE | \
81 					NWAM_FLAG_NCU_CLASS_ALL_LINK)
82 #define	NWAM_FLAG_NCU_TYPE_CLASS_ALL		(NWAM_FLAG_NCU_CLASS_ALL | \
83 						NWAM_FLAG_NCU_TYPE_ALL)
84 
85 /* flags used for selecting activation for walk */
86 #define	NWAM_FLAG_ACTIVATION_MODE_MANUAL		0x000000001ULL << 32
87 #define	NWAM_FLAG_ACTIVATION_MODE_SYSTEM		0x000000002ULL << 32
88 #define	NWAM_FLAG_ACTIVATION_MODE_PRIORITIZED		0x000000004ULL << 32
89 #define	NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ANY	0x000000008ULL << 32
90 #define	NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ALL	0x000000010ULL << 32
91 #define	NWAM_FLAG_ACTIVATION_MODE_ALL	(NWAM_FLAG_ACTIVATION_MODE_MANUAL |\
92 					NWAM_FLAG_ACTIVATION_MODE_SYSTEM |\
93 					NWAM_FLAG_ACTIVATION_MODE_PRIORITIZED |\
94 				NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ANY |\
95 				NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ALL)
96 
97 /* Walk known WLANs in order of priority (lowest first) */
98 #define	NWAM_FLAG_KNOWN_WLAN_WALK_PRIORITY_ORDER	0x000010000ULL << 32
99 /* Do not perform priority collision checking for known WLANs */
100 #define	NWAM_FLAG_KNOWN_WLAN_NO_COLLISION_CHECK		0x000020000ULL << 32
101 
102 /* nwam return codes */
103 typedef enum {
104 	NWAM_SUCCESS,			/* No error occured */
105 	NWAM_LIST_END,			/* End of list reached */
106 	NWAM_INVALID_HANDLE,		/* Entity handle is invalid */
107 	NWAM_HANDLE_UNBOUND,		/* Handle not bound to entity */
108 	NWAM_INVALID_ARG,		/* Argument is invalid */
109 	NWAM_PERMISSION_DENIED,		/* Insufficient privileges for action */
110 	NWAM_NO_MEMORY,			/* Out of memory */
111 	NWAM_ENTITY_EXISTS,		/* Entity already exists */
112 	NWAM_ENTITY_IN_USE,		/* Entity in use */
113 	NWAM_ENTITY_COMMITTED,		/* Entity already committed */
114 	NWAM_ENTITY_NOT_FOUND,		/* Entity not found */
115 	NWAM_ENTITY_TYPE_MISMATCH,	/* Entity type mismatch */
116 	NWAM_ENTITY_INVALID,		/* Validation of entity failed */
117 	NWAM_ENTITY_INVALID_MEMBER,	/* Entity member invalid */
118 	NWAM_ENTITY_INVALID_STATE,	/* Entity is not in appropriate state */
119 	NWAM_ENTITY_INVALID_VALUE,	/* Validation of entity value failed */
120 	NWAM_ENTITY_MISSING_MEMBER,	/* Required member is missing */
121 	NWAM_ENTITY_NO_VALUE,		/* No value associated with entity */
122 	NWAM_ENTITY_MULTIPLE_VALUES,	/* Multiple values for entity */
123 	NWAM_ENTITY_READ_ONLY,		/* Entity is marked read only */
124 	NWAM_ENTITY_NOT_DESTROYABLE,	/* Entity cannot be destroyed */
125 	NWAM_ENTITY_NOT_MANUAL,	/* Entity cannot be manually enabled/disabled */
126 	NWAM_WALK_HALTED,		/* Callback function returned nonzero */
127 	NWAM_ERROR_BIND,		/* Could not bind to backend */
128 	NWAM_ERROR_BACKEND_INIT,	/* Could not initialize backend */
129 	NWAM_ERROR_INTERNAL		/* Internal error */
130 } nwam_error_t;
131 
132 #define	NWAM_MAX_NAME_LEN		128
133 #define	NWAM_MAX_VALUE_LEN		256
134 #define	NWAM_MAX_FMRI_LEN		NWAM_MAX_VALUE_LEN
135 #define	NWAM_MAX_NUM_VALUES		32
136 #define	NWAM_MAX_NUM_PROPERTIES		32
137 
138 /* used for getting and setting of properties */
139 typedef enum {
140 	NWAM_VALUE_TYPE_BOOLEAN,
141 	NWAM_VALUE_TYPE_INT64,
142 	NWAM_VALUE_TYPE_UINT64,
143 	NWAM_VALUE_TYPE_STRING,
144 	NWAM_VALUE_TYPE_UNKNOWN
145 } nwam_value_type_t;
146 
147 /* Holds values of various types for getting and setting of properties */
148 /* Forward definition */
149 struct nwam_value;
150 typedef struct nwam_value *nwam_value_t;
151 
152 /* Value-related functions. */
153 extern nwam_error_t nwam_value_create_boolean(boolean_t, nwam_value_t *);
154 extern nwam_error_t nwam_value_create_boolean_array(boolean_t *, uint_t,
155     nwam_value_t *);
156 extern nwam_error_t nwam_value_create_int64(int64_t, nwam_value_t *);
157 extern nwam_error_t nwam_value_create_int64_array(int64_t *, uint_t,
158     nwam_value_t *);
159 extern nwam_error_t nwam_value_create_uint64(uint64_t, nwam_value_t *);
160 extern nwam_error_t nwam_value_create_uint64_array(uint64_t *, uint_t,
161     nwam_value_t *);
162 extern nwam_error_t nwam_value_create_string(char *, nwam_value_t *);
163 extern nwam_error_t nwam_value_create_string_array(char **, uint_t,
164     nwam_value_t *);
165 
166 extern nwam_error_t nwam_value_get_boolean(nwam_value_t, boolean_t *);
167 extern nwam_error_t nwam_value_get_boolean_array(nwam_value_t, boolean_t **,
168     uint_t *);
169 extern nwam_error_t nwam_value_get_int64(nwam_value_t, int64_t *);
170 extern nwam_error_t nwam_value_get_int64_array(nwam_value_t, int64_t **,
171     uint_t *);
172 extern nwam_error_t nwam_value_get_uint64(nwam_value_t, uint64_t *);
173 extern nwam_error_t nwam_value_get_uint64_array(nwam_value_t, uint64_t **,
174     uint_t *);
175 extern nwam_error_t nwam_value_get_string(nwam_value_t, char **);
176 extern nwam_error_t nwam_value_get_string_array(nwam_value_t, char ***,
177     uint_t *);
178 
179 extern nwam_error_t nwam_value_get_type(nwam_value_t, nwam_value_type_t *);
180 extern nwam_error_t nwam_value_get_numvalues(nwam_value_t, uint_t *);
181 
182 extern void nwam_value_free(nwam_value_t);
183 extern nwam_error_t nwam_value_copy(nwam_value_t, nwam_value_t *);
184 
185 extern nwam_error_t nwam_uint64_get_value_string(const char *, uint64_t,
186     const char **);
187 extern nwam_error_t nwam_value_string_get_uint64(const char *, const char *,
188     uint64_t *);
189 
190 /*
191  * To retrieve a localized error string
192  */
193 extern const char *nwam_strerror(nwam_error_t);
194 
195 /*
196  * State and auxiliary state describe the state of ENMs, NCUs and locations.
197  */
198 typedef enum {
199 	NWAM_STATE_UNINITIALIZED = 0x0,
200 	NWAM_STATE_INITIALIZED = 0x1,
201 	NWAM_STATE_OFFLINE = 0x2,
202 	NWAM_STATE_OFFLINE_TO_ONLINE = 0x4,
203 	NWAM_STATE_ONLINE_TO_OFFLINE = 0x8,
204 	NWAM_STATE_ONLINE = 0x10,
205 	NWAM_STATE_MAINTENANCE = 0x20,
206 	NWAM_STATE_DEGRADED = 0x40,
207 	NWAM_STATE_DISABLED = 0x80
208 } nwam_state_t;
209 
210 #define	NWAM_STATE_ANY	(NWAM_STATE_UNINITIALIZED | \
211 			NWAM_STATE_INITIALIZED | \
212 			NWAM_STATE_OFFLINE | \
213 			NWAM_STATE_OFFLINE_TO_ONLINE | \
214 			NWAM_STATE_ONLINE_TO_OFFLINE | \
215 			NWAM_STATE_ONLINE | \
216 			NWAM_STATE_MAINTENANCE | \
217 			NWAM_STATE_DEGRADED | \
218 			NWAM_STATE_DISABLED)
219 
220 /*
221  * The auxiliary state denotes specific reasons why an object is in a particular
222  * state (e.g. "script failed", "disabled by administrator", "waiting for DHCP
223  * response").
224  */
225 typedef enum {
226 	/* General auxiliary states */
227 	NWAM_AUX_STATE_UNINITIALIZED,
228 	NWAM_AUX_STATE_INITIALIZED,
229 	NWAM_AUX_STATE_CONDITIONS_NOT_MET,
230 	NWAM_AUX_STATE_MANUAL_DISABLE,
231 	NWAM_AUX_STATE_METHOD_FAILED,
232 	NWAM_AUX_STATE_METHOD_MISSING,
233 	NWAM_AUX_STATE_METHOD_RUNNING,
234 	NWAM_AUX_STATE_INVALID_CONFIG,
235 	NWAM_AUX_STATE_ACTIVE,
236 	/* Link-specific auxiliary states */
237 	NWAM_AUX_STATE_LINK_WIFI_SCANNING,
238 	NWAM_AUX_STATE_LINK_WIFI_NEED_SELECTION,
239 	NWAM_AUX_STATE_LINK_WIFI_NEED_KEY,
240 	NWAM_AUX_STATE_LINK_WIFI_CONNECTING,
241 	/* IP interface-specific auxiliary states */
242 	NWAM_AUX_STATE_IF_WAITING_FOR_ADDR,
243 	NWAM_AUX_STATE_IF_DHCP_TIMED_OUT,
244 	NWAM_AUX_STATE_IF_DUPLICATE_ADDR,
245 	/* Common link/interface auxiliary states */
246 	NWAM_AUX_STATE_UP,
247 	NWAM_AUX_STATE_DOWN,
248 	NWAM_AUX_STATE_NOT_FOUND
249 } nwam_aux_state_t;
250 
251 /* Activation modes */
252 typedef enum {
253 	NWAM_ACTIVATION_MODE_MANUAL,
254 	NWAM_ACTIVATION_MODE_SYSTEM,
255 	NWAM_ACTIVATION_MODE_CONDITIONAL_ANY,
256 	NWAM_ACTIVATION_MODE_CONDITIONAL_ALL,
257 	NWAM_ACTIVATION_MODE_PRIORITIZED
258 } nwam_activation_mode_t;
259 
260 /*
261  * Conditions are of the form
262  *
263  * ncu|enm|loc name is|is-not active
264  * ip-address is|is-not|is-in-range|is-not-in-range ipaddr[/prefixlen]
265  * advertised-domain is|is-not|contains|does-not-contain string
266  * system-domain is|is-not|contains|does-not-contain string
267  * essid is|is-not|contains|does-not-contain string
268  * bssid is|is-not <string>
269  */
270 
271 typedef enum {
272 	NWAM_CONDITION_IS,
273 	NWAM_CONDITION_IS_NOT,
274 	NWAM_CONDITION_IS_IN_RANGE,
275 	NWAM_CONDITION_IS_NOT_IN_RANGE,
276 	NWAM_CONDITION_CONTAINS,
277 	NWAM_CONDITION_DOES_NOT_CONTAIN
278 } nwam_condition_t;
279 
280 typedef enum {
281 	NWAM_CONDITION_OBJECT_TYPE_NCP,
282 	NWAM_CONDITION_OBJECT_TYPE_NCU,
283 	NWAM_CONDITION_OBJECT_TYPE_ENM,
284 	NWAM_CONDITION_OBJECT_TYPE_LOC,
285 	NWAM_CONDITION_OBJECT_TYPE_IP_ADDRESS,
286 	NWAM_CONDITION_OBJECT_TYPE_ADV_DOMAIN,
287 	NWAM_CONDITION_OBJECT_TYPE_SYS_DOMAIN,
288 	NWAM_CONDITION_OBJECT_TYPE_ESSID,
289 	NWAM_CONDITION_OBJECT_TYPE_BSSID
290 } nwam_condition_object_type_t;
291 
292 /*
293  * Activation condition-related functions that convert activation
294  * values to an appropriate string and back.
295  */
296 extern nwam_error_t nwam_condition_to_condition_string(
297     nwam_condition_object_type_t, nwam_condition_t, const char *, char **);
298 extern nwam_error_t nwam_condition_string_to_condition(const char *,
299     nwam_condition_object_type_t *, nwam_condition_t *, char **);
300 
301 /*
302  * Only one location can be active at one time. As a
303  * consequence, if the activation conditions of multiple
304  * locations are satisfied, we need to compare activation
305  * conditions to see if one is more specific than another.
306  *
307  * The following heuristics are applied to rate an
308  * activation condition:
309  * - "is" is the most specific condition
310  * - it is followed by "is-in-range" and "contains"
311  * - "is-not-in-range" and "does-not-contain" are next
312  * - finally "is-not" is least specific
313  *
314  * Regarding the objects these conditions apply to:
315  * - NCU, ENM and locations are most specific
316  * - system-domain is next
317  * - advertised-domain is next
318  * - IP address is next
319  * - wireless BSSID is next
320  * - wireless ESSID is least specific
321  *
322  */
323 extern nwam_error_t nwam_condition_rate(nwam_condition_object_type_t,
324     nwam_condition_t, uint64_t *);
325 
326 /*
327  * Location definitions.
328  */
329 
330 #define	NWAM_LOC_NAME_AUTOMATIC		"Automatic"
331 #define	NWAM_LOC_NAME_NO_NET		"NoNet"
332 #define	NWAM_LOC_NAME_LEGACY		"Legacy"
333 
334 #define	NWAM_LOC_NAME_PRE_DEFINED(name)	\
335 			(strcasecmp(name, NWAM_LOC_NAME_AUTOMATIC) == 0 || \
336 			strcasecmp(name, NWAM_LOC_NAME_NO_NET) == 0 || \
337 			strcasecmp(name, NWAM_LOC_NAME_LEGACY) == 0)
338 
339 /* Forward definition */
340 struct nwam_handle;
341 
342 typedef struct nwam_handle *nwam_loc_handle_t;
343 
344 /* Location properties */
345 
346 typedef enum {
347 	NWAM_NAMESERVICES_DNS,
348 	NWAM_NAMESERVICES_FILES,
349 	NWAM_NAMESERVICES_NIS,
350 	NWAM_NAMESERVICES_LDAP
351 } nwam_nameservices_t;
352 
353 typedef enum {
354 	NWAM_CONFIGSRC_MANUAL,
355 	NWAM_CONFIGSRC_DHCP
356 } nwam_configsrc_t;
357 
358 #define	NWAM_LOC_PROP_ACTIVATION_MODE		"activation-mode"
359 #define	NWAM_LOC_PROP_CONDITIONS		"conditions"
360 #define	NWAM_LOC_PROP_ENABLED			"enabled"
361 
362 /* Nameservice location properties */
363 #define	NWAM_LOC_PROP_NAMESERVICES		"nameservices"
364 #define	NWAM_LOC_PROP_NAMESERVICES_CONFIG_FILE	"nameservices-config-file"
365 #define	NWAM_LOC_PROP_DNS_NAMESERVICE_CONFIGSRC	"dns-nameservice-configsrc"
366 #define	NWAM_LOC_PROP_DNS_NAMESERVICE_DOMAIN	"dns-nameservice-domain"
367 #define	NWAM_LOC_PROP_DNS_NAMESERVICE_SERVERS	"dns-nameservice-servers"
368 #define	NWAM_LOC_PROP_DNS_NAMESERVICE_SEARCH	"dns-nameservice-search"
369 #define	NWAM_LOC_PROP_NIS_NAMESERVICE_CONFIGSRC	"nis-nameservice-configsrc"
370 #define	NWAM_LOC_PROP_NIS_NAMESERVICE_SERVERS	"nis-nameservice-servers"
371 #define	NWAM_LOC_PROP_LDAP_NAMESERVICE_CONFIGSRC "ldap-nameservice-configsrc"
372 #define	NWAM_LOC_PROP_LDAP_NAMESERVICE_SERVERS	"ldap-nameservice-servers"
373 #define	NWAM_LOC_PROP_DEFAULT_DOMAIN		"default-domain"
374 
375 /* NFSv4 domain */
376 #define	NWAM_LOC_PROP_NFSV4_DOMAIN		"nfsv4-domain"
377 
378 /* IPfilter configuration */
379 #define	NWAM_LOC_PROP_IPFILTER_CONFIG_FILE	"ipfilter-config-file"
380 #define	NWAM_LOC_PROP_IPFILTER_V6_CONFIG_FILE	"ipfilter-v6-config-file"
381 #define	NWAM_LOC_PROP_IPNAT_CONFIG_FILE		"ipnat-config-file"
382 #define	NWAM_LOC_PROP_IPPOOL_CONFIG_FILE	"ippool-config-file"
383 
384 /* IPsec configuration */
385 #define	NWAM_LOC_PROP_IKE_CONFIG_FILE		"ike-config-file"
386 #define	NWAM_LOC_PROP_IPSECPOLICY_CONFIG_FILE	"ipsecpolicy-config-file"
387 
388 /*
389  * NCP/NCU definitions.
390  */
391 
392 #define	NWAM_NCP_NAME_AUTOMATIC		"Automatic"
393 #define	NWAM_NCP_NAME_USER		"User"
394 
395 #define	NWAM_NCP_AUTOMATIC(name)	\
396 			(strcasecmp(name, NWAM_NCP_NAME_AUTOMATIC) == 0)
397 
398 typedef struct nwam_handle *nwam_ncp_handle_t;
399 
400 typedef struct nwam_handle *nwam_ncu_handle_t;
401 
402 typedef enum {
403 	NWAM_NCU_TYPE_UNKNOWN = -1,
404 	NWAM_NCU_TYPE_LINK,
405 	NWAM_NCU_TYPE_INTERFACE,
406 	NWAM_NCU_TYPE_ANY
407 } nwam_ncu_type_t;
408 
409 typedef enum {
410 	NWAM_NCU_CLASS_UNKNOWN = -1,
411 	NWAM_NCU_CLASS_PHYS,
412 	NWAM_NCU_CLASS_IP,
413 	NWAM_NCU_CLASS_ANY
414 } nwam_ncu_class_t;
415 
416 typedef enum {
417 	NWAM_ADDRSRC_DHCP,
418 	NWAM_ADDRSRC_AUTOCONF,
419 	NWAM_ADDRSRC_STATIC
420 } nwam_addrsrc_t;
421 
422 typedef enum {
423 	NWAM_PRIORITY_MODE_EXCLUSIVE,
424 	NWAM_PRIORITY_MODE_SHARED,
425 	NWAM_PRIORITY_MODE_ALL
426 } nwam_priority_mode_t;
427 
428 /* NCU properties common to all type/classes */
429 #define	NWAM_NCU_PROP_TYPE			"type"
430 #define	NWAM_NCU_PROP_CLASS			"class"
431 #define	NWAM_NCU_PROP_PARENT_NCP		"parent"
432 #define	NWAM_NCU_PROP_ACTIVATION_MODE		"activation-mode"
433 #define	NWAM_NCU_PROP_ENABLED			"enabled"
434 #define	NWAM_NCU_PROP_PRIORITY_GROUP		"priority-group"
435 #define	NWAM_NCU_PROP_PRIORITY_MODE		"priority-mode"
436 
437 /* Link NCU properties */
438 #define	NWAM_NCU_PROP_LINK_MAC_ADDR		"link-mac-addr"
439 #define	NWAM_NCU_PROP_LINK_AUTOPUSH		"link-autopush"
440 #define	NWAM_NCU_PROP_LINK_MTU			"link-mtu"
441 
442 /* IP NCU properties */
443 #define	NWAM_NCU_PROP_IP_VERSION		"ip-version"
444 #define	NWAM_NCU_PROP_IPV4_ADDRSRC		"ipv4-addrsrc"
445 #define	NWAM_NCU_PROP_IPV4_ADDR			"ipv4-addr"
446 #define	NWAM_NCU_PROP_IPV4_DEFAULT_ROUTE	"ipv4-default-route"
447 #define	NWAM_NCU_PROP_IPV6_ADDRSRC		"ipv6-addrsrc"
448 #define	NWAM_NCU_PROP_IPV6_ADDR			"ipv6-addr"
449 #define	NWAM_NCU_PROP_IPV6_DEFAULT_ROUTE	"ipv6-default-route"
450 
451 /* Some properties should only be set on creation */
452 #define	NWAM_NCU_PROP_SETONCE(prop)	\
453 				(strcmp(prop, NWAM_NCU_PROP_TYPE) == 0 || \
454 				strcmp(prop, NWAM_NCU_PROP_CLASS) == 0 || \
455 				strcmp(prop, NWAM_NCU_PROP_PARENT_NCP) == 0)
456 /*
457  * ENM definitions
458  */
459 
460 typedef struct nwam_handle *nwam_enm_handle_t;
461 
462 #define	NWAM_ENM_PROP_ACTIVATION_MODE	"activation-mode"
463 #define	NWAM_ENM_PROP_CONDITIONS	"conditions"
464 #define	NWAM_ENM_PROP_ENABLED		"enabled"
465 
466 /* FMRI associated with ENM */
467 #define	NWAM_ENM_PROP_FMRI		"fmri"
468 
469 /* Start/stop scripts associated with ENM */
470 #define	NWAM_ENM_PROP_START		"start"
471 #define	NWAM_ENM_PROP_STOP		"stop"
472 
473 /*
474  * Known Wireless LAN info (known WLAN) definitions.
475  */
476 
477 typedef struct nwam_handle *nwam_known_wlan_handle_t;
478 
479 #define	NWAM_KNOWN_WLAN_PROP_BSSIDS		"bssids"
480 #define	NWAM_KNOWN_WLAN_PROP_PRIORITY		"priority"
481 #define	NWAM_KNOWN_WLAN_PROP_KEYNAME		"keyname"
482 #define	NWAM_KNOWN_WLAN_PROP_KEYSLOT		"keyslot"
483 #define	NWAM_KNOWN_WLAN_PROP_SECURITY_MODE	"security-mode"
484 
485 /*
486  * Location Functions
487  */
488 
489 /* Create a location */
490 extern nwam_error_t nwam_loc_create(const char *, nwam_loc_handle_t *);
491 
492 /* Copy a location */
493 extern nwam_error_t nwam_loc_copy(nwam_loc_handle_t, const char *,
494     nwam_loc_handle_t *);
495 
496 /* Read a location from persistent storage */
497 extern nwam_error_t nwam_loc_read(const char *, uint64_t,
498     nwam_loc_handle_t *);
499 
500 /* Validate in-memory representation of a location */
501 extern nwam_error_t nwam_loc_validate(nwam_loc_handle_t, const char **);
502 
503 /* Commit in-memory representation of a location to persistent storage */
504 extern nwam_error_t nwam_loc_commit(nwam_loc_handle_t, uint64_t);
505 
506 /* Destroy a location in persistent storage */
507 extern nwam_error_t nwam_loc_destroy(nwam_loc_handle_t, uint64_t);
508 
509 /* Free in-memory representation of a location */
510 extern void nwam_loc_free(nwam_loc_handle_t);
511 
512 /* read all locs from persistent storage and walk through each at a time */
513 extern nwam_error_t nwam_walk_locs(int (*)(nwam_loc_handle_t, void *), void *,
514     uint64_t, int *);
515 
516 /* get/set loc name */
517 extern nwam_error_t nwam_loc_get_name(nwam_loc_handle_t, char **);
518 extern nwam_error_t nwam_loc_set_name(nwam_loc_handle_t, const char *);
519 extern boolean_t nwam_loc_can_set_name(nwam_loc_handle_t);
520 
521 /* activate/deactivate loc */
522 extern nwam_error_t nwam_loc_enable(nwam_loc_handle_t);
523 extern nwam_error_t nwam_loc_disable(nwam_loc_handle_t);
524 
525 /* walk all properties of an in-memory loc */
526 extern nwam_error_t nwam_loc_walk_props(nwam_loc_handle_t,
527 	int (*)(const char *, nwam_value_t, void *),
528 	void *, uint64_t, int *);
529 
530 /* delete/get/set validate loc property */
531 extern nwam_error_t nwam_loc_delete_prop(nwam_loc_handle_t,
532     const char *);
533 extern nwam_error_t nwam_loc_get_prop_value(nwam_loc_handle_t,
534     const char *, nwam_value_t *);
535 extern nwam_error_t nwam_loc_set_prop_value(nwam_loc_handle_t,
536     const char *, nwam_value_t);
537 extern nwam_error_t nwam_loc_validate_prop(nwam_loc_handle_t, const char *,
538     nwam_value_t);
539 
540 /* Get the read-only value for a particular loc property */
541 extern nwam_error_t nwam_loc_prop_read_only(const char *, boolean_t *);
542 
543 /* Whether the property is multi-valued or not */
544 extern nwam_error_t nwam_loc_prop_multivalued(const char *, boolean_t *);
545 
546 /* Retrieve data type */
547 extern nwam_error_t nwam_loc_get_prop_type(const char *, nwam_value_type_t *);
548 
549 /* Retrieve description */
550 extern nwam_error_t nwam_loc_get_prop_description(const char *, const char **);
551 
552 /* get default loc props */
553 extern nwam_error_t nwam_loc_get_default_proplist(const char ***, uint_t *);
554 
555 /* get sstate of loc from nwamd */
556 extern nwam_error_t nwam_loc_get_state(nwam_loc_handle_t, nwam_state_t *,
557 	nwam_aux_state_t *);
558 
559 /* Get whether the loc has manual activation-mode or not */
560 extern nwam_error_t nwam_loc_is_manual(nwam_loc_handle_t, boolean_t *);
561 
562 /*
563  * NCP/NCU functions
564  */
565 
566 /* Create an ncp */
567 extern nwam_error_t nwam_ncp_create(const char *, uint64_t,
568 	nwam_ncp_handle_t *);
569 
570 /* Read an ncp from persistent storage */
571 extern nwam_error_t nwam_ncp_read(const char *, uint64_t, nwam_ncp_handle_t *);
572 
573 /* Make a copy of existing ncp */
574 extern nwam_error_t nwam_ncp_copy(nwam_ncp_handle_t, const char *,
575 	nwam_ncp_handle_t *);
576 
577 /* Walk ncps */
578 extern nwam_error_t nwam_walk_ncps(int (*)(nwam_ncp_handle_t, void *),
579 	void *, uint64_t, int *);
580 
581 /* Get ncp name */
582 extern nwam_error_t nwam_ncp_get_name(nwam_ncp_handle_t, char **);
583 
584 /* Get the read-only value for this ncp */
585 extern nwam_error_t nwam_ncp_get_read_only(nwam_ncp_handle_t, boolean_t *);
586 
587 /* Destroy ncp */
588 extern nwam_error_t nwam_ncp_destroy(nwam_ncp_handle_t, uint64_t);
589 
590 /*
591  * Walk all ncus associated with ncp.  Specific types/classes of ncu can
592  * be selected via flags, or all via NWAM_FLAG_ALL.
593  */
594 extern nwam_error_t nwam_ncp_walk_ncus(nwam_ncp_handle_t,
595     int(*)(nwam_ncu_handle_t, void *), void *, uint64_t, int *);
596 
597 /* Activate ncp */
598 extern nwam_error_t nwam_ncp_enable(nwam_ncp_handle_t);
599 
600 /* Free in-memory representation of ncp */
601 extern void nwam_ncp_free(nwam_ncp_handle_t);
602 
603 /* Get state of NCP from nwamd */
604 extern nwam_error_t nwam_ncp_get_state(nwam_ncp_handle_t, nwam_state_t *,
605 	nwam_aux_state_t *);
606 
607 /* Get the active priority-group */
608 extern nwam_error_t nwam_ncp_get_active_priority_group(int64_t *);
609 
610 /* Create an ncu or read it from persistent storage */
611 extern nwam_error_t nwam_ncu_create(nwam_ncp_handle_t, const char *,
612 	nwam_ncu_type_t, nwam_ncu_class_t, nwam_ncu_handle_t *);
613 extern nwam_error_t nwam_ncu_read(nwam_ncp_handle_t, const char *,
614 	nwam_ncu_type_t, uint64_t, nwam_ncu_handle_t *);
615 
616 /* Destroy an ncu in persistent storage or free the in-memory representation */
617 extern nwam_error_t nwam_ncu_destroy(nwam_ncu_handle_t, uint64_t);
618 extern void nwam_ncu_free(nwam_ncu_handle_t);
619 
620 /* make a copy of existing ncu */
621 extern nwam_error_t nwam_ncu_copy(nwam_ncu_handle_t, const char *,
622 	nwam_ncu_handle_t *);
623 
624 /* Commit ncu changes to persistent storage */
625 extern nwam_error_t nwam_ncu_commit(nwam_ncu_handle_t, uint64_t);
626 
627 /* activate/deactivate an individual NCU (must be part of the active NCP) */
628 extern nwam_error_t nwam_ncu_enable(nwam_ncu_handle_t);
629 extern nwam_error_t nwam_ncu_disable(nwam_ncu_handle_t);
630 
631 /* Get state of NCU from nwamd */
632 extern nwam_error_t nwam_ncu_get_state(nwam_ncu_handle_t, nwam_state_t *,
633 	nwam_aux_state_t *);
634 
635 /* Get NCU type */
636 extern nwam_error_t nwam_ncu_get_ncu_type(nwam_ncu_handle_t, nwam_ncu_type_t *);
637 
638 /* Get NCU class */
639 extern nwam_error_t nwam_ncu_get_ncu_class(nwam_ncu_handle_t,
640 	nwam_ncu_class_t *);
641 
642 /* Validate ncu content */
643 extern nwam_error_t nwam_ncu_validate(nwam_ncu_handle_t, const char **);
644 
645 /* Walk all properties in in-memory representation of ncu */
646 extern nwam_error_t nwam_ncu_walk_props(nwam_ncu_handle_t,
647 	int (*)(const char *, nwam_value_t, void *),
648 	void *, uint64_t, int *);
649 
650 /* Get/set name of ncu, get parent ncp */
651 extern nwam_error_t nwam_ncu_get_name(nwam_ncu_handle_t, char **);
652 extern nwam_error_t nwam_ncu_name_to_typed_name(const char *, nwam_ncu_type_t,
653     char **);
654 extern nwam_error_t nwam_ncu_typed_name_to_name(const char *, nwam_ncu_type_t *,
655     char **);
656 extern nwam_error_t nwam_ncu_get_default_proplist(nwam_ncu_type_t,
657     nwam_ncu_class_t, const char ***, uint_t *);
658 extern nwam_error_t nwam_ncu_get_ncp(nwam_ncu_handle_t, nwam_ncp_handle_t *);
659 
660 /* delete/get/set/validate property from/in in-memory representation of ncu */
661 extern nwam_error_t nwam_ncu_delete_prop(nwam_ncu_handle_t,
662 	const char *);
663 extern nwam_error_t nwam_ncu_get_prop_value(nwam_ncu_handle_t,
664 	const char *, nwam_value_t *);
665 extern nwam_error_t nwam_ncu_set_prop_value(nwam_ncu_handle_t,
666 	const char *, nwam_value_t);
667 
668 extern nwam_error_t nwam_ncu_validate_prop(nwam_ncu_handle_t, const char *,
669 	nwam_value_t);
670 
671 /* Retrieve data type */
672 extern nwam_error_t nwam_ncu_get_prop_type(const char *, nwam_value_type_t *);
673 /* Retrieve prop description */
674 extern nwam_error_t nwam_ncu_get_prop_description(const char *, const char **);
675 
676 /* Get the read-only value from the handle or parent NCP */
677 extern nwam_error_t nwam_ncu_get_read_only(nwam_ncu_handle_t, boolean_t *);
678 
679 /* Get the read-only value for a particular NCU property */
680 extern nwam_error_t nwam_ncu_prop_read_only(const char *, boolean_t *);
681 
682 /* Whether the property is multi-valued or not */
683 extern nwam_error_t nwam_ncu_prop_multivalued(const char *, boolean_t *);
684 
685 /* Get whether the NCU has manual activation-mode or not */
686 extern nwam_error_t nwam_ncu_is_manual(nwam_ncu_handle_t, boolean_t *);
687 
688 /* Get the flag from the given class for walks */
689 extern uint64_t nwam_ncu_class_to_flag(nwam_ncu_class_t);
690 
691 /* Get the NCU type from the given class */
692 extern nwam_ncu_type_t nwam_ncu_class_to_type(nwam_ncu_class_t);
693 
694 /* ENM functions */
695 /*
696  * Obtain a specific enm handle, either be creating a new enm
697  * or reading an existing one from persistent storage.
698  */
699 extern nwam_error_t nwam_enm_create(const char *, const char *,
700 	nwam_enm_handle_t *);
701 extern nwam_error_t nwam_enm_read(const char *, uint64_t, nwam_enm_handle_t *);
702 
703 /* Make a copy of existing enm */
704 extern nwam_error_t nwam_enm_copy(nwam_enm_handle_t, const char *,
705 	nwam_enm_handle_t *);
706 
707 /*
708  * Obtain handles for all existing enms.  Caller-specified callback
709  * function will be called once for each enm, passing the handle and
710  * the caller-specified arg.
711  */
712 extern nwam_error_t nwam_walk_enms(int (*)(nwam_enm_handle_t, void *), void *,
713 	uint64_t, int *);
714 
715 /*
716  * Commit an enm to persistent storage.  Does not free the handle.
717  */
718 extern nwam_error_t nwam_enm_commit(nwam_enm_handle_t, uint64_t);
719 
720 /*
721  * Remove an enm from persistent storage.
722  */
723 extern nwam_error_t nwam_enm_destroy(nwam_enm_handle_t, uint64_t);
724 
725 /*
726  * Free an enm handle
727  */
728 extern void nwam_enm_free(nwam_enm_handle_t);
729 
730 /*
731  * Validate an enm, or a specific enm property.  If validating
732  * an entire enm, the invalid property type is returned.
733  */
734 extern nwam_error_t nwam_enm_validate(nwam_enm_handle_t, const char **);
735 extern nwam_error_t nwam_enm_validate_prop(nwam_enm_handle_t, const char *,
736 	nwam_value_t);
737 
738 /* Retrieve data type */
739 extern nwam_error_t nwam_enm_get_prop_type(const char *, nwam_value_type_t *);
740 /* Retrieve prop description */
741 extern nwam_error_t nwam_enm_get_prop_description(const char *, const char **);
742 
743 /*
744  * Delete/get/set enm property values.
745  */
746 extern nwam_error_t nwam_enm_delete_prop(nwam_enm_handle_t,
747 	const char *);
748 extern nwam_error_t nwam_enm_get_prop_value(nwam_enm_handle_t,
749 	const char *, nwam_value_t *);
750 extern nwam_error_t nwam_enm_set_prop_value(nwam_enm_handle_t,
751 	const char *, nwam_value_t);
752 
753 extern nwam_error_t nwam_enm_get_default_proplist(const char ***, uint_t *);
754 
755 /* Get the read-only value for a particular ENM property */
756 extern nwam_error_t nwam_enm_prop_read_only(const char *, boolean_t *);
757 
758 /* Whether the property is multi-valued or not */
759 extern nwam_error_t nwam_enm_prop_multivalued(const char *, boolean_t *);
760 
761 /*
762  * Walk all properties of a specific enm.  For each property, specified
763  * callback function is called.  Caller is responsible for freeing memory
764  * allocated for each property.
765  */
766 extern nwam_error_t nwam_enm_walk_props(nwam_enm_handle_t,
767     int (*)(const char *, nwam_value_t, void *),
768     void *, uint64_t, int *);
769 
770 /*
771  * Get/set the name of an enm.  When getting the name, the library will
772  * allocate a buffer; the caller is responsible for freeing the memory.
773  */
774 extern nwam_error_t nwam_enm_get_name(nwam_enm_handle_t, char **);
775 extern nwam_error_t nwam_enm_set_name(nwam_enm_handle_t, const char *);
776 extern boolean_t nwam_enm_can_set_name(nwam_enm_handle_t);
777 
778 /*
779  * Start/stop an enm.
780  */
781 extern nwam_error_t nwam_enm_enable(nwam_enm_handle_t);
782 extern nwam_error_t nwam_enm_disable(nwam_enm_handle_t);
783 
784 /*
785  * Get state of ENM from nwamd.
786  */
787 extern nwam_error_t nwam_enm_get_state(nwam_enm_handle_t, nwam_state_t *,
788 	nwam_aux_state_t *);
789 
790 /*
791  * Get whether the ENM has manual activation-mode or not.
792  */
793 extern nwam_error_t nwam_enm_is_manual(nwam_enm_handle_t, boolean_t *);
794 
795 /*
796  * Known Wireless LAN (WLAN) info.
797  */
798 
799 /* Create a known WLAN */
800 extern nwam_error_t nwam_known_wlan_create(const char *,
801     nwam_known_wlan_handle_t *);
802 
803 /* Read a known WLAN from persistent storage */
804 extern nwam_error_t nwam_known_wlan_read(const char *, uint64_t,
805     nwam_known_wlan_handle_t *);
806 
807 /*
808  * Destroy a known WLAN in persistent storage or free the in-memory
809  * representation.
810  */
811 extern nwam_error_t nwam_known_wlan_destroy(nwam_known_wlan_handle_t, uint64_t);
812 extern void nwam_known_wlan_free(nwam_known_wlan_handle_t);
813 
814 /* make a copy of existing known WLAN */
815 extern nwam_error_t nwam_known_wlan_copy(nwam_known_wlan_handle_t, const char *,
816     nwam_known_wlan_handle_t *);
817 
818 /* Commit known WLAN changes to persistent storage */
819 extern nwam_error_t nwam_known_wlan_commit(nwam_known_wlan_handle_t, uint64_t);
820 
821 /* Validate known WLAN content */
822 extern nwam_error_t nwam_known_wlan_validate(nwam_known_wlan_handle_t,
823     const char **);
824 
825 /* Walk known WLANs */
826 extern nwam_error_t nwam_walk_known_wlans
827 	(int(*)(nwam_known_wlan_handle_t, void *), void *, uint64_t, int *);
828 
829 /* get/set known WLAN name */
830 extern nwam_error_t nwam_known_wlan_get_name(nwam_known_wlan_handle_t, char **);
831 extern nwam_error_t nwam_known_wlan_set_name(nwam_known_wlan_handle_t,
832     const char *);
833 extern boolean_t nwam_known_wlan_can_set_name(nwam_known_wlan_handle_t);
834 
835 /* walk all properties of an in-memory known WLAN */
836 extern nwam_error_t nwam_known_wlan_walk_props(nwam_known_wlan_handle_t,
837     int (*)(const char *, nwam_value_t, void *),
838     void *, uint64_t, int *);
839 
840 /* delete/get/set/validate known WLAN property */
841 extern nwam_error_t nwam_known_wlan_delete_prop(nwam_known_wlan_handle_t,
842     const char *);
843 extern nwam_error_t nwam_known_wlan_get_prop_value(nwam_known_wlan_handle_t,
844     const char *, nwam_value_t *);
845 extern nwam_error_t nwam_known_wlan_set_prop_value(nwam_known_wlan_handle_t,
846     const char *, nwam_value_t);
847 extern nwam_error_t nwam_known_wlan_validate_prop(nwam_known_wlan_handle_t,
848     const char *, nwam_value_t);
849 
850 /* Retrieve data type */
851 extern nwam_error_t nwam_known_wlan_get_prop_type(const char *,
852     nwam_value_type_t *);
853 /* Retrieve prop description */
854 extern nwam_error_t nwam_known_wlan_get_prop_description(const char *,
855     const char **);
856 
857 /* get default known WLAN props */
858 extern nwam_error_t nwam_known_wlan_get_default_proplist(const char ***,
859     uint_t *);
860 
861 /* Whether the property is multi-valued or not */
862 extern nwam_error_t nwam_known_wlan_prop_multivalued(const char *, boolean_t *);
863 
864 /* Add a bssid to the known WLANs */
865 extern nwam_error_t nwam_known_wlan_add_to_known_wlans(const char *,
866     const char *, uint32_t, uint_t, const char *);
867 
868 /* Remove a bssid from known WLANs */
869 extern nwam_error_t nwam_known_wlan_remove_from_known_wlans(const char *,
870     const char *, const char *);
871 
872 /*
873  * nwam_wlan_t is used for scan/need choice/need key events and by
874  * nwam_wlan_get_scan_results().  The following fields are valid:
875  *
876  * - for scan and need choice event, ESSID, BSSID, signal strength, security
877  * mode, speed, channel, bsstype, key index, and if we already have a key
878  * (have_key), if the WLAN is the current selection (selected) and
879  * if the current WLAN is connected (connected).
880  * - for need key events, ESSID, security mode, have_key, selected and connected
881  * values are set.  The rest of the fields are not set since multiple WLANs
882  * may match the ESSID and have different speeds, channels etc.  If an
883  * ESSID/BSSID selection is specified, the BSSID will be set also.
884  *
885  */
886 typedef struct {
887 	char nww_essid[NWAM_MAX_NAME_LEN];
888 	char nww_bssid[NWAM_MAX_NAME_LEN];
889 	char nww_signal_strength[NWAM_MAX_NAME_LEN];
890 	uint32_t nww_security_mode; /* a dladm_wlan_secmode_t */
891 	uint32_t nww_speed; /* a dladm_wlan_speed_t */
892 	uint32_t nww_channel; /* a dladm_wlan_channel_t */
893 	uint32_t nww_bsstype; /* a dladm_wlan_bsstype_t */
894 	uint_t nww_keyindex;
895 	boolean_t nww_have_key;
896 	boolean_t nww_selected;
897 	boolean_t nww_connected;
898 } nwam_wlan_t;
899 
900 /*
901  * Active WLAN definitions. Used to scan WLANs/choose a WLAN/set a WLAN key.
902  */
903 extern nwam_error_t nwam_wlan_scan(const char *);
904 extern nwam_error_t nwam_wlan_get_scan_results(const char *, uint_t *,
905     nwam_wlan_t **);
906 extern nwam_error_t nwam_wlan_select(const char *, const char *, const char *,
907     uint32_t, boolean_t);
908 extern nwam_error_t nwam_wlan_set_key(const char *, const char *, const char *,
909     uint32_t, uint_t, const char *);
910 
911 /*
912  * Event notification definitions
913  */
914 #define	NWAM_EVENT_TYPE_NOOP			0
915 #define	NWAM_EVENT_TYPE_INIT			1
916 #define	NWAM_EVENT_TYPE_SHUTDOWN		2
917 #define	NWAM_EVENT_TYPE_OBJECT_ACTION		3
918 #define	NWAM_EVENT_TYPE_OBJECT_STATE		4
919 #define	NWAM_EVENT_TYPE_PRIORITY_GROUP		5
920 #define	NWAM_EVENT_TYPE_INFO			6
921 #define	NWAM_EVENT_TYPE_WLAN_SCAN_REPORT	7
922 #define	NWAM_EVENT_TYPE_WLAN_NEED_CHOICE	8
923 #define	NWAM_EVENT_TYPE_WLAN_NEED_KEY		9
924 #define	NWAM_EVENT_TYPE_WLAN_CONNECTION_REPORT	10
925 #define	NWAM_EVENT_TYPE_IF_ACTION		11
926 #define	NWAM_EVENT_TYPE_IF_STATE		12
927 #define	NWAM_EVENT_TYPE_LINK_ACTION		13
928 #define	NWAM_EVENT_TYPE_LINK_STATE		14
929 #define	NWAM_EVENT_MAX				NWAM_EVENT_TYPE_LINK_STATE
930 
931 #define	NWAM_EVENT_STATUS_OK			0
932 #define	NWAM_EVENT_STATUS_NOT_HANDLED		1
933 
934 #define	NWAM_EVENT_NETWORK_OBJECT_UNDEFINED	0
935 #define	NWAM_EVENT_NETWORK_OBJECT_LINK		1
936 #define	NWAM_EVENT_NETWORK_OBJECT_INTERFACE	2
937 
938 #define	NWAM_EVENT_REQUEST_UNDEFINED		0
939 #define	NWAM_EVENT_REQUEST_WLAN			1
940 #define	NWAM_EVENT_REQUEST_KEY			2
941 
942 /*
943  * Actions for nwamd to perform, used in conjunction with
944  * nwam_request_type_t in nwam_door_arg_t.
945  * Add string representations to nwam_action_to_string() in libnwam_util.c.
946  */
947 typedef enum {
948 	NWAM_ACTION_UNKNOWN = -1,
949 	NWAM_ACTION_ADD,
950 	NWAM_ACTION_REMOVE,
951 	NWAM_ACTION_REFRESH,
952 	NWAM_ACTION_ENABLE,
953 	NWAM_ACTION_DISABLE,
954 	NWAM_ACTION_DESTROY
955 } nwam_action_t;
956 
957 typedef enum {
958 	NWAM_OBJECT_TYPE_UNKNOWN = -1,
959 	NWAM_OBJECT_TYPE_NCP = 0,
960 	NWAM_OBJECT_TYPE_NCU = 1,
961 	NWAM_OBJECT_TYPE_LOC = 2,
962 	NWAM_OBJECT_TYPE_ENM = 3,
963 	NWAM_OBJECT_TYPE_KNOWN_WLAN = 4
964 } nwam_object_type_t;
965 
966 typedef struct nwam_event *nwam_event_t;
967 struct nwam_event {
968 	int nwe_type;
969 	uint32_t nwe_size;
970 
971 	union {
972 		struct nwam_event_object_action {
973 			nwam_object_type_t nwe_object_type;
974 			char nwe_name[NWAM_MAX_NAME_LEN];
975 			char nwe_parent[NWAM_MAX_NAME_LEN];
976 			nwam_action_t nwe_action;
977 		} nwe_object_action;
978 
979 		struct nwam_event_object_state {
980 			nwam_object_type_t nwe_object_type;
981 			char nwe_name[NWAM_MAX_NAME_LEN];
982 			char nwe_parent[NWAM_MAX_NAME_LEN];
983 			nwam_state_t nwe_state;
984 			nwam_aux_state_t nwe_aux_state;
985 		} nwe_object_state;
986 
987 		struct nwam_event_priority_group_info {
988 			int64_t nwe_priority;
989 		} nwe_priority_group_info;
990 
991 		struct nwam_event_info {
992 			char nwe_message[NWAM_MAX_VALUE_LEN];
993 		} nwe_info;
994 
995 		/*
996 		 * wlan_info stores both scan results and the single
997 		 * WLAN we require a key for in the case of _WLAN_NEED_KEY
998 		 * events.  For _WLAN_CONNECTION_REPORT events, it stores
999 		 * the WLAN the connection succeeded/failed for, indicating
1000 		 * success/failure using the 'connected' boolean.
1001 		 */
1002 		struct nwam_event_wlan_info {
1003 			char nwe_name[NWAM_MAX_NAME_LEN];
1004 			boolean_t nwe_connected;
1005 			uint16_t nwe_num_wlans;
1006 			nwam_wlan_t nwe_wlans[1];
1007 			/*
1008 			 * space may be allocated by user here for the
1009 			 * number of wlans
1010 			 */
1011 		} nwe_wlan_info;
1012 
1013 		struct nwam_event_if_action {
1014 			char nwe_name[NWAM_MAX_NAME_LEN];
1015 			nwam_action_t nwe_action;
1016 		} nwe_if_action;
1017 
1018 		struct nwam_event_if_state {
1019 			char nwe_name[NWAM_MAX_NAME_LEN];
1020 			uint32_t nwe_flags;
1021 			uint32_t nwe_addr_valid; /* boolean */
1022 			uint32_t nwe_addr_added; /* boolean */
1023 			struct sockaddr_storage nwe_addr;
1024 			struct sockaddr_storage nwe_netmask;
1025 		} nwe_if_state;
1026 
1027 		struct nwam_event_link_state {
1028 			char nwe_name[NWAM_MAX_NAME_LEN];
1029 			boolean_t nwe_link_up;
1030 			/* link_state_t from sys/mac.h */
1031 		} nwe_link_state;
1032 
1033 		struct nwam_event_link_action {
1034 			char nwe_name[NWAM_MAX_NAME_LEN];
1035 			nwam_action_t nwe_action;
1036 		} nwe_link_action;
1037 	} nwe_data;
1038 };
1039 
1040 /* NWAM client functions, used to register/unregister and receive events */
1041 extern nwam_error_t nwam_events_init(void);
1042 extern void nwam_events_fini(void);
1043 extern nwam_error_t nwam_event_wait(nwam_event_t *);
1044 extern void nwam_event_free(nwam_event_t);
1045 
1046 /* Event-related string conversion functions */
1047 extern const char *nwam_action_to_string(nwam_action_t);
1048 extern const char *nwam_event_type_to_string(int);
1049 extern const char *nwam_state_to_string(nwam_state_t);
1050 extern const char *nwam_aux_state_to_string(nwam_aux_state_t);
1051 
1052 extern const char *nwam_object_type_to_string(nwam_object_type_t);
1053 extern nwam_object_type_t nwam_string_to_object_type(const char *);
1054 
1055 /* Utility strtok_r-like function */
1056 extern char *nwam_tokenize_by_unescaped_delim(char *, char, char **);
1057 
1058 #ifdef	__cplusplus
1059 }
1060 #endif
1061 
1062 #endif	/* _LIBNWAM_H */
1063