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.
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.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * This file contains hidden implementation structures and APIs of libnwam,
28 * and is not installed in the proto area. Implementation is MT safe.
32 #ifndef _LIBNWAM_IMPL_H
33 #define _LIBNWAM_IMPL_H
39 #include <libnwam_priv.h>
43 * We separate global flags (which are applicable to all object types) from
44 * local flags (which only apply to specific object types). These definitions
45 * mask off the global vs. local portions of the flags value, with the former
46 * being the low-order 32 bits and the latter the high-order 32 bits.
48 #define NWAM_FLAG_GLOBAL_MASK 0xFFFFFFFF
49 #define NWAM_FLAG_LOCAL_MASK 0xFFFFFFFFULL << 32
50 #define NWAM_WALK_FILTER_MASK NWAM_FLAG_LOCAL_MASK
53 * Maximum object size is the size of a maximally-sized name/values property
54 * multiplied by the maximum number of properties. The maximum object size
55 * and the maximum number of objects are used to determine how much space
56 * needs to be allocated for door calls to retrieve objects from the
59 #define NWAM_MAX_OBJECT_LEN \
60 ((NWAM_MAX_NAME_LEN + \
61 (NWAM_MAX_VALUE_LEN * NWAM_MAX_NUM_VALUES)) * \
62 NWAM_MAX_NUM_PROPERTIES)
64 #define NWAM_MAX_NUM_OBJECTS 4192
66 #define NWAM_MAX_OBJECT_LIST_LEN \
67 (NWAM_MAX_NUM_OBJECTS * NWAM_MAX_NAME_LEN)
69 #define NWAM_BACKEND_DOOR_ARG_SIZE \
70 (sizeof (nwam_backend_door_arg_t) + \
71 (NWAM_MAX_OBJECT_LEN > NWAM_MAX_OBJECT_LIST_LEN ? \
72 NWAM_MAX_OBJECT_LEN : NWAM_MAX_OBJECT_LIST_LEN))
75 #define NWAMD_DOOR_ARG_SIZE \
76 (sizeof (nwamd_door_arg_t) + \
77 (NWAMD_MAX_NUM_WLANS * sizeof (nwam_wlan_t));
79 #define NWAM_CONF_DIR "/etc/nwam/"
81 #define NWAM_LOC_OBJECT_STRING "loc"
82 #define NWAM_LOC_CONF_FILE NWAM_CONF_DIR "loc.conf"
85 nwam_object_type_t nwh_object_type
;
86 char nwh_name
[NWAM_MAX_NAME_LEN
];
87 boolean_t nwh_committed
;
91 #define NWAM_OBJECT_NAMES_STRING "object-names"
92 #define NWAM_NCP_OBJECT_STRING "ncp"
93 #define NWAM_NCP_CONF_FILE_PRE "ncp-"
94 #define NWAM_NCP_CONF_FILE_SUF ".conf"
95 #define NWAM_NCU_LINK_NAME_PRE "link:"
96 #define NWAM_NCU_INTERFACE_NAME_PRE "interface:"
99 nwam_value_type_t nwv_value_type
;
100 uint_t nwv_value_numvalues
;
102 boolean_t
*nwv_boolean
;
104 uint64_t *nwv_uint64
;
109 /* Used in property table retrieval of property attributes */
110 #define NWAM_TYPE_ANY 1
111 #define NWAM_CLASS_ANY 1
113 typedef nwam_error_t (*nwam_prop_validate_func_t
)(nwam_value_t
);
115 /* Used to hold validation/description data for properties */
116 struct nwam_prop_table_entry
{
117 const char *prop_name
;
118 nwam_value_type_t prop_type
;
119 boolean_t prop_is_readonly
;
120 uint_t prop_min_numvalues
;
121 uint_t prop_max_numvalues
;
122 nwam_prop_validate_func_t prop_validate
;
123 const char *prop_description
;
124 uint64_t prop_type_membership
;
125 uint64_t prop_class_membership
;
128 struct nwam_prop_table
{
130 struct nwam_prop_table_entry
*entries
;
133 #define NWAM_ENM_OBJECT_STRING "enm"
134 #define NWAM_ENM_CONF_FILE NWAM_CONF_DIR "enm.conf"
136 #define NWAM_KNOWN_WLAN_OBJECT_STRING "known-wlan"
137 #define NWAM_KNOWN_WLAN_CONF_FILE NWAM_CONF_DIR "known-wlan.conf"
139 /* Definitions that are used to map uint64 property values to strings */
140 #define NWAM_ACTIVATION_MODE_MANUAL_STRING "manual"
141 #define NWAM_ACTIVATION_MODE_SYSTEM_STRING "system"
142 #define NWAM_ACTIVATION_MODE_PRIORITIZED_STRING "prioritized"
143 #define NWAM_ACTIVATION_MODE_CONDITIONAL_ANY_STRING "conditional-any"
144 #define NWAM_ACTIVATION_MODE_CONDITIONAL_ALL_STRING "conditional-all"
146 #define NWAM_CONDITION_IS_STRING "is"
147 #define NWAM_CONDITION_IS_NOT_STRING "is-not"
148 #define NWAM_CONDITION_IS_IN_RANGE_STRING "is-in-range"
149 #define NWAM_CONDITION_IS_NOT_IN_RANGE_STRING "is-not-in-range"
150 #define NWAM_CONDITION_CONTAINS_STRING "contains"
151 #define NWAM_CONDITION_DOES_NOT_CONTAIN_STRING "does-not-contain"
153 #define NWAM_CONDITION_OBJECT_TYPE_NCP_STRING "ncp"
154 #define NWAM_CONDITION_OBJECT_TYPE_NCU_STRING "ncu"
155 #define NWAM_CONDITION_OBJECT_TYPE_ENM_STRING "enm"
156 #define NWAM_CONDITION_OBJECT_TYPE_LOC_STRING "loc"
157 #define NWAM_CONDITION_OBJECT_TYPE_IP_ADDRESS_STRING "ip-address"
158 #define NWAM_CONDITION_OBJECT_TYPE_ADV_DOMAIN_STRING "advertised-domain"
159 #define NWAM_CONDITION_OBJECT_TYPE_SYS_DOMAIN_STRING "system-domain"
160 #define NWAM_CONDITION_OBJECT_TYPE_ESSID_STRING "essid"
161 #define NWAM_CONDITION_OBJECT_TYPE_BSSID_STRING "bssid"
163 #define NWAM_CONDITION_ACTIVE_STRING "active"
165 #define NWAM_NAMESERVICES_DNS_STRING "dns"
166 #define NWAM_NAMESERVICES_FILES_STRING "files"
167 #define NWAM_NAMESERVICES_NIS_STRING "nis"
168 #define NWAM_NAMESERVICES_LDAP_STRING "ldap"
170 #define NWAM_CONFIGSRC_MANUAL_STRING "manual"
171 #define NWAM_CONFIGSRC_DHCP_STRING "dhcp"
173 #define NWAM_NCU_TYPE_LINK_STRING "link"
174 #define NWAM_NCU_TYPE_INTERFACE_STRING "interface"
176 #define NWAM_NCU_CLASS_PHYS_STRING "phys"
177 #define NWAM_NCU_CLASS_IP_STRING "ip"
179 #define NWAM_IP_VERSION_IPV4_STRING "ipv4"
180 #define NWAM_IP_VERSION_IPV6_STRING "ipv6"
182 #define NWAM_ADDRSRC_DHCP_STRING "dhcp"
183 #define NWAM_ADDRSRC_AUTOCONF_STRING "autoconf"
184 #define NWAM_ADDRSRC_STATIC_STRING "static"
186 #define NWAM_PRIORITY_MODE_EXCLUSIVE_STRING "exclusive"
187 #define NWAM_PRIORITY_MODE_SHARED_STRING "shared"
188 #define NWAM_PRIORITY_MODE_ALL_STRING "all"
191 * Functions that interact with nwamd's door server to request
192 * object actions, states or to register for receipt of events from nwamd.
193 * See libnwam_door.c.
195 extern nwam_error_t
nwam_request_register_unregister(nwam_request_type_t
,
197 extern nwam_error_t
nwam_request_action(nwam_object_type_t
, const char *,
198 const char *, nwam_action_t
);
199 extern nwam_error_t
nwam_request_state(nwam_object_type_t
, const char *,
200 const char *, nwam_state_t
*, nwam_aux_state_t
*);
201 extern nwam_error_t
nwam_request_wlan(nwam_request_type_t
, const char *,
202 const char *, const char *, uint32_t, uint_t
, const char *, boolean_t
);
203 extern nwam_error_t
nwam_request_wlan_scan_results(const char *name
,
204 uint_t
*, nwam_wlan_t
**);
205 extern nwam_error_t
nwam_request_active_priority_group(int64_t *);
208 * Functions that access and manipulate backend representation of data -
209 * see libnwam_backend.c.
211 extern nwam_error_t
nwam_read_object_from_backend(char *, char *,
213 extern nwam_error_t
nwam_update_object_in_backend(char *, char *,
215 extern nwam_error_t
nwam_remove_object_from_backend(char *, char *,
219 * Functions that handle files-specific backend persistent representation
220 * of data - see libnwam_files.c.
222 extern nwam_error_t
nwam_read_object_from_files_backend(char *,
223 char *, uint64_t, void *);
224 extern nwam_error_t
nwam_update_object_in_files_backend(char *,
225 char *, uint64_t, void *);
226 extern nwam_error_t
nwam_remove_object_from_files_backend(char *,
230 * Utility functions for nwam data (values and lists of values) associated
231 * with objects - see libnwam_values.c.
233 nwam_error_t
nwam_alloc_object_list(void *);
234 void nwam_free_object_list(void *);
235 nwam_error_t
nwam_object_list_add_object_list(void *, char *, void *);
236 nwam_error_t
nwam_object_list_remove_object_list(void *, char *);
237 nwam_error_t
nwam_dup_object_list(void *, void *);
238 nwam_error_t
nwam_next_object_list(void *, char *, char **, void *);
239 nwam_error_t
nwam_next_object_prop(void *, char *, char **, nwam_value_t
*);
240 extern nwam_error_t
nwam_pack_object_list(void *, char **, size_t *);
241 extern nwam_error_t
nwam_unpack_object_list(char *, size_t, void *);
243 extern const char *nwam_value_type_to_string(nwam_value_type_t
);
244 extern nwam_value_type_t
nwam_string_to_value_type(const char *);
245 extern nwam_error_t
nwam_delete_prop(void *, const char *);
246 extern nwam_error_t
nwam_set_prop_value(void *, const char *, nwam_value_t
);
247 extern nwam_error_t
nwam_get_prop_value(void *, const char *, nwam_value_t
*);
250 * Utility functions for nwam objects (NCUs, ENMs, locations and known WLANs).
251 * See libnwam_object.c.
253 nwam_error_t
nwam_handle_create(nwam_object_type_t
, const char *,
254 struct nwam_handle
**);
255 nwam_error_t
nwam_read(nwam_object_type_t
, const char *, const char *,
256 uint64_t, struct nwam_handle
**);
257 nwam_error_t
nwam_create(nwam_object_type_t
, const char *, const char *,
258 struct nwam_handle
**);
259 nwam_error_t
nwam_get_name(struct nwam_handle
*, char **);
260 nwam_error_t
nwam_set_name(struct nwam_handle
*, const char *);
261 nwam_error_t
nwam_walk(nwam_object_type_t
, const char *,
262 int(*)(struct nwam_handle
*, void *), void *, uint64_t, int *,
263 int(*)(struct nwam_handle
*, uint64_t, void *));
264 void nwam_free(struct nwam_handle
*);
265 nwam_error_t
nwam_copy(const char *, struct nwam_handle
*, const char *,
266 struct nwam_handle
**);
267 nwam_error_t
nwam_walk_props(struct nwam_handle
*,
268 int(*)(const char *, nwam_value_t
, void *), void *, uint64_t, int *);
269 nwam_error_t
nwam_commit(const char *, struct nwam_handle
*, uint64_t);
270 nwam_error_t
nwam_destroy(const char *, struct nwam_handle
*, uint64_t);
271 nwam_error_t
nwam_enable(const char *, struct nwam_handle
*);
272 nwam_error_t
nwam_disable(const char *, struct nwam_handle
*);
273 struct nwam_prop_table_entry
*nwam_get_prop_table_entry(struct nwam_prop_table
,
275 nwam_error_t
nwam_get_prop_description(struct nwam_prop_table
, const char *,
277 nwam_error_t
nwam_get_prop_type(struct nwam_prop_table
, const char *,
278 nwam_value_type_t
*);
279 nwam_error_t
nwam_prop_multivalued(struct nwam_prop_table
, const char *,
281 nwam_error_t
nwam_prop_read_only(struct nwam_prop_table
, const char *,
283 nwam_error_t
nwam_validate_prop(struct nwam_prop_table
, struct nwam_handle
*,
284 const char *, nwam_value_t
);
285 nwam_error_t
nwam_validate(struct nwam_prop_table
, struct nwam_handle
*,
287 nwam_error_t
nwam_get_default_proplist(struct nwam_prop_table
, uint64_t,
288 uint64_t, const char ***, uint_t
*);
289 nwam_error_t
nwam_get_state(const char *, struct nwam_handle
*, nwam_state_t
*,
293 * Generic validation functions - see libnwam_util.c.
295 extern nwam_error_t
nwam_valid_flags(uint64_t, uint64_t);
296 extern nwam_error_t
nwam_valid_condition(nwam_value_t
);
297 extern nwam_error_t
nwam_valid_boolean(nwam_value_t
);
298 extern nwam_error_t
nwam_valid_uint64(nwam_value_t
);
299 extern nwam_error_t
nwam_valid_domain(nwam_value_t
);
300 extern nwam_error_t
nwam_valid_host_any(nwam_value_t
);
301 extern nwam_error_t
nwam_valid_host_v4(nwam_value_t
);
302 extern nwam_error_t
nwam_valid_route_v4(nwam_value_t
);
303 extern nwam_error_t
nwam_valid_host_v6(nwam_value_t
);
304 extern nwam_error_t
nwam_valid_route_v6(nwam_value_t
);
305 extern nwam_error_t
nwam_valid_host_or_domain(nwam_value_t
);
306 extern nwam_error_t
nwam_valid_file(nwam_value_t
);
307 extern nwam_error_t
nwam_valid_fmri(nwam_value_t
);
308 extern nwam_error_t
nwam_valid_mac_addr(nwam_value_t
);
310 /* Misc. util functions */
311 extern boolean_t
nwam_uid_is_special(void);
312 extern nwam_error_t
nwam_set_smf_string_property(const char *, const char *,
313 const char *, const char *);
314 extern nwam_error_t
nwam_get_smf_string_property(const char *, const char *,
315 const char *, char **);
316 extern int nwam_make_door_call(const char *, int *, void *, size_t);
317 extern nwam_error_t
nwam_errno_to_nwam_error(int);
319 /* Needed in libnwam_files.c to check if NCP filename is valid */
320 extern nwam_error_t
nwam_ncp_file_to_name(const char *path
, char **name
);
326 #endif /* _LIBNWAM_IMPL_H */