Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29962
  • 博文数量: 6
  • 博客积分: 28
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-20 15:05
文章分类
文章存档

2012年(6)

我的朋友

分类:

2012-07-25 11:01:35

Andrew Haung
 
一.Linux对于蓝牙的支持
--------------------------------------------------------------
参见如下协议图,在HCI界面之上需要软件来实现。
 
1.Linux 内核对蓝牙支持
 
在Linux 2.6内核已经实现如下协议。
   串口形式蓝牙设备驱动(HCI UART driver)
   USB蓝牙棒驱动(HCI USB driver)
 
  内核也实现了L2CAP,RFCOMM串口接口,以及SCO链路支持.
 
另外内核也直接支持BNEP(Bluetooth Network Encapsulation Protocol ),即把蓝牙网络当成一个无线局域网操作。
 
Linux也带了蓝牙输入设备的相关支持。
需要打开 HIDP 和HID2HCI两个选项都要打开.
 
DUND 把蓝牙网络当成一个拨号网络来处理。
.
2.蓝牙协议栈
   在实现了L2CAP后,也需要一个蓝牙协议栈处理。它起什么作用呢? 我的理解是内核封装到RFCOMM的层次,即只负责的蓝牙的包的封装与收发。至于包收上来,在蓝牙的四个阶段,如何应用的状态影响,以及如何响应正确的包,这一些事情由蓝牙协议栈来完成的。
 
   在Linux实现蓝牙功能有多个互相竞争的蓝牙协议栈,但是影响最大是bluez.几乎已经成为Linux下的标准协议栈的代名词。它的官网是 。在内核已经内置了bluez蓝牙协议栈。
  还有一个协议栈是 不过用的人比较少
 
在应用程序级,它主要由两部分组成,一个是bluez的应用程序库,主要负责与内核的bluez通信,和bluez-util工具。即完成蓝牙四阶段处理的一些命令行工具。
 
3.蓝牙的概念。
   配对由一方发起即可,如果本设备需要被其它设备搜索,需要有被发现功能。 
 
二.Linux关于蓝牙命令
-------------------------------------------------
 在Linux使用蓝牙最方便是使用bluez-util自带向个命令来测试。
 我们这里采用市面最容易找到的蓝牙棒来做物理层设备与手机进行通讯测试。把蓝牙棒插LINUX下的USB口后,在dmesg我们会看到提示
Bluetooth: Core ver 2.10
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: L2CAP ver 2.8
Bluetooth: L2CAP socket layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM ver 1.8
Bluetooth: HIDP (Human Interface Emulation) ver 1.1
eth1: no IPv6 routers present
usb 1-1: new full speed USB device using uhci_hcd and address 2
usb 1-1: configuration #1 chosen from 1 choice
usb 1-2: new full speed USB device using uhci_hcd and address 3
Bluetooth: HCI USB driver ver 2.9
usb 1-2: configuration #1 chosen from 1 choice
hub 1-2:1.0: USB hub found
hub 1-2:1.0: 7 ports detected
usbcore: registered new driver hci_usb
hci_scodata_packet: hci0 SCO packet for unknown connection handle 20480
hci_scodata_packet: hci0 SCO packet for unknown connection handle 43088
hci_acldata_packet: hci0 ACL packet for unknown connection handle 0
hci_acldata_packet: hci0 ACL packet for unknown connection handle 0
hci_scodata_packet: hci0 SCO packet for unknown connection handle 20480
hci_scodata_packet: hci0 SCO packet for unknown connection handle 43088
hci_scodata_packet: hci0 SCO packet for unknown

hci_scodata_packet: hci0 SCO packet for unknown connection handle 53248
usb 1-1: USB disconnect, address 2
usb 1-1: new full speed USB device using uhci_hcd and address 4
usb 1-1: configuration #1 chosen from 1 choice
表示USB蓝牙棒已经被识别了。如果
 
   操作系统自带HCI工具主要来自bluez-util.
 
 
/usr/sbin/hciattach : attach serial devices via UART HCI to BlueZ stack
 /usr/sbin/hcid     :Bluetooth Host Controller Interface Daemon
/usr/sbin/hciemu    :HCI emulator
/usr/sbin/hciconfig :  configure Bluetooth devices
 /usr/sbin/hcidump  : Parse HCI data
 /usr/bin/hcitool   : configure Bluetooth connections
/usr/bin/sdptool    : control and interrogate SDP servers

 
hciconfig类似于 hciconfig.类似的操作可以参见是
 
 
1.检测USB设备,lsusb
   
 #lsusb
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 003: ID 0e0f:0002
Bus 001 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
2.查看hci设备,hciconfig
 

