传统蓝牙协议栈串口协议SPP(SerialPortProfile)概念介绍

传统蓝⽛协议栈串⼝协议SPP(SerialPortProfile)概念介绍零. 概述
主要介绍下蓝⽛协议栈(bluetooth stack) 串⼝协议(bluetooth SPP)Serial Port Profile 协议概念介绍。
⼀. 声明
本专栏⽂章我们会以连载的⽅式持续更新,本专栏计划更新内容如下:
磷酸
第⼀篇:蓝⽛综合介绍 ,主要介绍蓝⽛的⼀些概念,产⽣背景,发展轨迹,市⾯蓝⽛介绍,以及蓝⽛开发板介绍。
第⼆篇:Transport层介绍,主要介绍蓝⽛协议栈跟蓝⽛芯⽚之前的硬件传输协议,⽐如基于UART的H4,H5,BCSP,基于USB的H2等
第三篇:传统蓝⽛controller介绍,主要介绍传统蓝⽛芯⽚的介绍,包括射频层(RF),基带层(baseband),链路管理层(LMP)等
第四篇:传统蓝⽛host介绍,主要介绍传统蓝⽛的协议栈,⽐如
HCI,L2CAP,SDP,RFCOMM,HFP,SPP,HID,AVDTP,AVCTP,A2DP,AVRCP,OBEX,PBAP,MAP等等⼀系列的协议吧。
第五篇:低功耗蓝⽛controller介绍,主要介绍低功耗蓝⽛芯⽚,包括物理层(PHY),链路层(LL)
第六篇:低功耗蓝⽛host介绍,低功耗蓝⽛协议栈的介绍,包括HCI,L2CAP,ATT,GATT,SM等
第七篇:蓝⽛芯⽚介绍,主要介绍⼀些蓝⽛芯⽚的初始化流程,基于HCI vendor command的扩展
第⼋篇:附录,主要介绍以上常⽤名词的介绍以及⼀些特殊流程的介绍等。
另外,开发板如下所⽰,对于想学习蓝⽛协议栈的最好⼈⼿⼀套。以便更好的学习蓝⽛协议栈,相信我,学完这⼀套视频你将拥有修改任何协议栈的能⼒(⽐如Linux下的bluez,Android下的bluedroid)。
-------------------------------------------------------------------------------------------------------------------------
蓝⽛交流扣扣:970324688
--------------------------------------------------------------------------------------------------------------------------
⼆. 蓝⽛串⼝SPP(Serial Port Profile)协议介绍
2.1 概念介绍
SPP是Serial Port Profile(串⼝协议)的缩写,其定义了使⽤蓝⽛进⾏RS232(或类似)串⾏电缆仿真的设备应使⽤的协议和过程。简单来说就是在蓝⽛设备之间建⽴虚拟的串⼝进⾏数据通信。说⽩了就是可以两个设备对端发送⾃定义数据,NOTED:苹果不⽀持SPP协议。
⽬前SIG最新的版本是V1.2,之前更早的版本在官⽹只有V1.1可以下载到,但是这两份⽂档没有功能上的差别,所以不做介绍
2.2 SPP协议在整个蓝⽛中的架构图如下
2.3 ⾓⾊介绍
Device A (DevA) – This is the device that takes initiative to form a connection to another device
Device B (DevB) – This is the device that waits for another device to take initiative to connect.
how often do you exercise说⽩了就是就是两台设备连接,谁发起的连接⾓⾊就是Device A,被连接的就是Device B,但是这个和其他协议不同,两台设备之前的code 基本都是⼀样,⾓⾊只是区分两台设备。
2.4 SPP特性
Device A是发起连接的主动房,所以Device A要⾄少⽀持Establish link and set up virtual serial connection.,Device B是被连接的⼄⽅,所以要⾄少⽀持Accept link and establish virtual serial connection和Register Service record for application in local SDP database.以便Device A查询服务并且连接,但是此协议漏掉最主要的两个功能,发送数据,接收数据,或者SIG是觉得rfcomm做到了这个功能,所以不写在SPP协议中吧,但是我还是决定要在SPP介绍收发功能。
2.4.1 Establish link and set up virtual serial connection.
This procedure refers to performing the steps necessary to establish a connection to an emulated serial port (or equivalent) in a remote device. The steps in this procedure are:
1)Submit a query using SDP to find out the RFCOMM Server channel number of the desired application in the remote device. This might include a browsing capability to let the user select among available ports (or services) in the peer device. Alternatively, if it is known exactly which service to contact, it is sufficient look up the necessary parameters using the Service Class ID associated with the desired service.
2)Optionally, require authentication of the remote device to be performed. Also optionally, require encryption to be turned on.
3)  Request a new L2CAP channel to the remote RFCOMM entity.
4)  Initiate an RFCOMM session on the L2CAP channel.
5)  Start a new data link connection on the RFCOMM session, using the aforementioned server channel number.After step 5, the virtual serial cable connection is ready to be used for communicatio
n between applications on both sides.
2.4.2 Accept link and establish virtual serial connection.
This procedure refers to taking part in the following steps:
1)If requested by the remote device, take part in authentication  procedure and, upon
further request, turn on encryption.
2)  Accept a new channel establishment indication from L2CAP.
赵腾达3)  Accept an RFCOMM session establishment on that channel.
4)  Accept a new data link connection on the RFCOMM session. This may trigger a local request to authenticate the remote device and turn on  encryption, if the user has required that for the emulated serial port being connected to (and authentication/encryption procedures have not already been carried out).扩散系数
2.4.3 Register Service record for application in local SDP database.
This procedure refers to registration of a service record for an emulated serial port (or equivalent) in the SDP database. This implies the existence of a Service Database, and the ability to respond to SDP queries.
NOTED:SPP只有安卓⼿机⽀持,并且部分安卓⼿机必须有SPP APP才可以连接,iphone⼿机不能直接SPP,但是⼜⼀个替代协议IAP,此协议需要买MFI chip才能⽤
2.5 SDP相关的注册
我看下我们的SDP注册:
static const uint8_t spp_service_record[] =
{
/* 1.ServiceClassIDList */
三维网SDP_DES_SIZE8, 0x8,
SDP_UINT16, BT_ATTRIBUTE_SERVICE_CLASS_ID_LIST>>8&0xff, BT_ATTRIBUTE_SERVICE_CLASS_ID_LIST&0xff, /* Service class ID list attribute */
SDP_DES_SIZE8, 3,
SDP_UUID16, BT_SERVICE_CLASS_SERIAL_PORT>>8&0xff, BT_SERVICE_CLASS_SERIAL_PORT&0xff,
/* 2.ProtocolDescriptorList */
SDP_DES_SIZE8, 0x11,
SDP_UINT16, BT_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST>>8&0xff, BT_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST&0xff,/* Protocol descripto            SDP_DES_SIZE8, 0xc,
SDP_DES_SIZE8, 0x3,
SDP_UUID16, BT_PROTOCOL_L2CAP>>8&0xff, BT_PROTOCOL_L2CAP&0xff, /*L2CAP*/
SDP_DES_SIZE8, 0x5,
SDP_UUID16, BT_PROTOCOL_RFCOMM>>8&0xff, BT_PROTOCOL_RFCOMM&0xff, /*RFCOMM*/
SDP_UINT8, RFCOMM_SPP_SERVER_CHNL, /*RFCOMM channel*/
/* BluetoothProfileDescriptorList */
SDP_DES_SIZE8, 0xd,特钢厂
SDP_UINT16, BT_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST>>8&0xff, BT_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST&            SDP_DES_SIZE8, 0x8,
SDP_DES_SIZE8,0x06,
SDP_UUID16,BT_SERVICE_CLASS_SERIAL_PORT>>8&0xff, BT_SERVICE_CLASS_SERIAL_PORT&0xff,
SDP_UINT16,0x01,0x02,  /* V1.2 */
};

本文发布于:2024-09-22 02:06:18,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/473400.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:介绍   协议   设备
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议