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