Skip to content

Commit

Permalink
prmac implementation (#187)
Browse files Browse the repository at this point in the history
prmac implementation to only allow decoded devices with random MAC addresses to be published if they are defined with their Identity MAC and IRK
  • Loading branch information
DigiH authored Dec 18, 2023
1 parent 5eb9ad0 commit 2d9fb3c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ def decode_advertisement(

if decoded_json:
decoded_json = json.loads(decoded_json)

decoded_json = self.process_prmacs(
decoded_json,
)

# Only process if the device is not a random mac address
if decoded_json["type"] != "RMAC":
# Only add manufacturer if device is compliant and no beacon
Expand Down Expand Up @@ -493,6 +498,20 @@ def decode_advertisement(
add_manufacturer(data_json, company_id)
self.publish_json(data_json, decoded=False)

def process_prmacs(
self,
decoded_json: DataJSONType,
) -> DataJSONType:
"""Process potential RMACs."""
if "prmac" in decoded_json:
address = decoded_json.get("id")
if address in self.configuration["identities"]:
decoded_json.pop("prmac", None)
else:
decoded_json["type"] = "RMAC"

return decoded_json

def publish_json(
self,
data_json: DataJSONType,
Expand Down

0 comments on commit 2d9fb3c

Please sign in to comment.