Skip to content

Commit

Permalink
ninafw: implement set random MAC address
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Zheng <[email protected]>
  • Loading branch information
xudongzheng committed Jan 19, 2024
1 parent 1ed1821 commit 8dc46b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions adapter_ninafw.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ func (a *Adapter) Enable() error {
return nil
}

func (a *Adapter) SetRandomAddress(mac MAC) error {
if err := a.hci.sendCommandWithParams(ogfLECtrl<<ogfCommandPos|ocfLESetRandomAddress, mac[:]); err != nil {
return err
}
copy(a.hci.address.MAC[:], mac[:])
a.hci.address.SetRandom(true)
return nil
}

func (a *Adapter) Address() (MACAddress, error) {
if err := a.hci.readBdAddr(); err != nil {
return MACAddress{}, err
Expand Down
12 changes: 8 additions & 4 deletions gap_ninafw.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err
println("Connect")
}

random := uint8(0)
peerRandom := uint8(0)
if address.isRandom {
random = 1
peerRandom = 1
}
localRandom := uint8(0)
if a.hci.address.isRandom {
localRandom = 1
}
if err := a.hci.leCreateConn(0x0060, 0x0030, 0x00,
random, makeNINAAddress(address.MAC),
0x00, 0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006); err != nil {
peerRandom, makeNINAAddress(address.MAC),
localRandom, 0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006); err != nil {
return Device{}, err
}

Expand Down

0 comments on commit 8dc46b3

Please sign in to comment.