[daily][device][bluetooth] 蓝牙怎么办!(archlinux下驱动蓝牙鼠标,以及三星手机)

-----------------------  update @ 2018-07-27 ---------------------

quick start

1.  systemctl start buletooth

2. bluetoothctl

3. scan on

发现鼠标后.

4. scan off

5. connect 4D:7D:96:B0:79:72

6. pair 4D:7D:96:B0:79:72

7. trust 4D:7D:96:B0:79:72

完.

-------------------------------------------------------------

去年地摊买的破无线鼠标坏掉了。看上微软的Designer Mouse蓝牙鼠,但是买之前我要确认我能不能驱起来。

这款鼠标只支持蓝牙4.0。系统支持windows8以上,不支持xp和windows7. 其他系统支持mac和android,没写linux。

由于之前也没搞过蓝牙设备,所以需要了解一下linux下的蓝牙设备。然后在解决鼠标的问题。

需要解决的问题:

1. archlinux下蓝牙设备的使用与配置

2. 确定T450的蓝牙版本。

3. 驱鼠标。

首先,按照惯例还是读一下万事万灵的archlinux文档

0. 插叙一部分其他内容。

  a. rfkill 用以控制无线设备的软开关,功能与键盘上边的快捷键Fn+WiFi,Fn+BT相同。演示如下:

[tong@T7 ~]$ rfkill list
: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: no
Hard blocked: no
: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
[tong@T7 ~]$ rfkill block
[tong@T7 ~]$ rfkill list
: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: yes
Hard blocked: no
: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
[tong@T7 ~]$ rfkill block
[tong@T7 ~]$ rfkill list
: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: yes
Hard blocked: no
: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: no
[tong@T7 ~]$ ip link
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN mode DEFAULT group default qlen
link/loopback ::::: brd :::::
: lan0: <BROADCAST,MULTICAST> mtu qdisc noop state DOWN mode DEFAULT group default qlen
link/ether :7b:9d:5c:1e:9b brd ff:ff:ff:ff:ff:ff
: wlan0: <BROADCAST,MULTICAST> mtu qdisc mq state DOWN mode DORMANT group default qlen
link/ether dc:::6c:b5:7e brd ff:ff:ff:ff:ff:ff
: internal-br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN mode DEFAULT group default qlen
link/ether :e4:a6:::9b brd ff:ff:ff:ff:ff:ff
[tong@T7 ~]$ rfkill unblock
[tong@T7 ~]$ ip link
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN mode DEFAULT group default qlen
link/loopback ::::: brd :::::
: lan0: <BROADCAST,MULTICAST> mtu qdisc noop state DOWN mode DEFAULT group default qlen
link/ether :7b:9d:5c:1e:9b brd ff:ff:ff:ff:ff:ff
: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc mq state UP mode DORMANT group default qlen
link/ether dc:::6c:b5:7e brd ff:ff:ff:ff:ff:ff
: internal-br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN mode DEFAULT group default qlen
link/ether :e4:a6:::9b brd ff:ff:ff:ff:ff:ff
[tong@T7 ~]$ rfkill list
: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: yes
Hard blocked: no
: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
[tong@T7 ~]$ rfkill unblock
[tong@T7 ~]$ rfkill list
: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: no
Hard blocked: no
: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
[tong@T7 ~]$

1. 使用lsusb命令查看蓝牙设备,我是使用 -v 参数查看到详细信息后最终确定才确定了 Bus2 Device5是蓝牙设备。关于蓝牙设备相关的知识,还需要深入的学习。

在使用lsusb命令前,首先应该使用rfkill命令unblock蓝牙开关(tpacpi_bluetooth_sw),之后才能在lsusb中可见。

[tong@T7 ~]$ lsusb
Bus Device : ID : Intel Corp.
Bus Device : ID 1d6b: Linux Foundation 2.0 root hub
Bus Device : ID 1d6b: Linux Foundation 3.0 root hub
Bus Device : ID 04f2:b449 Chicony Electronics Co., Ltd
Bus Device : ID :0a2a Intel Corp.
Bus Device : ID 138a: Validity Sensors, Inc. Fingerprint Reader
Bus Device : ID 1d6b: Linux Foundation 2.0 root hub
[tong@T7 ~]$

