Skip to content

Commit 51f0492

Browse files
committed
gap/linux: add implementation for SetRandomAddress() function
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 7d61c5f commit 51f0492

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

gap_linux.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,24 @@ func (d Device) Disconnect() error {
419419
func (d Device) RequestConnectionParams(params ConnectionParams) error {
420420
return nil
421421
}
422+
423+
// SetRandomAddress sets the random address to be used for advertising.
424+
func (a *Adapter) SetRandomAddress(mac MAC) error {
425+
addr, err := a.adapter.GetProperty("org.bluez.Adapter1.Address")
426+
if err != nil {
427+
if err, ok := err.(dbus.Error); ok && err.Name == "org.freedesktop.DBus.Error.UnknownObject" {
428+
return fmt.Errorf("bluetooth: adapter %s does not exist", a.adapter.Path())
429+
}
430+
return fmt.Errorf("could not get adapter address: %w", err)
431+
}
432+
a.address = mac.String()
433+
if err := addr.Store(&a.address); err != nil {
434+
return fmt.Errorf("could not set adapter address: %w", err)
435+
}
436+
437+
if err := a.adapter.SetProperty("org.bluez.Adapter1.AddressType", "random"); err != nil {
438+
return fmt.Errorf("could not set adapter address type: %w", err)
439+
}
440+
441+
return nil
442+
}

0 commit comments

Comments
 (0)