Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPConfiguration apple80211Open() crashes on iOS8

I am trying to read RSSI of iPhone WIFI connection to AP.

Using Xcode 6.1.1 with iPhone6+ ios 8.1.3

Code below crashes at apple80211Open() and gets EXC_BAD_ACCESS (code=1, address= 0) on iOS 8. (code works on iOS 7.1)

This is for app that is NOT for Apple Store -- for adhoc distribution only.

=================================================================

void *libHandle;
   void *airportHandle;

   int (*apple80211Open)(void *);
   int (*apple80211Bind)(void *, NSString *);
   int (*apple80211Close)(void *);
   int (*apple80211GetInfoCopy)(void *, CFDictionaryRef *);

   NSMutableDictionary *infoDict = [NSMutableDictionary new];
   NSDictionary * tempDictionary;
   libHandle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);

   char *dlerror_error;

   if (libHandle == NULL && (dlerror_error = dlerror()) != NULL)  {
      NSLog(@"%s", dlerror_error);
   }

   apple80211Open = dlsym(libHandle, "Apple80211Open");
   apple80211Bind = dlsym(libHandle, "Apple80211BindToInterface");
   apple80211Close = dlsym(libHandle, "Apple80211Close");
   apple80211GetInfoCopy = dlsym(libHandle, "Apple80211GetInfoCopy");

   apple80211Open(&airportHandle);
   apple80211Bind(airportHandle, @"en0");

   CFDictionaryRef info = NULL;

   apple80211GetInfoCopy(airportHandle, &info);

   tempDictionary = (__bridge NSDictionary *)info;

   apple80211Close(airportHandle);

   [infoDict setObject:(tempDictionary[@"RSSI"])[@"RSSI_CTL_AGR"] ? (tempDictionary[@"RSSI"])[@"RSSI_CTL_AGR"] : @"0" forKey:@"RSSI"];

   [infoDict setObject:tempDictionary[@"BSSID"] ? tempDictionary[@"BSSID"] : @"null" forKey:@"BSSID"];

   [infoDict setObject:tempDictionary[@"SSID_STR"] ? tempDictionary[@"SSID_STR"] : @"null" forKey:@"SSID"];

   [infoDict setObject:tempDictionary[@"RATE"] ? tempDictionary[@"RATE"] : @"0" forKey:@"SPEED"];
like image 483
Doug Null Avatar asked Sep 29 '22 13:09

Doug Null


1 Answers

That's because Apple removed the 80211 framework from within IPConfiguration. The symbols can't be found, dlsym returns NULL, and - a crash (you should always check return values, you know).

To begin with, this was a private framework. In new versions of iOS (8+), it's deprecated in favor of MobileWifi, and the use of entitlements (and XPC) so as to have /usr/libexec/wifid to all the work.

There's more detail on this in this article: http://newosxbook.com/articles/11208ellpA.html

like image 95
Technologeeks Avatar answered Oct 05 '22 22:10

Technologeeks