目次
FreeBSD 7 Release において。
usb bluetooth を利用。利用可能なデバイスは Release note 参照。ただし、usb bluetooth はリストに載っていなくても利用できた。チップが rel note に載っているものを利用しているのかもしれない。未調査。
インストール
カーネルモジュールをロードする。
- /boot/loader.conf に以下の記述。ブート時に必要なモジュールがロードされるようになる。
ng_ubt_load="YES"
- コマンドでやる場合は、次のようにやる。
# kldload ng_ubt
いろんなものの起動
# /etc/rc.d/bluetooth start
- この後に usb bluetooth を刺す。
hcsecd の準備
- /boot/rc.conf に追加
hcsecd_enable="YES"
- pin コードを使うデバイスのために必要なデーモン
sdpd の準備
- サービス発見のためのデーモン.後述の obexapp -s でサーバをあげる場合には、これが動いていないと、obexapp は起動しない.
- /etc/rc.conf に追加
sdpd_enable="YES"
- 自分でデーモンを起動するなら、以下のコマンド
# /etc/rc.d/sdpd start
スタック
HCI
- host controller interface
- 周辺機器の捜索、自分のアドレス管理、bdアドレスに対応した名前の取得など、デバイスに近いことを司るレイヤー。
l2cap
- logical link control and adaptation protocol
- アドレスの管理、パケットのセグメンテーション、リアセンブリなど、アドレスとデータグラムの操作を司るレイヤー。
- Maximum Transfer Unit(MTU) サイズはデフォルトで 672bytes.
- 最小:48 bytes, 最大:65535 bytes
プロファイル
- ハンズフリーとヘッドセットは未対応.(2008/07現在)
コマンドとか
hccontrol
- HCI レイヤーに対して命令するためのコマンド
hccontrol -n ubt0hci read_bd_addr
- 自分の bluetooth address を表示。
hccontrol -n ubt0hci inquiry
- 周辺機器を検索。
hccontrol -n ubt0hci read_remote_name_request <bdaddr>
- 機器の名前を取得。
obexapp
- comms/obexapp をインストール
- ファイル転送を行うのに使われるプロトコル。
サーバモード
- サーバを起動しておくと、obex でのファイル転送を受け付けられる.
# obexapp -s -C 1 -r /var/spool/obex/
- -C <channel number>
- -r <directory to store file>
- -s : サーバモードであることを指定.
クライアントモード
- ファイル転送
# obexapp -c -a <bd addr> -C <channel number> -n put <file name>
- -n 以下を省略すると、ftp のインタラクティブモードに類似したモードになる。そこで、put <filename> とするとファイル転送が可能となる.
プログラミング
socket
- raw socket 利用
socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI);
inquiry
- 近隣 bluetooth ノードを検索する
- デバイスに対して、inquiry することを伝える。
- デバイスが検索してきた結果を受け取る。
関数
bt_gethostbyaddr()
- /etc/bluetooth/hosts をルックアップする。
データ構造
バイトオーダー
- bluetooth のバイトオーダは,little endian
- (TCP/IP の場合は big endian)
自分のホストのbdアドレスを取得する場合
- socket へは以下のようなデータ構造
+----------------+ |ng_hci_cmd_pkt_t| +----------------+
- socket からは以下のようなデータ構造が返ってくる
+-----------------------+ |ng_hci_event_pkt_t | +-----------------------+ |ng_hci_command_compl_ep| +-----------------------+ |ng_hci_read_bdaddr_rp | +-----------------------+
- ng_hci_read_bdaddr_rp
#define NG_HCI_OCF_READ_BDADDR 0x0009 typedef struct { u_int8_t status; /* 0x00 - success */ bdaddr_t bdaddr; /* unit address */ } __attribute__ ((packed)) ng_hci_read_bdaddr_rp;
ドキュメント
- 基本 man とソースコード.freebsd 上での bluetooth programming の資料なんか web には転がってません。
man
- man ng_btsocket
- bluetooth socket に関するドキュメント