[CC2640] CC2640 MAC地址理解、使用和更改

[复制链接]
961|6
 楼主| 磨砂 发表于 2019-12-31 14:21 | 显示全部楼层 |阅读模式

说明:一般BLE在出厂时都有唯一的标识地址,俗称MAC地址,其在广播时,随设备名一起广播出去。请看用Packet Sniffer抓包结果:


ADVA :0X0AD0AD0AD0AD 就是MAC 地址。


可以修改,对应代码如下:


static void SimpleBLEPeripheral_init(void)

{

  // ******************************************************************

  // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp

  // ******************************************************************

  // Register the current thread as an ICall dispatcher application

  // so that the application can send and receive messages.

  ICall_registerApp(&selfEntity, &sem);           //ICall 注册当前线程任务


  // 以下功能为修改mac地址

  // Hard code the BD Address till CC2650 board gets its own IEEE address

  uint8 bdAddress[B_ADDR_LEN] = { 0xAD, 0xD0, 0x0A, 0xAD, 0xD0, 0x0A };

  HCI_EXT_SetBDADDRCmd(bdAddress);


  // Set device's Sleep Clock Accuracy

  HCI_EXT_SetSCACmd(40);


  // Create an RTOS queue for message from profile to be sent to app.

  appMsgQueue = Util_constructQueue(&appMsg); //建立与RTOS队列


其中:bdAddress[B_ADDR_LEN] 为要修改的MAC地址数组,B_ADDR_LEN为MAC地址数组长度,一般为6.


HCI_EXT_SetBDADDRCmd(bdAddress);执行MAC地址修改。执行之后要延时一段时间。使用函数HCI_EXT_SetSCACmd(40);


由函数可知 MAC地址的实现一般都是由HCI层来进行的。


如果将这两行代码屏蔽后会有什么现象呢?


static void SimpleBLEPeripheral_init(void)

{

  // ******************************************************************

  // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp

  // ******************************************************************

  // Register the current thread as an ICall dispatcher application

  // so that the application can send and receive messages.

  ICall_registerApp(&selfEntity, &sem);           //ICall 注册当前线程任务


  // 以下功能为修改mac地址

  // Hard code the BD Address till CC2650 board gets its own IEEE address

  //uint8 bdAddress[B_ADDR_LEN] = { 0xAD, 0xD0, 0x0A, 0xAD, 0xD0, 0x0A };

  //HCI_EXT_SetBDADDRCmd(bdAddress);


  // Set device's Sleep Clock Accuracy

  //HCI_EXT_SetSCACmd(40);


  // Create an RTOS queue for message from profile to be sent to app.

  appMsgQueue = Util_constructQueue(&appMsg); //建立与RTOS队列


Packet Sniffer 抓包结果如下:


316065e0ae8c7c8f6c.png


此时AdvA:0XA0E6F807ACD2。此为本BLE默认的MAC地址。


coshi 发表于 2020-1-6 10:57 | 显示全部楼层
非常感谢楼主分享
nawu 发表于 2020-1-6 11:33 | 显示全部楼层
非常感谢楼主分享
qcliu 发表于 2020-1-6 11:37 | 显示全部楼层
非常感谢楼主分享
tfqi 发表于 2020-1-6 11:42 | 显示全部楼层
非常感谢楼主分享
wiba 发表于 2020-1-6 11:46 | 显示全部楼层
非常感谢楼主分享
zljiu 发表于 2020-1-6 11:51 | 显示全部楼层
非常感谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

127

主题

4389

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部