[root@huisen ~]# hciconfig
hci0:   Type: USB
        BD Address: 00:1F:81:00:01:1C ACL MTU: 1021:4 SCO MTU: 180:1
        UP RUNNING PSCAN
        RX bytes:632 acl:0 sco:0 events:17 errors:0
        TX bytes:313 acl:0 sco:0 commands:16 errors:0

 
 激活设备
    hciconfig hci0 up
 
3.修改蓝牙配置文件
 蓝牙采用/etc/bluetooth/
hcid.conf  rfcomm.conf
 
   其中hcid.conf有关配对信息。其中security user;表示每次配对询问用户对方PIN,而auto则直接采用passkey中的PIN码。
 

# HCId options
options {
        # Automatically initialize new devices
        autoinit yes;

        # Security Manager mode
        #   none - Security manager disabled
        #   auto - Use local PIN for incoming connections
        #   user - Always ask user for a PIN
        #
        security user;

        # Pairing mode
        #   none  - Pairing disabled
        #   multi - Allow pairing with already paired devices
        #   once  - Pair once and deny successive attempts
        pairing multi;

        # Default PIN code for incoming connections
        passkey "BlueZ";
}


4.重启蓝牙服务
   如果修改了蓝牙配置后,需要重启蓝牙服务
  service bluetooth stop
  service bluetooth start 
 
5.扫描设备
 
hcitool scan
Scanning ...
        00:21:19:A4:E0:F1       Meizu M8
 
6.增加自动配对设置
  修改 /etc/bluetooth/rfcomm.conf
   增加扫描蓝牙地址
       
rfcomm0{
        bind no;
        device 00:21:19:A4:E0:F1;
        channel 1;
        comment "Meizu M8";
}
7.创建设备结点(只合适于第一次)
   rfcomm create dev #它将创建于/dev/rfcomm0 设备结点
  它等同于如下命令系列
     mknod /dev/rfcomm0 c 216 1
   chmod 666 /dev/rfcomm0
   rfcomm bind /dev/rfcomm0 00:21:19:A4:E0:F1-1

 
8.增加SDP消息信息
  为了减少麻烦,把所有支持的蓝牙服务都加上.
  sdptool add --channel=1 DID SP DUN LAN FAX OPUSH FTP HS HF SAP NAP GN PANU HID CIP CTP A2SRC A2SNK SYNCML NOKID PCSUITE SR1
 
9.增加蓝牙串口绑定
rfcomm bind /dev/rfcomm0 00:21:19:A4:E0:F1 1
 #rfcomm bind /dev/rfcomm0 蓝牙设备地址  通道,这个命令可选
  
10.解除蓝牙绑定 
 格式:rfcomm unbind /dev/rfcomm0 蓝牙设备地址   通道
 
11.联接蓝牙设备
   hcitool cc 00:21:19:A4:E0:F1

三.关于蓝牙配置文件
-------------------------------------------
 蓝牙的配置文件主要是 /etc/bluetooth目录下的hcid.conf和rfcomm.conf.
options {

  # Automatically initialize new devices

  autoinit yes;
  security user;

这里的security 是表示配对的认证模式,user表示由用户输入密码。这个需要在后面用
     pin_helper 指明用哪一个程序输入密码,这程序可以是图形界面程序,或者是字符界面程序。
常见的pin_helper有
   
/usr/bin/bluez-pin : bluez自带的pin输入界面


kbluepin


 passkey 配置项指明请求联接的设备的pin码。当采用auto模式时,将采用这个密码来联接.


 
 
阅读(3870) | 评论(1) | 转发(0) |
0

上一篇:linux设备驱动归纳总结

下一篇:没有了

给主人留下些什么吧!~~

最大行业软件2012-12-30 11:15:34

ANSA.v14.0.Pre.16.11.2012.Win32_64 1CD

Beta-CAE MetaPost 6.8.2 Win32_64 1CD

CMG Suite v2012.0 Win32-ISO 1DVD

CMG Suite v2012.0 Win64-ISO 1DVD

Delcam.PowerShape.2013.SP6.Update.Only.Win32_64 2CD

ESI PAM-Stamp 2G 2012.0 Linux32_64 1DVD

Surpac v6.3.2 Win32 1CD

Topcon.Tools.v8.2 1CD

Embird Plus v8.0 1CD

Keil RealView Microcontroller Development Kit 4.60 1CD