1b00044a2SJames Carlson /*
2b00044a2SJames Carlson  * CDDL HEADER START
3b00044a2SJames Carlson  *
4b00044a2SJames Carlson  * The contents of this file are subject to the terms of the
5b00044a2SJames Carlson  * Common Development and Distribution License (the "License").
6b00044a2SJames Carlson  * You may not use this file except in compliance with the License.
7b00044a2SJames Carlson  *
8b00044a2SJames Carlson  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9b00044a2SJames Carlson  * or http://www.opensolaris.org/os/licensing.
10b00044a2SJames Carlson  * See the License for the specific language governing permissions
11b00044a2SJames Carlson  * and limitations under the License.
12b00044a2SJames Carlson  *
13b00044a2SJames Carlson  * When distributing Covered Code, include this CDDL HEADER in each
14b00044a2SJames Carlson  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15b00044a2SJames Carlson  * If applicable, add the following below this CDDL HEADER, with the
16b00044a2SJames Carlson  * fields enclosed by brackets "[]" replaced with your own identifying
17b00044a2SJames Carlson  * information: Portions Copyright [yyyy] [name of copyright owner]
18b00044a2SJames Carlson  *
19b00044a2SJames Carlson  * CDDL HEADER END
20b00044a2SJames Carlson  */
21b00044a2SJames Carlson /*
22f6da83d4SAnurag S. Maskey  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23*b31320a7SChris Fraire  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
24b00044a2SJames Carlson  */
25b00044a2SJames Carlson 
266ba597c5SAnurag S. Maskey /*
276ba597c5SAnurag S. Maskey  * This file contains data structures and APIs of libnwam.
286ba597c5SAnurag S. Maskey  * Implementation is MT safe.
296ba597c5SAnurag S. Maskey  */
30b00044a2SJames Carlson #ifndef _LIBNWAM_H
31b00044a2SJames Carlson #define	_LIBNWAM_H
32b00044a2SJames Carlson 
336ba597c5SAnurag S. Maskey #ifdef	__cplusplus
346ba597c5SAnurag S. Maskey extern "C" {
356ba597c5SAnurag S. Maskey #endif
366ba597c5SAnurag S. Maskey 
376ba597c5SAnurag S. Maskey #include <bsm/adt.h>
386ba597c5SAnurag S. Maskey #include <net/if.h>
396ba597c5SAnurag S. Maskey #include <inet/ip.h>
406ba597c5SAnurag S. Maskey #include <inet/ip6.h>
416ba597c5SAnurag S. Maskey #include <sys/types.h>
426ba597c5SAnurag S. Maskey #include <sys/socket.h>
43b00044a2SJames Carlson 
44b00044a2SJames Carlson /*
456ba597c5SAnurag S. Maskey  * Note - several interface functions below are not utilized in ON, but are
466ba597c5SAnurag S. Maskey  * used by the GNOME nwam-manager.  One example is nwam_enm_get_name().
47b00044a2SJames Carlson  */
48b00044a2SJames Carlson 
496ba597c5SAnurag S. Maskey /*
506ba597c5SAnurag S. Maskey  * Common definitions
516ba597c5SAnurag S. Maskey  */
526ba597c5SAnurag S. Maskey 
536ba597c5SAnurag S. Maskey /* nwam FMRI and properties */
546ba597c5SAnurag S. Maskey #define	NWAM_FMRI		"svc:/network/physical:nwam"
556ba597c5SAnurag S. Maskey #define	NWAM_PG			"nwamd"
566ba597c5SAnurag S. Maskey #define	NWAM_PROP_ACTIVE_NCP	"active_ncp"
576ba597c5SAnurag S. Maskey 
586ba597c5SAnurag S. Maskey /* nwam flags used for read/commit */
596ba597c5SAnurag S. Maskey /* Block waiting for commit if necessary */
606ba597c5SAnurag S. Maskey #define	NWAM_FLAG_BLOCKING		0x00000001
616ba597c5SAnurag S. Maskey /* Committed object must be new */
626ba597c5SAnurag S. Maskey #define	NWAM_FLAG_CREATE		0x00000002
636ba597c5SAnurag S. Maskey /* Tell destroy functions not to free handle */
646ba597c5SAnurag S. Maskey #define	NWAM_FLAG_DO_NOT_FREE		0x00000004
656ba597c5SAnurag S. Maskey /* Object is being enabled/disabled */
666ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ENTITY_ENABLE		0x00000008
676ba597c5SAnurag S. Maskey /* Known WLAN being read, committed or destroyed */
686ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ENTITY_KNOWN_WLAN	0x00000010
696ba597c5SAnurag S. Maskey 
706ba597c5SAnurag S. Maskey /* nwam flags used for selecting ncu type for walk */
716ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_TYPE_LINK		0x00000001ULL << 32
726ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_TYPE_INTERFACE	0x00000002ULL << 32
736ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_TYPE_ALL		(NWAM_FLAG_NCU_TYPE_LINK | \
746ba597c5SAnurag S. Maskey 					NWAM_FLAG_NCU_TYPE_INTERFACE)
756ba597c5SAnurag S. Maskey 
766ba597c5SAnurag S. Maskey /* nwam flags used for selecting ncu class for walk */
776ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_CLASS_PHYS		0x00000100ULL << 32
786ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_CLASS_IP			0x00010000ULL << 32
796ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_CLASS_ALL_LINK		NWAM_FLAG_NCU_CLASS_PHYS
806ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_CLASS_ALL_INTERFACE	NWAM_FLAG_NCU_CLASS_IP
816ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_CLASS_ALL		(NWAM_FLAG_NCU_CLASS_ALL_INTERFACE | \
826ba597c5SAnurag S. Maskey 					NWAM_FLAG_NCU_CLASS_ALL_LINK)
836ba597c5SAnurag S. Maskey #define	NWAM_FLAG_NCU_TYPE_CLASS_ALL		(NWAM_FLAG_NCU_CLASS_ALL | \
846ba597c5SAnurag S. Maskey 						NWAM_FLAG_NCU_TYPE_ALL)
856ba597c5SAnurag S. Maskey 
866ba597c5SAnurag S. Maskey /* flags used for selecting activation for walk */
876ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ACTIVATION_MODE_MANUAL		0x000000001ULL << 32
886ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ACTIVATION_MODE_SYSTEM		0x000000002ULL << 32
896ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ACTIVATION_MODE_PRIORITIZED		0x000000004ULL << 32
906ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ANY	0x000000008ULL << 32
916ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ALL	0x000000010ULL << 32
926ba597c5SAnurag S. Maskey #define	NWAM_FLAG_ACTIVATION_MODE_ALL	(NWAM_FLAG_ACTIVATION_MODE_MANUAL |\
936ba597c5SAnurag S. Maskey 					NWAM_FLAG_ACTIVATION_MODE_SYSTEM |\
946ba597c5SAnurag S. Maskey 					NWAM_FLAG_ACTIVATION_MODE_PRIORITIZED |\
956ba597c5SAnurag S. Maskey 				NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ANY |\
966ba597c5SAnurag S. Maskey 				NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ALL)
976ba597c5SAnurag S. Maskey 
986ba597c5SAnurag S. Maskey /* Walk known WLANs in order of priority (lowest first) */
996ba597c5SAnurag S. Maskey #define	NWAM_FLAG_KNOWN_WLAN_WALK_PRIORITY_ORDER	0x000010000ULL << 32
1006ba597c5SAnurag S. Maskey /* Do not perform priority collision checking for known WLANs */
1016ba597c5SAnurag S. Maskey #define	NWAM_FLAG_KNOWN_WLAN_NO_COLLISION_CHECK		0x000020000ULL << 32
1026ba597c5SAnurag S. Maskey 
1036ba597c5SAnurag S. Maskey /* nwam return codes */
1046ba597c5SAnurag S. Maskey typedef enum {
1056ba597c5SAnurag S. Maskey 	NWAM_SUCCESS,			/* No error occured */
1066ba597c5SAnurag S. Maskey 	NWAM_LIST_END,			/* End of list reached */
1076ba597c5SAnurag S. Maskey 	NWAM_INVALID_HANDLE,		/* Entity handle is invalid */
1086ba597c5SAnurag S. Maskey 	NWAM_HANDLE_UNBOUND,		/* Handle not bound to entity */
1096ba597c5SAnurag S. Maskey 	NWAM_INVALID_ARG,		/* Argument is invalid */
1106ba597c5SAnurag S. Maskey 	NWAM_PERMISSION_DENIED,		/* Insufficient privileges for action */
1116ba597c5SAnurag S. Maskey 	NWAM_NO_MEMORY,			/* Out of memory */
1126ba597c5SAnurag S. Maskey 	NWAM_ENTITY_EXISTS,		/* Entity already exists */
1136ba597c5SAnurag S. Maskey 	NWAM_ENTITY_IN_USE,		/* Entity in use */
1146ba597c5SAnurag S. Maskey 	NWAM_ENTITY_COMMITTED,		/* Entity already committed */
1156ba597c5SAnurag S. Maskey 	NWAM_ENTITY_NOT_FOUND,		/* Entity not found */
1166ba597c5SAnurag S. Maskey 	NWAM_ENTITY_TYPE_MISMATCH,	/* Entity type mismatch */
1176ba597c5SAnurag S. Maskey 	NWAM_ENTITY_INVALID,		/* Validation of entity failed */
1186ba597c5SAnurag S. Maskey 	NWAM_ENTITY_INVALID_MEMBER,	/* Entity member invalid */
1196ba597c5SAnurag S. Maskey 	NWAM_ENTITY_INVALID_STATE,	/* Entity is not in appropriate state */
1206ba597c5SAnurag S. Maskey 	NWAM_ENTITY_INVALID_VALUE,	/* Validation of entity value failed */
1216ba597c5SAnurag S. Maskey 	NWAM_ENTITY_MISSING_MEMBER,	/* Required member is missing */
1226ba597c5SAnurag S. Maskey 	NWAM_ENTITY_NO_VALUE,		/* No value associated with entity */
1236ba597c5SAnurag S. Maskey 	NWAM_ENTITY_MULTIPLE_VALUES,	/* Multiple values for entity */
1246ba597c5SAnurag S. Maskey 	NWAM_ENTITY_READ_ONLY,		/* Entity is marked read only */
1256ba597c5SAnurag S. Maskey 	NWAM_ENTITY_NOT_DESTROYABLE,	/* Entity cannot be destroyed */
1266ba597c5SAnurag S. Maskey 	NWAM_ENTITY_NOT_MANUAL,	/* Entity cannot be manually enabled/disabled */
1276ba597c5SAnurag S. Maskey 	NWAM_WALK_HALTED,		/* Callback function returned nonzero */
1286ba597c5SAnurag S. Maskey 	NWAM_ERROR_BIND,		/* Could not bind to backend */
1296ba597c5SAnurag S. Maskey 	NWAM_ERROR_BACKEND_INIT,	/* Could not initialize backend */
1306ba597c5SAnurag S. Maskey 	NWAM_ERROR_INTERNAL		/* Internal error */
1316ba597c5SAnurag S. Maskey } nwam_error_t;
1326ba597c5SAnurag S. Maskey 
1336ba597c5SAnurag S. Maskey #define	NWAM_MAX_NAME_LEN		128
1346ba597c5SAnurag S. Maskey #define	NWAM_MAX_VALUE_LEN		256
1356ba597c5SAnurag S. Maskey #define	NWAM_MAX_FMRI_LEN		NWAM_MAX_VALUE_LEN
1366ba597c5SAnurag S. Maskey #define	NWAM_MAX_NUM_VALUES		32
1376ba597c5SAnurag S. Maskey #define	NWAM_MAX_NUM_PROPERTIES		32
1386ba597c5SAnurag S. Maskey 
1396ba597c5SAnurag S. Maskey /* used for getting and setting of properties */
1406ba597c5SAnurag S. Maskey typedef enum {
1416ba597c5SAnurag S. Maskey 	NWAM_VALUE_TYPE_BOOLEAN,
1426ba597c5SAnurag S. Maskey 	NWAM_VALUE_TYPE_INT64,
1436ba597c5SAnurag S. Maskey 	NWAM_VALUE_TYPE_UINT64,
1446ba597c5SAnurag S. Maskey 	NWAM_VALUE_TYPE_STRING,
1456ba597c5SAnurag S. Maskey 	NWAM_VALUE_TYPE_UNKNOWN
1466ba597c5SAnurag S. Maskey } nwam_value_type_t;
1476ba597c5SAnurag S. Maskey 
1486ba597c5SAnurag S. Maskey /* Holds values of various types for getting and setting of properties */
1496ba597c5SAnurag S. Maskey /* Forward definition */
1506ba597c5SAnurag S. Maskey struct nwam_value;
1516ba597c5SAnurag S. Maskey typedef struct nwam_value *nwam_value_t;
1526ba597c5SAnurag S. Maskey 
1536ba597c5SAnurag S. Maskey /* Value-related functions. */
1546ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_boolean(boolean_t, nwam_value_t *);
1556ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_boolean_array(boolean_t *, uint_t,
1566ba597c5SAnurag S. Maskey     nwam_value_t *);
1576ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_int64(int64_t, nwam_value_t *);
1586ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_int64_array(int64_t *, uint_t,
1596ba597c5SAnurag S. Maskey     nwam_value_t *);
1606ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_uint64(uint64_t, nwam_value_t *);
1616ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_uint64_array(uint64_t *, uint_t,
1626ba597c5SAnurag S. Maskey     nwam_value_t *);
1636ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_string(char *, nwam_value_t *);
1646ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_create_string_array(char **, uint_t,
1656ba597c5SAnurag S. Maskey     nwam_value_t *);
1666ba597c5SAnurag S. Maskey 
1676ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_boolean(nwam_value_t, boolean_t *);
1686ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_boolean_array(nwam_value_t, boolean_t **,
1696ba597c5SAnurag S. Maskey     uint_t *);
1706ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_int64(nwam_value_t, int64_t *);
1716ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_int64_array(nwam_value_t, int64_t **,
1726ba597c5SAnurag S. Maskey     uint_t *);
1736ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_uint64(nwam_value_t, uint64_t *);
1746ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_uint64_array(nwam_value_t, uint64_t **,
1756ba597c5SAnurag S. Maskey     uint_t *);
1766ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_string(nwam_value_t, char **);
1776ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_string_array(nwam_value_t, char ***,
1786ba597c5SAnurag S. Maskey     uint_t *);
1796ba597c5SAnurag S. Maskey 
1806ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_type(nwam_value_t, nwam_value_type_t *);
1816ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_get_numvalues(nwam_value_t, uint_t *);
1826ba597c5SAnurag S. Maskey 
1836ba597c5SAnurag S. Maskey extern void nwam_value_free(nwam_value_t);
1846ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_copy(nwam_value_t, nwam_value_t *);
1856ba597c5SAnurag S. Maskey 
1866ba597c5SAnurag S. Maskey extern nwam_error_t nwam_uint64_get_value_string(const char *, uint64_t,
1876ba597c5SAnurag S. Maskey     const char **);
1886ba597c5SAnurag S. Maskey extern nwam_error_t nwam_value_string_get_uint64(const char *, const char *,
1896ba597c5SAnurag S. Maskey     uint64_t *);
1906ba597c5SAnurag S. Maskey 
1916ba597c5SAnurag S. Maskey /*
1926ba597c5SAnurag S. Maskey  * To retrieve a localized error string
1936ba597c5SAnurag S. Maskey  */
1946ba597c5SAnurag S. Maskey extern const char *nwam_strerror(nwam_error_t);
1956ba597c5SAnurag S. Maskey 
1966ba597c5SAnurag S. Maskey /*
1976ba597c5SAnurag S. Maskey  * State and auxiliary state describe the state of ENMs, NCUs and locations.
1986ba597c5SAnurag S. Maskey  */
1996ba597c5SAnurag S. Maskey typedef enum {
2006ba597c5SAnurag S. Maskey 	NWAM_STATE_UNINITIALIZED = 0x0,
2016ba597c5SAnurag S. Maskey 	NWAM_STATE_INITIALIZED = 0x1,
2026ba597c5SAnurag S. Maskey 	NWAM_STATE_OFFLINE = 0x2,
2036ba597c5SAnurag S. Maskey 	NWAM_STATE_OFFLINE_TO_ONLINE = 0x4,
2046ba597c5SAnurag S. Maskey 	NWAM_STATE_ONLINE_TO_OFFLINE = 0x8,
2056ba597c5SAnurag S. Maskey 	NWAM_STATE_ONLINE = 0x10,
2066ba597c5SAnurag S. Maskey 	NWAM_STATE_MAINTENANCE = 0x20,
2076ba597c5SAnurag S. Maskey 	NWAM_STATE_DEGRADED = 0x40,
2086ba597c5SAnurag S. Maskey 	NWAM_STATE_DISABLED = 0x80
2096ba597c5SAnurag S. Maskey } nwam_state_t;
2106ba597c5SAnurag S. Maskey 
2116ba597c5SAnurag S. Maskey #define	NWAM_STATE_ANY	(NWAM_STATE_UNINITIALIZED | \
2126ba597c5SAnurag S. Maskey 			NWAM_STATE_INITIALIZED | \
2136ba597c5SAnurag S. Maskey 			NWAM_STATE_OFFLINE | \
2146ba597c5SAnurag S. Maskey 			NWAM_STATE_OFFLINE_TO_ONLINE | \
2156ba597c5SAnurag S. Maskey 			NWAM_STATE_ONLINE_TO_OFFLINE | \
2166ba597c5SAnurag S. Maskey 			NWAM_STATE_ONLINE | \
2176ba597c5SAnurag S. Maskey 			NWAM_STATE_MAINTENANCE | \
2186ba597c5SAnurag S. Maskey 			NWAM_STATE_DEGRADED | \
2196ba597c5SAnurag S. Maskey 			NWAM_STATE_DISABLED)
2206ba597c5SAnurag S. Maskey 
2216ba597c5SAnurag S. Maskey /*
2226ba597c5SAnurag S. Maskey  * The auxiliary state denotes specific reasons why an object is in a particular
2236ba597c5SAnurag S. Maskey  * state (e.g. "script failed", "disabled by administrator", "waiting for DHCP
2246ba597c5SAnurag S. Maskey  * response").
2256ba597c5SAnurag S. Maskey  */
2266ba597c5SAnurag S. Maskey typedef enum {
2276ba597c5SAnurag S. Maskey 	/* General auxiliary states */
2286ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_UNINITIALIZED,
2296ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_INITIALIZED,
2306ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_CONDITIONS_NOT_MET,
2316ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_MANUAL_DISABLE,
2326ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_METHOD_FAILED,
2336ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_METHOD_MISSING,
2346ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_METHOD_RUNNING,
2356ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_INVALID_CONFIG,
2366ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_ACTIVE,
2376ba597c5SAnurag S. Maskey 	/* Link-specific auxiliary states */
2386ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_LINK_WIFI_SCANNING,
2396ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_LINK_WIFI_NEED_SELECTION,
2406ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_LINK_WIFI_NEED_KEY,
2416ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_LINK_WIFI_CONNECTING,
2426ba597c5SAnurag S. Maskey 	/* IP interface-specific auxiliary states */
2436ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_IF_WAITING_FOR_ADDR,
2446ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_IF_DHCP_TIMED_OUT,
2456ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_IF_DUPLICATE_ADDR,
2466ba597c5SAnurag S. Maskey 	/* Common link/interface auxiliary states */
2476ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_UP,
2486ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_DOWN,
2496ba597c5SAnurag S. Maskey 	NWAM_AUX_STATE_NOT_FOUND
2506ba597c5SAnurag S. Maskey } nwam_aux_state_t;
2516ba597c5SAnurag S. Maskey 
2526ba597c5SAnurag S. Maskey /* Activation modes */
2536ba597c5SAnurag S. Maskey typedef enum {
2546ba597c5SAnurag S. Maskey 	NWAM_ACTIVATION_MODE_MANUAL,
2556ba597c5SAnurag S. Maskey 	NWAM_ACTIVATION_MODE_SYSTEM,
2566ba597c5SAnurag S. Maskey 	NWAM_ACTIVATION_MODE_CONDITIONAL_ANY,
2576ba597c5SAnurag S. Maskey 	NWAM_ACTIVATION_MODE_CONDITIONAL_ALL,
2586ba597c5SAnurag S. Maskey 	NWAM_ACTIVATION_MODE_PRIORITIZED
2596ba597c5SAnurag S. Maskey } nwam_activation_mode_t;
2606ba597c5SAnurag S. Maskey 
2616ba597c5SAnurag S. Maskey /*
2626ba597c5SAnurag S. Maskey  * Conditions are of the form
2636ba597c5SAnurag S. Maskey  *
2646ba597c5SAnurag S. Maskey  * ncu|enm|loc name is|is-not active
2656ba597c5SAnurag S. Maskey  * ip-address is|is-not|is-in-range|is-not-in-range ipaddr[/prefixlen]
2666ba597c5SAnurag S. Maskey  * advertised-domain is|is-not|contains|does-not-contain string
2676ba597c5SAnurag S. Maskey  * system-domain is|is-not|contains|does-not-contain string
2686ba597c5SAnurag S. Maskey  * essid is|is-not|contains|does-not-contain string
2696ba597c5SAnurag S. Maskey  * bssid is|is-not <string>
2706ba597c5SAnurag S. Maskey  */
2716ba597c5SAnurag S. Maskey 
2726ba597c5SAnurag S. Maskey typedef enum {
2736ba597c5SAnurag S. Maskey 	NWAM_CONDITION_IS,
2746ba597c5SAnurag S. Maskey 	NWAM_CONDITION_IS_NOT,
2756ba597c5SAnurag S. Maskey 	NWAM_CONDITION_IS_IN_RANGE,
2766ba597c5SAnurag S. Maskey 	NWAM_CONDITION_IS_NOT_IN_RANGE,
2776ba597c5SAnurag S. Maskey 	NWAM_CONDITION_CONTAINS,
2786ba597c5SAnurag S. Maskey 	NWAM_CONDITION_DOES_NOT_CONTAIN
2796ba597c5SAnurag S. Maskey } nwam_condition_t;
2806ba597c5SAnurag S. Maskey 
2816ba597c5SAnurag S. Maskey typedef enum {
2826ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_NCP,
2836ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_NCU,
2846ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_ENM,
2856ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_LOC,
2866ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_IP_ADDRESS,
2876ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_ADV_DOMAIN,
2886ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_SYS_DOMAIN,
2896ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_ESSID,
2906ba597c5SAnurag S. Maskey 	NWAM_CONDITION_OBJECT_TYPE_BSSID
2916ba597c5SAnurag S. Maskey } nwam_condition_object_type_t;
2926ba597c5SAnurag S. Maskey 
2936ba597c5SAnurag S. Maskey /*
2946ba597c5SAnurag S. Maskey  * Activation condition-related functions that convert activation
2956ba597c5SAnurag S. Maskey  * values to an appropriate string and back.
2966ba597c5SAnurag S. Maskey  */
2976ba597c5SAnurag S. Maskey extern nwam_error_t nwam_condition_to_condition_string(
2986ba597c5SAnurag S. Maskey     nwam_condition_object_type_t, nwam_condition_t, const char *, char **);
2996ba597c5SAnurag S. Maskey extern nwam_error_t nwam_condition_string_to_condition(const char *,
3006ba597c5SAnurag S. Maskey     nwam_condition_object_type_t *, nwam_condition_t *, char **);
3016ba597c5SAnurag S. Maskey 
3026ba597c5SAnurag S. Maskey /*
3036ba597c5SAnurag S. Maskey  * Only one location can be active at one time. As a
3046ba597c5SAnurag S. Maskey  * consequence, if the activation conditions of multiple
3056ba597c5SAnurag S. Maskey  * locations are satisfied, we need to compare activation
3066ba597c5SAnurag S. Maskey  * conditions to see if one is more specific than another.
3076ba597c5SAnurag S. Maskey  *
3086ba597c5SAnurag S. Maskey  * The following heuristics are applied to rate an
3096ba597c5SAnurag S. Maskey  * activation condition:
3106ba597c5SAnurag S. Maskey  * - "is" is the most specific condition
3116ba597c5SAnurag S. Maskey  * - it is followed by "is-in-range" and "contains"
3126ba597c5SAnurag S. Maskey  * - "is-not-in-range" and "does-not-contain" are next
3136ba597c5SAnurag S. Maskey  * - finally "is-not" is least specific
3146ba597c5SAnurag S. Maskey  *
3156ba597c5SAnurag S. Maskey  * Regarding the objects these conditions apply to:
3166ba597c5SAnurag S. Maskey  * - NCU, ENM and locations are most specific
3176ba597c5SAnurag S. Maskey  * - system-domain is next
3186ba597c5SAnurag S. Maskey  * - advertised-domain is next
3196ba597c5SAnurag S. Maskey  * - IP address is next
3206ba597c5SAnurag S. Maskey  * - wireless BSSID is next
3216ba597c5SAnurag S. Maskey  * - wireless ESSID is least specific
3226ba597c5SAnurag S. Maskey  *
3236ba597c5SAnurag S. Maskey  */
3246ba597c5SAnurag S. Maskey extern nwam_error_t nwam_condition_rate(nwam_condition_object_type_t,
3256ba597c5SAnurag S. Maskey     nwam_condition_t, uint64_t *);
3266ba597c5SAnurag S. Maskey 
3276ba597c5SAnurag S. Maskey /*
3286ba597c5SAnurag S. Maskey  * Location definitions.
3296ba597c5SAnurag S. Maskey  */
3306ba597c5SAnurag S. Maskey 
3316ba597c5SAnurag S. Maskey #define	NWAM_LOC_NAME_AUTOMATIC		"Automatic"
3326ba597c5SAnurag S. Maskey #define	NWAM_LOC_NAME_NO_NET		"NoNet"
3336ba597c5SAnurag S. Maskey #define	NWAM_LOC_NAME_LEGACY		"Legacy"
3346ba597c5SAnurag S. Maskey 
3356ba597c5SAnurag S. Maskey #define	NWAM_LOC_NAME_PRE_DEFINED(name)	\
3366ba597c5SAnurag S. Maskey 			(strcasecmp(name, NWAM_LOC_NAME_AUTOMATIC) == 0 || \
3376ba597c5SAnurag S. Maskey 			strcasecmp(name, NWAM_LOC_NAME_NO_NET) == 0 || \
3386ba597c5SAnurag S. Maskey 			strcasecmp(name, NWAM_LOC_NAME_LEGACY) == 0)
3396ba597c5SAnurag S. Maskey 
3406ba597c5SAnurag S. Maskey /* Forward definition */
3416ba597c5SAnurag S. Maskey struct nwam_handle;
342