請問官方技術關于CH579從機設置白名單,主機無法連接的問題

目的是想讓從機僅主機可連接,其他設備無法掃描。根據(jù)官方提供的CH579 CH573 CH582 藍牙從機設置白名單 - debugdabiaoge - 博客園 (cnblogs.com),在從機的?Peripheral_Init( )函數(shù)添加如下代碼:

void?Peripheral_Init(?)
{
??Peripheral_TaskID?=?TMOS_ProcessEventRegister(?Peripheral_ProcessEvent?);
??
??//?Setup?the?GAP?Peripheral?Role?Profile
??{
????uint8?initial_advertising_enable?=?TRUE;
????uint16?desired_min_interval?=?DEFAULT_DESIRED_MIN_CONN_INTERVAL;
????uint16?desired_max_interval?=?DEFAULT_DESIRED_MAX_CONN_INTERVAL;

????//?Set?the?GAP?Role?Parameters
????GAPRole_SetParameter(?GAPROLE_ADVERT_ENABLED,?sizeof(?uint8?),?&initial_advertising_enable?);
????GAPRole_SetParameter(?GAPROLE_SCAN_RSP_DATA,?sizeof?(?scanRspData?),?scanRspData?);
????GAPRole_SetParameter(?GAPROLE_ADVERT_DATA,?sizeof(?advertData?),?advertData?);
????GAPRole_SetParameter(?GAPROLE_MIN_CONN_INTERVAL,?sizeof(?uint16?),?&desired_min_interval?);
????GAPRole_SetParameter(?GAPROLE_MAX_CONN_INTERVAL,?sizeof(?uint16?),?&desired_max_interval?);
??}

??//?Set?the?GAP?Characteristics
??GGS_SetParameter(?GGS_DEVICE_NAME_ATT,?GAP_DEVICE_NAME_LEN,?attDeviceName?);

??//?Set?advertising?interval
??{
????uint16?advInt?=?DEFAULT_ADVERTISING_INTERVAL;

????GAP_SetParamValue(?TGAP_DISC_ADV_INT_MIN,?advInt?);
????GAP_SetParamValue(?TGAP_DISC_ADV_INT_MAX,?advInt?);
??}

??//?Setup?the?GAP?Bond?Manager
??{
????uint32?passkey?=?0;?//?passkey?"000000"
????uint8?pairMode?=?GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
????uint8?mitm?=?TRUE;
????uint8?bonding?=?TRUE;
????uint8?ioCap?=?GAPBOND_IO_CAP_DISPLAY_ONLY;
????GAPBondMgr_SetParameter(?GAPBOND_PERI_DEFAULT_PASSCODE,?sizeof?(?uint32?),?&passkey?);
????GAPBondMgr_SetParameter(?GAPBOND_PERI_PAIRING_MODE,?sizeof?(?uint8?),?&pairMode?);
????GAPBondMgr_SetParameter(?GAPBOND_PERI_MITM_PROTECTION,?sizeof?(?uint8?),?&mitm?);
????GAPBondMgr_SetParameter(?GAPBOND_PERI_IO_CAPABILITIES,?sizeof?(?uint8?),?&ioCap?);
????GAPBondMgr_SetParameter(?GAPBOND_PERI_BONDING_ENABLED,?sizeof?(?uint8?),?&bonding?);
??}

??//?Initialize?GATT?attributes
??GGS_AddService(?GATT_ALL_SERVICES?);????????????//?GAP
??GATTServApp_AddService(?GATT_ALL_SERVICES?);????//?GATT?attributes
??DevInfo_AddService();???????????????????????????//?Device?Information?Service
??SimpleProfile_AddService(?GATT_ALL_SERVICES?);??//?Simple?GATT?Profile


??????ble_ota_add_service();
??//?Init?Connection?Item
??peripheralInitConnItem(?&peripheralConnList?);

??//?Register?callback?with?SimpleGATTprofile
??SimpleProfile_RegisterAppCBs(?&Peripheral_SimpleProfileCBs?);
?
??//?添加白名單
	GAPRole_BroadcasterSetCB(?&Broadcaster_BroadcasterCBs?);
	{
	????uint8?filter_policy?=?GAP_FILTER_POLICY_WHITE;//允許白名單中的設備掃描和連接。
????????????uint8?mac0[6]={0x1C,0xE0,?0x0D,?0xE4,?0xC2,?0x84};//指定的主機mac地址
	????uint8?macType?=?1;?//指定地址類型
	
	????LL_ClearWhiteList();
	????LL_AddWhiteListDevice(macType,mac0);
	????GAPRole_SetParameter(?GAPROLE_ADV_FILTER_POLICY,?sizeof(?uint8?),?&filter_policy?);//設置白名單
	}
	//?Setup?a?delayed?profile?startup
??tmos_set_event(?Peripheral_TaskID,?SBP_START_DEVICE_EVT?);
}

但是呢,主機這邊總是嘗試連接,但總是失敗。主機打印信息如下:

Discovering...
Device?found...
Connecting...
Connected...
Disconnected...Reason:3e
Discovering...

如此循環(huán),就是連接不了從機。如果修改為

uint8?filter_policy?=?GAP_FILTER_POLICY_WHITE_SCAN;//允許任何設備掃描,但只能主機掃描連接。

主機倒是可以和從機連接和通信,但不是我要的效果。

請問這是什么問題,還是代碼沒完善?


將macType設置為0,從你的現(xiàn)象來看,應該是macType和mac當中存在錯誤導致,可以先不加白名單,先讓主從正常連接,從機連接后獲取下主機的macType和mac對比下與你從機這邊設置的是否一致。

獲取方式如下:在從機Peripheral_LinkEstablished函數(shù)中添加打印,emobile_2023-01-11_21-25-15.png




謝謝啦@TECH_Hy?,將macType設置成0就好了,感謝!


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频