Keyboard layout using devd backend

So here is another thing which changed while I wasn’t using FreeBSD: xorg switched from using HAL to devd for automatic configuration of devices. This meant my old configuration file had zero effect on my desktop – which I quickly noticed, because the keyboard layout was off.

This is how I configured the keyboard previously, using HAL: just created a file named 10-keyboard-layout.fdi inside /usr/local/etc/hal/fdi/policy and added the following to it:

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.keyboard">
      <merge key="input.xkb.layout" type="string">us</merge>
      <merge key="input.xkb.variant" type="string">altgr-intl</merge> 
    </match>
  </device>
</deviceinfo>

After reading up on the changes, the new way I did this was by creating a file named keyboard.conf inside /usr/local/etc/X11/xorg.conf.d and translating the configuration into:

Section "InputClass"
        Identifier              "Keyboard Defaults"
        Driver                  "keyboard"
        MatchIsKeyboard         "on"
        Option                  "XkbLayout" "us"
        Option                  "XkbVariant" "altgr-intl"
EndSection

I have to admit I like this configuration much better – XML wasn’t really my thing. I also took the opportunity to break down my old and long /etc/X11/xorg.conf into smaller /usr/local/etc/X11/xorg.conf.d/*.conf files, broken down by context: one for font configuration, one for video driver etc.

Reference: blogs.freebsdish.org/graphics/2014/11/19/xserver-1-14-update-ready/

Bluetooth Apple Magic Mouse on FreeBSD 10

After quite some time, I decided to move back to my Lenovo T420s running FreeBSD (right now at 10-STABLE). Previously, I was using a MacBook Pro and my home-office setup has a Das Keyboard, an Apple Magic Mouse and an external monitor. Because I like this setup and I’m comfortable with it, I decided to keep it for the T420s. This is how I configured the Magic Mouse:

First I had to load the kernel module for the Bluetooth controller – add to /boot/loader.conf:

ng_ubt_load="YES"
ng_hci_load="YES"

Then enable the related services in /etc/rc.conf:

hcsecd_enable="YES"
sdpd_enable="YES"
bthidd_enable="YES"

Next, I started some of the services manually:

# kldload ng_ubt
# service sdpd start
# service hcsecd start

Now I turned on the Magic Mouse and started looking for the Bluetooth device (the mouse turns itself off if there is no computer connected to it, if you get errors on the following steps, try “turning it off and on again”):

# hccontrol -n ubt0hci inquiry

The result was something like:

Inquiry result, num_responses=1
Inquiry result #0
	BD_ADDR: 04:0c:ce:2b:85:7e
	Page Scan Rep. Mode: 0x1
	Page Scan Period Mode: 00
	Page Scan Mode: 00
	Class: 00:25:80
	Clock offset: 0xaef
Inquiry complete. Status: No error [00]

I then added the address to the known Bluetooth hosts list:

# echo "04:0c:ce:2b:85:7e  applemouse" >> /etc/bluetooth/hosts

Now I had to register the device with bthidd. To do this I ran the following command:

# bthidcontrol -a 04:0c:ce:2b:85:7e query

Copy the output and save it into /etc/bluetooth/bthidd.conf. Again, I had to “reboot” the mouse because it had gone into sleep mode already and got a “Connection refused” error.

Now I needed the device name, so I queried for it using hccontrol. The name is usually configured in OSX, so boot a mac if you need to change it.

# hccontrol remote_name_request 04:0c:ce:2b:85:7e

And the output was this:

BD_ADDR: applemouse
Name: rodolpho's mouse

The next step is to add an entry like the following into /etc/bluetooth/hcsecd.conf (use the address and name from the previous steps and the pin is 0000 by default):

device {
	bdaddr	04:0c:ce:2b:85:7e;
	name	"rodolpho's mouse";
	key	nokey;
	pin	"0000";
}

By now, all configuration is in place – let’s restart the daemons:

# service hcsecd restart
# service bthidd restart

After rebooting the mouse, the following was logged into /var/log/messages and the mouse was working:

Jan 15 12:56:01 poseidon bthidd[39108]: Accepted control connection from 04:0c:ce:2b:85:7e
Jan 15 12:56:01 poseidon bthidd[39108]: Accepted interrupt connection from 04:0c:ce:2b:85:7e

Thanks to the following references:
FreeBSD Handbook
modal.us/blog/2013/09/16/bluetooth-freebsd-9-1-macbook/
astralblue.livejournal.com/357664.html