2. 查看驱动,蓝牙设备由 btusb 驱动。

[tong@T7 ~]$ lsmod |grep ^btusb
btusb
[tong@T7 ~]$ modinfo btusb
filename: /lib/modules/4.7.--ARCH/kernel/drivers/bluetooth/btusb.ko.gz
license: GPL
version: 0.8
description: Generic Bluetooth USB driver ver 0.8
... ...

3. 管理程序,蓝牙设备由软件包bluez (linux蓝牙协议栈实现之一) 进行管理。

[tong@T7 ~]$ pacman -Qii bluez
Name : bluez
Version : 5.42-
Description : Daemons for the bluetooth protocol stack
Architecture : x86_64
URL : http://www.bluez.org/
... ...
UNMODIFIED /etc/dbus-/system.d/bluetooth.conf
UNMODIFIED /etc/bluetooth/main.conf
[tong@T7 ~]$ pacman -Ql bluez
bluez /etc/bluetooth/main.conf
bluez /etc/dbus-/system.d/bluetooth.conf
bluez /usr/lib/bluetooth/bluetoothd
bluez /usr/lib/systemd/system/bluetooth.service
... ...
bluez /usr/share/man/man8/bluetoothd..gz
[tong@T7 ~]$

根据配置文件 bluetooth.conf 中的设置,使用bluetoothd的用户需要加入 ‘lp’ 用户组。

[tong@T7 ~]$ groups
lp wheel docker tong
[tong@T7 ~]$ systemctl start bluetooth
[tong@T7 ~]$

发现报错如下:(ERROR 1)

[tong@T7 ~]$ systemctl status bluetooth 
● bluetooth.service - Bluetooth service
  Loaded: loaded (/usr/lib/systemd/system/bluetooth.service; disabled; vendor preset: disabled)
  Active: active (running) since Fri 2016-10-07 22:32:47 CST; 16min ago
    Docs: man:bluetoothd(8)
Main PID: 570 (bluetoothd)
  Status: "Running"
   Tasks: 1 (limit: 4915)
  CGroup: /system.slice/bluetooth.service
          └─570 /usr/lib/bluetooth/bluetoothd
Oct 07 22:32:47 T7 systemd[1]: Starting Bluetooth service...
Oct 07 22:32:47 T7 bluetoothd[570]: Bluetooth daemon 5.42
Oct 07 22:32:47 T7 systemd[1]: Started Bluetooth service.
Oct 07 22:32:47 T7 bluetoothd[570]: Starting SDP server
Oct 07 22:32:47 T7 bluetoothd[570]: Bluetooth management interface 1.12 initialized
Oct 07 22:32:47 T7 bluetoothd[570]: Failed to obtain handles for "Service Changed" characteristic
Oct 07 22:32:47 T7 bluetoothd[570]: Sap driver initialization failed.
Oct 07 22:32:47 T7 bluetoothd[570]: sap-server: Operation not permitted (1)
[tong@T7 ~]$

KDE图型化配置工具 bluedevil。在发生上面的这个错误之后,有手机s7e进行测试,手机可以接收电脑发送的文件,电脑不能对手机发起链接,每次点击connect按钮错误信息如下:(ERROR 2)

Oct 07 23:30:28 T7 bluetoothd[8666]: a2dp-source profile connect failed for xxx:93:D4: Protocol not available
Oct 07 23:30:59 T7 bluetoothd[8666]: a2dp-source profile connect failed for xxxx93:D4: Protocol not available

a2dp 全名Advanced Audio Distribution Profile,大概因为手机默认会使用这种音频传输,所以由于电脑不支持导致了问题。 从 文档的audio章节 得到的内容,可以尝试安装音频包  pulseaudio-bluetooth 。 安装后果然可以成功connect了。链接成功之后,电脑会自动播放手机的音频。然而手机主动推送给电脑的文件,仍然不能正确接受。

