ble协议栈从零开始五(linklayer细致分析下)

SIG BLE MESH 视频 教程https://edu.csdn.net/course/detail/27321​​​​​​​

1、前言:

本章主要详细的展开linklayer的如下的内容

1)什么是白名单?,以及白名单的策略

2)详细的说明advertising state ,scanning state ,connection state下的流程,以及时序的要求。

2、白名单

白名单是linklayer的过滤机制,可以通过判断对方的地址在不在白名单进而进行过滤。首先我们要添加一条条设备地址和地址类型到white list 中。linelayer 都应该支持白名单的机制,除非这个linklayer只能发送non-connectable advertising (蓝牙的mesh网路就是基于这种广播包)。这种过滤机制能独立存在advertising state,scanning state、Initiating State 三种状态。如果处于advertising state,advertising filter policy 将会使用,如果处于scanning states,scanning filter policy 将会被使用,如果处于initiating state,initiator filter policy 将会被使用。听起来很绕,其实很简单,比如 A设发送adv,advertising filter policy指示只有在white list的B设备可以连接,B设备处于initiating state,B设备准备连接A设备,initiator filter policy

指示只有在white list的C设备才会发起连接请求,所以B设备不会去连接A设备。

白名单的机制是一个你情我愿的机制。

2.1 advertising state

当 advertising filter policy 为 0 的时候,任何设备都可以扫描和连接

                                           为1 的时候,任何设备都可以连接和但只有在白名单的设备才能扫描

                                           为2 的时候,任何设备都可以扫描和但只有在白名单的设备才能连接

                                           为3的时候,只有在白名单的设备才能扫描和连接

2.2 scanning states

                    


当scanning filter policy 为 0的时候,可以扫描所有的设备,除非对面发送的是直接连接的报文

                                      为 1的时候,只能扫描在白名单的设备

                                      后面的2个是拓展的

 

2.3 initiating state

initiator filter policy 为  0 不考虑白名单的地址

                                 为 1只连接出现在白名单的地址

 

 

3、advertising state

 

host可以发送LE_Set_Advertise_Enable command让linklayer进入advertising state。 进入advertising state在每一个advertising event 发送 adv 的PDU。

advertising event  分为如下几种,每一个 advertising event 对应不同的pdu

• a connectable undirected event  -》 ADV_IND
• a connectable directed event      -》ADV_DIRECT_IND
• a non-connectable undirected event  -》 ADV_NONCONN_IND
• a scannable undirected event -》ADV_SCAN_IND
 

3.1 Advertising的间隔


如上图 T_advEvent = advInterval + advDelay, advInterval 的单位是0.625ms, advDelay 是一个0到10ms的随机延时。

 

advInterval  的 范围(20ms,10.25S),如果 advertising event type 是a non-connectable undirected event或者a scannable undirected event,advInterval  的 范围(100ms,10.25S)。

 

 

3.2 connectable undirected event

如上图connectable undirected event,广播通道选择了 37 38 39 三个通道,2个相邻的通道时间间隔小于10ms(nordic的芯片基本是无缝连接,这样很结实功耗的)。广播的pdu是ADV_IND。

如上图是一个onnectable undirected event,T_IFS是Inter Frame Space是缩写,这个发生在 event 同一个通道连续的包的间隔时间,这个时间是150us(误差小于50ppm即2us)。

上图,意味着我们每发送一个adv_ind,在150us后都要scan。你想一下,我们发送一个adv_ind,对方发送scan_req,如果不这样约束一个时间,我们怎么能接受对方的报文呢?发送一个adv_ind150us后,scan的时间很短,如果scan到数据就会拉长scan的时间直到收完数据。这些操作一般都是MAC做的,不占用软件的时间。

 

3.3 connectable directed event

connectable directed event 分为 low duty cycle、high duty cycle

3.31 low duty cycle

如上图connectable directed event,广播通道选择了 37 38 39 三个通道,2个相邻的通道时间间隔小于10ms(nordic的芯片基本是无缝连接,这样很结实功耗的)。广播的pdu是ADV_direct IND。

如上图一旦收到connect_req 就 退出了 advertising event,否则要 39通道的pdu发送完(adv 的通道是可以在 37 38 39选择一个或者多个)。

3.32 high duty cycle

 

 

如上图所有pdu都是均匀的时间发送,advertising event的间隔小于3.75ms,advertising state 将会在1.28s退出。意味着这发送连接请求的设备需要提前发送connect_req,注意initiator设备发送connect_req的命令之前会SCAN的(这个是MAC控制的,自动的)。一旦SCAN到dav_DIRECT_IND,解析对方的目的地址就是自己的本地地址,就会在150us后发送connect_req。

 

 

 

3.4 a non-connectable undirected event

 

 

不能够被扫描和连接,这的扫描指的是可以不能发送scan_req命令。ble的mesh的网路就是使用这个广播包。

 

 

3.5 a scannable undirected event

可以被扫描的广播,就不贴图了。

4、scanning  state

处于scanning state设备,会在每隔scan interval时间扫描scan window大小的时间。比如scan interval = 1s,scan window = 0.5s,那就是每隔1s扫描0.5秒。哈哈如果scan interval  = scan window  就会一直扫描。

scanning 的模式分为 passive scanning 和 active scanning

4.1 passive scanning

只监听对方的设备的广播,不发生scan req

4.2 active scanning

不仅监听对方的设备的广播,还会发送scan req广播。这儿有一个问题,一个advertising设备发送adv,多个scanning设备都开了active scanning模式,大家都发送scan_req,都在等待scan_rsp。这会不产生碰撞?哈哈别着急,sig提供了一个算法实现交错的发送scan_req。
算法:

 

scanning设备初始化2个变量backoffCount = 1,upperLimit = 1,。每次准备发送scan_req时backoffCount 递减1,如果backoffCount =0,就发送scan_req,然后等待150us扫描scan_rsp命令,如果收到scan_rsp命令判决成功,否则判决失败。连续2次失败upperLimit 的值倍增,倍增的上限是256,连续2次成功,upperLimit 的值倍减。每次发完scan_req,backoffCount 的值要在1和upperLimit 随机生成。

结果经常成功的设备,大概率会先发scan_req,结果经常失败的设备会大概率延迟发送scan_req

 

4、initiating  state

 

这个其实没什么好说的,它都是使用scanning的scan interval,scan window的参数在扫描。比如你要发送connect_req,前提要是你能扫描到

 

 

connection state的过程比较多,放在下一节在写吧

 

 

 

 

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XG_2013

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值