MacBookBuntu Take 2

So, it seems that it is possible to get the last feature that I really, really wanted to use on my MacBook, NetworkManager, to work under Ubuntu Edgy without a custom kernel.  The steps involved are not difficult, but they are tricky, due to an interlocking matrix of bugs.  Thanks to some insomnia and procrastination I've decided to write it up.
Screenshot

Reader beware!  These steps are designed to work around a particular set of bugs on a particular revision of Ubuntu for a particular piece of hardware.  If you're reading this at some point in the future, chances are that the madwifi project has already produced a driver.  To find out, check to see if madwifi ticket 1001 has been resolved before you do any of this.

If you are running Ubuntu Edgy, with the default kernel, and you have a black rev.2 MacBook and you want to get NetworkManager working without screwing around with Feisty kernels, read on.
  • First, you will have to build your own ndiswrapper.  You need at least version 1.29, which is quite a bit newer than the version packaged with edgy.  I chose 1.31 - not too old, not too new.  You need at least version 1.43.  (Earlier versions seemed to work, but 1.44 was the first version I installed which could suspend and resume reliably and did not very occasionally produce random crashes.) These instructions may very well work with older or newer revisions, but I am not going to build a big revision matrix; the whole point of this is a temporary workaround.  Install it with "make uninstall; make install" to make sure to remove ubuntu's packaged ndiswrapper driver first.  Keep in mind that if you upgrade your kernel via apt, you may need to repeat this step, so keep the sources around.
  • Next, you will want to get the driver from d-link.  Go to this page, and get version 1.02.  Some discussion on the Madwifi page says to get version 1.01 instead because 1.02 crashes.  Ignore it.  As far as I can tell, it's just wrong.  I originally followed this advice, which is why I thought that it crashed ndiswrapper; I also had other problems with version 1.01 such as not being able to associate with various public access points.  See my later post about which driver to get.  Anyhow, install the driver into ndiswrapper by unzipping the downloaded archive and running "sudo ndiswrapper -i net5416.inf".
  • Test to make sure the driver works.  If you are already running NetworkManager and nm-applet, simply doing 'modprobe ndiswrapper' ought to set it up nicely and you should get immediate visual feedback that it is working.
  • Configure the module to un-load itself when you suspend or sleep and re-load itself when you resume.  This is important because otherwise ndiswrapper will not allow anything   This is accomplished by editing the file /etc/default/acpi-support and changing the 'MODULES' line to say 'MODULES="ndiswrapper"'.  While you're in there, you might want to also change the 'STOP_SERVICES' line to say 'STOP_SERVICES="mysql bluetooth "' instead of just mysql, since bluetooth is notoriously unreliable in the face of power management, and bluetooth connections, like wifi connections, will not survive a suspend/resume cycle anyway.
    • Make sure that ndiswrapper does not create a 'wlan0' alias for itself; you probably don't need to do anything, but if you're using a different version of the ndiswrapper script, it may create a file called "/etc/modprobe.d/ndiswrapper" with an alias for "wlan0" in it.  If you see this, remove it.  NetworkManager knows about the module name 'wlan0' and will constantly try to load it if it becomes unloaded for some reason.  This results in a particularly nasty race condition where the suspend machinery politely removes ndiswrapper in preparation for suspending and then NetworkManager loads it again, resulting in a hang from which it is impossible to recover without a hard reboot.  I managed to create this situation for myself through experimentation, so it probably won't happen to you, but just in case make sure that file doesn't contain any reference to 'wlan0'.
  • Test suspending and resuming and make sure that the driver loads as expected.
  • Configure the driver to load at boot.  This consists of editing the file /etc/modules and adding a line that says "ndiswrapper". DO NOT do this until you are sure the driver works with your machine; if it causes a crash, this might make your machine unbootable.
There you have it.  It's an unfortunately jury rigged situation, but now that I've gone through these steps, I can effectively (mostly) forget about ndiswrapper and compiling kernel modules and so on, and avoid the tedious and unpleasant typing "iwlist wlan0 scan | less" and instead just click on the access point that I want.

Recovering from PyCon

Last weekend, I attended PyCon 2007. I hadn't originally intended to go, but I could hardly miss my father giving the final keynote.


The keynote was riveting as expected. To be honest, I hadn't expected much of the conference beyond that. The first PyCon was an amazing experience, but as the topics drifted more towards "web frameworks" and away from more general programming, later ones were progressively less interesting. I missed last year's and nothing I read caused me to regret it much.


I'm happy to say that this expectation was completely wrong, and this conference was amazing. I thoroughly enjoyed it on many levels.


In previous years, a lot of my time was soaked up by justifications, answering questions like "why does Twisted make me do foo" or "why haven't you made Nevow do bar yet". This year, the discussions I participated in were all productive and engaging, including the two, multi-hour Twisted birds-of-a-feather sessions which I attended.


