]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/CaptiveNetwork.c
configd-395.11.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / CaptiveNetwork.c
1 /*
2 * Copyright (c) 2009, 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 #include <sys/types.h>
26 #include <sys/param.h>
27 #include <sys/stat.h>
28 #include <dlfcn.h>
29
30 #include <SystemConfiguration/CaptiveNetwork.h>
31
32
33 #pragma mark -
34 #pragma mark CaptiveNetwork.framework APIs (exported through the SystemConfiguration.framework)
35
36 const CFStringRef kCNNetworkInfoKeySSIDData = CFSTR("SSIDDATA");
37 const CFStringRef kCNNetworkInfoKeySSID = CFSTR("SSID");
38 const CFStringRef kCNNetworkInfoKeyBSSID = CFSTR("BSSID");
39
40 static void *
41 __loadCaptiveNetwork(void) {
42 static void *image = NULL;
43 if (NULL == image) {
44 const char *framework = "/System/Library/PrivateFrameworks/CaptiveNetwork.framework/CaptiveNetwork";
45 struct stat statbuf;
46 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
47 char path[MAXPATHLEN];
48
49 strlcpy(path, framework, sizeof(path));
50 if (suffix) strlcat(path, suffix, sizeof(path));
51 if (0 <= stat(path, &statbuf)) {
52 image = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
53 } else {
54 image = dlopen(framework, RTLD_LAZY | RTLD_LOCAL);
55 }
56 }
57 return (void *)image;
58 }
59
60
61 Boolean
62 CNSetSupportedSSIDs(CFArrayRef ssidArray)
63 {
64 static typeof (CNSetSupportedSSIDs) *dyfunc = NULL;
65 if (!dyfunc) {
66 void *image = __loadCaptiveNetwork();
67 if (image) dyfunc = dlsym(image, "__CNSetSupportedSSIDs");
68 }
69 return dyfunc ? dyfunc(ssidArray) : FALSE;
70 }
71
72
73 Boolean
74 CNMarkPortalOnline(CFStringRef interfaceName)
75 {
76 static typeof (CNMarkPortalOnline) *dyfunc = NULL;
77 if (!dyfunc) {
78 void *image = __loadCaptiveNetwork();
79 if (image) dyfunc = dlsym(image, "__CNMarkPortalOnline");
80 }
81 return dyfunc ? dyfunc(interfaceName) : FALSE;
82 }
83
84
85 Boolean
86 CNMarkPortalOffline(CFStringRef interfaceName)
87 {
88 static typeof (CNMarkPortalOffline) *dyfunc = NULL;
89 if (!dyfunc) {
90 void *image = __loadCaptiveNetwork();
91 if (image) dyfunc = dlsym(image, "__CNMarkPortalOffline");
92 }
93 return dyfunc ? dyfunc(interfaceName) : FALSE;
94 }
95
96 CFArrayRef
97 CNCopySupportedInterfaces(void)
98 {
99 static typeof (CNCopySupportedInterfaces) *dyfunc = NULL;
100 if (!dyfunc) {
101 void *image = __loadCaptiveNetwork();
102 if (image) dyfunc = dlsym(image, "__CNCopySupportedInterfaces");
103 }
104 return dyfunc ? dyfunc() : NULL;
105 }
106
107 CFDictionaryRef
108 CNCopyCurrentNetworkInfo(CFStringRef interfaceName)
109 {
110 static typeof (CNCopyCurrentNetworkInfo) *dyfunc = NULL;
111 if (!dyfunc) {
112 void *image = __loadCaptiveNetwork();
113 if (image) dyfunc = dlsym(image, "__CNCopyCurrentNetworkInfo");
114 }
115 return dyfunc ? dyfunc(interfaceName) : NULL;
116 }