debian下蓝牙适配器的配置和使用
本文打算将蓝牙适配器和手机蓝牙进行配对。
买了个支持蓝牙4.0协议的蓝牙适配器,将其插入到pc(debian 7.4)的usb口。
查看手机蓝牙信息:
选择手机中"设置"->"关于手机"->"状态信息"可以看到蓝牙地址是18:DC:56:D2:1C:1A
pc上安装蓝牙工具:
sudo apt-get install bluez bluez-hcidump
查看系统输出信息:
$ dmesg | tail -n
[25259.408121] usb -1.2: new full-speed USB device number using ehci_hcd
[25259.614615] usb -1.2: New USB device found, idVendor=0a12, idProduct=
[25259.614621] usb -1.2: New USB device strings: Mfr=, Product=, SerialNumber=
[25259.614626] usb -1.2: Product: CSR8510 A10
查看蓝牙适配器设备信息:
$ lsusb
Bus Device : ID 1d6b: Linux Foundation 2.0 root hub
Bus Device : ID 1d6b: Linux Foundation 1.1 root hub
Bus Device : ID 1d6b: Linux Foundation 1.1 root hub
Bus Device : ID 1d6b: Linux Foundation 1.1 root hub
Bus Device : ID 1d6b: Linux Foundation 1.1 root hub
Bus Device : ID 1a40: Terminus Technology Inc. -Port HUB
Bus 001 Device 031: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus Device : ID 046d:c05a Logitech, Inc. Optical Mouse M90
Bus Device : ID 413c: Dell Computer Corp. Keyboard
$ lsusb -s : -v Bus Device : ID 0a12: Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Couldn't open device, some information will be missing
Device Descriptor:
bLength
bDescriptorType
bcdUSB 2.00
bDeviceClass Wireless
bDeviceSubClass Radio Frequency
bDeviceProtocol Bluetooth
bMaxPacketSize0
idVendor 0x0a12 Cambridge Silicon Radio, Ltd
idProduct 0x0001 Bluetooth Dongle (HCI mode)
bcdDevice 88.91
iManufacturer
iProduct
iSerial
bNumConfigurations
Configuration Descriptor:
bLength
bDescriptorType
wTotalLength
bNumInterfaces
bConfigurationValue
iConfiguration
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x81 EP IN
bmAttributes
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0010 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x02 EP OUT
bmAttributes
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x82 EP IN
bmAttributes
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x bytes
bInterval
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x03 EP OUT
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0000 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x83 EP IN
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0000 1x bytes
bInterval
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x03 EP OUT
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0009 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x83 EP IN
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0009 1x bytes
bInterval
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x03 EP OUT
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0011 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x83 EP IN
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0011 1x bytes
bInterval
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x03 EP OUT
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0019 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x83 EP IN
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0019 1x bytes
bInterval
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x03 EP OUT
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0021 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x83 EP IN
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0021 1x bytes
bInterval
Interface Descriptor:
bLength
bDescriptorType
bInterfaceNumber
bAlternateSetting
bNumEndpoints
bInterfaceClass Wireless
bInterfaceSubClass Radio Frequency
bInterfaceProtocol Bluetooth
iInterface
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x03 EP OUT
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0031 1x bytes
bInterval
Endpoint Descriptor:
bLength
bDescriptorType
bEndpointAddress 0x83 EP IN
bmAttributes
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0031 1x bytes
bInterval
安装bluez后,会提供两个工具hciconfig和hcitool进行蓝牙相关的配置。
查看当前蓝牙适配器参数配置:
$ sudo hciconfig -a
hci0: Type: BR/EDR Bus: USB
BD Address: :1A:7D:DA:: ACL MTU: : SCO MTU: :
UP RUNNING PSCAN
RX bytes: acl: sco: events: errors:
TX bytes: acl: sco: commands: errors:
Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'debian-0'
Class: 0x420100
Service Classes: Networking, Telephony
Device Class: Computer, Uncategorized
HCI Version: 4.0 (0x6) Revision: 0x22bb
LMP Version: 4.0 (0x6) Subversion: 0x22bb
Manufacturer: Cambridge Silicon Radio ()
蓝牙适配器的mac地址是: 00:1A:7D:DA:71:13,名称是debian-0。
查看蓝牙适配器提供的各种功能:
$ sdptool browse local
Browsing FF:FF:FF::: ...
Service Name: SIM Access Server
Service RecHandle: 0x10000
Service Class ID List:
"SIM Access" (0x112d)
"Generic Telephony" (0x1204)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel:
Profile Descriptor List:
"SIM Access" (0x112d)
Version: 0x0101 Service Name: Headset Audio Gateway
Service RecHandle: 0x10001
Service Class ID List:
"Headset Audio Gateway" (0x1112)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel:
Profile Descriptor List:
"Headset" (0x1108)
Version: 0x0102 Service Name: Hands-Free Audio Gateway
Service RecHandle: 0x10002
Service Class ID List:
"Handsfree Audio Gateway" (0x111f)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel:
Profile Descriptor List:
"Handsfree" (0x111e)
Version: 0x0105 Service Name: AVRCP TG
Service RecHandle: 0x10003
Service Class ID List:
"AV Remote Target" (0x110c)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM:
"AVCTP" (0x0017)
uint16: 0x103
Profile Descriptor List:
"AV Remote" (0x110e)
Version: 0x0103 Service Name: AVRCP CT
Service RecHandle: 0x10004
Service Class ID List:
"AV Remote" (0x110e)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM:
"AVCTP" (0x0017)
uint16: 0x103
Profile Descriptor List:
"AV Remote" (0x110e)
Version: 0x0100 Service Name: Dial-Up Networking
Service RecHandle: 0x10005
Service Class ID List:
"Dialup Networking" (0x1103)
"Generic Networking" (0x1201)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel:
Profile Descriptor List:
"Dialup Networking" (0x1103)
Version: 0x0100 Service Name: OBEX Object Push
Service RecHandle: 0x10006
Service Class ID List:
"OBEX Object Push" (0x1105)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel:
"OBEX" (0x0008)
Profile Descriptor List:
"OBEX Object Push" (0x1105)
Version: 0x0100 Service Name: OBEX File Transfer
Service RecHandle: 0x10007
Service Class ID List:
"OBEX File Transfer" (0x1106)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel:
"OBEX" (0x0008)
Profile Descriptor List:
"OBEX File Transfer" (0x1106)
Version: 0x0100
扫描蓝牙设备:
$ hcitool scan
Scanning ...
C4::FE:F6::FF PC-
CC::AF:4F:: HR-6F1397D64651
18:DC:56:D2:1C:1A Coolpad 8297
使用hcitool获取手机蓝牙信息:
$ hcitool name :DC::D2:1C:1A
Coolpad
$ sudo hcitool info :DC::D2:1C:1A
Requesting information ...
BD Address: :DC::D2:1C:1A
Device Name: Coolpad
LMP Version: 4.0 (0x6) LMP Subversion: 0x0
Manufacturer: MediaTek, Inc. ()
Features page : 0xbf 0x3e 0x8d 0xfe 0xdb 0xff 0x5b 0x87
<-slot packets> <-slot packets> <encryption> <slot offset>
<timing accuracy> <role switch> <sniff mode> <RSSI>
<channel quality> <SCO link> <HV2 packets> <HV3 packets>
<CVSD> <power control> <transparent SCO> <broadcast encrypt>
<EDR ACL Mbps> <EDR ACL Mbps> <enhanced iscan>
<interlaced iscan> <interlaced pscan> <inquiry with RSSI>
<extended SCO> <EV4 packets> <EV5 packets> <AFH cap. slave>
<AFH class. slave> <LE support> <-slot EDR ACL>
<-slot EDR ACL> <sniff subrating> <pause encryption>
<AFH cap. master> <AFH class. master> <EDR eSCO Mbps>
<EDR eSCO Mbps> <-slot EDR eSCO> <extended inquiry>
<LE and BR/EDR> <simple pairing> <encapsulated PDU>
<non-flush flag> <LSTO> <inquiry TX power> <EPC>
<extended features>
Features page : 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Features page : 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
配置蓝牙适配器使得能被其他设备搜索到:
$ sudo hciconfig hci0 iscan
这时在手机中搜索蓝牙设备可以搜索到"debian-0",但是使用手机配对时提示“PIN或者配对密钥不正确,无法和debian-0进行配对"。
在执行下面几条命令:
$ sudo hciconfig hci0 pscan
$ sudo hciconfig hci0 noencrypt
$ sudo hciconfig hci0 noauth
然后在手机里可以对"debian-0"配对即可配对成功。
此时可以在pc上执行l2ping命令 :
host@debian:~$ sudo l2ping -c :DC::D2:1C:1A
[sudo] password for host:
Ping: :DC::D2:1C:1A from :1A:7D:DA:: (data size ) ...
bytes from :DC::D2:1C:1A id time .00ms
bytes from :DC::D2:1C:1A id time .16ms
bytes from :DC::D2:1C:1A id time .14ms
sent, received, % loss
如果不使用上面的hciconfig命令来进行配置,也可以使用blueman或者gnome-bluetooth来配置蓝牙,安装这些工具:
sudo apt-get install blueman gnome-bluetooth
这两个工具都是图形化界面,使用起来相当方便,只是需要从手机端发起配对请求,然后在pc端和手机端分别进行确认即完成配对。
然后可以在pc端用蓝牙来向手机发送文件。
上面这两种情况下都是在手机端发起配对请求,之后也只是能通过蓝牙发文件。
但我希望能够使用bluez系列工具中提供的命令行工具从pc端发起配对请求,以便于以后将蓝牙适配器用到嵌入式开发板上。
参考《在linux下蓝牙使用rfcomm连接》 、《BluetoothUser》以及《Bluetooth_Mouse》进行操作,但都没成功,
这是因为我使用的bluez版本是4.99,没有bluez5中的bluetoothctl工具,也没有bluez4中的hidd工具,也没有常用的bluez3中的/etc/bluetooth/hcid.conf配置文件,
进行配对时总是会因为pin或者key的问题而导致配对失败,导致网络上大部分教程都不适用于这个版本。
最终我选用了另一种方式,先从手机来对蓝牙设备进行配对,然后将其模式修改成master,再从pc下执行命令就可以了。
首先配置rfcomm,修改/etc/bluetooth/rfcomm.conf(其实我不确定是否需要该配置,只是在参考网络文章时修改了这个配置文件):
host@debian:~$ cat /etc/bluetooth/rfcomm.conf
#
# RFCOMM configuration file.
# rfcomm0 {
# Automatically bind the device at startup
bind no; # Bluetooth address of the device
device :DC::D2:1C:1A; # RFCOMM channel for the connection
channel ; # Description of the connection
comment "Example Bluetooth device";
}
重启蓝牙服务:
sudo /etc/init.d/bluetooth restart
可以使用hcidump(类似于tcpdump工具能够打印bluez中每步都执行了什么功能,可以用于调试):
sudo hcidump -Xt
按照前面的步骤从手机来对蓝牙适配器进行配对,可以配对成功。
查看hci0(类似于网卡的eth0接口)的连接模式(link mode,可以是master或者slave):
$ sudo hciconfig hci0 lm
hci0: Type: BR/EDR Bus: USB
BD Address: :1A:7D:DA:: ACL MTU: : SCO MTU: :
Link mode: SLAVE ACCEPT
将其连接模式从SLAVE修改为master:
sudo hciconfig hci0 lm master
这时查看连接模式:
$ sudo hciconfig hci0 lm
[sudo] password for host:
hci0: Type: BR/EDR Bus: USB
BD Address: :1A:7D:DA:: ACL MTU: : SCO MTU: :
Link mode: MASTER
已经将link mode修改为master模式。
使用rfcomm来连接手机蓝牙设备:
$ sudo rfcomm connect hci0 :DC::D2:1C:1A
Connected /dev/rfcomm0 to :DC::D2:1C:1A on channel
Press CTRL-C for hangup
连接成功,查看连接信息:
$ sudo hcitool con
Connections:
< ACL :DC::D2:1C:1A handle state lm MASTER AUTH ENCRYPT
可以执行hcitool中的cmd命令,例如下面的命令将当前设备的名称改成"ABCD":
$ sudo hcitool cmd 0x03 0x0013 0x41 0x42 0x43 0x44
< HCI Command: ogf 0x03, ocf 0x0013, plen > HCI Event: 0x0e plen
0C
此时在hcidump对应窗口显示下面的信息:
-- ::22.929405 < HCI Command: Write Local Name (0x03|0x0013) plen
name 'ABCDBCD'
-- ::22.930381 > HCI Event: Command Complete (0x0e) plen
Write Local Name (0x03|0x0013) ncmd
status 0x00
-- ::22.930474 < HCI Command: Read Local Name (0x03|0x0014) plen
-- ::22.947378 > HCI Event: Command Complete (0x0e) plen
Read Local Name (0x03|0x0014) ncmd
status 0x00 name 'ABCD'
使用hciconfig工具也可以查看到当前蓝牙适配器名称:
$ sudo hciconfig hci0 name
hci0: Type: BR/EDR Bus: USB
BD Address: :1A:7D:DA:: ACL MTU: : SCO MTU: :
Name: 'ABCD'
可以看到蓝牙适配器的名称已经被改成ABCD了。
还有其他很多命令都可以用hcitool hci0 cmd来进行配置,《利用 hcitool 通过hci 命令与芯片交互》中提供了其他的一些命令,感兴趣的话可以自己玩玩看。
也可以下载《蓝牙4.0规范》,从704-1103页有关于蓝牙命令的详细说明。
debian下蓝牙适配器的配置和使用的更多相关文章
- debian下mysql主从配置
1.确保master/slave只有一份/etc/mysql/my.cnf , 不要在其他地方再有my.cnf (如/etc/my.cnf /usr/local之类) 2.master配置: 在[m ...
- debian下samba配置
debian下samba配置 http://blog.chinaunix.net/uid-2282111-id-2113216.html 服务器端配置过程:1. apt-get install sa ...
- Debian下配置防火墙iptables
debian下iptables输入命令后即时生效,但重启之后配置就会消失,可用iptables-save快速保存配置,因为Debian上iptables是不会保存规则的,然后在开机自动的时候让ipta ...
- debian下配置keepalived ha
抄袭自http://blog.51yip.com/server/1417.html,做了一些修改 可以参考http://blog.linuxphp.org/archives/1615/ 备注:NAT模 ...
- debian下安装zendframework
第一步,打开apache的rewrite模块,因为在debian下使用apache必须执行这一步 a2enmod rewrite #激活rewrite模块 /etc/init.d/apache2 re ...
- debian下使用gitosis+gitweb搭建SSH认证的git服务器
搭建完成Git服务器后,需要使用两台机器进行测试,一台机器作为服务器端server,一台服务器作为客户端client.整个系统,需要三个计算机账户,这里假设server端的账户名为git,client ...
- Debian 入门安装与配置2
Debian 入门安装与配置2 1. C/C++开发必装软件 atp-get install gcc 这个不用说,用来编译C程序 apt-get install g++ 用来编译C++程序 ap ...
- Debian 入门安装与配置1
Debian 入门安装与配置1 最近安装了多个发行版本的Linux,包括Ubuntu.Fedora.Centos和Debian,发现只有Debian在界面和稳定性等综合特性上表现最优,自己也最喜欢,所 ...
- debian下软件包管理方式总结
linux最流行的包管理方式除了rpm之外就是debian的deb格式了.目前采用deb管理方式的主流操作系统主要有debian和ubuntu系列.和rpm包管理方式不同的是,虽然debian也有包含 ...
随机推荐
- UIViewController新方法的使用(transitionFromViewController:toViewController:duration:options:animations:completion:)
iOS5中,UIViewController新添加了几个方法: - (void)addChildViewController:(UIViewController *)childController N ...
- 摘录 LDAP
1.LDAP就是 light DAP, 轻量级目录访问协议 LDAP是轻量目录访问协议(Lightweight Directory Access Protocol)的缩写 LDAP标准 ...
- Java编程手冊-Collection框架(上)
该文章所讲内容基本涵盖了Collection里面的全部东西,尽管基于jdk 1.5的.可是思路非常清晰 1.引言 1.1 Collection框架的介绍 尽管我们能够使用数组去存储具有同样类型的元素集 ...
- 【.net项目中。。】.net一般处理程序使用方法
1.基本原理图 IsReusable属性用来表示在IHttpHandlerFactory对象创建IHttpHandler的时候是否能够将这个Handler存入池中以便重用. 一般处理程序(HttpHa ...
- mysql更改表结构:添加、删除、修改字段、调整字段顺序
添加字段: alter table `user_movement_log` Add column GatewayId int not null default 0 AFTER `Regionid` ( ...
- thinkphp5或3.2 php动态修改config配置文件永久保存
thinkphp默认的参数方法只能读取,或者动态修改不能永久修改. 这是自己摸索出来的特发出来给需要的朋友(懂的朋友别笑话,功能我自己使用是没任何问题).有些参数还是保存在配置文件方便快捷!不一定所有 ...
- 解析spark RDD
RDD是spark抽象的基石,可以说整个spark编程就是对RDD进行的操作 RDD是弹性的分布式数据集,它是只读的,可分区的,这个数据集的全部或者部分数据可以缓存在内存中,在多次计算间重用.所谓 ...
- 从零開始学Swift之Hello World进化版
上节课,也就是昨晚啦,我们学习到从零開始学Swift之Hello World.那一节仅仅有一句代码,大家会认为不够过瘾. 那么这节课,就给大家来多点瘾货吧! 先上图! //var 代表变量的类型, s ...
- pip安装错误,用镜像
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'Connec ...
- 基于markdown的blog系统调研1:typecho
))