xref: /illumos-gate/usr/src/lib/libnwam/common/libnwam.h (revision 7f848965aa84f3ffafe9b934c813f94048ea42f8)
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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LIBNWAM_H
28 #define	_LIBNWAM_H
29 
30 #include <netinet/in.h>
31 
32 /*
33  * This file defines the programming interface for libnwam.  It is a private
34  * (undocumented, subject to change) interface shared between the NWAM GUI and
35  * nwamd.
36  */
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct libnwam_wlan_attr_s {
43 	const char		*wla_essid;
44 	const char		*wla_bssid;
45 	const char		*wla_secmode;
46 	const char		*wla_strength;
47 	const char		*wla_mode;
48 	const char		*wla_speed;
49 	const char		*wla_auth;
50 	const char		*wla_bsstype;
51 	int			wla_channel;
52 } libnwam_wlan_attr_t;
53 
54 /* Number of strings above; used for internal allocation purposes */
55 #define	WLA_NUM_STRS	8
56 
57 /*
58  * The descriptive event types shared with nwamd and with the GUI client.  With
59  * all events other than deInitial, led_interface is always valid.  The other
60  * fields are present when indicated, and otherwise must be left unused.
61  */
62 typedef enum libnwam_descr_evtype_e {
63 	deInitial,		/* no other fields; new active client */
64 	deInterfaceUp,		/* led_v4address led_prefixlen */
65 	deInterfaceDown,	/* led_cause */
66 	deInterfaceAdded,
67 	deInterfaceRemoved,
68 	deWlanConnectFail,
69 	deWlanDisconnect,	/* led_wlan */
70 	deWlanConnected,	/* led_wlan */
71 	deLLPSelected,
72 	deLLPUnselected,	/* led_cause */
73 	deULPActivated,
74 	deULPDeactivated,
75 	deScanChange,
76 	deScanSame,
77 	deWlanKeyNeeded,	/* led_wlan */
78 	deWlanSelectionNeeded
79 } libnwam_descr_evtype_t;
80 
81 typedef enum libnwam_diag_cause_e {
82 	dcNone = 0,		/* no cause */
83 	dcDHCP,			/* DHCP left interface down or with zero addr */
84 	dcTimer,		/* gave up on DHCP; switching to next best */
85 	dcUnplugged,		/* interface lost RUNNING flag */
86 	dcUser,			/* user changed priority */
87 	dcBetter,		/* higher-priority interface became RUNNING */
88 	dcNewAP,		/* scan completed on higher-priority i/f */
89 	dcGone,			/* periodic wireless scan showed disconnect */
90 	dcFaded,		/* periodic scan showed "very weak" signal */
91 	dcAllDown,		/* all-but-one taken down (initial LLP) */
92 	dcUnwanted,		/* another higher-priority interface is up */
93 	dcShutdown,		/* daemon is being shut down */
94 	dcSelect,		/* different AP selected (forced down/up) */
95 	dcRemoved,		/* interface removed from system */
96 	dcFailed		/* interface bring-up failed */
97 } libnwam_diag_cause_t;
98 
99 typedef struct libnwam_event_data_s {
100 	libnwam_descr_evtype_t	led_type;
101 	libnwam_diag_cause_t	led_cause;
102 	struct in_addr		led_v4address;	/* deInterfaceUp only */
103 	int			led_prefixlen;	/* deInterfaceUp only */
104 	libnwam_wlan_attr_t	led_wlan;
105 	char			*led_interface;
106 } libnwam_event_data_t;
107 
108 typedef enum libnwam_ipv4src_e {
109 	IPV4SRC_STATIC,
110 	IPV4SRC_DHCP
111 } libnwam_ipv4src_t;
112 
113 typedef enum libnwam_interface_type_e {
114 	IF_UNKNOWN,
115 	IF_WIRED,
116 	IF_WIRELESS,
117 	IF_TUN
118 } libnwam_interface_type_t;
119 
120 typedef struct libnwam_llp_s {
121 	const char	*llp_interface;
122 	int		llp_pri;	/* lower number => higher priority */
123 	libnwam_interface_type_t llp_type;
124 	libnwam_ipv4src_t llp_ipv4src;
125 	boolean_t	llp_primary;	/* selected primary interface */
126 	boolean_t	llp_locked;	/* selected is locked */
127 	boolean_t	llp_link_failed; /* unusable due to link failure */
128 	boolean_t	llp_dhcp_failed; /* unusable due to DHCP failure */
129 	boolean_t	llp_link_up;	/* datalink layer is up */
130 	boolean_t	llp_need_wlan;	/* wlan/AP not yet selected */
131 	boolean_t	llp_need_key;	/* wlan key not set */
132 } libnwam_llp_t;
133 
134 typedef struct libnwam_wlan_s {
135 	libnwam_wlan_attr_t wlan_attrs;
136 	const char	*wlan_interface;
137 	boolean_t	wlan_known;
138 	boolean_t	wlan_haskey;
139 	boolean_t	wlan_connected;
140 } libnwam_wlan_t;
141 
142 typedef struct libnwam_known_ap_s {
143 	const char	*ka_essid;
144 	const char	*ka_bssid;
145 	boolean_t	ka_haskey;
146 } libnwam_known_ap_t;
147 
148 extern libnwam_event_data_t *libnwam_wait_event(void);
149 extern void libnwam_free_event(libnwam_event_data_t *);
150 extern libnwam_llp_t *libnwam_get_llp_list(uint_t *);
151 extern void libnwam_free_llp_list(libnwam_llp_t *);
152 extern int libnwam_set_llp_priority(const char *, int);
153 extern int libnwam_lock_llp(const char *);
154 extern libnwam_wlan_t *libnwam_get_wlan_list(uint_t *);
155 extern void libnwam_free_wlan_list(libnwam_wlan_t *);
156 extern libnwam_known_ap_t *libnwam_get_known_ap_list(uint_t *);
157 extern void libnwam_free_known_ap_list(libnwam_known_ap_t *);
158 extern int libnwam_add_known_ap(const char *, const char *);
159 extern int libnwam_delete_known_ap(const char *, const char *);
160 extern int libnwam_select_wlan(const char *, const char *, const char *);
161 extern int libnwam_wlan_key(const char *, const char *, const char *,
162     const char *);
163 #pragma weak libnwam_wlan_key_secmode
164 extern int libnwam_wlan_key_secmode(const char *, const char *, const char *,
165     const char *, const char *);
166 extern int libnwam_start_rescan(const char *);
167 extern int libnwam_fini(void);
168 extern int libnwam_init(int);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* _LIBNWAM_H */
175