ERROR 1 的错误仍然存在,先rfkill unblock就会打印ERROR 1. 先启动再unblock,就不会打印。当unblock时才打印。23333。

Oct  :: T7 plasmashell[]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property 'devices' of undefined
Oct :: T7 plasmashell[]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property 'devices' of undefined
Oct :: T7 plasmashell[]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property 'devices' of undefined
Oct :: T7 plasmashell[]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property 'devices' of undefined
Oct :: T7 plasmashell[]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property 'devices' of undefined
Oct :: T7 plasmashell[]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property 'devices' of undefined

跟踪了日志,不能上传文件,看似是UI程序的问题。可以忽略,使用命令行工具继续测试。

4. 命令行配置工具 bluetoothctl , 通过安装工具包 bluez-utils。

  a. 启动服务

[tong@T7 ~]$ sudo systemctl start bluetooth
[tong@T7 ~]$ rfkill unblock

  b. 使用 bluetoothctl

Start the bluetoothctl interactive command. There one can input help to get a list of available commands.
  1. Turn the power to the controller on by entering power on. It is off by default.
  2. Enter devices to get the MAC Address of the device with which to pair.
  3. Enter device discovery mode with scan on command if device is not yet on the list.
  4. Turn the agent on with agent on.
  5. Enter pair MAC Address to do the pairing (tab completion works).
  6. If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter trust MAC Address to do so.
  7. Finally, use connect MAC_address to establish a connection.

连接成功了,但是文件传输过程中,仍然各种报错,除了 sdptool browse 20:2D:xxxxxx 成功意外,其他方式 (obexfs, obexftp, ussp-push) 都不能成功。

在bluetoothctl 中有如下报错信息:

[bluetooth]# connect :xxxD4
Attempting to connect to :xxxxx:D4
[CHG] Device :xxxxx:D4 Connected: yes
[CHG] Device :xxxxx:D4 ServicesResolved: yes
Failed to connect: org.bluez.Error.NotAvailable
[CHG] Device :xxxxx:D4 ServicesResolved: no
[CHG] Device :xxxxx:D4 Connected: no
[bluetooth]# connect :xxxxx:D4
Attempting to connect to :xxxxx:D4
[CHG] Device :xxxxx:D4 Connected: yes
[CHG] Device :xxxxx:D4 ServicesResolved: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device :xxxxx:D4 ServicesResolved: no
[CHG] Device :xxxxx:D4 Connected: no
[CHG] Device :xxxxx:D4 Connected: yes
[CHG] Device :xxxxx:D4 Connected: no
[bluetooth]#

journal里有如下信息:

Oct  :: T7 sudo[]: pam_unix(sudo:session): session closed for user root
Oct :: T7 bluetoothd[]: :xxxxx:D4: error updating services: Connection timed out ()
Oct :: T7 bluetoothd[]: Unable to get a audio source object
Oct :: T7 bluetoothd[]: Unable to get a audio source object
Oct :: T7 bluetoothd[]: :xxxxx:D4: error updating services: Connection timed out ()
Oct :: T7 bluedevil-sendfile[]: bluedevil.sendfile: Device "/org/bluez/hci0/dev_20_xxxx_D4"
Oct :: T7 bluedevil-sendfile[]: bluedevil.sendfile: Files ()
Oct :: T7 bluedevil-sendfile[]: bluedevil.sendfile: Manager initialized
Oct :: T7 bluedevil-sendfile[]: BluezQt: PendingCall Error: "Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken."
Oct :: T7 bluedevil-sendfile[]: bluedevil.sendfile: Error creating session "Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken."
Oct :: T7 bluedevil-sendfile[]: bluedevil.sendfile: Initialize Fail Page
Oct :: T7 obexd[]: Unable to find service record
Oct :: T7 bluedevil-sendfile[]: bluedevil.sendfile: Wizard done:

暂时放弃了。。。

