Skip to content

Commit

Permalink
examples/bluetooth: Raise ValueError when advertising data is too large.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Wilde <[email protected]>
  • Loading branch information
Alexander Wilde authored and dpgeorge committed Sep 1, 2023
1 parent 845d0c7 commit b94ab6a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/bluetooth/ble_advertising.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
_ADV_TYPE_UUID128_MORE = const(0x6)
_ADV_TYPE_APPEARANCE = const(0x19)

_ADV_MAX_PAYLOAD = const(31)


# Generate a payload to be passed to gap_advertise(adv_data=...).
def advertising_payload(limited_disc=False, br_edr=False, name=None, services=None, appearance=0):
Expand Down Expand Up @@ -50,6 +52,9 @@ def _append(adv_type, value):
if appearance:
_append(_ADV_TYPE_APPEARANCE, struct.pack("<h", appearance))

if len(payload) > _ADV_MAX_PAYLOAD:
raise ValueError("advertising payload too large")

return payload


Expand Down

0 comments on commit b94ab6a

Please sign in to comment.