2015年6月27日 星期六

Bluetooth 藍芽配對連接

Debug 在置底。

---------------------------------------------------------------------
說明:筆者使用於筆電之內建藍芽與藍芽機械式鍵盤進行配對 。

*** 規格 ***
系統: Debian Jessie 8.0
核心:3.16.7
筆電:Acer v3-772g
鍵盤:ZIPPY BW7050
---------------------------------------------------------------------
查看無線驅動:
lspci -k|grep -iA2 Network
0d:00.0 Network controller: Qualcomm Atheros AR9462 Wireless Network Adapter (rev 01)
Subsystem: Foxconn International, Inc. Device e052
Kernel driver in use: ath9k
---------------------------------------------------------------------
檢查驅動:
lsmod |grep ath9k
lsmod |grep bluetooth
---------------------------------------------------------------------
安裝 bluetooth 套件:
apt-get update
apt-get install bluetooth bluez
apt-get upgrade -y
---------------------------------------------------------------------
啟動服務:
systemctl enable bluetooth.service
systemctl start bluetooth.service
systemctl status bluetooth.service
---------------------------------------------------------------------
設定檔:vi /etc/default/bluetooth
# Defaults for bluez-utils

# This file supersedes /etc/default/bluez-pan. If
# that exists on your system, you should use this
# file instead and remove the old one. Until you
# do so, the contents of this file will be ignored.

# start bluetooth on boot?
# compatibility note: If this variable is not found bluetooth will
# start
BLUETOOTH_ENABLED=1

# This setting will switch HID devices (e.g mouse/keyboad) to HCI mode, that is
# you will have bluetooth functionality from your dongle instead of only HID.
# Note that not every bluetooth dongle is capable of switching back to HID
# mode, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=355497
HID2HCI_ENABLED=1
HID2HCI_UNDO=1
---------------------------------------------------------------------
常用指令:
hciconfig: 顯示本機藍芽裝置
hciconfig -a: 顯示本機藍芽裝置詳細資訊
hciconfig hci0 up/down: 啟用 / 關閉第一個藍芽裝置 ( hci0 )
hcitool dev: 顯示本機所有藍芽裝置address
hcitool scan: 搜尋周邊欄芽裝置
---------------------------------------------------------------------
無線裝置軟/硬體開關 (blocked:no 為裝置開啟):
sudo rfkill list
0: acer-wireless: Wireless LAN
Soft blocked: yes
Hard blocked: no
1: acer-bluetooth: Bluetooth
Soft blocked: no
Hard blocked: no
2: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: yes
3: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
sudo rfkill block all -----------> 關閉全部無線裝置
rfkill unblock bluetooth--------> 只開啟 bluetooth
---------------------------------------------------------------------
使用 bluetoothctl 指令配對連線:
bluetoothctl -----------> 進入 bleutoothctl 指令模式 exit 或 quit 可離開

以下為 [bluetooth]# 下的指令:
help
version
power on -------------> 開啟藍芽
list --------------------> 查看本機 Bluetooth
discoverable off -------> 筆電藍芽不開放給別人看到
pairable off ------------> 筆電藍芽不開放給別人配對
scan on ----------------> 開啟掃描,此時會抓到我的鍵盤 BT address
[NEW] Device AB:CD:EF:00:11:22 我的鍵盤 BT Address

開始連線 ( [bluetooth]# 下):
info AB:CD:EF:00:11:22 -----> 查看鍵盤藍芽裝置
pair AB:CD:EF:00:11:22 -----> 配對
trust AB:CD:EF:00:11:22 -----> 加到信任
unblock AB:CD:EF:00:11:22 -> 不阻擋
connect AB:CD:EF:00:11:22 -> 連線

此時沒意外話,可以連上鍵盤了。
---------------------------------------------------------------------
Debug

善用幾個指令 debug 看系統訊息,方便至 google 爬文。
dmesg | grep -i bluetooth
sudo grep bluetooth /var/log/syslog
systemctl status bluetooth
---------------------------------------------------------------------
Debug1

核心驅動問題
cd /usr/src/linux
make menuconfig

進入 -*- Networking support  ---> <M>   Bluetooth subsystem support  --->
--- Bluetooth subsystem support
  │ │    [ ]   Bluetooth 6LoWPAN support
  │ │       RFCOMM protocol support
  │ │    [*]     RFCOMM TTY support
  │ │       BNEP protocol support
  │ │    [*]     Multicast filter support
  │ │    [*]     Protocol filter support
  │ │       CMTP protocol support
  │ │       HIDP protocol support
  │ │          Bluetooth device drivers  --->

進入 -*- Networking support  ---> <M>   Bluetooth subsystem support  ---> Bluetooth device drivers  -->
 HCI USB driver 
  │ │     HCI SDIO driver
  │ │     HCI UART driver
  │ │    [*]   UART (H4) protocol support
  │ │    [*]   BCSP protocol support
  │ │    [*]   Atheros AR300x serial support
  │ │    [*]   HCILL protocol support
  │ │    [*]   Three-wire UART (H5) protocol support
  │ │     HCI BCM203x USB driver
  │ │     HCI BPA10x USB driver
  │ │     HCI BlueFRITZ! USB driver
  │ │     HCI DTL1 (PC Card) driver
  │ │     HCI BT3C (PC Card) driver
  │ │     HCI BlueCard (PC Card) driver
  │ │     HCI UART (PC Card) device driver
  │ │     HCI VHCI (Virtual HCI device) driver
  │ │     Marvell Bluetooth driver support
  │ │       Marvell BT-over-SDIO driver
  │ │     Atheros firmware download driver

save ---> exit
time make-kpkg --initrd --revision=$version kernel_image -j $CORE
dpkg -i linux-image-$version_amd64.deb
reboot
.
.
.
其他驅動問題,參考 http://ubuntuforums.org/showthread.php?t=2251009

至 http://drvbp1.linux-foundation.org/~mcgrof/rel-html/backports/ 下載對應核心之 backport 檔,接著做:
cd Desktop/backports-3.18-rc1-1
make defconfig-ath9k
make
sudo make install
sudo reboot
---------------------------------------------------------------------
Debut 2

hciconfig ------> 無輸出
hcitool dev ----> 無裝置
hcitool scan ---> 無輸出

查看無線 WiFi/Bluetooth 卡是不是 Atheros 的?
lspci -k |grep -i network

參考 http://unix.stackexchange.com/questions/146097/bluetooth-device-not-working-debian-wheezy
可以試試安裝
apt-get install firmware-atheros
---------------------------------------------------------------------
Debug 3

因本人在編譯其他軔體時,不小心誤將 Bluetooth 的其中一個 firmware 刪除或覆蓋,因此在開機的時候,就顯示如下圖:



使用以下指令也可以看到此錯誤訊息:
dmesg | grep -i bluetooth

使用下列指令去尋找 ar3k 這個資料夾:
find / -name ar3k

確實裏面找不到 ramps_0x11020100_40.dfu 這個檔案

可以到以下網址去下載:
http://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/ar3k

將所缺失的檔案載入,就ok了。

然後在 reboot 。
---------------------------------------------------------------------



Reference:
https://wiki.debian.org/BluetoothUser




沒有留言:

張貼留言