Many of the exciting developments that I enjoyed while I was there aren't ready for public consumption quite yet, so I can't say much here. I can give you some incredibly vague hints though! It was a very rewarding conference both from a business and community development perspective. (Those of you with privileged information, please do not add anything revealing to the comments. Seriously.)


One cool thing that I can shout from the rooftops already is that Guido, a group of concerned hackers, and I got to have a meeting of the minds, which Guido has already blogged about, addressing many upcoming concerns we all had about Python 3. That, and several other discussions with the responsible developers about the proposed transition plans for the 3.0 release have put my mind at ease. That's not to say that I agree with every decision that has been made - and I definitely need to participate in a few more mailing list discussions - but I feel much more comfortable that the whole thing is in good hands.


My major regret for this conference is that I was completely unprepared for the truckload of great stuff that happened. I thought I would take it easy for a few days and get back to work. If I had a better idea of what would be happening, I would have prepared at least a few lightning talks, a more structured BoF session, and better allocated my time to the many interesting folks who wanted to bend my ear so that I wasn't rushing from conversation to conversation.


I told a lot of people that I'd be doing a lot of things as soon as the conference was over. Unfortunately the first thing I actually did when the conference was over was develop the worst cold I've had in the last 5 years, and promptly stay home sick from work for a week, sleeping most of the time. To make matters worse, the conference and the illness coincided with the blackberry software on my phone crashing very badly and a not-quite-perfect beta-test of the Divmod migration process on my email account.


In other words, if I told you I'd get back to you at the conf, I probably haven't. I'm trying desperately to claw through my backlog right now, but it's going to take a while. Please be patient, and if you haven't heard from me in a week or so, feel free to send some repeat emails and nag me. If I said I wanted to get back to you, I really do.


I should warn you that I'm still not quite back at 100% HP/MP yet, and I have lots of actual work work to do as well, so you might want to wait a few days, but please, everybody, stay in touch.

Twisted BoF at PyCon

The attendance list seems a bit anemic so far, so I thought I'd point it out:


Twisted Birds of a Feather session at PyCon 2007


I'll be there.

I Got the Black One

As I predicted, I purchased the black MacBook.

After every other laptop I've purchased, I experienced some form of buyer's remorse.  In this case, I didn't.  The overall experience has been positive.  I really don't have time to do a complete review (especially after spending all that time trying to remember how the heck bluetooth modems work - ugh!), but I'll offer the highlights, from an outline I was working on to do a fuller review:
  • It's very fast.  It runs the unit tests even faster than my work machine, a beefy Opteron.
  • More than any other Apple computer or appliance I've owned, its design is a work of art.  There are no special function keys (unless you count "eject"), no latches, no status indicator lights, clips or plug covers or anything.  The only moving parts are the keys and the disc drive.  It's also almost completely silent.  This can be slightly creepy: there's hard disk light, no sound from the disk, no network activity light, no external indicators to show that the machine is doing something.  I might have to get some blinkenlights panel applets just to make myself feel comfortable!
    • MagSafe is a really, really good idea.  It's not just about not knocking your laptop off of the table - it makes every other laptop plug you've ever used feel like utter crap.  The Vaio still holds a strong second in my book, because it allows for a fair amount of play on the plug before anything starts to bend or break, but... this is really in a class by itself.
  • The keyboard is delicious.  For some reason I had the impression that macbook keyboards were bad, probably because of the silly placement of the 'ctrl' key if you don't re-map it.
    • Old school powerbook/linux and powerbook/emacs people, you'll know what I mean when I say this: capslock-as-ctrl doesn't stick.  In either OS.
  • It works well with Ubuntu, with a few minor caveats:
    • The bad news:
      • The 'fn' key is in software, which means I don't get pgup/pgdn/home/end or volume control keys in linux.  Also, the 'fn' key shows up in 'showkey' but not in 'xev' - it's not accessible to X for some reason. I don't know why this is, but it isn't really enough of an annoyance for me to bother with fixing yet.
      • Suspend has some issues around restoring the display properly when waking up.  I really don't care, so I'm unlikely to figure out how to fix this - I prefer the machine to hibernate when I close the lid anyway.
    • In general, however, lots of things worked out of the box or with minimal tweaking in linux:
    • sound
    • video (with accelerated 3D)
    • bluetooth
    • USB
    • firewire
    • wired ethernet
    • hibernate
    • CD/DVD burning
    • 3-button mouse emulation (using right-apple and enter keys as middle and right click)
