====== Linux 下使用 Bluetooth USB Dongle ======
===== 1 加載藍牙模組 =====
需要加載的模組有 bluetooth, btusb, hci_uart, l2cap, rfcomm, sco, bnep, 位於 /lib/modules/`uname-r`/kernel/net/bluetooth 和 /lib/modules/`uname -r`/kernel/driver/bluetooth 裡
$ make ARCH=arm menuconfig
[*] Networking support --->
Bluetooth subsystem support --->
--- Bluetooth subsystem support
[M] L2CAP protocol support
[M] SCO links support (NEW)
RFCOMM protocol support
[ ] RFCOMM TTY support (NEW)
BNEP protocol support (NEW)
< > HIDP protocol support (NEW)
Bluetooth device drivers --->
HCI USB driver
< > HCI SDIO driver
HCI UART driver
[ ] UART (H4) protocol support (NEW)
[ ] BCSP protocol support (NEW)
[ ] Atheros AR300x serial support (NEW)
[ ] HCILL protocol support (NEW)
< > HCI BCM203x USB driver (NEW)
< > HCI BPA10x USB driver (NEW)
< > HCI BlueFRITZ! USB driver (NEW)
< > HCI VHCI (Virtual HCI device) driver (NEW)
< > Marvell Bluetooth driver support (NEW)
< > Atheros firmware download driver (NEW)
建議:
- 可以寫 bt_ins.sh 與 bt_rm.sh 兩個腳本, 進行藍牙模組的添加與刪除
- 模組是有相依性的, 請注意順序
[root@fedora14 ~]# lsmod
Module Size Used by
rfcomm 54383 4
sco 13825 2
bnep 11942 2
l2cap 43256 16 rfcomm,bnep
btusb 12562 2
bluetooth 73201 9 rfcomm,sco,bnep,l2cap,btusb
rfkill 13580 2 bluetooth
...
- 因 bluetooth.ko 須 rfkill.ko, 所必要時先 insmod rfkill.ko
#!/bin/bash
#name: bt_in.sh
#author:young
#date: 2007-01-16
#decription: insmod for bt modules
insmod /lib/modules/`uname -r`/kernel/net/bluetooth/bluetooth.ko
insmod /lib/modules/`uname -r`/kernel/net/bluetooth/l2cap.ko
insmod /lib/modules/`uname -r`/kernel/net/bluetooth/sco.ko
insmod /lib/modules/`uname -r`/kernel/net/bluetooth/bnep/bnep.ko
insmod /lib/modules/`uname -r`/kernel/net/bluetooth/rfcomm/rfcomm.ko
insmod /lib/modules/`uname -r`/kernel/drivers/bluetooth/btusb.ko
insmod /lib/modules/`uname -r`/kernel/drivers/bluetooth/hci_uart.ko
lsmod | grep bluetooth
#!/bin/bash
#name: bt_rm.sh
#author:young
#date: 2007-01-16
#description: rmmod bt modules from kernel
rmmod hci_uart
rmmod btusb
rmmod bnep
rmmod sco
rmmod rfcomm
rmmod l2cap
rmmod bluetooth
lsmod | grep bluetooth
===== 2. Install Bluez =====
Bluez is the Official Linux Bluetooth protocol stack (http://www.bluez.org/) and you need to install it to do any further action with Bluetooth. This stack is available as standard Debian package with the name bluez-utils so to install it simply type:
debarm:~# apt-get update
...
debarm:~# apt-get install bluez
...
===== 3. 常用指命 =====
* hciconfig: 顯示本機藍芽裝置
* hciconfig -a: 顯示本機藍芽裝置詳細資訊
* hciconfig hci0 up/down: 啟用 / 關閉第一個藍芽裝置 ( hci0 )
* hcitool dev: 顯示本機所有藍芽裝置address
* hcitool scan: 搜尋周邊欄芽裝置
**hciconfig: 顯示本機藍芽裝置**
[root@fedora14 ~]# hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:21:F7:2C ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:766 acl:0 sco:0 events:34 errors:0
TX bytes:1347 acl:0 sco:0 commands:34 errors:0
[root@fedora14 ~]#
**hciconfig -a: 顯示本機藍芽裝置詳細資訊**
[root@fedora14 ~]# hciconfig -a
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:21:F7:2C ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:766 acl:0 sco:0 events:34 errors:0
TX bytes:1347 acl:0 sco:0 commands:34 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'fedora14-0'
Class: 0x480100
Service Classes: Capturing, Telephony
Device Class: Computer, Uncategorized
HCI Version: 4.0 (0x6) Revision: 0x1000
LMP Version: 4.0 (0x6) Subversion: 0x220e
Manufacturer: Broadcom Corporation (15)
[root@fedora14 ~]#
**hciconfig hci0 up/down: 啟用 / 關閉第一個藍芽裝置 ( hci0 )**
[root@fedora14 ~]# hciconfig hci0 down
[root@fedora14 ~]# hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:21:F7:2C ACL MTU: 1021:8 SCO MTU: 64:1
DOWN
RX bytes:1617 acl:0 sco:0 events:44 errors:0
TX bytes:1364 acl:0 sco:0 commands:39 errors:0
[root@fedora14 ~]# hciconfig hci0 up
[root@fedora14 ~]# hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:21:F7:2C ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:2365 acl:0 sco:0 events:76 errors:0
TX bytes:2458 acl:0 sco:0 commands:70 errors:0
[root@fedora14 ~]#
**hcitool dev: 顯示本機所有藍芽裝置address**
[root@fedora14 ~]# hcitool dev
Devices:
hci0 00:02:72:21:F7:2C
[root@fedora14 ~]#
**hcitool scan: 搜尋周邊欄芽裝置**
[root@fedora14 ~]# hcitool scan
Scanning ...
E0:06:E6:B6:5F:40 JIMMY-THINK
00:08:CA:FA:E8:27 Bluetooth USB Host Controller
E0:B9:A5:68:D3:AC JOHNSONWANG-NB
00:1E:37:65:16:AB INGRASYS-1A59C6
00:02:72:C0:03:E8 ANDYWU-XP
[root@fedora14 ~]#
===== PS. 新的 bluetooth(系統不認得的) =====
**1. 先得取此 bluetooth 的 VID/PID**
[root@fedora14 ~]# lsusb
Bus 002 Device 004: ID 0a5c:21e8 Broadcom Corp.
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[root@fedora14 ~]#
在此 0a5c:21e8 Broadcom Corp. 即為我們的 VID/PID(0a5c/21e8)
**2. 將此VID/PID加入 btusb 內**
改 kernel source, {src}/drivers/bluetooth/btusb.c
static struct usb_device_id btusb_table[] = {
/* Generic Bluetooth USB device */
{ USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
.
.
.
/* Broadcom BCM20720A0 */
{ USB_DEVICE(0x0489, 0xe042) },
{ USB_DEVICE(0x0a5c, 0x21e3) },
{ USB_DEVICE(0x0a5c, 0x21e6) },
{ USB_DEVICE(0x0a5c, 0x21e8) },
{ } /* Terminating entry */
};
**3. make modules 並複制到系統 modules 目錄內**
[root@fedora14 linux-2.6.35.6]# make modules
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CC [M] drivers/bluetooth/btusb.o
Building modules, stage 2.
MODPOST 2233 modules
WARNING: modpost: Found 7 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
CC drivers/bluetooth/btusb.mod.o
LD [M] drivers/bluetooth/btusb.ko
[root@fedora14 linux-2.6.35.6]# cp drivers/bluetooth/btusb.ko /lib/modules/2.6.35.6/kernel/drivers/bluetooth/btusb.ko
cp: overwrite `/lib/modules/2.6.35.6/kernel/drivers/bluetooth/btusb.ko'? y
[root@fedora14 linux-2.6.35.6]#
**4. OK~**