2 * Copyright (c) 2009, 2010 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <sys/types.h>
26 #include <sys/param.h>
30 #include <SystemConfiguration/CaptiveNetwork.h>
34 #pragma mark CaptiveNetwork.framework APIs (exported through the SystemConfiguration.framework)
36 const CFStringRef kCNNetworkInfoKeySSIDData
= CFSTR("SSIDDATA");
37 const CFStringRef kCNNetworkInfoKeySSID
= CFSTR("SSID");
38 const CFStringRef kCNNetworkInfoKeyBSSID
= CFSTR("BSSID");
41 __loadCaptiveNetwork(void) {
42 static void *image
= NULL
;
44 const char *framework
= "/System/Library/PrivateFrameworks/CaptiveNetwork.framework/CaptiveNetwork";
46 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
47 char path
[MAXPATHLEN
];
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
);
54 image
= dlopen(framework
, RTLD_LAZY
| RTLD_LOCAL
);
62 CNSetSupportedSSIDs(CFArrayRef ssidArray
)
64 static typeof (CNSetSupportedSSIDs
) *dyfunc
= NULL
;
66 void *image
= __loadCaptiveNetwork();
67 if (image
) dyfunc
= dlsym(image
, "__CNSetSupportedSSIDs");
69 return dyfunc
? dyfunc(ssidArray
) : FALSE
;
74 CNMarkPortalOnline(CFStringRef interfaceName
)
76 static typeof (CNMarkPortalOnline
) *dyfunc
= NULL
;
78 void *image
= __loadCaptiveNetwork();
79 if (image
) dyfunc
= dlsym(image
, "__CNMarkPortalOnline");
81 return dyfunc
? dyfunc(interfaceName
) : FALSE
;
86 CNMarkPortalOffline(CFStringRef interfaceName
)
88 static typeof (CNMarkPortalOffline
) *dyfunc
= NULL
;
90 void *image
= __loadCaptiveNetwork();
91 if (image
) dyfunc
= dlsym(image
, "__CNMarkPortalOffline");
93 return dyfunc
? dyfunc(interfaceName
) : FALSE
;
97 CNCopySupportedInterfaces(void)
99 static typeof (CNCopySupportedInterfaces
) *dyfunc
= NULL
;
101 void *image
= __loadCaptiveNetwork();
102 if (image
) dyfunc
= dlsym(image
, "__CNCopySupportedInterfaces");
104 return dyfunc
? dyfunc() : NULL
;
108 CNCopyCurrentNetworkInfo(CFStringRef interfaceName
)
110 static typeof (CNCopyCurrentNetworkInfo
) *dyfunc
= NULL
;
112 void *image
= __loadCaptiveNetwork();
113 if (image
) dyfunc
= dlsym(image
, "__CNCopyCurrentNetworkInfo");
115 return dyfunc
? dyfunc(interfaceName
) : NULL
;