Home | History | Annotate | Download | only in nwamd
      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 _STRUCTURES_H
     28 #define	_STRUCTURES_H
     29 
     30 #include <search.h>
     31 #include <net/if.h>
     32 #include <libscf.h>
     33 #include <libdlwlan.h>
     34 #include <libnwam.h>
     35 
     36 /*
     37  * XXX More work on the state machine is needed.  In the future,
     38  * events will be more like EV_NEWADDR, identifying the actual
     39  * event that we care about, rather than the source of the event
     40  * that we originally implemented.  It's a bit of a mix
     41  * right now.
     42  */
     43 enum np_event_type {
     44 	EV_LINKDROP,		/* IFF_RUNNING flag dropped */
     45 	EV_LINKUP,		/* Wired link is up */
     46 	EV_LINKFADE,		/* Wireless link has poor signal */
     47 	EV_LINKDISC,		/* Wireless link has disconnected */
     48 	EV_NEWAP,		/* New AP in list / wireless link up */
     49 	EV_USER,		/* User altered interface priority */
     50 	EV_TIMER,		/* Timer(s) have expired */
     51 	EV_SHUTDOWN,		/* Nwamd is shutting down */
     52 	EV_NEWADDR,		/* Address established on interface */
     53 	EV_RESELECT,		/* Client disconnect; retry operations */
     54 	EV_DOOR_TIME,		/* Door server needs new timer */
     55 	EV_ADDIF,		/* New interface detected */
     56 	EV_REMIF,		/* Old interface removed */
     57 	EV_TAKEDOWN		/* Take interface down; AP reselected */
     58 };
     59 
     60 /*
     61  * Three-valued return types; used for cases where the processing terminates in
     62  * a wait for the user.
     63  */
     64 typedef enum {
     65 	SUCCESS = 0,
     66 	FAILURE,
     67 	WAITING
     68 } return_vals_t;
     69 
     70 struct np_event {
     71 	enum np_event_type npe_type;
     72 	char *npe_name;
     73 	struct np_event *npe_next;
     74 };
     75 
     76 /*
     77  * This structure is used to represent the current state of the system.  We
     78  * maintain these for IPv4 as proxies for links in the system.  This is
     79  * differentiated from the LLP which contains the intended configuration of
     80  * the system.
     81  *
     82  * Currently these are stored on ifs_head with the wired interfaces sorted
     83  * together and the wireless ones sorted together with ifs_wired and
     84  * ifs_wireless pointed at these sublists.  Access to these lists is not
     85  * currently MT-safe.
     86  *
     87  * We explicitly do not maintain IPv6 interface structures.  In the current
     88  * state machine, IPv6 interfaces are completely dependent on their IPv4
     89  * counterparts.  For example, we make a decision to bring up an interface
     90  * based on routing socket messages read from an AF_INET socket; we will
     91  * always bring up v4, and may additionally bring up v6.  Also, when we
     92  * start up, we find all interfaces in the system by doing 'ifconfig -a
     93  * plumb', which will plumb v4 on all links; we always keep the v4 interface
     94  * plumbed, taking it up and down depending on whether it's currently in use
     95  * or not.  v6 interfaces are not plumbed initially; when we decide a link
     96  * should be active (and its llp tells us to do v6), we'll mark the (already
     97  * existing) v4 interface up, and 'plumb up' the v6 interface.  Conversely,
     98  * when a link is no longer active, we 'down unplumb' the v6 interface, but
     99  * only 'down' the v4 interface.
    100  */
    101 struct interface {
    102 	char if_name[LIFNAMSIZ];
    103 	sa_family_t if_family;
    104 	uint64_t if_flags;
    105 	uint32_t if_lflags;
    106 	libnwam_interface_type_t if_type;
    107 	uint32_t if_timer_expire;
    108 	boolean_t if_v6onlink;
    109 	boolean_t if_up_attempted;
    110 	dladm_wlan_strength_t if_strength;
    111 	in_addr_t if_ipv4addr;
    112 	pthread_t if_thr;
    113 	struct interface *if_next;
    114 };
    115 
    116 /*
    117  * interface local flag values
    118  */
    119 /*
    120  * IF_DHCPFAILED: indicates that we timed out a dhcp request.  Will be
    121  * cleared if the request eventually succeeds, or if the IFF_RUNNING flag
    122  * is toggled off/on (i.e. the cable is unplugged/plugged)
    123  */
    124 #define	IF_DHCPFAILED	0x01
    125 /*
    126  * IF_DHCPSTARTED: much like IFF_DHCPRUNNING; but means specifically that
    127  * we have inititated dhcp on this interface.  Used to prevent overlapping
    128  * invocations of dhcp.
    129  */
    130 #define	IF_DHCPSTARTED	0x02
    131 /*
    132  * IF_DHCPACQUIRED: indicates that dhcp successfully acquired a lease.
    133  */
    134 #define	IF_DHCPACQUIRED	0x04
    135 
    136 #define	IF_DHCPFLAGS	(IF_DHCPFAILED | IF_DHCPSTARTED | IF_DHCPACQUIRED)
    137 
    138 /*
    139  * This structure contains the intended configuration of the system as
    140  * differentiated from the actual IPv4 configuration of the system represented
    141  * by the interface structures.
    142  *
    143  * llp structures are held on the list llp_head.  Access to this list is
    144  * protected by llp_lock.
    145  */
    146 typedef struct llp {
    147 	struct qelem llp_links;
    148 	char	llp_lname[LIFNAMSIZ];
    149 	int	llp_pri;		/* lower number => higher priority */
    150 	int	llp_fileorder;
    151 	libnwam_interface_type_t llp_type;
    152 	boolean_t llp_failed;		/* interface bringup failed */
    153 	boolean_t llp_waiting;		/* waiting for user interface */
    154 	libnwam_ipv4src_t llp_ipv4src;
    155 	char	*llp_ipv4addrstr;	/* if ipsrc is STATIC */
    156 	char	*llp_ipv6addrstr;	/* if the user provided a static addr */
    157 	boolean_t llp_ipv6onlink;	/* true if we plumb up a v6 interface */
    158 
    159 	/* These are used only with door communication */
    160 	boolean_t llp_dhcp_failed;
    161 	boolean_t llp_link_up;
    162 	boolean_t llp_need_wlan;
    163 	boolean_t llp_need_key;
    164 } llp_t;
    165 
    166 /*
    167  * The wireless module uses a separate thread to check AP status and scan for
    168  * AP changes.  Some wireless operations (such as scanning) may take a long
    169  * time.  For that reason, we maintain our own wireless interface structure to
    170  * keep interface-specific wireless state.
    171  */
    172 typedef struct wireless_if_s {
    173 	struct qelem wi_links;
    174 	char wi_name[LIFNAMSIZ];
    175 	datalink_id_t wi_linkid;
    176 	boolean_t wi_scan_running;
    177 	boolean_t wi_wireless_done;
    178 	boolean_t wi_need_key;
    179 	dladm_wlan_strength_t wi_strength;
    180 } wireless_if_t;
    181 
    182 /*
    183  * These entries are user allocated and should be managed by whoever
    184  * originates the structure.
    185  */
    186 struct wireless_lan {
    187 	dladm_wlan_attr_t attrs;
    188 	boolean_t known;
    189 	boolean_t connected;
    190 	boolean_t scanned;
    191 	boolean_t rescan;
    192 	char *essid;
    193 	char *bssid;
    194 	char *signal_strength;
    195 	char *raw_key;
    196 	dladm_wlan_key_t *cooked_key;
    197 	char wl_if_name[LIFNAMSIZ];
    198 };
    199 
    200 /*
    201  * A holder for all the resources needed to get a property value
    202  * using libscf.
    203  */
    204 typedef struct scf_resources {
    205 	scf_handle_t *sr_handle;
    206 	scf_instance_t *sr_inst;
    207 	scf_snapshot_t *sr_snap;
    208 	scf_propertygroup_t *sr_pg;
    209 	scf_property_t *sr_prop;
    210 	scf_value_t *sr_val;
    211 } scf_resources_t;
    212 
    213 /*
    214  * These are used to deliver events to the GUI.  See door.c and libnwam.
    215  */
    216 typedef struct nwam_descr_event_s {
    217 	libnwam_descr_evtype_t	nde_type;
    218 	libnwam_diag_cause_t	nde_cause;
    219 	struct in_addr		nde_v4address;
    220 	int			nde_prefixlen;
    221 	dladm_wlan_attr_t	nde_attrs;
    222 	struct wireless_lan	*nde_wlans;
    223 	size_t			nde_wlansize;
    224 	char			nde_interface[LIFNAMSIZ];
    225 } nwam_descr_event_t;
    226 
    227 typedef enum nwam_door_cmd_type_e {
    228 	ndcNull,
    229 	ndcWaitEvent,
    230 	ndcGetLLPList,
    231 	ndcSetLLPPriority,
    232 	ndcLockLLP,
    233 	ndcGetWlanList,
    234 	ndcSelectWlan,
    235 	ndcWlanKey,
    236 	ndcStartRescan,
    237 	ndcGetKnownAPList,
    238 	ndcAddKnownAP,
    239 	ndcDeleteKnownAP
    240 } nwam_door_cmd_type_t;
    241 
    242 typedef struct nwam_door_cmd_s {
    243 	nwam_door_cmd_type_t	ndc_type;
    244 	char			ndc_interface[LIFNAMSIZ];
    245 	int			ndc_priority;
    246 	char			ndc_essid[DLADM_STRSIZE];
    247 	char			ndc_bssid[DLADM_STRSIZE];
    248 	char			ndc_key[DLADM_STRSIZE];
    249 	char			ndc_secmode[DLADM_STRSIZE];
    250 } nwam_door_cmd_t;
    251 
    252 typedef struct nwam_llp_data_s {
    253 	uint_t	nld_count;		/* number of llp_t struct following */
    254 	char	nld_selected[LIFNAMSIZ];
    255 	char	nld_locked[LIFNAMSIZ];
    256 } nwam_llp_data_t;
    257 
    258 typedef struct nwam_known_ap_s {
    259 	uint_t	nka_count;		/* number of libnwam_known_ap_t */
    260 } nwam_known_ap_t;
    261 
    262 #endif /* _STRUCTURES_H */
    263