Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrf528xx: add advertiser random address #328

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gap.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ func (buf *rawAdvertisementPayload) reset() {
// before the call) from the advertisement options. It returns true if it fits,
// false otherwise.
func (buf *rawAdvertisementPayload) addFromOptions(options AdvertisementOptions) (ok bool) {
buf.addFlags(0x06)
// do not add flags for non-connectable advertisements
if options.AdvertisementType != AdvertisingTypeNonConnInd {
buf.addFlags(0x06)
}
if options.LocalName != "" {
if !buf.addCompleteLocalName(options.LocalName) {
return false
Expand Down
27 changes: 26 additions & 1 deletion gap_nrf528xx-advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,26 @@ func (a *Advertisement) Configure(options AdvertisementOptions) error {
return errAdvertisementPacketTooBig
}

var typ uint8
switch options.AdvertisementType {
case AdvertisingTypeInd:
typ = C.BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED
case AdvertisingTypeDirectInd:
typ = C.BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED
case AdvertisingTypeScanInd:
typ = C.BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED
case AdvertisingTypeNonConnInd:
typ = C.BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED
}

data := C.ble_gap_adv_data_t{}
data.adv_data = C.ble_data_t{
p_data: (*C.uint8_t)(unsafe.Pointer(&a.payload.data[0])),
len: C.uint16_t(a.payload.len),
}
params := C.ble_gap_adv_params_t{
properties: C.ble_gap_adv_properties_t{
_type: C.BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED,
_type: typ,
},
interval: C.uint32_t(options.Interval),
}
Expand All @@ -84,3 +96,16 @@ func (a *Advertisement) Stop() error {
errCode := C.sd_ble_gap_adv_stop(a.handle)
return makeError(errCode)
}

// SetRandomAddress sets the random address to be used for advertising.
func (a *Adapter) SetRandomAddress(mac MAC) error {
var addr C.ble_gap_addr_t
addr.addr = makeSDAddress(mac)
addr.set_bitfield_addr_type(C.BLE_GAP_ADDR_TYPE_RANDOM_STATIC)

errCode := C.sd_ble_gap_addr_set(&addr)
if errCode != 0 {
return Error(errCode)
}
return nil
}
Loading