Bluetooth and VirtualBox on an OS X host

I've recently been playing around with the Crazyflie nano quadcopter, using the Ubuntu-based Bitcraze VM to run the radio and Python client. I've been using a PS3 controller attached via USB, but recently decided to connect via Bluetooth so I didn't have to be tethered to my laptop while flying. Unfortunately, simply turning off Bluetooth in OS X doesn't allow the guest machine to take control of the Bluetooth adapter.

Fortunately, this post gives the commands for unloading the Bluetooth daemon and kernel extensions which in turn allows the guest operating system to use the Bluetooth device. The only hiccup I found was with the last command - in Mountain Lion, the kextunload -b com.apple.iokit.BroadcomBluetoothHCIControllerUSBTransport command didn't work. Stealing the kextstat| grep -i bluet command from the next post down showed up the following extensions:

com.apple.iokit.IOBluetoothFamily
com.apple.iokit.IOBluetoothSerialManager
com.apple.iokit.IOBluetoothHostControllerUSBTransport
com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport

Considering how close the last line was to the one in the post, I took a guess and it worked! So, to enable Bluetooth on a guest OS with a Mountain Lion or Mavericks host (I've since upgraded, but the commands still work), you need to run:

$ sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
$ sudo kextunload -b com.apple.iokit.IOBluetoothSerialManager
$ sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport

And then to re-enable Bluetooth within OS X:

$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
$ sudo kextload -b com.apple.iokit.IOBluetoothSerialManager
$ sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport