CC2640 广播数据构成分析
2016-01-13 15:49
267 查看
第二章 CC2640广播数据构成
第一步:将SimpleBLEPeripheral例程烧录到蓝牙中然后就开启广播之旅了。。。。。。。。。
用Packet Sniffer
抓包
![](http://img.blog.csdn.net/20160113155144086?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
1 2 3 4 5 6 7 8 9 10
下标为1 P.nbr
表示为接收数据包个数。
下标为2Time(us)表示从接收第一个数据包开始计时,每接一个包的间隔。故第一个为0,第二个为108003us,所以广播间隔大概为100ms。在此处有定义
// Advertising interval when device is discoverable (units of 625us, 160=100ms)
#define DEFAULT_ADVERTISING_INTERVAL 160
当改变DEFAULT_ADVERTISING_INTERVAL的值为320时,结果为:
![](http://img.blog.csdn.net/20160113155345532?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
此时广播间隔为205006us,即约为200ms。
下标为3 Channel
为广播通道,0X25十进制为37.
{
uint8_t AdvMap = GAP_ADVCHAN_37;
GAPRole_SetParameter(GAPROLE_ADV_CHANNEL_MAP, sizeof(uint8_t), &AdvMap);
}
通过改变AdvMap的可以设置专用广播信道。默认的情况下为GAP_ADVCHAN_ALL所有信道都在广播。建议在实际使用是使用默认,这样可以提高抗干扰能力。
GAP_ADVCHAN_37可以在GAP.h中找。
/** @defgroup GAP_ADVCHAN_DEFINES GAP Advertisement Channel Map
* @{
*/
#define GAP_ADVCHAN_37 0x01 //!< Advertisement Channel 37
#define GAP_ADVCHAN_38 0x02 //!< Advertisement Channel 38
#define GAP_ADVCHAN_39 0x04 //!< Advertisement Channel 39
#define GAP_ADVCHAN_ALL (GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39) //!< All Advertisement Channels Enabled
/** @} End GAP_ADVCHAN_DEFINES */
下标为4Access Address
为Dongle 自己MAC地址。
下标为5Adv PDU Type
广播报文类型为ADV_IND 解释如下
#define GAP_ADTYPE_ADV_IND 0x00 //!< Connectable undirected advertisement
可非定向广播连接。
在程序中的位置为
static void gapRole_init(void)
{
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntity, &sem);
gapRole_state = GAPROLE_INIT;
gapRole_ConnectionHandle = INVALID_CONNHANDLE;
// Get link DB maximum number of connections
linkDBNumConns = linkDB_NumConns();
// Setup timers as one-shot timers 分派一个时钟。
Util_constructClock(&startAdvClock, gapRole_clockHandler,
0, 0, false, START_ADVERTISING_EVT);
Util_constructClock(&startUpdateClock, gapRole_clockHandler,
0, 0, false, START_CONN_UPDATE_EVT);
Util_constructClock(&updateTimeoutClock, gapRole_clockHandler,
0, 0, false, CONN_PARAM_TIMEOUT_EVT);
// Initialize the Profile Advertising and Connection Parameters
gapRole_profileRole = GAP_PROFILE_PERIPHERAL;
VOID memset(gapRole_IRK, 0, KEYLEN);
VOID memset(gapRole_SRK, 0, KEYLEN);
gapRole_signCounter = 0;
gapRole_AdvEventType = GAP_ADTYPE_ADV_IND;
gapRole_AdvDirectType = ADDRTYPE_PUBLIC;
gapRole_AdvChanMap = GAP_ADVCHAN_ALL;
gapRole_AdvFilterPolicy = GAP_FILTER_POLICY_ALL;
// Restore Items from NV
VOID osal_snv_read(BLE_NVID_IRK, KEYLEN, gapRole_IRK);
VOID osal_snv_read(BLE_NVID_CSRK, KEYLEN, gapRole_SRK);
VOID osal_snv_read(BLE_NVID_SIGNCOUNTER, sizeof(uint32_t),
&gapRole_signCounter);
}
下标为6 Adv PDU Header
报头。
广播类型是通用广播(Type 为0
见AdvPDU Type)。
地址类型都是public即gapRole_AdvDirectType = ADDRTYPE_PUBLIC;见上图。(TxAdd和RxAdd都为0)。
长度字段指示PDU-Length 指AdvA + AdvData之和。
下标为7的AdvA
为本机MAC地址。在第一章中已经提到。
下标为8的AdvData为广播数据,可以在
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8_t advertData[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
#ifdef FEATURE_OAD
LO_UINT16(OAD_SERVICE_UUID),
HI_UINT16(OAD_SERVICE_UUID)
#else
LO_UINT16(SIMPLEPROFILE_SERV_UUID),
HI_UINT16(SIMPLEPROFILE_SERV_UUID)
#endif //!FEATURE_OAD
};
中找到答案。
第一步:将SimpleBLEPeripheral例程烧录到蓝牙中然后就开启广播之旅了。。。。。。。。。
用Packet Sniffer
抓包
1 2 3 4 5 6 7 8 9 10
下标为1 P.nbr
表示为接收数据包个数。
下标为2Time(us)表示从接收第一个数据包开始计时,每接一个包的间隔。故第一个为0,第二个为108003us,所以广播间隔大概为100ms。在此处有定义
// Advertising interval when device is discoverable (units of 625us, 160=100ms)
#define DEFAULT_ADVERTISING_INTERVAL 160
当改变DEFAULT_ADVERTISING_INTERVAL的值为320时,结果为:
此时广播间隔为205006us,即约为200ms。
下标为3 Channel
为广播通道,0X25十进制为37.
{
uint8_t AdvMap = GAP_ADVCHAN_37;
GAPRole_SetParameter(GAPROLE_ADV_CHANNEL_MAP, sizeof(uint8_t), &AdvMap);
}
通过改变AdvMap的可以设置专用广播信道。默认的情况下为GAP_ADVCHAN_ALL所有信道都在广播。建议在实际使用是使用默认,这样可以提高抗干扰能力。
GAP_ADVCHAN_37可以在GAP.h中找。
/** @defgroup GAP_ADVCHAN_DEFINES GAP Advertisement Channel Map
* @{
*/
#define GAP_ADVCHAN_37 0x01 //!< Advertisement Channel 37
#define GAP_ADVCHAN_38 0x02 //!< Advertisement Channel 38
#define GAP_ADVCHAN_39 0x04 //!< Advertisement Channel 39
#define GAP_ADVCHAN_ALL (GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39) //!< All Advertisement Channels Enabled
/** @} End GAP_ADVCHAN_DEFINES */
下标为4Access Address
为Dongle 自己MAC地址。
下标为5Adv PDU Type
广播报文类型为ADV_IND 解释如下
#define GAP_ADTYPE_ADV_IND 0x00 //!< Connectable undirected advertisement
可非定向广播连接。
在程序中的位置为
static void gapRole_init(void)
{
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntity, &sem);
gapRole_state = GAPROLE_INIT;
gapRole_ConnectionHandle = INVALID_CONNHANDLE;
// Get link DB maximum number of connections
linkDBNumConns = linkDB_NumConns();
// Setup timers as one-shot timers 分派一个时钟。
Util_constructClock(&startAdvClock, gapRole_clockHandler,
0, 0, false, START_ADVERTISING_EVT);
Util_constructClock(&startUpdateClock, gapRole_clockHandler,
0, 0, false, START_CONN_UPDATE_EVT);
Util_constructClock(&updateTimeoutClock, gapRole_clockHandler,
0, 0, false, CONN_PARAM_TIMEOUT_EVT);
// Initialize the Profile Advertising and Connection Parameters
gapRole_profileRole = GAP_PROFILE_PERIPHERAL;
VOID memset(gapRole_IRK, 0, KEYLEN);
VOID memset(gapRole_SRK, 0, KEYLEN);
gapRole_signCounter = 0;
gapRole_AdvEventType = GAP_ADTYPE_ADV_IND;
gapRole_AdvDirectType = ADDRTYPE_PUBLIC;
gapRole_AdvChanMap = GAP_ADVCHAN_ALL;
gapRole_AdvFilterPolicy = GAP_FILTER_POLICY_ALL;
// Restore Items from NV
VOID osal_snv_read(BLE_NVID_IRK, KEYLEN, gapRole_IRK);
VOID osal_snv_read(BLE_NVID_CSRK, KEYLEN, gapRole_SRK);
VOID osal_snv_read(BLE_NVID_SIGNCOUNTER, sizeof(uint32_t),
&gapRole_signCounter);
}
下标为6 Adv PDU Header
报头。
广播类型是通用广播(Type 为0
见AdvPDU Type)。
地址类型都是public即gapRole_AdvDirectType = ADDRTYPE_PUBLIC;见上图。(TxAdd和RxAdd都为0)。
长度字段指示PDU-Length 指AdvA + AdvData之和。
下标为7的AdvA
为本机MAC地址。在第一章中已经提到。
下标为8的AdvData为广播数据,可以在
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertisting)
static uint8_t advertData[] =
{
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
#ifdef FEATURE_OAD
LO_UINT16(OAD_SERVICE_UUID),
HI_UINT16(OAD_SERVICE_UUID)
#else
LO_UINT16(SIMPLEPROFILE_SERV_UUID),
HI_UINT16(SIMPLEPROFILE_SERV_UUID)
#endif //!FEATURE_OAD
};
中找到答案。
相关文章推荐
- java连接数据库
- shell命令批量杀死MySQL连接进程
- Linux与hadoop相关命令
- js 判断字符为空
- WPF 程序在 Windows XP 下报错:The image format is unrecognized.
- JQuery实现点击div里面的a的能触发点击时间,但是不触发外面的div的点击事件
- 编译安装zabbix error: MySQL library not found
- 整洁的测试遵循的规则
- 整洁的测试遵循的规则
- 即时通讯之Socket.IO的学习,及使用nodejs 搭建websocket 聊天室
- 用ladon框架封装Python为Webservice接口以及调用接口的方法
- storm安装、运行
- Linux下DRBD配置
- openvas
- sql数据密文显示
- ibatis中iterate的用法(conjunction="or" ",")
- 【腾讯开放平台】Android、IOS实现指定QQ临时会话功能
- markdown编辑器
- swift 用协议实现代理传值功能
- FFmpeg常用基本命令