@@ -594,7 +594,7 @@ STATIC void check_data_fit(size_t data_len, bool connectable) {
594
594
}
595
595
}
596
596
597
- uint32_t _common_hal_bleio_adapter_start_advertising (bleio_adapter_obj_t * self , bool connectable , float interval , uint8_t * advertising_data , uint16_t advertising_data_len , uint8_t * scan_response_data , uint16_t scan_response_data_len ) {
597
+ uint32_t _common_hal_bleio_adapter_start_advertising (bleio_adapter_obj_t * self , bool connectable , bool anonymous , float interval , uint8_t * advertising_data , uint16_t advertising_data_len , uint8_t * scan_response_data , uint16_t scan_response_data_len ) {
598
598
if (self -> current_advertising_data != NULL && self -> current_advertising_data == self -> advertising_data ) {
599
599
return NRF_ERROR_BUSY ;
600
600
}
@@ -605,7 +605,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
605
605
common_hal_bleio_adapter_stop_advertising (self );
606
606
}
607
607
608
-
608
+ uint32_t err_code ;
609
609
bool extended = advertising_data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX ||
610
610
scan_response_data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX ;
611
611
@@ -626,7 +626,27 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
626
626
adv_type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED ;
627
627
}
628
628
629
- uint32_t err_code ;
629
+ if (anonymous ) {
630
+ ble_gap_privacy_params_t privacy = {
631
+ .privacy_mode = BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY ,
632
+ .private_addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE ,
633
+ .private_addr_cycle_s = 0 ,
634
+ .p_device_irk = NULL ,
635
+ };
636
+ err_code = sd_ble_gap_privacy_set (& privacy );
637
+ } else {
638
+ ble_gap_privacy_params_t privacy = {
639
+ .privacy_mode = BLE_GAP_PRIVACY_MODE_OFF ,
640
+ .private_addr_type = BLE_GAP_ADDR_TYPE_PUBLIC ,
641
+ .private_addr_cycle_s = 0 ,
642
+ .p_device_irk = NULL ,
643
+ };
644
+ err_code = sd_ble_gap_privacy_set (& privacy );
645
+ }
646
+ if (err_code != NRF_SUCCESS ) {
647
+ return err_code ;
648
+ }
649
+
630
650
ble_gap_adv_params_t adv_params = {
631
651
.interval = SEC_TO_UNITS (interval , UNIT_0_625_MS ),
632
652
.properties .type = adv_type ,
@@ -657,7 +677,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
657
677
}
658
678
659
679
660
- void common_hal_bleio_adapter_start_advertising (bleio_adapter_obj_t * self , bool connectable , mp_float_t interval , mp_buffer_info_t * advertising_data_bufinfo , mp_buffer_info_t * scan_response_data_bufinfo ) {
680
+ void common_hal_bleio_adapter_start_advertising (bleio_adapter_obj_t * self , bool connectable , bool anonymous , mp_float_t interval , mp_buffer_info_t * advertising_data_bufinfo , mp_buffer_info_t * scan_response_data_bufinfo ) {
661
681
if (self -> current_advertising_data != NULL && self -> current_advertising_data == self -> advertising_data ) {
662
682
mp_raise_bleio_BluetoothError (translate ("Already advertising." ));
663
683
}
@@ -681,7 +701,7 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
681
701
memcpy (self -> advertising_data , advertising_data_bufinfo -> buf , advertising_data_bufinfo -> len );
682
702
memcpy (self -> scan_response_data , scan_response_data_bufinfo -> buf , scan_response_data_bufinfo -> len );
683
703
684
- check_nrf_error (_common_hal_bleio_adapter_start_advertising (self , connectable , interval ,
704
+ check_nrf_error (_common_hal_bleio_adapter_start_advertising (self , connectable , anonymous , interval ,
685
705
self -> advertising_data ,
686
706
advertising_data_bufinfo -> len ,
687
707
self -> scan_response_data ,
0 commit comments