The real litmus test for this laptop was that, immediately after purchasing it, I ended up having to drive all over Quincy for some reason, while also trying to catch up on several days of work.  The laptop performed like a charm; I connected to seven or eight different wifi networks, wrote several hundred lines of code, hibernated and resumed half a dozen times, sometimes just snapping it shut and tossing it in my bag without worrying about heat issues (the vents are along the top of this machine, where the bag is open, instead of along the side where they'll be instantly blocked).

This experience was actually quite pleasant, devoid of the usual "new laptop that doesn't quite have all the drivers installed" experiences I've come to expect.  Edgy can take some of the credit for this, of course, but the macbook itself is fast, light, comfortable to use, and has good battery life.

A Graphical Guide to Getting your God Damned Bluetooth Modem to Work Again in Linux (Ubuntu Edgy)

Much to the chagrin of my cell phone company, I use Bluetooth tethering to provide myself with always-on internet connectivity so that I can always be connected, even when traveling unexpectedly.  It's shocking how often I end up in areas without wifi coverage of any kind, but such is the world we live in.

For the fifth time now, I have managed to convince myself that configuring this in Linux is really easy, and not bothered to back up the one or two critical tidbits which allow it to work.  Also for the fifth time I have found myself in a situation where I needed to use my phone as a modem through my laptop and have been in an awkward situation because I could not.  For myself as much as for anyone else, I'm going to post the instructions for getting a bluetooth tethered modem up and running quickly under Linux, using GUI tools as much as possible.  Other tutorials that I've found for setting this up are rambling monstrosities that cover everything from a threat analysis of bluetooth security to a 1000-line-long configuration for command-line ppp dialer, so I am aiming to just provide a brief overview of how to get the phone up and running.  These instructions are fairly generic, but in my particular case, they apply to Cingular, the Nokia 9300 smartphone, and Ubuntu Edgy.
WARNING: BE AWARE OF THE BILLING IMPLICATIONS OF TETHERING BEFORE YOU FOLLOW ANY OF THESE STEPS, EVEN IF THEY SOUND NEAT.  CELL PHONE COMPANIES HATE TETHERING LIKE RED SOX FANS HATE YANKEES FANS.  THEY WOULD MUCH RATHER SELL YOU A MUCH FASTER AND BETTER DATA CONNECTION THAN ALLOW YOU TO USE YOUR PHONE IN THIS CAPACITY.  TETHERING DATA IS NOT BILLED THE SAME AS DATA ON YOUR DEVICE, YOU MAY INCUR EXTRA CHARGES EVEN IF YOU HAVE A VERY GOOD DATA PLAN FOR YOUR SMART PHONE.  TETHERING ON A DEVICE IS NOT THE SAME AS USING A DATA CARD EVEN IF BOTH ARE ON THE SAME ACCOUNT, AND YOU WILL INCUR EXTRA CHARGES FOR THAT.  IF YOU DO NOT HAVE A PREVIOUS AGREEMENT WHICH YOU ARE VERY SURE GRANTS YOU A LARGE AMOUNT OF TETHERING BANDWIDTH, DOING THIS MAY RESULT IN THOUSANDS OF DOLLARS IN DATA CHARGES.  I AM NOT LIABLE IF THIS HAPPENS TO YOU.  YOU HAVE BEEN WARNED.
Ahem.  Now that that's out of the way, let's move on to the main event.

Step One: make sure your bluetooth device is up and running.  This should happen automatically in edgy, so if you don't see output like this, it is unfortunately likely that your device is entirely unsupported.  You might try restarting your bluetooth device if it isn't visible here.



Step Two: Once you know your device is there, you'll need Linux to talk to your phone.  Scan the area for your phone, and then discover what channel your phone provides Dial-Up Networking (DUN) on.



Step Three: As root, edit /etc/bluetooth/hcid.conf and change the 'security' to 'auto'.  I've found that other methods for communicating the PIN are less reliable.  If you want to change your PIN, edit the "passkey" here.



Step Four: as root, edit /etc/bluetooth/rfcomm.conf to bind "rfcomm0" to your device's modem functionality.  Make sure to set both the "device" and the "channel". from Step Two.



Step Five: install the "gnome-ppp" package.  This is a nice graphical dialer that integrates well into the desktop.



Step Six: Run gnome-ppp.



Step Seven: In the initial window that comes up, enter any username and password that you like.  These are usually ignored by your provider, but they must be present.  I use 'user' and 'pass'.



Step Eight: Click the "Setup" button, and configure:
  • your Device to be "/dev/rfcomm0"
  • your Type to be "USB Modem"
  • your Speed to be something nice and high


Step Nine: Click "Init Strings" and type in the obvious strings that come to mind:
  • ATZ
  • AT+CGDCONT=1,"IP","isp.cingular"


Step Ten: Completely stop and then start your bluetooth services to make sure your phone is available.



Step Eleven: Click "connect" in gnome-ppp.  You will have to enter a PIN on your phone.  Hopefully, this will happen:



Then, the dialog will disappear and an icon will appear in your notification area telling you about the PPP connection.  There you have it!  Cellular internet connectivity, as easy as AT+CGDCONT=1,"IP","isp.cingular"!

I have absolutely no idea how, or why, any of this stuff works.  If the above steps don't work for you, unfortunately, I will not be of much help; I don't know how to diagnose problems other than googling around and running long bluetooth command lines that I don't really understand.  Still, I've been lucky enough to get it working every time after only a little banging my head against a wall.  Good luck!