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 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * This file contains private data structures and APIs of libnwam.  Currently
28  * these are used by nwamd (nwam_event_*() and nwam_record_audit_event()) and
29  * netcfgd (nwam_backend_*()) only, supporting the event messaging, audit
30  * and backend configuration access that nwamd and netcfgd supply.
31  *
32  * Implementation is MT safe.
33  */
34 #ifndef _LIBNWAM_PRIV_H
35 #define	_LIBNWAM_PRIV_H
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #include <libnwam.h>
42 
43 /* Name of directory containing the doors */
44 #define	NWAM_DOOR_DIR		"/etc/svc/volatile/nwam"
45 
46 /* Name of door used to communicate with libnwam backend (in netcfgd) */
47 #define	NWAM_BACKEND_DOOR_FILE	NWAM_DOOR_DIR "/nwam_backend_door"
48 
49 /* Name of door used to communicate with nwamd */
50 #define	NWAM_DOOR		NWAM_DOOR_DIR "/nwam_door"
51 
52 /* Requests to nwamd door */
53 typedef enum {
54 	NWAM_REQUEST_TYPE_NOOP,
55 	NWAM_REQUEST_TYPE_EVENT_REGISTER,
56 	NWAM_REQUEST_TYPE_EVENT_UNREGISTER,
57 	NWAM_REQUEST_TYPE_ACTION,
58 	NWAM_REQUEST_TYPE_STATE,
59 	NWAM_REQUEST_TYPE_PRIORITY_GROUP,
60 	NWAM_REQUEST_TYPE_WLAN_SCAN,
61 	NWAM_REQUEST_TYPE_WLAN_SCAN_RESULTS,
62 	NWAM_REQUEST_TYPE_WLAN_SELECT,
63 	NWAM_REQUEST_TYPE_WLAN_SET_KEY
64 } nwam_request_type_t;
65 
66 /* Status returned by nwamd door */
67 typedef enum {
68 	NWAM_REQUEST_STATUS_OK,
69 	NWAM_REQUEST_STATUS_FAILED,
70 	NWAM_REQUEST_STATUS_UNKNOWN,
71 	NWAM_REQUEST_STATUS_ALREADY
72 } nwam_request_status_t;
73 
74 #define	NWAMD_MAX_NUM_WLANS	64
75 
76 typedef union {
77 	/* Used for EVENT_[UN]REGISTER requests */
78 	struct nwdad_register_info {
79 		char nwdad_name[MAXPATHLEN];
80 	} nwdad_register_info;
81 
82 	/* Used for ACTION requests */
83 	struct nwdad_object_action {
84 		nwam_object_type_t nwdad_object_type;
85 		char nwdad_name[NWAM_MAX_NAME_LEN];
86 		char nwdad_parent[NWAM_MAX_NAME_LEN];
87 		nwam_action_t nwdad_action;
88 	} nwdad_object_action;
89 
90 	/* Used for STATE requests */
91 	struct nwdad_object_state {
92 		nwam_object_type_t nwdad_object_type;
93 		char nwdad_name[NWAM_MAX_NAME_LEN];
94 		char nwdad_parent[NWAM_MAX_NAME_LEN];
95 		nwam_state_t nwdad_state;
96 		nwam_aux_state_t nwdad_aux_state;
97 	} nwdad_object_state;
98 
99 	/* Used for PRIORITY_GROUP requests */
100 	struct nwdad_priority_group_info {
101 		int64_t nwdad_priority;
102 	} nwdad_priority_group_info;
103 
104 	/* Used for WLAN request/responses */
105 	struct nwdad_wlan_info {
106 		char nwdad_name[NWAM_MAX_NAME_LEN];
107 		char nwdad_essid[NWAM_MAX_NAME_LEN];
108 		char nwdad_bssid[NWAM_MAX_NAME_LEN];
109 		uint32_t nwdad_security_mode;
110 		char nwdad_key[NWAM_MAX_NAME_LEN];
111 		uint_t nwdad_keyslot;
112 		boolean_t nwdad_add_to_known_wlans;
113 		uint_t nwdad_num_wlans;
114 		nwam_wlan_t nwdad_wlans[NWAMD_MAX_NUM_WLANS];
115 	} nwdad_wlan_info;
116 
117 } nwamd_door_arg_data_t;
118 
119 typedef struct {
120 	nwam_request_type_t nwda_type;
121 	nwam_request_status_t nwda_status;
122 	nwam_error_t nwda_error;
123 	uint32_t nwda_align;				/* for next member */
124 	nwamd_door_arg_data_t nwda_data;
125 } nwamd_door_arg_t;
126 
127 typedef enum {
128 	NWAM_BACKEND_DOOR_CMD_READ_REQ,
129 	NWAM_BACKEND_DOOR_CMD_UPDATE_REQ,
130 	NWAM_BACKEND_DOOR_CMD_REMOVE_REQ
131 } nwam_backend_door_cmd_t;
132 
133 typedef struct nwam_backend_door_arg {
134 	nwam_backend_door_cmd_t nwbda_cmd;
135 	char nwbda_dbname[MAXPATHLEN];			/* config filename */
136 	char nwbda_object[NWAM_MAX_NAME_LEN];		/* config object */
137 	uint32_t nwbda_datalen;				/* data follows arg */
138 	nwam_error_t nwbda_result;			/* return code */
139 	uint32_t nwbda_align;				/* for next member */
140 	uint64_t nwbda_flags;
141 } nwam_backend_door_arg_t;
142 
143 /*
144  * Functions needed to initialize/stop processing of libnwam backend data
145  * (used in netcfgd).
146  */
147 extern nwam_error_t nwam_backend_init(void);
148 extern void nwam_backend_fini(void);
149 
150 /*
151  * create audit session, report event, end session.  Used by nwamd.
152  */
153 extern void nwam_record_audit_event(const ucred_t *, au_event_t, char *, char *,
154     int, int);
155 
156 /*
157  * NWAM daemon functions, used to send, stop sending, initialize or finish
158  * event IPC.  Used by nwamd.
159  */
160 extern nwam_error_t nwam_event_send(nwam_event_t);
161 extern void nwam_event_send_fini(void);
162 extern nwam_error_t nwam_event_queue_init(const char *);
163 extern void nwam_event_queue_fini(const char *);
164 
165 #ifdef	__cplusplus
166 }
167 #endif
168 
169 #endif	/* _LIBNWAM_PRIV_H */
170