1*6ba597c5SAnurag S. Maskey /*
2*6ba597c5SAnurag S. Maskey * CDDL HEADER START
3*6ba597c5SAnurag S. Maskey *
4*6ba597c5SAnurag S. Maskey * The contents of this file are subject to the terms of the
5*6ba597c5SAnurag S. Maskey * Common Development and Distribution License (the "License").
6*6ba597c5SAnurag S. Maskey * You may not use this file except in compliance with the License.
7*6ba597c5SAnurag S. Maskey *
8*6ba597c5SAnurag S. Maskey * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6ba597c5SAnurag S. Maskey * or http://www.opensolaris.org/os/licensing.
10*6ba597c5SAnurag S. Maskey * See the License for the specific language governing permissions
11*6ba597c5SAnurag S. Maskey * and limitations under the License.
12*6ba597c5SAnurag S. Maskey *
13*6ba597c5SAnurag S. Maskey * When distributing Covered Code, include this CDDL HEADER in each
14*6ba597c5SAnurag S. Maskey * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6ba597c5SAnurag S. Maskey * If applicable, add the following below this CDDL HEADER, with the
16*6ba597c5SAnurag S. Maskey * fields enclosed by brackets "[]" replaced with your own identifying
17*6ba597c5SAnurag S. Maskey * information: Portions Copyright [yyyy] [name of copyright owner]
18*6ba597c5SAnurag S. Maskey *
19*6ba597c5SAnurag S. Maskey * CDDL HEADER END
20*6ba597c5SAnurag S. Maskey */
21*6ba597c5SAnurag S. Maskey
22*6ba597c5SAnurag S. Maskey /*
23*6ba597c5SAnurag S. Maskey * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24*6ba597c5SAnurag S. Maskey * Use is subject to license terms.
25*6ba597c5SAnurag S. Maskey */
26*6ba597c5SAnurag S. Maskey
27*6ba597c5SAnurag S. Maskey #include <assert.h>
28*6ba597c5SAnurag S. Maskey #include <ctype.h>
29*6ba597c5SAnurag S. Maskey #include <sys/param.h>
30*6ba597c5SAnurag S. Maskey #include <sys/types.h>
31*6ba597c5SAnurag S. Maskey #include <sys/stat.h>
32*6ba597c5SAnurag S. Maskey #include <stdio.h>
33*6ba597c5SAnurag S. Maskey #include <stdlib.h>
34*6ba597c5SAnurag S. Maskey #include <strings.h>
35*6ba597c5SAnurag S. Maskey #include <unistd.h>
36*6ba597c5SAnurag S. Maskey #include <libscf.h>
37*6ba597c5SAnurag S. Maskey #include "libnwam_impl.h"
38*6ba597c5SAnurag S. Maskey #include <libnwam_priv.h>
39*6ba597c5SAnurag S. Maskey #include <libnwam.h>
40*6ba597c5SAnurag S. Maskey
41*6ba597c5SAnurag S. Maskey /*
42*6ba597c5SAnurag S. Maskey * Functions to support creating, modifying, destroying, querying the
43*6ba597c5SAnurag S. Maskey * state of and changing the state of ENM (External Network Modifier)
44*6ba597c5SAnurag S. Maskey * objects. ENMs represent services or scripts that can be enabled
45*6ba597c5SAnurag S. Maskey * either manually or conditionally for a combination of the set of
46*6ba597c5SAnurag S. Maskey * available conditions (an IP address is present, a location is active etc).
47*6ba597c5SAnurag S. Maskey */
48*6ba597c5SAnurag S. Maskey
49*6ba597c5SAnurag S. Maskey typedef nwam_error_t (*nwam_enm_prop_validate_func_t)(nwam_value_t);
50*6ba597c5SAnurag S. Maskey
51*6ba597c5SAnurag S. Maskey static nwam_error_t valid_enm_activation_mode(nwam_value_t);
52*6ba597c5SAnurag S. Maskey
53*6ba597c5SAnurag S. Maskey struct nwam_prop_table_entry enm_prop_table_entries[] = {
54*6ba597c5SAnurag S. Maskey {NWAM_ENM_PROP_ACTIVATION_MODE, NWAM_VALUE_TYPE_UINT64, B_FALSE, 1, 1,
55*6ba597c5SAnurag S. Maskey valid_enm_activation_mode,
56*6ba597c5SAnurag S. Maskey "specifies the ENM activation mode - valid values are:\n"
57*6ba597c5SAnurag S. Maskey "\'manual\', \'conditional-any\' and \'conditional-all\'",
58*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY},
59*6ba597c5SAnurag S. Maskey {NWAM_ENM_PROP_CONDITIONS, NWAM_VALUE_TYPE_STRING, B_FALSE, 0,
60*6ba597c5SAnurag S. Maskey NWAM_MAX_NUM_VALUES, nwam_valid_condition,
61*6ba597c5SAnurag S. Maskey "specifies the activation condition. Conditions are of the form:\n"
62*6ba597c5SAnurag S. Maskey "ncp|ncu|enm|loc name is|is-not active\n"
63*6ba597c5SAnurag S. Maskey "ip-address is|is-not|is-in-range|is-not-in-range| 1.2.3.4[/24]\n"
64*6ba597c5SAnurag S. Maskey "advertised-domain is|is-not|contains|does-not-contain string\n"
65*6ba597c5SAnurag S. Maskey "system-domain is|is-not|contains|does-not-contain string\n"
66*6ba597c5SAnurag S. Maskey "essid is|is-not|contains|does-not-contain string\n"
67*6ba597c5SAnurag S. Maskey "bssid is|is-not string",
68*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY},
69*6ba597c5SAnurag S. Maskey {NWAM_ENM_PROP_ENABLED, NWAM_VALUE_TYPE_BOOLEAN, B_TRUE, 0, 1,
70*6ba597c5SAnurag S. Maskey nwam_valid_boolean,
71*6ba597c5SAnurag S. Maskey "specifies if manual ENM is to be enabled",
72*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY},
73*6ba597c5SAnurag S. Maskey {NWAM_ENM_PROP_FMRI, NWAM_VALUE_TYPE_STRING, B_FALSE, 0, 1,
74*6ba597c5SAnurag S. Maskey nwam_valid_fmri,
75*6ba597c5SAnurag S. Maskey "specifies SMF FMRI of service to be enabled on ENM activation",
76*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY},
77*6ba597c5SAnurag S. Maskey {NWAM_ENM_PROP_START, NWAM_VALUE_TYPE_STRING, B_FALSE, 0, 1,
78*6ba597c5SAnurag S. Maskey nwam_valid_file,
79*6ba597c5SAnurag S. Maskey "specifies absolute path to start script to be run on ENM "
80*6ba597c5SAnurag S. Maskey "activation",
81*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY},
82*6ba597c5SAnurag S. Maskey {NWAM_ENM_PROP_STOP, NWAM_VALUE_TYPE_STRING, B_FALSE, 0, 1,
83*6ba597c5SAnurag S. Maskey nwam_valid_file,
84*6ba597c5SAnurag S. Maskey "specifies absolute path to stop script to be run on ENM "
85*6ba597c5SAnurag S. Maskey "deactivation",
86*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY}
87*6ba597c5SAnurag S. Maskey };
88*6ba597c5SAnurag S. Maskey
89*6ba597c5SAnurag S. Maskey #define NWAM_NUM_ENM_PROPS (sizeof (enm_prop_table_entries) / \
90*6ba597c5SAnurag S. Maskey sizeof (*enm_prop_table_entries))
91*6ba597c5SAnurag S. Maskey
92*6ba597c5SAnurag S. Maskey struct nwam_prop_table enm_prop_table =
93*6ba597c5SAnurag S. Maskey { NWAM_NUM_ENM_PROPS, enm_prop_table_entries };
94*6ba597c5SAnurag S. Maskey
95*6ba597c5SAnurag S. Maskey static uint64_t
nwam_enm_activation_to_flag(nwam_activation_mode_t activation)96*6ba597c5SAnurag S. Maskey nwam_enm_activation_to_flag(nwam_activation_mode_t activation)
97*6ba597c5SAnurag S. Maskey {
98*6ba597c5SAnurag S. Maskey switch (activation) {
99*6ba597c5SAnurag S. Maskey case NWAM_ACTIVATION_MODE_MANUAL:
100*6ba597c5SAnurag S. Maskey return (NWAM_FLAG_ACTIVATION_MODE_MANUAL);
101*6ba597c5SAnurag S. Maskey case NWAM_ACTIVATION_MODE_CONDITIONAL_ANY:
102*6ba597c5SAnurag S. Maskey return (NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ANY);
103*6ba597c5SAnurag S. Maskey case NWAM_ACTIVATION_MODE_CONDITIONAL_ALL:
104*6ba597c5SAnurag S. Maskey return (NWAM_FLAG_ACTIVATION_MODE_CONDITIONAL_ALL);
105*6ba597c5SAnurag S. Maskey default:
106*6ba597c5SAnurag S. Maskey return (0);
107*6ba597c5SAnurag S. Maskey }
108*6ba597c5SAnurag S. Maskey }
109*6ba597c5SAnurag S. Maskey
110*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_read(const char * name,uint64_t flags,nwam_enm_handle_t * enmhp)111*6ba597c5SAnurag S. Maskey nwam_enm_read(const char *name, uint64_t flags, nwam_enm_handle_t *enmhp)
112*6ba597c5SAnurag S. Maskey {
113*6ba597c5SAnurag S. Maskey return (nwam_read(NWAM_OBJECT_TYPE_ENM, NWAM_ENM_CONF_FILE, name,
114*6ba597c5SAnurag S. Maskey flags, enmhp));
115*6ba597c5SAnurag S. Maskey }
116*6ba597c5SAnurag S. Maskey
117*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_create(const char * name,const char * fmri,nwam_enm_handle_t * enmhp)118*6ba597c5SAnurag S. Maskey nwam_enm_create(const char *name, const char *fmri, nwam_enm_handle_t *enmhp)
119*6ba597c5SAnurag S. Maskey {
120*6ba597c5SAnurag S. Maskey nwam_error_t err;
121*6ba597c5SAnurag S. Maskey nwam_value_t actval = NULL, falseval = NULL, fmrival = NULL;
122*6ba597c5SAnurag S. Maskey
123*6ba597c5SAnurag S. Maskey assert(enmhp != NULL && name != NULL);
124*6ba597c5SAnurag S. Maskey
125*6ba597c5SAnurag S. Maskey if ((err = nwam_create(NWAM_OBJECT_TYPE_ENM, NWAM_ENM_CONF_FILE, name,
126*6ba597c5SAnurag S. Maskey enmhp)) != NWAM_SUCCESS)
127*6ba597c5SAnurag S. Maskey return (err);
128*6ba597c5SAnurag S. Maskey
129*6ba597c5SAnurag S. Maskey /*
130*6ba597c5SAnurag S. Maskey * Create new object list for ENM. The initial activation mode is set,
131*6ba597c5SAnurag S. Maskey * and the FMRI property is set, if specified.
132*6ba597c5SAnurag S. Maskey */
133*6ba597c5SAnurag S. Maskey if ((err = nwam_alloc_object_list(&((*enmhp)->nwh_data)))
134*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS)
135*6ba597c5SAnurag S. Maskey goto finish;
136*6ba597c5SAnurag S. Maskey
137*6ba597c5SAnurag S. Maskey if ((err = nwam_value_create_uint64(NWAM_ACTIVATION_MODE_MANUAL,
138*6ba597c5SAnurag S. Maskey &actval)) != NWAM_SUCCESS ||
139*6ba597c5SAnurag S. Maskey ((fmri != NULL) &&
140*6ba597c5SAnurag S. Maskey (err = nwam_value_create_string((char *)fmri, &fmrival))
141*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS) ||
142*6ba597c5SAnurag S. Maskey (err = nwam_value_create_boolean(B_FALSE, &falseval))
143*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS) {
144*6ba597c5SAnurag S. Maskey goto finish;
145*6ba597c5SAnurag S. Maskey }
146*6ba597c5SAnurag S. Maskey if ((err = nwam_set_prop_value((*enmhp)->nwh_data,
147*6ba597c5SAnurag S. Maskey NWAM_ENM_PROP_ACTIVATION_MODE, actval)) == NWAM_SUCCESS &&
148*6ba597c5SAnurag S. Maskey (err = nwam_set_prop_value((*enmhp)->nwh_data,
149*6ba597c5SAnurag S. Maskey NWAM_ENM_PROP_ENABLED, falseval)) == NWAM_SUCCESS) {
150*6ba597c5SAnurag S. Maskey if (fmri != NULL) {
151*6ba597c5SAnurag S. Maskey err = nwam_set_prop_value((*enmhp)->nwh_data,
152*6ba597c5SAnurag S. Maskey NWAM_ENM_PROP_FMRI, fmrival);
153*6ba597c5SAnurag S. Maskey }
154*6ba597c5SAnurag S. Maskey }
155*6ba597c5SAnurag S. Maskey
156*6ba597c5SAnurag S. Maskey finish:
157*6ba597c5SAnurag S. Maskey nwam_value_free(actval);
158*6ba597c5SAnurag S. Maskey nwam_value_free(falseval);
159*6ba597c5SAnurag S. Maskey if (fmrival != NULL)
160*6ba597c5SAnurag S. Maskey nwam_value_free(fmrival);
161*6ba597c5SAnurag S. Maskey
162*6ba597c5SAnurag S. Maskey if (err != NWAM_SUCCESS) {
163*6ba597c5SAnurag S. Maskey nwam_enm_free(*enmhp);
164*6ba597c5SAnurag S. Maskey *enmhp = NULL;
165*6ba597c5SAnurag S. Maskey }
166*6ba597c5SAnurag S. Maskey
167*6ba597c5SAnurag S. Maskey return (err);
168*6ba597c5SAnurag S. Maskey }
169*6ba597c5SAnurag S. Maskey
170*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_get_name(nwam_enm_handle_t enmh,char ** namep)171*6ba597c5SAnurag S. Maskey nwam_enm_get_name(nwam_enm_handle_t enmh, char **namep)
172*6ba597c5SAnurag S. Maskey {
173*6ba597c5SAnurag S. Maskey return (nwam_get_name(enmh, namep));
174*6ba597c5SAnurag S. Maskey }
175*6ba597c5SAnurag S. Maskey
176*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_set_name(nwam_enm_handle_t enmh,const char * name)177*6ba597c5SAnurag S. Maskey nwam_enm_set_name(nwam_enm_handle_t enmh, const char *name)
178*6ba597c5SAnurag S. Maskey {
179*6ba597c5SAnurag S. Maskey return (nwam_set_name(enmh, name));
180*6ba597c5SAnurag S. Maskey }
181*6ba597c5SAnurag S. Maskey
182*6ba597c5SAnurag S. Maskey boolean_t
nwam_enm_can_set_name(nwam_enm_handle_t enmh)183*6ba597c5SAnurag S. Maskey nwam_enm_can_set_name(nwam_enm_handle_t enmh)
184*6ba597c5SAnurag S. Maskey {
185*6ba597c5SAnurag S. Maskey return (!enmh->nwh_committed);
186*6ba597c5SAnurag S. Maskey }
187*6ba597c5SAnurag S. Maskey
188*6ba597c5SAnurag S. Maskey /* ARGSUSED2 */
189*6ba597c5SAnurag S. Maskey static int
enm_selectcb(struct nwam_handle * hp,uint64_t flags,void * data)190*6ba597c5SAnurag S. Maskey enm_selectcb(struct nwam_handle *hp, uint64_t flags, void *data)
191*6ba597c5SAnurag S. Maskey {
192*6ba597c5SAnurag S. Maskey nwam_enm_handle_t enmh = hp;
193*6ba597c5SAnurag S. Maskey uint64_t activation, actflag, walkfilter;
194*6ba597c5SAnurag S. Maskey nwam_value_t actval;
195*6ba597c5SAnurag S. Maskey
196*6ba597c5SAnurag S. Maskey /*
197*6ba597c5SAnurag S. Maskey * Get a bitmapped flag value corresponding to this enm's
198*6ba597c5SAnurag S. Maskey * activation value - if the activation value is not recognized,
199*6ba597c5SAnurag S. Maskey * actflag will be set to 0, and will thus fail to match
200*6ba597c5SAnurag S. Maskey * any bit flag passed in by the caller.
201*6ba597c5SAnurag S. Maskey */
202*6ba597c5SAnurag S. Maskey if (nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_ACTIVATION_MODE,
203*6ba597c5SAnurag S. Maskey &actval) != NWAM_SUCCESS) {
204*6ba597c5SAnurag S. Maskey return (NWAM_INVALID_ARG);
205*6ba597c5SAnurag S. Maskey }
206*6ba597c5SAnurag S. Maskey if (nwam_value_get_uint64(actval, &activation) != NWAM_SUCCESS) {
207*6ba597c5SAnurag S. Maskey nwam_value_free(actval);
208*6ba597c5SAnurag S. Maskey return (NWAM_INVALID_ARG);
209*6ba597c5SAnurag S. Maskey }
210*6ba597c5SAnurag S. Maskey
211*6ba597c5SAnurag S. Maskey actflag = nwam_enm_activation_to_flag(activation);
212*6ba597c5SAnurag S. Maskey nwam_value_free(actval);
213*6ba597c5SAnurag S. Maskey if ((walkfilter = flags & NWAM_WALK_FILTER_MASK) == 0)
214*6ba597c5SAnurag S. Maskey walkfilter = NWAM_FLAG_ACTIVATION_MODE_ALL;
215*6ba597c5SAnurag S. Maskey if (actflag & walkfilter)
216*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
217*6ba597c5SAnurag S. Maskey return (NWAM_INVALID_ARG);
218*6ba597c5SAnurag S. Maskey }
219*6ba597c5SAnurag S. Maskey
220*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_walk_enms(int (* cb)(nwam_enm_handle_t,void *),void * data,uint64_t flags,int * retp)221*6ba597c5SAnurag S. Maskey nwam_walk_enms(int(*cb)(nwam_enm_handle_t, void *), void *data, uint64_t flags,
222*6ba597c5SAnurag S. Maskey int *retp)
223*6ba597c5SAnurag S. Maskey {
224*6ba597c5SAnurag S. Maskey nwam_error_t err = nwam_valid_flags(flags,
225*6ba597c5SAnurag S. Maskey NWAM_FLAG_ACTIVATION_MODE_ALL | NWAM_FLAG_BLOCKING);
226*6ba597c5SAnurag S. Maskey
227*6ba597c5SAnurag S. Maskey if (err != NWAM_SUCCESS)
228*6ba597c5SAnurag S. Maskey return (err);
229*6ba597c5SAnurag S. Maskey
230*6ba597c5SAnurag S. Maskey return (nwam_walk(NWAM_OBJECT_TYPE_ENM, NWAM_ENM_CONF_FILE,
231*6ba597c5SAnurag S. Maskey cb, data, flags, retp, enm_selectcb));
232*6ba597c5SAnurag S. Maskey }
233*6ba597c5SAnurag S. Maskey
234*6ba597c5SAnurag S. Maskey void
nwam_enm_free(nwam_enm_handle_t enmh)235*6ba597c5SAnurag S. Maskey nwam_enm_free(nwam_enm_handle_t enmh)
236*6ba597c5SAnurag S. Maskey {
237*6ba597c5SAnurag S. Maskey nwam_free(enmh);
238*6ba597c5SAnurag S. Maskey }
239*6ba597c5SAnurag S. Maskey
240*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_copy(nwam_enm_handle_t oldenmh,const char * newname,nwam_enm_handle_t * newenmhp)241*6ba597c5SAnurag S. Maskey nwam_enm_copy(nwam_enm_handle_t oldenmh, const char *newname,
242*6ba597c5SAnurag S. Maskey nwam_enm_handle_t *newenmhp)
243*6ba597c5SAnurag S. Maskey {
244*6ba597c5SAnurag S. Maskey return (nwam_copy(NWAM_ENM_CONF_FILE, oldenmh, newname, newenmhp));
245*6ba597c5SAnurag S. Maskey }
246*6ba597c5SAnurag S. Maskey
247*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_delete_prop(nwam_enm_handle_t enmh,const char * propname)248*6ba597c5SAnurag S. Maskey nwam_enm_delete_prop(nwam_enm_handle_t enmh, const char *propname)
249*6ba597c5SAnurag S. Maskey {
250*6ba597c5SAnurag S. Maskey nwam_error_t err;
251*6ba597c5SAnurag S. Maskey boolean_t ro;
252*6ba597c5SAnurag S. Maskey void *olddata;
253*6ba597c5SAnurag S. Maskey boolean_t manual;
254*6ba597c5SAnurag S. Maskey
255*6ba597c5SAnurag S. Maskey assert(enmh != NULL && propname != NULL);
256*6ba597c5SAnurag S. Maskey
257*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_prop_read_only(propname, &ro)) != NWAM_SUCCESS)
258*6ba597c5SAnurag S. Maskey return (err);
259*6ba597c5SAnurag S. Maskey if (ro) {
260*6ba597c5SAnurag S. Maskey /*
261*6ba597c5SAnurag S. Maskey * If the activation-mode is not manual, allow the enabled
262*6ba597c5SAnurag S. Maskey * property to be deleted.
263*6ba597c5SAnurag S. Maskey */
264*6ba597c5SAnurag S. Maskey if (strcmp(propname, NWAM_ENM_PROP_ENABLED) != 0)
265*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_READ_ONLY);
266*6ba597c5SAnurag S. Maskey
267*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_is_manual(enmh, &manual)) != NWAM_SUCCESS)
268*6ba597c5SAnurag S. Maskey return (err);
269*6ba597c5SAnurag S. Maskey if (manual)
270*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_READ_ONLY);
271*6ba597c5SAnurag S. Maskey }
272*6ba597c5SAnurag S. Maskey
273*6ba597c5SAnurag S. Maskey /*
274*6ba597c5SAnurag S. Maskey * Duplicate data, remove property and validate. If validation
275*6ba597c5SAnurag S. Maskey * fails, revert to data duplicated prior to remove.
276*6ba597c5SAnurag S. Maskey */
277*6ba597c5SAnurag S. Maskey if ((err = nwam_dup_object_list(enmh->nwh_data, &olddata))
278*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS)
279*6ba597c5SAnurag S. Maskey return (err);
280*6ba597c5SAnurag S. Maskey if ((err = nwam_delete_prop(enmh->nwh_data, propname))
281*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS) {
282*6ba597c5SAnurag S. Maskey nwam_free_object_list(enmh->nwh_data);
283*6ba597c5SAnurag S. Maskey enmh->nwh_data = olddata;
284*6ba597c5SAnurag S. Maskey return (err);
285*6ba597c5SAnurag S. Maskey }
286*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_validate(enmh, NULL)) != NWAM_SUCCESS) {
287*6ba597c5SAnurag S. Maskey nwam_free_object_list(enmh->nwh_data);
288*6ba597c5SAnurag S. Maskey enmh->nwh_data = olddata;
289*6ba597c5SAnurag S. Maskey return (err);
290*6ba597c5SAnurag S. Maskey }
291*6ba597c5SAnurag S. Maskey nwam_free_object_list(olddata);
292*6ba597c5SAnurag S. Maskey
293*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
294*6ba597c5SAnurag S. Maskey }
295*6ba597c5SAnurag S. Maskey
296*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_set_prop_value(nwam_enm_handle_t enmh,const char * propname,nwam_value_t value)297*6ba597c5SAnurag S. Maskey nwam_enm_set_prop_value(nwam_enm_handle_t enmh, const char *propname,
298*6ba597c5SAnurag S. Maskey nwam_value_t value)
299*6ba597c5SAnurag S. Maskey {
300*6ba597c5SAnurag S. Maskey nwam_error_t err;
301*6ba597c5SAnurag S. Maskey boolean_t ro;
302*6ba597c5SAnurag S. Maskey
303*6ba597c5SAnurag S. Maskey assert(enmh != NULL && propname != NULL && value != NULL);
304*6ba597c5SAnurag S. Maskey
305*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_validate_prop(enmh, propname, value))
306*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS ||
307*6ba597c5SAnurag S. Maskey (err = nwam_enm_prop_read_only(propname, &ro)) != NWAM_SUCCESS)
308*6ba597c5SAnurag S. Maskey return (err);
309*6ba597c5SAnurag S. Maskey if (ro)
310*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_READ_ONLY);
311*6ba597c5SAnurag S. Maskey
312*6ba597c5SAnurag S. Maskey return (nwam_set_prop_value(enmh->nwh_data, propname, value));
313*6ba597c5SAnurag S. Maskey }
314*6ba597c5SAnurag S. Maskey
315*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_get_prop_value(nwam_enm_handle_t enmh,const char * propname,nwam_value_t * valuep)316*6ba597c5SAnurag S. Maskey nwam_enm_get_prop_value(nwam_enm_handle_t enmh, const char *propname,
317*6ba597c5SAnurag S. Maskey nwam_value_t *valuep)
318*6ba597c5SAnurag S. Maskey {
319*6ba597c5SAnurag S. Maskey return (nwam_get_prop_value(enmh->nwh_data, propname, valuep));
320*6ba597c5SAnurag S. Maskey }
321*6ba597c5SAnurag S. Maskey
322*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_walk_props(nwam_enm_handle_t enmh,int (* cb)(const char *,nwam_value_t,void *),void * data,uint64_t flags,int * retp)323*6ba597c5SAnurag S. Maskey nwam_enm_walk_props(nwam_enm_handle_t enmh,
324*6ba597c5SAnurag S. Maskey int (*cb)(const char *, nwam_value_t, void *),
325*6ba597c5SAnurag S. Maskey void *data, uint64_t flags, int *retp)
326*6ba597c5SAnurag S. Maskey {
327*6ba597c5SAnurag S. Maskey return (nwam_walk_props(enmh, cb, data, flags, retp));
328*6ba597c5SAnurag S. Maskey }
329*6ba597c5SAnurag S. Maskey
330*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_commit(nwam_enm_handle_t enmh,uint64_t flags)331*6ba597c5SAnurag S. Maskey nwam_enm_commit(nwam_enm_handle_t enmh, uint64_t flags)
332*6ba597c5SAnurag S. Maskey {
333*6ba597c5SAnurag S. Maskey nwam_error_t err;
334*6ba597c5SAnurag S. Maskey
335*6ba597c5SAnurag S. Maskey assert(enmh != NULL && enmh->nwh_data != NULL);
336*6ba597c5SAnurag S. Maskey
337*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_validate(enmh, NULL)) != NWAM_SUCCESS)
338*6ba597c5SAnurag S. Maskey return (err);
339*6ba597c5SAnurag S. Maskey
340*6ba597c5SAnurag S. Maskey return (nwam_commit(NWAM_ENM_CONF_FILE, enmh, flags));
341*6ba597c5SAnurag S. Maskey }
342*6ba597c5SAnurag S. Maskey
343*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_destroy(nwam_enm_handle_t enmh,uint64_t flags)344*6ba597c5SAnurag S. Maskey nwam_enm_destroy(nwam_enm_handle_t enmh, uint64_t flags)
345*6ba597c5SAnurag S. Maskey {
346*6ba597c5SAnurag S. Maskey return (nwam_destroy(NWAM_ENM_CONF_FILE, enmh, flags));
347*6ba597c5SAnurag S. Maskey }
348*6ba597c5SAnurag S. Maskey
349*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_get_prop_description(const char * propname,const char ** descriptionp)350*6ba597c5SAnurag S. Maskey nwam_enm_get_prop_description(const char *propname, const char **descriptionp)
351*6ba597c5SAnurag S. Maskey {
352*6ba597c5SAnurag S. Maskey return (nwam_get_prop_description(enm_prop_table, propname,
353*6ba597c5SAnurag S. Maskey descriptionp));
354*6ba597c5SAnurag S. Maskey }
355*6ba597c5SAnurag S. Maskey
356*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_prop_read_only(const char * propname,boolean_t * readp)357*6ba597c5SAnurag S. Maskey nwam_enm_prop_read_only(const char *propname, boolean_t *readp)
358*6ba597c5SAnurag S. Maskey {
359*6ba597c5SAnurag S. Maskey return (nwam_prop_read_only(enm_prop_table, propname, readp));
360*6ba597c5SAnurag S. Maskey }
361*6ba597c5SAnurag S. Maskey
362*6ba597c5SAnurag S. Maskey /* Property-specific value validation functions follow */
363*6ba597c5SAnurag S. Maskey
364*6ba597c5SAnurag S. Maskey static nwam_error_t
valid_enm_activation_mode(nwam_value_t value)365*6ba597c5SAnurag S. Maskey valid_enm_activation_mode(nwam_value_t value)
366*6ba597c5SAnurag S. Maskey {
367*6ba597c5SAnurag S. Maskey uint64_t activation_mode;
368*6ba597c5SAnurag S. Maskey
369*6ba597c5SAnurag S. Maskey if (nwam_value_get_uint64(value, &activation_mode) != NWAM_SUCCESS)
370*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_INVALID_VALUE);
371*6ba597c5SAnurag S. Maskey
372*6ba597c5SAnurag S. Maskey switch (activation_mode) {
373*6ba597c5SAnurag S. Maskey case NWAM_ACTIVATION_MODE_MANUAL:
374*6ba597c5SAnurag S. Maskey case NWAM_ACTIVATION_MODE_CONDITIONAL_ANY:
375*6ba597c5SAnurag S. Maskey case NWAM_ACTIVATION_MODE_CONDITIONAL_ALL:
376*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
377*6ba597c5SAnurag S. Maskey }
378*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_INVALID_VALUE);
379*6ba597c5SAnurag S. Maskey }
380*6ba597c5SAnurag S. Maskey
381*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_validate(nwam_enm_handle_t enmh,const char ** errpropp)382*6ba597c5SAnurag S. Maskey nwam_enm_validate(nwam_enm_handle_t enmh, const char **errpropp)
383*6ba597c5SAnurag S. Maskey {
384*6ba597c5SAnurag S. Maskey uint64_t activation;
385*6ba597c5SAnurag S. Maskey nwam_value_t activationval, enabledval, fmrival = NULL, startval = NULL;
386*6ba597c5SAnurag S. Maskey nwam_value_t conditionval = NULL;
387*6ba597c5SAnurag S. Maskey char **conditions, *name;
388*6ba597c5SAnurag S. Maskey uint_t i, numvalues;
389*6ba597c5SAnurag S. Maskey nwam_condition_object_type_t object_type;
390*6ba597c5SAnurag S. Maskey nwam_condition_t condition;
391*6ba597c5SAnurag S. Maskey
392*6ba597c5SAnurag S. Maskey assert(enmh != NULL);
393*6ba597c5SAnurag S. Maskey
394*6ba597c5SAnurag S. Maskey /*
395*6ba597c5SAnurag S. Maskey * Make sure enm is internally consistent: must have either
396*6ba597c5SAnurag S. Maskey * an fmri or a start string; and if activation type is conditional,
397*6ba597c5SAnurag S. Maskey * the condition string must be specified.
398*6ba597c5SAnurag S. Maskey */
399*6ba597c5SAnurag S. Maskey if ((nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_FMRI, &fmrival)
400*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS) &&
401*6ba597c5SAnurag S. Maskey (nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_START, &startval)
402*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS)) {
403*6ba597c5SAnurag S. Maskey if (fmrival != NULL) {
404*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
405*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_START;
406*6ba597c5SAnurag S. Maskey nwam_value_free(fmrival);
407*6ba597c5SAnurag S. Maskey } else {
408*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
409*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_FMRI;
410*6ba597c5SAnurag S. Maskey }
411*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_MISSING_MEMBER);
412*6ba597c5SAnurag S. Maskey }
413*6ba597c5SAnurag S. Maskey if (fmrival != NULL)
414*6ba597c5SAnurag S. Maskey nwam_value_free(fmrival);
415*6ba597c5SAnurag S. Maskey if (startval != NULL)
416*6ba597c5SAnurag S. Maskey nwam_value_free(startval);
417*6ba597c5SAnurag S. Maskey
418*6ba597c5SAnurag S. Maskey if (nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_ACTIVATION_MODE,
419*6ba597c5SAnurag S. Maskey &activationval) != NWAM_SUCCESS) {
420*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
421*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_ACTIVATION_MODE;
422*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_MISSING_MEMBER);
423*6ba597c5SAnurag S. Maskey }
424*6ba597c5SAnurag S. Maskey if (nwam_value_get_uint64(activationval, &activation)
425*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS) {
426*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
427*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_ACTIVATION_MODE;
428*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_INVALID_VALUE);
429*6ba597c5SAnurag S. Maskey }
430*6ba597c5SAnurag S. Maskey nwam_value_free(activationval);
431*6ba597c5SAnurag S. Maskey
432*6ba597c5SAnurag S. Maskey if (activation == NWAM_ACTIVATION_MODE_CONDITIONAL_ANY ||
433*6ba597c5SAnurag S. Maskey activation == NWAM_ACTIVATION_MODE_CONDITIONAL_ALL) {
434*6ba597c5SAnurag S. Maskey if (nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_CONDITIONS,
435*6ba597c5SAnurag S. Maskey &conditionval) != NWAM_SUCCESS) {
436*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
437*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_CONDITIONS;
438*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_MISSING_MEMBER);
439*6ba597c5SAnurag S. Maskey }
440*6ba597c5SAnurag S. Maskey /*
441*6ba597c5SAnurag S. Maskey * Are conditions self-referential? In other words, do any
442*6ba597c5SAnurag S. Maskey * of the activation conditions refer to this ENM?
443*6ba597c5SAnurag S. Maskey */
444*6ba597c5SAnurag S. Maskey if (nwam_value_get_string_array(conditionval, &conditions,
445*6ba597c5SAnurag S. Maskey &numvalues) != NWAM_SUCCESS) {
446*6ba597c5SAnurag S. Maskey nwam_value_free(conditionval);
447*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
448*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_CONDITIONS;
449*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_INVALID_VALUE);
450*6ba597c5SAnurag S. Maskey }
451*6ba597c5SAnurag S. Maskey if (nwam_enm_get_name(enmh, &name) != NWAM_SUCCESS) {
452*6ba597c5SAnurag S. Maskey nwam_value_free(conditionval);
453*6ba597c5SAnurag S. Maskey return (NWAM_INVALID_ARG);
454*6ba597c5SAnurag S. Maskey }
455*6ba597c5SAnurag S. Maskey for (i = 0; i < numvalues; i++) {
456*6ba597c5SAnurag S. Maskey char *object_name = NULL;
457*6ba597c5SAnurag S. Maskey
458*6ba597c5SAnurag S. Maskey if (nwam_condition_string_to_condition(conditions[i],
459*6ba597c5SAnurag S. Maskey &object_type, &condition, &object_name)
460*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS) {
461*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
462*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_CONDITIONS;
463*6ba597c5SAnurag S. Maskey free(name);
464*6ba597c5SAnurag S. Maskey nwam_value_free(conditionval);
465*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_INVALID_VALUE);
466*6ba597c5SAnurag S. Maskey }
467*6ba597c5SAnurag S. Maskey if (object_name != NULL &&
468*6ba597c5SAnurag S. Maskey object_type == NWAM_CONDITION_OBJECT_TYPE_ENM &&
469*6ba597c5SAnurag S. Maskey strcmp(object_name, name) == 0) {
470*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
471*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_CONDITIONS;
472*6ba597c5SAnurag S. Maskey free(name);
473*6ba597c5SAnurag S. Maskey free(object_name);
474*6ba597c5SAnurag S. Maskey nwam_value_free(conditionval);
475*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_INVALID_VALUE);
476*6ba597c5SAnurag S. Maskey }
477*6ba597c5SAnurag S. Maskey free(object_name);
478*6ba597c5SAnurag S. Maskey }
479*6ba597c5SAnurag S. Maskey free(name);
480*6ba597c5SAnurag S. Maskey nwam_value_free(conditionval);
481*6ba597c5SAnurag S. Maskey }
482*6ba597c5SAnurag S. Maskey
483*6ba597c5SAnurag S. Maskey if (activation == NWAM_ACTIVATION_MODE_MANUAL) {
484*6ba597c5SAnurag S. Maskey if (nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_ENABLED,
485*6ba597c5SAnurag S. Maskey &enabledval) != NWAM_SUCCESS) {
486*6ba597c5SAnurag S. Maskey if (errpropp != NULL)
487*6ba597c5SAnurag S. Maskey *errpropp = NWAM_ENM_PROP_ENABLED;
488*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_MISSING_MEMBER);
489*6ba597c5SAnurag S. Maskey }
490*6ba597c5SAnurag S. Maskey nwam_value_free(enabledval);
491*6ba597c5SAnurag S. Maskey }
492*6ba597c5SAnurag S. Maskey
493*6ba597c5SAnurag S. Maskey return (nwam_validate(enm_prop_table, enmh, errpropp));
494*6ba597c5SAnurag S. Maskey }
495*6ba597c5SAnurag S. Maskey
496*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_validate_prop(nwam_enm_handle_t enmh,const char * propname,nwam_value_t value)497*6ba597c5SAnurag S. Maskey nwam_enm_validate_prop(nwam_enm_handle_t enmh, const char *propname,
498*6ba597c5SAnurag S. Maskey nwam_value_t value)
499*6ba597c5SAnurag S. Maskey {
500*6ba597c5SAnurag S. Maskey assert(enmh != NULL);
501*6ba597c5SAnurag S. Maskey
502*6ba597c5SAnurag S. Maskey return (nwam_validate_prop(enm_prop_table, enmh, propname, value));
503*6ba597c5SAnurag S. Maskey }
504*6ba597c5SAnurag S. Maskey
505*6ba597c5SAnurag S. Maskey /*
506*6ba597c5SAnurag S. Maskey * Given a property, return expected property data type
507*6ba597c5SAnurag S. Maskey */
508*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_get_prop_type(const char * propname,nwam_value_type_t * typep)509*6ba597c5SAnurag S. Maskey nwam_enm_get_prop_type(const char *propname, nwam_value_type_t *typep)
510*6ba597c5SAnurag S. Maskey {
511*6ba597c5SAnurag S. Maskey return (nwam_get_prop_type(enm_prop_table, propname, typep));
512*6ba597c5SAnurag S. Maskey }
513*6ba597c5SAnurag S. Maskey
514*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_prop_multivalued(const char * propname,boolean_t * multip)515*6ba597c5SAnurag S. Maskey nwam_enm_prop_multivalued(const char *propname, boolean_t *multip)
516*6ba597c5SAnurag S. Maskey {
517*6ba597c5SAnurag S. Maskey return (nwam_prop_multivalued(enm_prop_table, propname, multip));
518*6ba597c5SAnurag S. Maskey }
519*6ba597c5SAnurag S. Maskey
520*6ba597c5SAnurag S. Maskey /*
521*6ba597c5SAnurag S. Maskey * Determine if the ENM has manual activation-mode or not.
522*6ba597c5SAnurag S. Maskey */
523*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_is_manual(nwam_enm_handle_t enmh,boolean_t * manualp)524*6ba597c5SAnurag S. Maskey nwam_enm_is_manual(nwam_enm_handle_t enmh, boolean_t *manualp)
525*6ba597c5SAnurag S. Maskey {
526*6ba597c5SAnurag S. Maskey nwam_error_t err;
527*6ba597c5SAnurag S. Maskey nwam_value_t actval;
528*6ba597c5SAnurag S. Maskey uint64_t activation;
529*6ba597c5SAnurag S. Maskey
530*6ba597c5SAnurag S. Maskey assert(enmh != NULL);
531*6ba597c5SAnurag S. Maskey
532*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_ACTIVATION_MODE,
533*6ba597c5SAnurag S. Maskey &actval)) != NWAM_SUCCESS)
534*6ba597c5SAnurag S. Maskey return (err);
535*6ba597c5SAnurag S. Maskey err = nwam_value_get_uint64(actval, &activation);
536*6ba597c5SAnurag S. Maskey nwam_value_free(actval);
537*6ba597c5SAnurag S. Maskey if (err != NWAM_SUCCESS)
538*6ba597c5SAnurag S. Maskey return (err);
539*6ba597c5SAnurag S. Maskey
540*6ba597c5SAnurag S. Maskey if (activation == NWAM_ACTIVATION_MODE_MANUAL)
541*6ba597c5SAnurag S. Maskey *manualp = B_TRUE;
542*6ba597c5SAnurag S. Maskey else
543*6ba597c5SAnurag S. Maskey *manualp = B_FALSE;
544*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
545*6ba597c5SAnurag S. Maskey }
546*6ba597c5SAnurag S. Maskey
547*6ba597c5SAnurag S. Maskey /* Determine if ENM is enabled or not */
548*6ba597c5SAnurag S. Maskey static nwam_error_t
nwam_enm_is_enabled(nwam_enm_handle_t enmh,boolean_t * enabledp)549*6ba597c5SAnurag S. Maskey nwam_enm_is_enabled(nwam_enm_handle_t enmh, boolean_t *enabledp)
550*6ba597c5SAnurag S. Maskey {
551*6ba597c5SAnurag S. Maskey nwam_error_t err;
552*6ba597c5SAnurag S. Maskey nwam_value_t enabledval;
553*6ba597c5SAnurag S. Maskey
554*6ba597c5SAnurag S. Maskey assert(enmh != NULL);
555*6ba597c5SAnurag S. Maskey
556*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_get_prop_value(enmh, NWAM_ENM_PROP_ENABLED,
557*6ba597c5SAnurag S. Maskey &enabledval)) != NWAM_SUCCESS)
558*6ba597c5SAnurag S. Maskey return (err);
559*6ba597c5SAnurag S. Maskey err = nwam_value_get_boolean(enabledval, enabledp);
560*6ba597c5SAnurag S. Maskey nwam_value_free(enabledval);
561*6ba597c5SAnurag S. Maskey return (err);
562*6ba597c5SAnurag S. Maskey }
563*6ba597c5SAnurag S. Maskey
564*6ba597c5SAnurag S. Maskey /* Update the enabled property */
565*6ba597c5SAnurag S. Maskey static nwam_error_t
nwam_enm_update_enabled(nwam_enm_handle_t enmh,boolean_t enabled)566*6ba597c5SAnurag S. Maskey nwam_enm_update_enabled(nwam_enm_handle_t enmh, boolean_t enabled)
567*6ba597c5SAnurag S. Maskey {
568*6ba597c5SAnurag S. Maskey nwam_error_t err;
569*6ba597c5SAnurag S. Maskey nwam_value_t enabledval;
570*6ba597c5SAnurag S. Maskey
571*6ba597c5SAnurag S. Maskey if ((err = nwam_value_create_boolean(enabled, &enabledval))
572*6ba597c5SAnurag S. Maskey != NWAM_SUCCESS)
573*6ba597c5SAnurag S. Maskey return (err);
574*6ba597c5SAnurag S. Maskey err = nwam_set_prop_value(enmh->nwh_data, NWAM_ENM_PROP_ENABLED,
575*6ba597c5SAnurag S. Maskey enabledval);
576*6ba597c5SAnurag S. Maskey nwam_value_free(enabledval);
577*6ba597c5SAnurag S. Maskey if (err != NWAM_SUCCESS)
578*6ba597c5SAnurag S. Maskey return (err);
579*6ba597c5SAnurag S. Maskey return (nwam_enm_commit(enmh, NWAM_FLAG_ENTITY_ENABLE));
580*6ba597c5SAnurag S. Maskey }
581*6ba597c5SAnurag S. Maskey
582*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_enable(nwam_enm_handle_t enmh)583*6ba597c5SAnurag S. Maskey nwam_enm_enable(nwam_enm_handle_t enmh)
584*6ba597c5SAnurag S. Maskey {
585*6ba597c5SAnurag S. Maskey nwam_error_t err;
586*6ba597c5SAnurag S. Maskey boolean_t manual, enabled;
587*6ba597c5SAnurag S. Maskey
588*6ba597c5SAnurag S. Maskey assert(enmh != NULL);
589*6ba597c5SAnurag S. Maskey
590*6ba597c5SAnurag S. Maskey /* Only enms with manual activation-mode can be enabled */
591*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_is_manual(enmh, &manual)) != NWAM_SUCCESS)
592*6ba597c5SAnurag S. Maskey return (err);
593*6ba597c5SAnurag S. Maskey if (!manual)
594*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_NOT_MANUAL);
595*6ba597c5SAnurag S. Maskey
596*6ba597c5SAnurag S. Maskey /* Make sure ENM is not enabled */
597*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_is_enabled(enmh, &enabled)) != NWAM_SUCCESS)
598*6ba597c5SAnurag S. Maskey return (err);
599*6ba597c5SAnurag S. Maskey if (enabled)
600*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
601*6ba597c5SAnurag S. Maskey
602*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_update_enabled(enmh, B_TRUE)) != NWAM_SUCCESS)
603*6ba597c5SAnurag S. Maskey return (err);
604*6ba597c5SAnurag S. Maskey
605*6ba597c5SAnurag S. Maskey err = nwam_enable(NULL, enmh);
606*6ba597c5SAnurag S. Maskey
607*6ba597c5SAnurag S. Maskey /* nwamd may not be running, that's okay. */
608*6ba597c5SAnurag S. Maskey if (err == NWAM_ERROR_BIND)
609*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
610*6ba597c5SAnurag S. Maskey else
611*6ba597c5SAnurag S. Maskey return (err);
612*6ba597c5SAnurag S. Maskey }
613*6ba597c5SAnurag S. Maskey
614*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_disable(nwam_enm_handle_t enmh)615*6ba597c5SAnurag S. Maskey nwam_enm_disable(nwam_enm_handle_t enmh)
616*6ba597c5SAnurag S. Maskey {
617*6ba597c5SAnurag S. Maskey nwam_error_t err;
618*6ba597c5SAnurag S. Maskey boolean_t manual, enabled;
619*6ba597c5SAnurag S. Maskey
620*6ba597c5SAnurag S. Maskey assert(enmh != NULL);
621*6ba597c5SAnurag S. Maskey
622*6ba597c5SAnurag S. Maskey /* Only enms with manual activation-mode can be disabled */
623*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_is_manual(enmh, &manual)) != NWAM_SUCCESS)
624*6ba597c5SAnurag S. Maskey return (err);
625*6ba597c5SAnurag S. Maskey if (!manual)
626*6ba597c5SAnurag S. Maskey return (NWAM_ENTITY_NOT_MANUAL);
627*6ba597c5SAnurag S. Maskey
628*6ba597c5SAnurag S. Maskey /* Make sure ENM is enabled */
629*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_is_enabled(enmh, &enabled)) != NWAM_SUCCESS)
630*6ba597c5SAnurag S. Maskey return (err);
631*6ba597c5SAnurag S. Maskey if (!enabled)
632*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
633*6ba597c5SAnurag S. Maskey
634*6ba597c5SAnurag S. Maskey if ((err = nwam_enm_update_enabled(enmh, B_FALSE)) != NWAM_SUCCESS)
635*6ba597c5SAnurag S. Maskey return (err);
636*6ba597c5SAnurag S. Maskey
637*6ba597c5SAnurag S. Maskey err = nwam_disable(NULL, enmh);
638*6ba597c5SAnurag S. Maskey
639*6ba597c5SAnurag S. Maskey /* nwamd may not be running, that's okay. */
640*6ba597c5SAnurag S. Maskey if (err == NWAM_ERROR_BIND)
641*6ba597c5SAnurag S. Maskey return (NWAM_SUCCESS);
642*6ba597c5SAnurag S. Maskey else
643*6ba597c5SAnurag S. Maskey return (err);
644*6ba597c5SAnurag S. Maskey }
645*6ba597c5SAnurag S. Maskey
646*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_get_default_proplist(const char *** prop_list,uint_t * numvaluesp)647*6ba597c5SAnurag S. Maskey nwam_enm_get_default_proplist(const char ***prop_list, uint_t *numvaluesp)
648*6ba597c5SAnurag S. Maskey {
649*6ba597c5SAnurag S. Maskey return (nwam_get_default_proplist(enm_prop_table,
650*6ba597c5SAnurag S. Maskey NWAM_TYPE_ANY, NWAM_CLASS_ANY, prop_list, numvaluesp));
651*6ba597c5SAnurag S. Maskey }
652*6ba597c5SAnurag S. Maskey
653*6ba597c5SAnurag S. Maskey nwam_error_t
nwam_enm_get_state(nwam_enm_handle_t enmh,nwam_state_t * statep,nwam_aux_state_t * auxp)654*6ba597c5SAnurag S. Maskey nwam_enm_get_state(nwam_enm_handle_t enmh, nwam_state_t *statep,
655*6ba597c5SAnurag S. Maskey nwam_aux_state_t *auxp)
656*6ba597c5SAnurag S. Maskey {
657*6ba597c5SAnurag S. Maskey return (nwam_get_state(NULL, enmh, statep, auxp));
658*6ba597c5SAnurag S. Maskey }
659