Skip to content

Commit a211012

Browse files
committed
hci: use current MAC address when Advertiser, allowing support for random advertiser addresses
Signed-off-by: deadprogram <[email protected]>
1 parent 70ef92c commit a211012

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

adapter_hci.go

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func (a *hciAdapter) enable() error {
5050
}
5151

5252
func (a *hciAdapter) Address() (MACAddress, error) {
53+
var empty MAC
54+
if a.hci.address.MAC != empty {
55+
return a.hci.address, nil
56+
}
57+
5358
if err := a.hci.readBdAddr(); err != nil {
5459
return MACAddress{}, err
5560
}

gap_hci.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,13 @@ func (a *Advertisement) Start() error {
358358
// uint8_t type = (_connectable) ? 0x00 : (_localName ? 0x02 : 0x03);
359359
typ := uint8(a.advertisementType)
360360

361+
localRandom := uint8(0)
362+
if a.adapter.hci.address.isRandom {
363+
localRandom = 1
364+
}
365+
361366
if err := a.adapter.hci.leSetAdvertisingParameters(a.interval, a.interval,
362-
typ, 0x00, 0x00, [6]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x07, 0); err != nil {
367+
typ, localRandom, 0x00, [6]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0x07, 0); err != nil {
363368
return err
364369
}
365370

0 commit comments

Comments
 (0)