Export to GitHub

iphone-wireless - issue #20

Apple80211Associate method signature


Posted on May 9, 2008 by Swift Hippo

Hi,

I had to associate my iPhone to a given SSID, so I reverse engineered the associate function:

int Apple80211Associate(struct Apple80211 *handle, CFDictionaryRef *network, CFString *wpa_key);

handle: An open handle from an Apple80211Open call, that has also been bound to an interface using Apple80211BindToInterface.

network: one of the CFDictionaryRefs returned by the Apple80211Scan function.

wpa_key: NSString containing the WPA PSK.

Hopes that helps, Renault

Comment #1

Posted on Jul 13, 2008 by Swift Elephant

Hi Renault,

I would like to join a special SSID but do not know how? Could you explain me how you managed to do so?

I was wondering if there exist Wifi libraries for IPhone that offer functions such Access Point scanning, association.... Actually, I would like to store my credentials (login/password) on the IPhone and to log automatically on an HTML authentication based Access Point. I I tried to search on the web, especially on apple website but I did not find anything...

I really need some help! Thanks

Comment #2

Posted on Apr 15, 2009 by Swift Wombat

Hi Ranult, I am also trying to use the same Apple80211Associate using its address(pointer) to associae to unsecure AP,I am passing the same dictionary as the secone argument returned by the scan. But the function fails with error code 9. Were you able to associte using this function. If YES could you please help me outif I'm missing anything.

Thanks Raj

Comment #3

Posted on Apr 16, 2009 by Swift Hippo

can you post the code snippet?

Comment #4

Posted on Jul 16, 2009 by Swift Bird

Hmm ... I've got everything working except associating with a network in 3.0. I'm getting a -101 result--??

Comment #5

Posted on Jul 16, 2009 by Swift Bird

Comment deleted

Comment #6

Posted on Aug 28, 2009 by Happy Bear

Russmcb, you are too nearer the goal.

first confirm that you are passing single network(access point) data as network parameter and password(if it is WPA/WAP network) in 3rd parameter else nil.

Comment #7

Posted on Aug 28, 2009 by Swift Bird

Should've posted some time ago that the 3rd parameter must be nil, not an empty string. Had this working for some time. Thanks, though!

Comment #8

Posted on Mar 12, 2010 by Grumpy Bear

Has anyone been able to use Apple80211Associate on 3.1.*? It doesn't work for me and I'm at a loss as to why. I get all kinds of error codes: 9, -4, -101 but never 0 and I have no indication that it worked at all. I've tried both with a network without encryption and one with encryption.

Also, is this a blocking call? Or does it trigger an asynchronous task that fires a notification when done? If so, what notification is raised?

Thanks!

Comment #9

Posted on Mar 12, 2010 by Swift Hippo

Hi, the Apple80211Associate is still working (at least on 3.1.2). Between the iPhone OS 2 and 3, the framework has changed name, so you should bind your functions as following:

void *airportHandle; int (*Apple80211Open)(void *); int (*Apple80211BindToInterface)(void *, NSString *); int (*Apple80211Close)(void *); int (*Apple80211Info)(void , NSDictionary*); int (*Apple80211Associate)(void , NSDictionary, void *); int (*Apple80211Scan)(void , NSArray *, void *);

libHandle = dlopen("/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager", RTLD_LAZY); Apple80211Open = dlsym(libHandle, "Apple80211Open"); Apple80211BindToInterface = dlsym(libHandle, "Apple80211BindToInterface"); Apple80211Scan = dlsym(libHandle, "Apple80211Scan"); Apple80211Close = dlsym(libHandle, "Apple80211Close"); Apple80211Info = dlsym(libHandle, "Apple80211GetInfoCopy"); Apple80211Associate = dlsym(libHandle, "Apple80211Associate");

The most significant change from v2 to v3 is SCAN_RSSI_THRESHOLD parameter (used for the scan function). It use to take a positive number, far from the physical dB it should have been
and now it takes the dB of the signal. If you make use of it, you can set it to -100:

Here is a code snipped (cherry picked from my code, so untested as is):

void *airportHandle;

NSArray *keys = [NSArray arrayWithObjects:@"SCAN_RSSI_THRESHOLD", @"SSID_STR", nil]; NSArray *objects = [NSArray arrayWithObjects:[NSNumber numberWithInt:-100], ssid, nil];

NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSArray *found;

int openResult = Apple80211Open(&airportHandle); NSLog(@"Openning wifi interface %@", (openResult == 0?@"succeeded":@"failed"));

int bindResult = Apple80211BindToInterface(airportHandle, @IF_NAME);

int scanResult = Apple80211Scan(airportHandle, &found, params);

NSDictionary *network;

// get the first network found network = [found objectAtIndex:0]; int associateResult = Apple80211Associate(airportHandle, network,NULL);

Apple80211Close(airportHandle);

Hope that's helps, Renault

Comment #10

Posted on Mar 23, 2010 by Grumpy Bear

Hey thanks for the quick and detailed answer Renault. Got it working now :-) One extra question: is there a way to know when the association is complete? Following the call, the OS pops up the Wifi network selection dialog and I'd like to wait until the user has dismissed this dialog before attempting to connect to a host. Do you know if some notification is raised to signal that?

Thanks a bunch

Comment #11

Posted on Mar 29, 2010 by Quick Dog

Deal all,

when i try to use the framework, the following error happened, could you please tell me what shall i do? dlopen(/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager, 1): image not found

my simulator is OS 3.1.3. thanks a lot.

Comment #12

Posted on Apr 6, 2010 by Happy Cat

Anyone have an explanation on the return values yet? I can associate with my network using the WPA key. But sometimes it fails, giving me either a return value of -6 or 16

Comment #13

Posted on Apr 12, 2010 by Happy Rhino

@ToLiBing: this only works on the actual device, not on the Simulator.

Comment #14

Posted on Jun 8, 2010 by Massive Cat

im curently looking to make an app for the iphone that scans for a particular wifi networkk and connects to it. im however not able to make a headstart. could anyone help point me in a direction to using the stumbler code in my application?

Comment #15

Posted on Jun 30, 2010 by Swift Bird

How are things working in OS 4.0?

Comment #16

Posted on Jul 1, 2010 by Happy Cat

My App still works, so I guess nothing changed since 3.1.3

Comment #17

Posted on Jul 5, 2010 by Quick Giraffe

How can I detect signal strenght and other information of nearby bluetooth devices ? Will applications that use these libraries be allowed on the itunes store ?

Comment #18

Posted on Jul 14, 2010 by Swift Hippo

My app fails over ios4.

Comment #19

Posted on Jul 14, 2010 by Swift Hippo

I'm sorry, I found that there is a problem if u're running with simulator.

Comment #20

Posted on Jul 23, 2010 by Quick Monkey

i have problem working on ios4 too.

Comment #21

Posted on Jul 29, 2010 by Swift Hippo

Yes now I can't use bluetooth over iOS4!!

Comment #22

Posted on Jul 29, 2010 by Happy Cat

this still works fine for me on iOS4: - (id)init { self = [super init]; NetworksManager = self; networks = [[NSMutableDictionary alloc] init]; types = [NSArray arrayWithObjects:@"80211", @"Bluetooth", @"GSM", nil]; [types retain]; autoScanInterval = 5; //seconds libHandle = dlopen("/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager", RTLD_LAZY); open = dlsym(libHandle, "Apple80211Open"); bind = dlsym(libHandle, "Apple80211BindToInterface"); close = dlsym(libHandle, "Apple80211Close"); scan = dlsym(libHandle, "Apple80211Scan");

open(&airportHandle);
bind(airportHandle, @"en0");
return self;

}

  • (void)scan { NSLog(@"Scanning..."); scanning = true; [[NSNotificationCenter defaultCenter] postNotificationName:@"startedScanning" object:self]; NSArray *scan_networks; NSDictionary *parameters = [[NSDictionary alloc] init]; scan(airportHandle, &scan_networks, parameters); int i; bool changed; for (i = 0; i < [scan_networks count]; i++) { if([networks objectForKey:[[scan_networks objectAtIndex: i] objectForKey:@"BSSID"]] != nil && ![[networks objectForKey:[[scan_networks objectAtIndex: i] objectForKey:@"BSSID"]] isEqualToDictionary:[scan_networks objectAtIndex: i]]) changed = true; [networks setObject:[scan_networks objectAtIndex: i] forKey:[[scan_networks objectAtIndex: i] objectForKey:@"BSSID"]]; } if(changed) { [[NSNotificationCenter defaultCenter] postNotificationName:@"NetworksUpdated" object:self]; } scanning = false; [[NSNotificationCenter defaultCenter] postNotificationName:@"stoppedScanning" object:self]; NSLog(@"Scan Finished..."); }

Comment #23

Posted on Jul 29, 2010 by Swift Hippo

Can you connect between two iphones via bluetooth over iOS4?

Comment #24

Posted on Jul 29, 2010 by Happy Cat

I'm not sure if it's possible using this method. BUT Apple allows iPhone-to-iPhone communication over bluetooth in the GameKit Framework: http://stackoverflow.com/questions/1049393/gamekit-in-iphone-sdk-3-0

Comment #25

Posted on Aug 11, 2010 by Swift Bear

Comment deleted

Comment #26

Posted on Aug 11, 2010 by Swift Bear

Hi guys,

I have just started to make a iPhone Wifi scanning app. I have searched a lot websites, finally I have the recent code the below. Someone told this is working for iPhoneOS4.0 well.

libHandle = dlopen("/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager", RTLD_LAZY); open = dlsym(libHandle, "Apple80211Open"); bind = dlsym(libHandle, "Apple80211BindToInterface"); close = dlsym(libHandle, "Apple80211Close"); scan = dlsym(libHandle, "Apple80211Scan");

But, I have the below warnings.

warning: Unable to read symbols for "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0.1/Symbols/usr/lib/libpcap.A.dylib" (file not found). warning: Unable to read symbols for "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0.1/Symbols/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager" (file not found).

I am using xcode_3.2.3_and_ios_sdk_4.0.1 and iPhone 3G device that jailbroken, unlocked and updated to 4.0.1.

I know, if I use a private API, can not service and get a risks, but I should do that. If you any clue about this, please let me know.

Thanks.

Comment #27

Posted on Aug 11, 2010 by Swift Hippo

This code does not work on the simulator, only on the device. Try to run your code on the iPhone directly.

Renault

Comment #28

Posted on Aug 11, 2010 by Swift Bear

I have tried it on he device. but the same. The device is jailbroken, unlocked and updated to 4.0.1.

Comment #29

Posted on Aug 11, 2010 by Happy Cat

What are the errors when you run on the device? because the errors you pasted are from the simulator.

Comment #30

Posted on Aug 16, 2010 by Swift Bear

Thank you for your reply, the code is working fine, I can ignore the warning. Thanks. Does anybody know about the error codes of associate? What is the meaning of -101 and others?

Comment #31

Posted on Aug 23, 2010 by Swift Hippo

I am having a problem connecting to unsecured networks. My app will connect fine to my WEP network, but I get a -3900 error when I try to connect to a network without a password. I have tried sending both an empty string and nil for the third parameter, but neither worked

Comment #32

Posted on Sep 2, 2010 by Swift Bear

Does anyone here know how to get the IP Address after associated.

Comment #33

Posted on Sep 3, 2010 by Swift Bear

Comment deleted

Comment #34

Posted on Sep 3, 2010 by Swift Bear

When I associate to hotspot, it is just associated, not connected to the hotspot access point. After associated, how can I make it connected?

After associated, If I open a browser, the browser make it connected. So, I think, the browser do something, but I do not know the something. ^^;;;;

Comment #35

Posted on Sep 28, 2010 by Grumpy Rhino

Hi Renault

Which tools have you used to reverse engineered Apple80211Associate? could you describe the process to me please? my email is: jibrilg@gmail.com.

Regards

Comment #36

Posted on Sep 30, 2010 by Massive Rhino

Hi, Renault,

Do you have any idea how I can detect the signal strenghts of several access points? I will need it for an academic test, thanks very much!

Comment #37

Posted on Sep 30, 2010 by Swift Hippo

Hi Zhyujjh (is it your name or an acronym?)

You have to use the scan function. If this function call is successful, it will return in the variable "CFArrayRef *list" the list of all available networks (it is a list of NSDictionary). Iterate over this array and extract the RSSI key, from the dictionary.

I hope it helps, Renault

Comment #38

Posted on Feb 17, 2011 by Swift Bird

Does anyone know how to toggle the Wifi on an off? On the desktop library, at least, we've got functions like: WirelessSetPower(). Any ideas?

Thanks, r

Comment #39

Posted on Jun 1, 2011 by Quick Rhino

hi, i m new to iphone and want to know how can i scan other wifi enabled devices. i read the discussion above but not getting where to start from.is there any framework that i need to import? any suggestion? thanks.

Shreya

Comment #40

Posted on Feb 16, 2013 by Massive Cat

Comment deleted

Comment #41

Posted on Sep 12, 2014 by Quick Giraffe

Apple has moved the API /System/Library/SystemConfiguration/IPConfiguration.bundle to somewhere else in IOS8 ... As this API is not working ... Can Anyone Please tell me the new Path ..

Comment #42

Posted on Feb 20, 2015 by Quick Kangaroo

Dear All, I am currently looking for making an app for iPhone that scans for a particular wifi network and connects to it. I will have list of all SSID & passwords. Also, I have to upload this application to store. So, I cannot use Private frameworks. Could anyone please help me.

I tried above solutions but its not working. I am not getting where to start from. Any suggestions?

Thanks.

Comment #43

Posted on Jul 16, 2015 by Quick Panda

i am not find the list of all scan wifi network device SSID.

Status: New

Labels:
Type-Defect Priority-Medium