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

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

说明:一般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_LENMAC地址数组长度,一般为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 抓包结果如下:

此时AdvA0XA0E6F807ACD2。此为本BLE默认的MAC地址。

 

 

你可能感兴趣的:(CC2640 MAC地址理解、使用和更改)