Skip to content

Commit

Permalink
gap/linux: add implementation for SetRandomAddress() function
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jan 8, 2025
1 parent 1eb86fe commit 13d71b4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion gap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,21 @@ func (d Device) RequestConnectionParams(params ConnectionParams) error {

// SetRandomAddress sets the random address to be used for advertising.
func (a *Adapter) SetRandomAddress(mac MAC) error {
return errors.ErrUnsupported
addr, err := a.adapter.GetProperty("org.bluez.Adapter1.Address")
if err != nil {
if err, ok := err.(dbus.Error); ok && err.Name == "org.freedesktop.DBus.Error.UnknownObject" {
return fmt.Errorf("bluetooth: adapter %s does not exist", a.adapter.Path())
}
return fmt.Errorf("could not get adapter address: %w", err)
}
a.address = mac.String()
if err := addr.Store(&a.address); err != nil {
return fmt.Errorf("could not set adapter address: %w", err)
}

if err := a.adapter.SetProperty("org.bluez.Adapter1.AddressType", "random"); err != nil {
return fmt.Errorf("could not set adapter address type: %w", err)
}

return nil
}

0 comments on commit 13d71b4

Please sign in to comment.