<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dougt&#039;s blog &#187; CoreWlan</title>
	<atom:link href="http://dougt.org/wordpress/tag/corewlan/feed/" rel="self" type="application/rss+xml" />
	<link>http://dougt.org/wordpress</link>
	<description>best. tagline. ever.</description>
	<lastBuildDate>Mon, 26 Jul 2010 03:18:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Using CoreWLAN on MacOS 10.5</title>
		<link>http://dougt.org/wordpress/2009/09/usingcorewlan/</link>
		<comments>http://dougt.org/wordpress/2009/09/usingcorewlan/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 20:13:28 +0000</pubDate>
		<dc:creator>dougt</dc:creator>
				<category><![CDATA[mozilla]]></category>
		<category><![CDATA[10.6]]></category>
		<category><![CDATA[CoreWlan]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[MacOS]]></category>

		<guid isPermaLink="false">http://dougt.org/wordpress/?p=481</guid>
		<description><![CDATA[When Apple&#8217;s OS X version 10.6 shipped, they broke compatibility will all 3rd party geolocation applications.  This wasn&#8217;t entirely unexpected as we all were using a private framework which wasn&#8217;t documented.  So, Firefox 3.5 and Gears, and probably Skyhook, are busted right now on OS X 10.6. Apple has provided, with limited documentation, a new [...]]]></description>
			<content:encoded><![CDATA[<p>When Apple&#8217;s OS X version 10.6 shipped, they broke compatibility will all 3rd party geolocation applications.  This wasn&#8217;t entirely unexpected as we all were using a private framework which wasn&#8217;t documented.  So, Firefox 3.5 and Gears, and probably Skyhook, are busted right now on OS X 10.6.</p>
<p>Apple has provided, with limited documentation, a new public framework called CoreWLAN.  It looks pretty easy to use.  To do a scan of the WIFI access points, you can simply do:</p>
<blockquote><p>#import &lt;Cocoa/Cocoa.h&gt;<br />
#import &lt;CoreWLAN/CoreWLAN.h&gt;</p>
<p>NSError *err = nil;<br />
NSDictionary *params = nil;</p>
<p>NSArray* scan = [NSMutableArray arrayWithArray:[[CWInterface interface] scanForNetworksWithParameters:params error:&amp;err]];</p></blockquote>
<p>This is all fine and dandy.  However, Firefox uses 10.5, and so using the above code will not compile using the old SDK.  Unfortunately, Apple didn&#8217;t provide any C apis &#8211; only exposing this objective-C API.  So, what I had to do was some objective-c magic.  Check out the reference (http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html)</p>
<p>Basically, we needed to be able to dynamically load the CoreWLAN library, that is simple enough:</p>
<blockquote><p>void *corewlan_library = dlopen(&#8220;/System/Library/Frameworks/CoreWLAN.framework/CoreWLAN&#8221;,  RTLD_LOCAL);</p></blockquote>
<p>Now that this library has been loaded, we want to simulate the objective-c call &#8220;[CWInterface interface]&#8220;.</p>
<blockquote><p>// get the class<br />
Class CWI_class = objc_getClass(&#8220;CWInterface&#8221;);<br />
// register the selector name<br />
SEL interfaceSel = sel_registerName(&#8220;interface&#8221;);<br />
// make the call<br />
id interface = objc_msgSend(CWI_class, interfaceSel);</p></blockquote>
<p>This mess above is the same as:</p>
<blockquote><p>id interface = [CWInterface interface];</p></blockquote>
<p>As you probably can see, it isn&#8217;t that hard to do this, just it is syntactically nasty.  Here is the source to the little application I was testing with:</p>
<blockquote><p>#include &lt;mach-o/dyld.h&gt;<br />
#include &lt;dlfcn.h&gt;<br />
#include &lt;unistd.h&gt;</p>
<p>#include &lt;objc/objc.h&gt;<br />
#include &lt;objc/objc-runtime.h&gt;</p>
<p>Class CWI_class = objc_getClass(&#8220;CWInterface&#8221;);<br />
printf(&#8220;cwi class %x\n&#8221;, CWI_class);</p>
<p>SEL interfaceSel = sel_registerName(&#8220;interface&#8221;);<br />
printf(&#8220;sel: %x\n&#8221;, interfaceSel);</p>
<p>SEL scanSel = sel_registerName(&#8220;scanForNetworksWithParameters:error:&#8221;);<br />
printf(&#8220;scanSel: %x\n&#8221;, interfaceSel);</p>
<p>id interface = objc_msgSend(CWI_class, interfaceSel);<br />
printf(&#8220;interface: %x\n&#8221;, interface);</p>
<p>id scanResult = objc_msgSend(interface, scanSel, 0, 0);<br />
printf(&#8220;scanResult: %x\n&#8221;, scanResult);</p></blockquote>
<p>Hope this helps.  Please let me know of an easier way, if one exists.</p>
]]></content:encoded>
			<wfw:commentRss>http://dougt.org/wordpress/2009/09/usingcorewlan/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
