When Mac OS X WiFi Country Code goes wrong…

Usually Mac OS X is a joy to use as things use to just work ™. However, sometimes -well- they just do not :-/ Recently I had a very mysterious issue in Moscow, Russia. Often WiFi would just work ™, however, sometimes that specific access point station would simply not show up at all in the network list. I kept resettings that AP point a couple of times and even started to reboot Mac OS X in misbelieve - what else should one do when that WiFi would not show up nor auto-connect again? More mysteriously that AP I kept resettings worked just fine with with plenty of iPhone’s and iPad’s and the like around. I started to really wonder what was wrong with my Mac when I noticed holding the option key to the boot chooser, that the recovery netbook WiFi selector would show that AP’s SSID network! Hah! I thought it must be some caching issue / plist corruption whatever that irritates the full Mac OS X network stack, but even a few more reboots and wiping of the network settings still made no difference. It was then when I noticed something strange was going on with the Wifi Country Code and thus allowed frequency channels (yeah, I got some inside knowledge, working on drivers and such).

Mar 18 19:53:25 retina kernel[0]: en0: 802.11d country code set to ‘TW’.
Mar 18 22:56:20 retina kernel[0]: en0: 802.11d country code set to ‘X3′.
Mar 18 22:56:21 retina kernel[0]: en0: 802.11d country code set to ‘TW’.
Mar 18 22:56:38 retina kernel[0]: en0: 802.11d country code set to ‘X3′.
Mar 18 22:56:40 retina kernel[0]: en0: 802.11d country code set to ‘TW’.
Mar 18 22:57:26 retina kernel[0]: en0: 802.11d country code set to ‘TW’.
Mar 18 22:59:11 retina kernel[0]: en0: 802.11d country code set to ‘TW’.
Mar 18 23:00:58 retina kernel[0]: en0: 802.11d country code set to ‘X3′.

TW? Taiwan? And what is X3? Rest of world or what??? Either does not sound particularly Russian, so where does it come from? Turns out in Mac OS X Lions 10.7 / 10.8 there is a command line WiFi scanner hidden in the Apple80211.framework:

$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
Xyz 01:23:45:67:89:a0 -83 13 Y TW WPA(PSK/TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)

It reveled the three or so access points around all were broadcasting with a TW Country Code, obscure bits, nobody cares about, set in the Linux-based firmware once in Taiwan, probably a hardcoded C struct, and forgotten they are. And then all those forgotten bits and pieces lead to this user annoying behavior in the field. Thank you very much! :-/ Mac OS X picks up the mostly TW Country Code bits in the air, … and then concludes channel 13 is not valid, and, … your precious network never makes it into the higher levels of the network stack, nor the UI to choose from.

Given that we can not (too easily and legally) hack into those offending access points and alter the Country Code, how can we fix that? Turns out the access point had a nice sticker with username and password on the bottom side, which allowed me to login and notice it’s channel was set to “Auto”. This explains why sometimes the network worked for me, when the AP choose another channel than 13, … which allowed my MacBook to connect in the “TW” region.

A simply change from “Auto” to a channels with in the range that was not used around by other routers, and I had a WiFi connection happily ever after, …

I hope this helps, and educates not to broadcast random, and wrong settings thru the air!

4 Responses to “When Mac OS X WiFi Country Code goes wrong…”

  1. casey Says:

    This has been driving me nuts for months now! The only fix that has worked for me is to re-configure the router and then have to update all my devices. Thank you for this post!

  2. Eirik H. Blix Says:

    I found out that I could binary patch the driver on my Mac Book Pro, so it would not change country code. I wrote about it on my blog that I put in the website to here.

  3. Facundo Says:

    I think this might help http://apple.stackexchange.com/a/129681/90086 it seems to be a patch to make X2 country code default. I was not able to make it work, but it seems to be a good solution.

  4. John Says:

    I have had similar issues with a trendNet router duel band. But only with one band the 5 Ghz band and a 2014 Macbook Air. It kept thinking I was in Albania with a Country code AL rather then US which the 2.4 ghz Band recognized. Funny thing my iPhones, Apple, TV and Windows 7 in Bootcamp on my MBA all recognized the 5Ghz correctly as US. So I figured this was a Yosemite problem.
    Funny how these issues keep re appearing in OS X. I mean the forums are filled with Apple WiFi issues. Seems to me Apple needs to fix these issues in a more timely fashion. Not everyone knows how to dig through the crap to fix these issues.

Leave a Reply