码迷,mamicode.com
首页 > 其他好文 > 详细

[daily][device][bluetooth] 蓝牙怎么办!

时间:2016-10-08 07:36:40      阅读:665      评论:0      收藏:0      [点我收藏+]

标签:

去年地摊买的破蓝牙鼠坏掉了。看上微软的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
0: tpacpi_bluetooth_sw: Bluetooth
        Soft blocked: no
        Hard blocked: no
2: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
7: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no
[tong@T7 ~]$ rfkill block 0
[tong@T7 ~]$ rfkill list   
0: tpacpi_bluetooth_sw: Bluetooth
        Soft blocked: yes
        Hard blocked: no
2: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
[tong@T7 ~]$ rfkill block 2   
[tong@T7 ~]$ rfkill list
0: tpacpi_bluetooth_sw: Bluetooth
        Soft blocked: yes
        Hard blocked: no
2: phy0: Wireless LAN
        Soft blocked: yes
        Hard blocked: no
[tong@T7 ~]$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: lan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 50:7b:9d:5c:1e:9b brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
    link/ether dc:53:60:6c:b5:7e brd ff:ff:ff:ff:ff:ff
4: internal-br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 12:e4:a6:90:01:9b brd ff:ff:ff:ff:ff:ff
[tong@T7 ~]$ rfkill unblock 2
[tong@T7 ~]$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: lan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 50:7b:9d:5c:1e:9b brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether dc:53:60:6c:b5:7e brd ff:ff:ff:ff:ff:ff
4: internal-br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 12:e4:a6:90:01:9b brd ff:ff:ff:ff:ff:ff
[tong@T7 ~]$ rfkill list
0: tpacpi_bluetooth_sw: Bluetooth
        Soft blocked: yes
        Hard blocked: no
2: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
[tong@T7 ~]$ rfkill unblock 0
[tong@T7 ~]$ rfkill list
0: tpacpi_bluetooth_sw: Bluetooth
        Soft blocked: no
        Hard blocked: no
2: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
8: 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 001 Device 002: ID 8087:8001 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 004: ID 04f2:b449 Chicony Electronics Co., Ltd 
Bus 002 Device 005: ID 8087:0a2a Intel Corp. 
Bus 002 Device 002: ID 138a:0017 Validity Sensors, Inc. Fingerprint Reader
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[tong@T7 ~]$ 

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

[tong@T7 ~]$ lsmod |grep ^btusb          
btusb                  40960  0
[tong@T7 ~]$ modinfo btusb
filename:       /lib/modules/4.7.6-1-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-1
Description     : Daemons for the bluetooth protocol stack
Architecture    : x86_64
URL             : http://www.bluez.org/
... ...
UNMODIFIED      /etc/dbus-1/system.d/bluetooth.conf
UNMODIFIED      /etc/bluetooth/main.conf
[tong@T7 ~]$ pacman -Ql bluez
bluez /etc/bluetooth/main.conf
bluez /etc/dbus-1/system.d/bluetooth.conf
bluez /usr/lib/bluetooth/bluetoothd
bluez /usr/lib/systemd/system/bluetooth.service
... ...
bluez /usr/share/man/man8/bluetoothd.8.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 08 00:42:02 T7 plasmashell[651]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property ‘devices‘ of undefined
Oct 08 00:42:02 T7 plasmashell[651]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property ‘devices‘ of undefined
Oct 08 00:42:02 T7 plasmashell[651]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property ‘devices‘ of undefined
Oct 08 00:42:06 T7 plasmashell[651]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property ‘devices‘ of undefined
Oct 08 00:42:06 T7 plasmashell[651]: file:///usr/share/plasma/plasmoids/org.kde.plasma.bluetooth/contents/ui/logic.js:34: TypeError: Cannot read property ‘devices‘ of undefined
Oct 08 00:42:06 T7 plasmashell[651]: 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 0

  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 20:xxxD4
Attempting to connect to 20:xxxxx:D4
[CHG] Device 20:xxxxx:D4 Connected: yes
[CHG] Device 20:xxxxx:D4 ServicesResolved: yes
Failed to connect: org.bluez.Error.NotAvailable
[CHG] Device 20:xxxxx:D4 ServicesResolved: no
[CHG] Device 20:xxxxx:D4 Connected: no
[bluetooth]# connect 20:xxxxx:D4 
Attempting to connect to 20:xxxxx:D4
[CHG] Device 20:xxxxx:D4 Connected: yes
[CHG] Device 20:xxxxx:D4 ServicesResolved: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device 20:xxxxx:D4 ServicesResolved: no
[CHG] Device 20:xxxxx:D4 Connected: no
[CHG] Device 20:xxxxx:D4 Connected: yes
[CHG] Device 20:xxxxx:D4 Connected: no
[bluetooth]# 

journal里有如下信息:

Oct 08 01:57:12 T7 sudo[2164]: pam_unix(sudo:session): session closed for user root
Oct 08 01:57:32 T7 bluetoothd[1918]: 20:xxxxx:D4: error updating services: Connection timed out (110)
Oct 08 02:01:44 T7 bluetoothd[1918]: Unable to get a audio source object
Oct 08 02:02:08 T7 bluetoothd[1918]: Unable to get a audio source object
Oct 08 02:03:28 T7 bluetoothd[1918]: 20:xxxxx:D4: error updating services: Connection timed out (110)
Oct 08 02:03:44 T7 bluedevil-sendfile[2242]: bluedevil.sendfile: Device "/org/bluez/hci0/dev_20_xxxx_D4"
Oct 08 02:03:44 T7 bluedevil-sendfile[2242]: bluedevil.sendfile: Files ()
Oct 08 02:03:44 T7 bluedevil-sendfile[2242]: bluedevil.sendfile: Manager initialized
Oct 08 02:04:14 T7 bluedevil-sendfile[2242]: 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 08 02:04:14 T7 bluedevil-sendfile[2242]: 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 08 02:04:14 T7 bluedevil-sendfile[2242]: bluedevil.sendfile: Initialize Fail Page
Oct 08 02:04:30 T7 obexd[726]: Unable to find service record
Oct 08 02:05:49 T7 bluedevil-sendfile[2242]: bluedevil.sendfile: Wizard done:  0

暂时放弃了。。。

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

[tong@T7 ~]$ hciconfig -a 
hci0:   Type: Primary  Bus: USB
        BD Address: DC:53:60:6C:B5:82  ACL MTU: 1021:5  SCO MTU: 96:6
        UP RUNNING PSCAN ISCAN 
        RX bytes:59028 acl:385 sco:0 events:1456 errors:0
        TX bytes:50956 acl:341 sco:0 commands:563 errors:0
        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. (2)

 

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

[daily][device][bluetooth] 蓝牙怎么办!

标签:

原文地址:http://www.cnblogs.com/hugetong/p/5929314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!