6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * CDDL HEADER START
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * The contents of this file are subject to the terms of the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Common Development and Distribution License (the "License").
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * You may not use this file except in compliance with the License.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * or http://www.opensolaris.org/os/licensing.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * See the License for the specific language governing permissions
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * and limitations under the License.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * When distributing Covered Code, include this CDDL HEADER in each
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If applicable, add the following below this CDDL HEADER, with the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * fields enclosed by brackets "[]" replaced with your own identifying
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * information: Portions Copyright [yyyy] [name of copyright owner]
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * CDDL HEADER END
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * conditions.c - contains routines which check state to see if activation
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * conditions for NWAM objects are satisfied and rates activation conditions to
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * help determine which is most specific.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If the activation-mode is CONDITIONAL_ANY or CONDITIONAL_ALL, the conditions
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * property is set to a string made up of conditional expressions. Each
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * expression is made up of a condition that can be assigned a boolean value,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * e.g. "system-domain is sun.com" or "ncu ip:bge0 is-not active". If the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * activation-mode is CONDITIONAL_ANY, the condition will be satisfied if any
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * one of the conditions is true; if the activation-mode is CONDITIONAL_ALL,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * the condition is satisfied only if all of the conditions are true.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyuint64_t condition_check_interval = CONDITION_CHECK_INTERVAL_DEFAULT;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyextern int getdomainname(char *, int);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* NCP, NCU, ENM and location conditions */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_ncp(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_ncu(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_enm(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_loc(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* IP address conditions */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_ip_address(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* domainname conditions */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_sys_domain(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_adv_domain(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* WLAN conditions */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_wireless_essid(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic boolean_t test_condition_wireless_bssid(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t (*condition_func)(nwam_condition_t, const char *);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_NCP, test_condition_ncp },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_NCU, test_condition_ncu },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_ENM, test_condition_enm },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_LOC, test_condition_loc },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_IP_ADDRESS, test_condition_ip_address },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_SYS_DOMAIN, test_condition_sys_domain },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_ADV_DOMAIN, test_condition_adv_domain },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_ESSID, test_condition_wireless_essid },
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey { NWAM_CONDITION_OBJECT_TYPE_BSSID, test_condition_wireless_bssid }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * This function takes which kind of conditions (is or is not) we are testing
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * the object against and an object and applies the conditon to the object.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_object_state(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_object_type_t object_type, const char *object_name)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey object = nwamd_object_find(object_type, object_name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_ncp(nwam_condition_t condition, const char *name)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_lock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey active = (strcasecmp(active_ncp, name) == 0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&active_ncp_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_ncu(nwam_condition_t condition, const char *name)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* names are case-insensitive, so get real name from libnwam */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_ncu_read(active_ncph, name, NWAM_NCU_TYPE_INTERFACE, 0, &ncuh)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey } else if (nwam_ncu_read(active_ncph, name, NWAM_NCU_TYPE_LINK, 0,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_ncu_get_name(ncuh, &real_name) != NWAM_SUCCESS) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Name may be either unqualified or qualified by NCU type
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * (interface:/link:). Need to translate unqualified names
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * to qualified, specifying interface:name if an interface
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * NCU is present, otherwise link:ncu.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_ncu_name_to_typed_name(real_name, ncu_type, &ncu_name)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey rv = test_condition_object_state(condition, NWAM_OBJECT_TYPE_NCU,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_enm(nwam_condition_t condition, const char *enm_name)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* names are case-insensitive, so get real name from libnwam */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_enm_read(enm_name, 0, &enmh) != NWAM_SUCCESS)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_enm_get_name(enmh, &real_name) != NWAM_SUCCESS) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey rv = test_condition_object_state(condition, NWAM_OBJECT_TYPE_ENM,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_loc(nwam_condition_t condition, const char *loc_name)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* names are case-insensitive, so get real name from libnwam */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_loc_read(loc_name, 0, &loch) != NWAM_SUCCESS)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_loc_get_name(loch, &real_name) != NWAM_SUCCESS) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey rv = test_condition_object_state(condition, NWAM_OBJECT_TYPE_LOC,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_domain(nwam_condition_t condition, const char *target_domain,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char target[MAXHOSTNAMELEN], found[MAXHOSTNAMELEN];
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey len_t = target_domain == NULL ? 0 : strlen(target_domain);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey len_f = found_domain == NULL ? 0 : strlen(found_domain);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* convert target_domain and found_domain to lowercase for strstr() */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey for (i = 0; i < len_t; i++)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey for (i = 0; i < len_f; i++)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (found_domain != NULL && strcmp(found, target) == 0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (found_domain == NULL || strcmp(found, target) != 0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (found_domain != NULL && strstr(found, target) != NULL);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (found_domain == NULL || strstr(found, target) == NULL);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyget_adv_domains(nwamd_object_t obj, void *arg)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_ncu_t *ncu = (nwamd_ncu_t *)obj->nwamd_object_data;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct ncu_adv_domains **headpp = (struct ncu_adv_domains **)arg;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (ncu->ncu_type != NWAM_NCU_TYPE_INTERFACE)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey dns = nwamd_get_dhcpinfo_data("DNSdmain", ncu->ncu_name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nis = nwamd_get_dhcpinfo_data("NISdmain", ncu->ncu_name);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey adp = (struct ncu_adv_domains *)malloc(sizeof (*adp));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_sys_domain(nwam_condition_t condition, const char *domainname)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (getdomainname(cur_domainname, MAXHOSTNAMELEN) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (test_condition_domain(condition, domainname, cur_domainname));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_adv_domain(nwam_condition_t condition, const char *domainname)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct ncu_adv_domains *adv_domains = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) nwamd_walk_objects(NWAM_OBJECT_TYPE_NCU, get_adv_domains,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey positive = (condition == NWAM_CONDITION_IS ||
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Walk the advertised domain list. Our test function tests one
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * single domain, but we're dealing with a list: if our condition
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * is positive ('is' or 'contains'), the test function for each
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * domain results are or'd together; if our condition is negative
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * ('is-not' or 'does-not-contain'), the test function results must
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * be and'd. Thus our short-circuit exit value depends on our
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * condition: if the test function returns TRUE it implies immediate
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * success for a positive condition; if it returns FALSE it implies
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * immediate failure for a negative condition.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((test_condition_domain(condition, domainname,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (test_condition_domain(condition, domainname,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * We did not short-circuit; we therefore failed if our
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * condition was positive, and succeeded if our condition
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * was negative.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* now free the domain list */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Returns true if prefixlen bits of addr1 match prefixlen bits of addr2.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyprefixmatch(uchar_t *addr1, uchar_t *addr2, int prefixlen)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int i, j = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* Ensure at least one byte is tested */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (j == 0) j++;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey for (i = 0; i < j; i++) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((addr1[i] & mask[i]) != (addr2[i] & mask[i]))
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * Given a string representation of an IPv4 or IPv6 address returns the
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * sockaddr representation. Note that 'sockaddr' should point at the correct
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * sockaddr structure for the address family (sockaddr_in for AF_INET or
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * sockaddr_in6 for AF_INET6) or alternatively at a sockaddr_storage
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskeynwamd_str2sockaddr(sa_family_t af, const char *straddr,
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey err = inet_pton(AF_INET, straddr, &sin->sin_addr);
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey err = inet_pton(AF_INET6, straddr, &sin6->sin6_addr);
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskeycheck_ipaddr(sa_family_t family, struct ifaddrs *ifa, void *arg)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_ipaddr_condition_walk_arg *wa = arg;
64639aaf7beb84086b88f186ea1fa9ccf0be8c57Darren Reed (void) memcpy(&addr, ifa->ifa_addr, sizeof (addr));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey addr2 = (uchar_t *)&(((struct sockaddr_in *)
64639aaf7beb84086b88f186ea1fa9ccf0be8c57Darren Reed (void) memcpy(&addr6, ifa->ifa_addr, sizeof (addr6));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey addr2 = (uchar_t *)&(((struct sockaddr_in6 *)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey match = prefixmatch(addr1, addr2, wa->prefixlen);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "check_ipaddr: match %d\n", match);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_ip_address(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char *copy, *ip_address, *prefixlen_string, *lasts;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((copy = strdup(ip_address_string)) == NULL)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((ip_address = strtok_r(copy, " \t/", &lasts)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey prefixlen_string = strtok_r(NULL, " \t", &lasts);
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey if (nwamd_str2sockaddr(AF_INET, ip_address, &wa.sockaddr) != NULL) {
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey } else if (nwamd_str2sockaddr(AF_INET6, ip_address, &wa.sockaddr)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "test_condition_ip_address: "
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey "nwamd_str2sockaddr failed for %s: %s", ip_address,
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey nlog(LOG_ERR, "test_condition_ip_address: "
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey for (ifap = ifa; ifap != NULL; ifap = ifap->ifa_next) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey struct nwamd_wlan_condition_walk_arg *wa = arg;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((status = dladm_name2info(dld_handle, linkname, &linkid, NULL, NULL,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "check_wlan: dladm_name2info() for %s "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey status = dladm_wlan_get_linkattr(dld_handle, linkid, &attr);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "check_wlan: dladm_wlan_get_linkattr() for %s "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (attr.la_status == DLADM_WLAN_LINK_DISCONNECTED)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* Is the NIC associated with the expected access point? */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) dladm_wlan_essid2str(&attr.la_wlan_attr.wa_essid,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->res = strcmp(cur_essid, wa->exp_essid) == 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->res = strcmp(cur_essid, wa->exp_essid) != 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->res = strstr(cur_essid, wa->exp_essid) != NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->res = strstr(cur_essid, wa->exp_essid) == NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* Is the NIC associated with the expected access point? */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) dladm_wlan_bssid2str(&attr.la_wlan_attr.wa_bssid,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->res = strcmp(cur_bssid, wa->exp_bssid) == 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey wa->res = strcmp(cur_bssid, wa->exp_bssid) != 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Neither an ESSID or BSSID match is required - being connected to a
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * WLAN is enough.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*NOTREACHED*/
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_wireless_essid(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) dladm_walk(check_wlan, dld_handle, &wa, DATALINK_CLASS_PHYS,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (wa.num_connected > 0 && wa.res == B_TRUE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytest_condition_wireless_bssid(nwam_condition_t condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) dladm_walk(check_wlan, dld_handle, &wa, DATALINK_CLASS_PHYS,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (wa.num_connected > 0 && wa.res == B_TRUE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * This function takes an activation mode and a string representation of a
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * condition and evaluates it.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_check_conditions(nwam_activation_mode_t activation_mode,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char **condition_strings, uint_t num_conditions)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey for (i = 0; i < num_conditions; i++) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_condition_string_to_condition(condition_strings[i],
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey &object_type, &condition, &object_name) != NWAM_SUCCESS) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "check_conditions: invalid condition %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey for (j = 0; j < (sizeof (condition_map) /
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey sizeof (struct nwamd_condition_map)); j++) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (condition_map[j].object_type == object_type)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey ret = condition_map[j].condition_func(condition,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (activation_mode == NWAM_ACTIVATION_MODE_CONDITIONAL_ANY &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (activation_mode == NWAM_ACTIVATION_MODE_CONDITIONAL_ALL &&
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (activation_mode == NWAM_ACTIVATION_MODE_CONDITIONAL_ANY && ret)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (activation_mode == NWAM_ACTIVATION_MODE_CONDITIONAL_ALL && ret)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * In rating activation conditions, we take the best-rated CONDITIONAL_ANY
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * condition, or sum all the CONDITIONAL_ALL condition ratings. This allows
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * us to compare between location activation conditions to pick the best.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_rate_conditions(nwam_activation_mode_t activation_mode,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey for (i = 0; i < num_conditions; i++) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (nwam_condition_string_to_condition(conditions[i],
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey &object_type, &condition, &object_name) != NWAM_SUCCESS ||
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwam_condition_rate(object_type, condition, &rating)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_rate_conditions: could not rate "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "condition");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (activation_mode == NWAM_ACTIVATION_MODE_CONDITIONAL_ANY) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Different from nwamd_triggered_check_all_conditions() in that this
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * function enqueues a timed check event.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_t check_event = nwamd_event_init
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (NWAM_EVENT_TYPE_TIMED_CHECK_CONDITIONS, NWAM_OBJECT_TYPE_UNKNOWN,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /* Add another timed event to recheck conditions */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey condition_check_interval > CONDITION_CHECK_INTERVAL_MIN ?
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey condition_check_interval : CONDITION_CHECK_INTERVAL_MIN);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Does not enqueue another check event.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_create_timed_condition_check_event(void)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nwamd_event_t check_event = nwamd_event_init
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (NWAM_EVENT_TYPE_TIMED_CHECK_CONDITIONS, NWAM_OBJECT_TYPE_UNKNOWN,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_create_triggered_condition_check_event(uint32_t when)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (!nwamd_event_enqueued(NWAM_EVENT_TYPE_TRIGGERED_CHECK_CONDITIONS,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (NWAM_EVENT_TYPE_TRIGGERED_CHECK_CONDITIONS,