Sandboxing coreWLAN?

1.7k Views Asked by At

I'm writing an OS X application that depends on the ability to determine wireless signal strength, but I can't figure out what entitlements to use to sandbox it.

Whenever I use

NSMutableArray *scanResults;
CWInterface *currentInterface = [CWInterface interface];
NSLog(@"currInterface: %@\n", currentInterface);
NSMutableDictionary *signalsDict = [[NSMutableDictionary alloc] init];
    NSError *err = nil;
    scanResults = [NSMutableSet setWithSet:[currentInterface scanForNetworksWithSSID:nil error:&err]];

I get the error The operation couldn't be completed. (com.apple.coreWLAN.error error 1.) despite having all entitlements checked in XCode. What entitlement(s) am I missing?

The CoreWLANWirelessManager sample project has the same problem.

4

There are 4 best solutions below

1
On

You might want to use Apple80211 private framework by using dlfcn.h library. An iphone example can be found here:

http://www.csse.uwa.edu.au/~chris/iphone/APlogger/

Download the source file and investigate scanner module.

In summary, you will come up with something like this:

#define IF_NAME "en0"
#include <dlfcn.h>

- (void)performScan
{
    int (*open)(void *);
    int (*bind)(void *, NSString *);
    int (*close)(void *);
    int (*scan)(void *, NSArray **, void *);
    void *libHandle;
    void *airportHandle;

    libHandle = dlopen("/System/Library/Frameworks/Preferences.framework/Preferences", RTLD_LAZY);
    open = dlsym(libHandle, "Apple80211Open");
    bind = dlsym(libHandle, "Apple80211BindToInterface");
    scan = dlsym(libHandle, "Apple80211Scan");
    close = dlsym(libHandle, "Apple80211Close");

    open(&airportHandle);
    bind(airportHandle, @IF_NAME);
    NSArray     *found;
    NSDictionary    *params = [[NSDictionary alloc] init];
    scan(airportHandle, &found, params);

    int nnw = [found count];
    for(int i=0 ; i < nnw ; i++) {
        NSDictionary *nw = [found objectAtIndex:i];
        NSString *ssid = [self fixSSID:nw];
        // RSSI indicates signal strength
        int rssi = [[nw objectForKey:@"RSSI"] intValue];
    }
    // Cleanup
    close(airportHandle);
    dlclose(libHandle);
}

-(NSString *)fixSSID:(NSDictionary *)nw
{
    if ([[nw objectForKey:@"HIDDEN_NETWORK"] boolValue])
    return @"<hidden>";
    else
    return [nw objectForKey:@"SSID_STR"];
}

Note that if you use private frameworks in your iOS apps, you will not be able to publish them on App Store (Apple will reject your app because there is no public documentation for Apple80211 framework). but since your question is regarding OSX development, this doesn't apply for your case.

Hope it helps.

2
On

How about the entitlements for the Wifi Diagnostics app that ships with Mac OS X 10.11.1, located at /System/Library/CoreServices/Applications/. Checking entitlements I see that it posseses the following: com.apple.wifi.associate, com.apple.wifi.scan, com.apple.wifi.set_channel, com.apple.wifi.start_autojoin, com.apple.wireless-diagnostics, and com.apple.wireless-diagnostics.basic_report.

Are we mere mortals working in a sandbox not able to get these?

0
On

CoreWLAN doesn't seem to be available at all to sandboxed apps.

Apple's developer documentation states "With App Sandbox, your app cannot modify the system’s network configuration (whether with the System Configuration framework, the CoreWLAN framework, or other similar APIs)", which seems to imply that reading but not writing settings might be OK, but that doesn't seem to work in practice, and this is confirmed by a post by Apple DTS: https://forums.developer.apple.com/thread/11307

1
On

enter image description here

I think you need to check Outgoing Connections (Client).