From Evernote: |
全Linux生活:第7天 - Bluetooth & bluez |
藍牙滑鼠終於可以用了!其實第2天的時候就已經把藍牙滑鼠與電腦配對,只是當時配對時沒有弄好,導致清單雖然可以看到滑鼠,但是不能使用,最慘的是想移除也移除不了,不知哪裡出了錯?後來因為太忙就先放著不管了。今天想說應該要來處理一下這個問題了。於是用dpkg看了一下ubuntu的到底是使用什麼藍牙套件:
$ dpkg --get-selections|grep blue
bluez install
bluez-alsa install
bluez-cups install
bluez-gstreamer install
gnome-bluetooth install
libbluetooth3 install
libgnome-bluetooth8 install
pulseaudio-module-bluetooth install
bluez-alsa install
bluez-cups install
bluez-gstreamer install
gnome-bluetooth install
libbluetooth3 install
libgnome-bluetooth8 install
pulseaudio-module-bluetooth install
看起來應該是bluez,接下來看看有什麼線索可以下手:
$ dpkg -L bluez|grep /bin/
/usr/bin/bluetooth-agent
/usr/bin/bluez-simple-agent
/usr/bin/bluez-simple-service
/usr/bin/bluez-test-adapter
/usr/bin/bluez-test-audio
/usr/bin/bluez-test-device
/usr/bin/bluez-test-discovery
/usr/bin/bluez-test-input
/usr/bin/bluez-test-manager
/usr/bin/bluez-test-network
/usr/bin/bluez-test-serial
/usr/bin/bluez-test-service
/usr/bin/bluez-test-telephony
/usr/bin/ciptool
/usr/bin/dfutool
/usr/bin/hcitool
/usr/bin/l2ping
/usr/bin/l2test
/usr/bin/rctest
/usr/bin/rfcomm
/usr/bin/sdptool
/usr/bin/bluez-simple-agent
/usr/bin/bluez-simple-service
/usr/bin/bluez-test-adapter
/usr/bin/bluez-test-audio
/usr/bin/bluez-test-device
/usr/bin/bluez-test-discovery
/usr/bin/bluez-test-input
/usr/bin/bluez-test-manager
/usr/bin/bluez-test-network
/usr/bin/bluez-test-serial
/usr/bin/bluez-test-service
/usr/bin/bluez-test-telephony
/usr/bin/ciptool
/usr/bin/dfutool
/usr/bin/hcitool
/usr/bin/l2ping
/usr/bin/l2test
/usr/bin/rctest
/usr/bin/rfcomm
/usr/bin/sdptool
在經過一陣亂猜跟亂試的過程後,發現hcitool這個東西比較有搞頭,看一下它有哪些參數可以用:
$ hcitool --help
hcitool - HCI Tool ver 4.91
Usage:
hcitool [options] <command> [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
spinq Start periodic inquiry
epinq Exit periodic inquiry
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lp Set/display link policy settings
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock
lescan Start LE scan
lewladd Add device to LE White List
lewlrm Remove device from LE White List
lewlsz Read size of LE White List
lewlclr Clear LE White list
lecc Create a LE Connection
ledc Disconnect a LE Connection
lecup LE Connection Update
For more information on the usage of each command use:
hcitool <command> --help
hcitool - HCI Tool ver 4.91
Usage:
hcitool [options] <command> [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
spinq Start periodic inquiry
epinq Exit periodic inquiry
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lp Set/display link policy settings
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock
lescan Start LE scan
lewladd Add device to LE White List
lewlrm Remove device from LE White List
lewlsz Read size of LE White List
lewlclr Clear LE White list
lecc Create a LE Connection
ledc Disconnect a LE Connection
lecup LE Connection Update
For more information on the usage of each command use:
hcitool <command> --help
又經過一陣亂試之後,發現以下結論:
掃描藍牙裝置可以用:
$ hcitool scan
Scanning ...
00:07:61:FC:C2:B9 Logitech Bluetooth Mouse M555b
00:07:61:FC:C2:B9 Logitech Bluetooth Mouse M555b
取得藍牙裝置名稱:
$ hcitool name 00:07:61:FC:C2:B9
Logitech Bluetooth Mouse M555b
取得藍牙裝置資訊:
$ sudo hcitool info 00:07:61:FC:C2:B9
[sudo] password for rudy:
Requesting information ...
BD Address: 00:07:61:FC:C2:B9
Device Name: Logitech Bluetooth Mouse M555b
LMP Version: 2.0 (0x3) LMP Subversion: 0x229
Manufacturer: Broadcom Corporation (15)
Features: 0xbc 0x02 0x04 0x38 0x08 0x00 0x00 0x00
<encryption> <slot offset> <timing accuracy> <role switch>
<sniff mode> <RSSI> <power control> <enhanced iscan>
<interlaced iscan> <interlaced pscan> <AFH cap. slave>
[sudo] password for rudy:
Requesting information ...
BD Address: 00:07:61:FC:C2:B9
Device Name: Logitech Bluetooth Mouse M555b
LMP Version: 2.0 (0x3) LMP Subversion: 0x229
Manufacturer: Broadcom Corporation (15)
Features: 0xbc 0x02 0x04 0x38 0x08 0x00 0x00 0x00
<encryption> <slot offset> <timing accuracy> <role switch>
<sniff mode> <RSSI> <power control> <enhanced iscan>
<interlaced iscan> <interlaced pscan> <AFH cap. slave>
裝置配對:
$ bluez-simple-agent hci0 00:07:61:FC:C2:B9
設定信任關係:
$ bluez-test-device trusted 00:07:61:FC:C2:B9 yes
連線藍牙滑鼠:
$ bluez-test-input connect 00:07:61:FC:C2:B9
這樣就ok了!以上步驟跟直接使用gnome-bluetooth的GUI介面設定結果相同,且設定結果也會反應在GUI介面上,看起來gnome-bluetooth內部也是使用bluez套件作為底層的指令。
No comments:
Post a Comment