This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] MAC地址过滤

Other Parts Discussed in Thread: SYSCONFIG


过滤表是链接层(LL)可用于过滤广告商,扫描器或启动器的设备列表。LL将能够在不唤醒主机的情况下过滤数据包,如果Peer设备没有使用Privacy,则可以在不唤醒内核M4的情况下在RF内核中过滤传入的数据包,这样可以节省更多电量。如果是一组固定的BLE设备,知道所有设备的MAC地址,可以将它们添加到过滤表中。

在本练习中,我们将在Central和Peripheral设备上实现地址过滤。为此,我们将使用Simple Central和Simple Peripheral。

 

1)将Simple CentralSimple Peripheral下载到两个CC13X2CC26X2 LaunchPad

打开串口工具Tera Term,在Simple Central设备上进行扫描,查看扫描到设备的数量和地址信息:

 

2)将Simple Peripheral添加到过滤表中

首先通过sysconfig将Peripheral设备地址修改为Public Address,编译后重新下载到launchpad。

打开串口工具,可以看到设备的MAC地址:

现在将该地址添加到Central设备的过滤表中,插入地址时注意地址顺序,在串口工具中,地址是big-endian格式,但是添加地址的函数需要使用little-endian格式。上面Peripheral设备的地址是0x806FB0EEB3A9转换为 [0xA9, 0xB3, 0xEE, 0xB0, 0x6F, 0x80]。

在simple_central.c的SimpleCentral_doDiscoverDevices()中,添加以下代码:

//Update the Scan filter policy

   uint8_t whitelistfilter = SCAN_FLT_POLICY_WL;

   GapScan_setParam(SCAN_PARAM_FLT_POLICY, &whitelistfilter);

 

   //Adding an address to the white list

   static uint8 bdAddressPeer[6] = {0xA9, 0xB3, 0xEE, 0xB0, 0x6F, 0x80};

   HCI_LE_ClearWhiteListCmd();

HCI_LE_AddWhiteListCmd(ADDRMODE_PUBLIC, bdAddressPeer);

 

3)编译Simple Central下载到Launchpad并进行扫描

现在可以看到,只扫描到一个设备,只有中央设备才可以连接到该设备,如果发现的设备数量为0,再次检查是否添加了正确的地址。

 

4)将Central设备添加到过滤表

同样地,可以在Simple Peripheral添加过滤表。首先将Simple Central 设为 public address

然后在simple_peripheral.syscfg中将Filter Policy设置为Process requests only from devices in WL.

在SimplePeripheral_processGapMessage()的GAP_DEVICE_INIT_DONE_EVENT中添加以下代码:

// Add the central device address to the white list

       static uint8 bdAddressPeer[6] = {0xF7, 0xD7, 0x1E, 0xB0, 0x6F, 0x80};

       HCI_LE_ClearWhiteListCmd();

       HCI_LE_AddWhiteListCmd(ADDRTYPE_PUBLIC, bdAddressPeer);

注意将地址改为自己Central设备的MAC地址

分别编译两个工程并下载中Launchpad中,可以看到只有上面MAC地址的Central设备可以扫描并且连接到Peripheral设备: