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

hci: implement set random MAC address #229

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion adapter_hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ func (a *hciAdapter) Address() (MACAddress, error) {
return MACAddress{}, err
}

return MACAddress{MAC: makeAddress(a.hci.address)}, nil
return a.hci.address, 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 newBLEStack(uart *machine.UART) (*hci, *att) {
Expand Down
12 changes: 8 additions & 4 deletions gap_hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,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
4 changes: 2 additions & 2 deletions hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type hci struct {
att *att
l2cap *l2cap
buf []byte
address [6]byte
address MACAddress
cmdCompleteOpcode uint16
cmdCompleteStatus uint8
cmdResponse []byte
Expand Down Expand Up @@ -256,7 +256,7 @@ func (h *hci) readBdAddr() error {
return err
}

copy(h.address[:], h.cmdResponse[:7])
copy(h.address.MAC[:], h.cmdResponse[:7])

return nil
}
Expand Down
Loading