实战Linux Bluetooth编程(四) L2CAP层编程
(L2CAP协议简介,L2CAP在BlueZ中的实现以及L2CAP编程接口)
一:L2CAP协议简介:
Logical Link Control and Adaptation Protocol(L2CAP)
逻辑连接控制和适配协议 (L2CAP) 为上层协议提供面向连接和无连接的数据服务,并提供多协议功能和分割重组操作。L2CAP 充许上层协议和应用软件传输和接收最大长度为 64K 的 L2CAP 数据包。
L2CAP 基于 通道(channel) 的概念。 通道 (Channel) 是位于基带 (baseband) 连接之上的逻辑连接。每个通道以多对一的方式绑定一个单一协议 (single protocol)。多个通道可以绑定同一个协议,但一个通道不可以绑定多个协议。 每个在通道里接收到的 L2CAP 数据包被传到相应的上层协议。 多个通道可共享同一个基带连接。
L2CAP处于Bluetooth协议栈的位置如下:
也就是说,所有L2CAP数据均通过HCI传输到Remote Device。且上层协议的数据,大都也通过L2CAP来传送。
L2CAP可以发送Command。例如连接,断连等等。
下面看Command例子:Connection Request:
其中PSM比较需要注意,L2CAP 使用L2CAP连接请求(Connection Request )命令中的PSM字段实现协议复用。L2CAP可以复用发给上层协议的连接请求,这些上层协议包括服务发现协议SDP(PSM = 0x0001)、RFCOMM(PSM = 0x0003)和电话控制(PSM = 0x0005)等。
ProtocolPSMReference
SDP
0x0001
See Bluetooth Service Discovery Protocol (SDP), Bluetooth SIG.
RFCOMM
0x0003
See RFCOMM with TS 07.10, Bluetooth SIG.
TCS-BIN
0x0005
See Bluetooth Telephony Control Specification / TCS Binary, Bluetooth SIG.
TCS-BIN-CORDLESS
0x0007
See Bluetooth Telephony Control Specification / TCS Binary, Bluetooth SIG.
BNEP
0x000F
See Bluetooth Network Encapsulation Protocal, Bluetooth SIG.
HID_Control
0x0011
See Human Interface Device , Bluetooth SIG.
HID_Interrupt
0x0013
See Human Interface Device, Bluetooth SIG.
UPnP
0x0015
See [ESDP] , Bluetooth SIG.
AVCTP
0x0017
See Audio/Video Control Transport Protocol , Bluetooth SIG.
AVDTP
0x0019
See Audio/Video Distribution Transport Protocol , Bluetooth SIG.
AVCTP_Browsing
0x001B
See Audio/Video Remote Control Profile, Bluetooth SIG
UDI_C-Plane
0x001D
See the Unrestricted Digital Information Profile [UDI], Bluetooth SIG
二:L
相关文档:
完善Linux系统
1.开机自动挂载window分区
fedora10虽然能自动挂载,但是挂载的分区有时会不认汉字文件夹
从终端用vi或gedit打开/etc/fstab,在其中添加:
/dev/sda1 /mnt/1 ntfs default 0 0
注:第一项是分区驱动地址
......
1. wrote driver function file(s) .
2. stored in the proper folder, eg: character driver stored in folder drivers/char/
3. modified Makefile in this folder(eg: drivers/char/)
-added configuration at somewhere: type like that "obj-$(CONFIG_TESTD ......
tar vxfz ttt-1.00.tar.bz2后出现以上错误是怎么回事啊?
gzip:stdin:not in gzip format
tar:Child returned status1
tar:Error exit delayed from prvious errors
tar jxvf busybox-1.00.tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
bz2格式用j
gz格式用z
c是创建
......
1. man 对你熟悉或不熟悉的命令提供帮助解释
eg:man ls 就可以查看ls相关的用法
注:按q键或者ctrl+c退出,在linux下可以使用ctrl+c终止当前程序运行。
2. ls 查看目录或者文件的属*,列举出任一目录下面的文件
eg: ls /usr/man
ls -l
a.d表示目录(directory),如果是一个"-"表示是文件,如果是l则表示是一个连接文件 ......
前面讲了使用 ioctl发送HCI Command的方法。但HCI protocol还有一些Command,比如Inquiry等,他们则不需要使用ioctl来发送。blueZ 直接提供了支持,虽然他们的最终都是用同样办法实现的。
在应用程序中:
hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
这样需要包含blueZ 头文件如下:
#include //BT ......