打印
[CC2640]

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

[复制链接]
571|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 抓包结果如下:



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


使用特权

评论回复

相关帖子

沙发
coshi| | 2020-1-6 10:57 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
板凳
nawu| | 2020-1-6 11:33 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
地板
qcliu| | 2020-1-6 11:37 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
5
tfqi| | 2020-1-6 11:42 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
6
wiba| | 2020-1-6 11:46 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
7
zljiu| | 2020-1-6 11:51 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

94

主题

4066

帖子

2

粉丝