蓝牙版本:也学是从这里看吧?!反正看见了4.2

[tong@T7 ~]$ hciconfig -a
hci0: Type: Primary Bus: USB
BD Address: DC:::6C:B5: ACL MTU: : SCO MTU: :
UP RUNNING PSCAN ISCAN
RX bytes: acl: sco: events: errors:
TX bytes: acl: sco: commands: errors:
Features: 0xff 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF
Link mode: SLAVE ACCEPT
Name: 'T7'
Class: 0x1c010c
Service Classes: Rendering, Capturing, Object Transfer
Device Class: Computer, Laptop
HCI Version: 4.2 (0x8) Revision: 0x1000
LMP Version: 4.2 (0x8) Subversion: 0x1000
Manufacturer: Intel Corp. ()

最后,管他驱不驱得起,买了再说!

到货! 哪里需要那么复杂,只要打开 bluetooth.service 然后在KDE状态栏配对连接就ok了。马上可用!

长时间使用会不会断啊,什么之类的,还有在观察,有问题以后更新。

简单评价一下这个 鼠。外观设计真的超赞,价钱也不贵。电池藏磁吸附设计,电池的触点也非常的特别。感觉每一个细节都是精心的设计。滑轮的手感我个人不太喜欢,但是也还好。缺点说实在的在于手感。因为这种扁平的设计,当你把手放在鼠标上的时候,手指是悬空的没有支持,并不舒服。当然这一点我在买之前就已经想到了。毕竟在完美好看的外观面前,舒适又算什么呢?2333.

上照一张,附带我提前衰老的爪。

[daily][device][bluetooth] 蓝牙怎么办!(archlinux下驱动蓝牙鼠标,以及三星手机)

过一段时间,补充稳定性等问题,并补充开关机自动识别之类的设置。等不及了,我要开始体验了。

(2个小时以后)。。。

这么快就回来补充配置了。

第一步,rfkill,rfkill的配置是重启保留的,即如果你之前是block的,关完机再开机它还是block的。如果你之前是unblock的,你关完机再开机它还是unblock的。

第二步,bluez(即守护进程bluetoothd)。使用 systemctl enable bluetooth 设置成开机启动。

第三步,bluetoothctl。依据前文提到的操作,顺序执行 pair, trust, connect. 之后就可以顺利使用了。

  然后,当我退出bluetoothctl时,实际上关于bluetoothctl的这些配置就都失效了。即蓝牙鼠标的关联是断开的。当我把x状态保留在display manager没有登录之前时,就可以测试鼠标的这一时效状态。但是login进入kde之后,鼠标又好使了,因为这个时候kde启动了bluedevil程序用以蓝牙管理。而它会继承之前在bluetoothctl中对蓝牙设备进行的配对等操作。所以在无人工配置的情况下,不进入KDE,蓝牙鼠标就不能用。而这一点我是可以接受的,因为不进KDE,要鼠标又有什么用呢? 当然,FVWM下想必也不好使,这个可以留到之后在处理了。

最后,完成了以上三步之后,在KDE环境里,蓝牙鼠就是完美可用状态。out of box。只要在鼠标上打开开关。在电脑上打开开关(rfkill)。无论重启或开机,或怎么,随时可用,

完,: )

Update @ 20161028

这一周恢复了正常上下班活动,在公司也增加了鼠标的使用频率,有了一些进一步的使用体验,虽然还有小红点。

在左键点击的时候,偶尔会出现塑料与塑料之间摩擦的‘吱吱’的声音,影响使用体验,单击动作也相应的不够干脆清爽。整体上,有一种廉价的质感,有一种做工不精良的感觉。

update @ 20170703

换了新电脑,重新pair鼠标

[root@T7 ~]# bluetoothctl 

不太好用,最后在plasma UI里面莫名其妙的成功了。

上一篇:Bluetooth in Android 4.2 and 4.3(一):综述


下一篇:关于 使用python向qq好友发送消息(对爬虫的作用----当程序执行完毕或者报错无限给自己qq发送消息,直到关闭)