-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add randomize bdaddr implementation #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! A few changes are required.
@@ -72,6 +75,11 @@ def process_packet(socket): | |||
if packet[13:25] != BLE_PACKET: | |||
return | |||
|
|||
# Print sender's bdaddr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to Bluetooth MAC address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
# Print sender's bdaddr | ||
bdaddr = packet[7:13] | ||
bdaddr = bdaddr[::-1].hex().upper() | ||
logger.info(f"Received packet from {':'.join(bdaddr[i:i+2] for i in range(0, len(bdaddr), 2))}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this .debug
; we don't want it in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
def generate_random_bdaddr(): | ||
bdaddr = secrets.token_hex(6) | ||
bdaddr = list(bdaddr) | ||
locally_administer_elements = ['2', '6', 'a', 'e'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
administered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
bdaddr = list(bdaddr) | ||
locally_administer_elements = ['2', '6', 'a', 'e'] | ||
|
||
# The above values denote that the bdaddr is locally administared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment before the line you comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
locally_administer_elements = ['2', '6', 'a', 'e'] | ||
|
||
# The above values denote that the bdaddr is locally administared | ||
bdaddr[1] = secrets.choice(locally_administer_elements) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment each line with an example of what bdaddr will contain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added an example and comments to each line of this function.
@@ -84,6 +85,17 @@ def set_transmit(interface, ephid, rssi): | |||
run_command(cmd) | |||
|
|||
|
|||
def generate_random_bdaddr(): | |||
bdaddr = secrets.token_hex(6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would mac_addr
be more appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAC address is used for both Ethernet and Bluetooth technologies.
I have selected bdaddr because it stands for the Bluetooth device address.
Maybe, we can also use bd_addr, but if you insist we can change it to mac_addr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Then add a function comment, documenting what the function does and explaining that it returns a random "Bluetooth Device (MAC) Address (bdaddr)".
@@ -151,6 +163,18 @@ def main(): | |||
transmitter.check_advance_day(now) | |||
ephid = transmitter.get_ephid_for_time(now) | |||
if ephid != current_ephid: | |||
# Stop advetising before chaning bdaddr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
bdaddr = generate_random_bdaddr() | ||
|
||
# Change local device bdaddr and reset | ||
run_command(["sudo", "bdaddr", "-i", interface, "-r", bdaddr]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for sudo, because we run as root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
Issue: #12