LoginSignup
7
6

More than 5 years have passed since last update.

Linux bluetooth LE 6lowpan

Last updated at Posted at 2015-07-16

CSR 8510 A10 なドングルと broadcom BCM20702A1 なドングルどっちも使えたよ!

MLでのPOST はこんな感じだった。今のところ debugfs 使う以外に手が無いのだよなー。

In the slave side do this:

$ modprobe bluetooth_6lowpan
$ echo 62 > /sys/kernel/debug/bluetooth/6lowpan_psm
$ hciconfig hci0 leadv

In the master side do this:

$ modprobe bluetooth_6lowpan
$ echo 62 > /sys/kernel/debug/bluetooth/6lowpan_psm
$ echo 'connect E0:06:E6:B7:2A:73 1' > \
                  /sys/kernel/debug/bluetooth/6lowpan_control

今の archlinux 4.0.8-3 ではこんな感じ。kernel が ML POST 時点より新しくなって、ちょっとだけ変更されてる。

In the slave side do this:

$ modprobe bluetooth_6lowpan
$ echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
$ hciconfig hci0 up
$ hciconfig hci0 leadv

In the master side do this:

$ modprobe bluetooth_6lowpan
$ echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
$ hciconfig hci0 up
$ echo 'connect E0:06:E6:B7:2A:73 1' > \
                  /sys/kernel/debug/bluetooth/6lowpan_control

6lowpan_control に入力する文字列の意味が読み取りにくいけど、こんな風になってる(参考)。

# connect <addr> <addr_type>
connect E0:06:E6:B7:2A:73 1
# disconnect <addr> <addr_type>
disconnect E0:06:E6:B7:2A:73 1

addr_type は universal(0) or local(1) bit になってて、数字の割り当ては:

/* BD Address type */
#define BDADDR_BREDR            0x00
#define BDADDR_LE_PUBLIC        0x01
#define BDADDR_LE_RANDOM        0x02

で、接続が終わるとおもむろに netdev bt0 というのが出てくるはず。

[root@alpha ~]# ip -d link show bt0
3: bt0: <POINTOPOINT,MULTICAST,UP,LOWER_UP> mtu 1280 qdisc noqueue state UNKNOWN mode DEFAULT group default
    link/[825] e0:06:e6:ff:fe:b7:2a:73 peer 00:00:00:00:00:00:00:00 promiscuity 0 addrgenmode eui64

address generation mode が eui64 で、真ん中に ff:fe が入り込んでますね。ping6 で通信できるのは確認できる。btmon を起動してメッセージを眺めてみると面白い。

[root@bravo ~]# btmon
Bluetooth monitor ver 5.32
= New Index: 5C:F3:70:63:A8:A0 (BR/EDR,USB,hci0)                                                                               [hci0] 0.447015
> ACL Data RX: Handle 64 flags 0x02 dlen 27                                                                                    [hci0] 2.648865
> ACL Data RX: Handle 64 flags 0x01 dlen 27                                                                                    [hci0] 2.648987
> ACL Data RX: Handle 64 flags 0x01 dlen 19                                                                                    [hci0] 2.650382
      Channel: 64 len 69 [PSM 0 mode 0] {chan 0}
        43 00 7a 33 3a 80 00 5b 9b 01 43 00 01 07 f2 b5  C.z3:..[..C.....
        55 a4 1e 09 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12  U...............
        13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22  ............. !"
        23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32  #$%&'()*+,-./012
        33 34 35 36 37                                   34567
< ACL Data TX: Handle 64 flags 0x00 dlen 27                                                                                    [hci0] 2.656375
< ACL Data TX: Handle 64 flags 0x01 dlen 27                                                                                    [hci0] 2.656441
< ACL Data TX: Handle 64 flags 0x01 dlen 19                                                                                    [hci0] 2.656463
      Channel: 64 len 69 [PSM 0 mode 0] {chan 0}
        43 00 7a 33 3a 81 00 5a 9b 01 43 00 01 07 f2 b5  C.z3:..Z..C.....
        55 a4 1e 09 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12  U...............
        13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22  ............. !"
        23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32  #$%&'()*+,-./012
        33 34 35 36 37                                   34567
> HCI Event: Number of Completed Packets (0x13) plen 5                                                                         [hci0] 2.720982
        Num handles: 1
        Handle: 64
        Count: 2
> HCI Event: Number of Completed Packets (0x13) plen 5                                                                         [hci0] 3.005013
        Num handles: 1
        Handle: 64
        Count: 1

動かしてみてあれこれ

6lowpanでコネクション成立するとlescanに応答しなくなるみたい。そういうもの?…(BLEの調べもの)…そういうものらしい。bluetoothはconnection切断後は、idle状態に遷移するということで、再接続したい場合はadvertise状態に遷移させないとダメってことか。

echo "disconnect E0:06:E6:B7:2A:73 1' > /sys/kernel/debug/bluetooth/6lowpan_control

をやると、このホストでは bt0: Lost carrier とメッセージが出る。再度 connect する際は、対向で hciconfig chi0 leadv を実行してからやると、再接続できる様子。その際 bt0: Gained carrier とメッセージが出る。

…disconnectまわりは怪しい。

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6