summaryrefslogtreecommitdiffstatshomepage
path: root/examples
diff options
context:
space:
mode:
authorAlexander Wilde <alexander.wilde87@gmail.com>2023-06-20 11:07:45 +0100
committerDamien George <damien@micropython.org>2023-09-01 14:02:51 +1000
commitb94ab6a2ef56fce3f8db2f84b26e3ac0f4b3b155 (patch)
treef8e069904cf8a9a55401ac007b6d969eb2176f14 /examples
parent845d0c79ff798b4524c463be78c769b96528d01c (diff)
downloadmicropython-b94ab6a2ef56fce3f8db2f84b26e3ac0f4b3b155.tar.gz
micropython-b94ab6a2ef56fce3f8db2f84b26e3ac0f4b3b155.zip
examples/bluetooth: Raise ValueError when advertising data is too large.
Signed-off-by: Alexander Wilde <alexander.wilde87@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/bluetooth/ble_advertising.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/examples/bluetooth/ble_advertising.py b/examples/bluetooth/ble_advertising.py
index eed527f55d..6dc78c5e3d 100644
--- a/examples/bluetooth/ble_advertising.py
+++ b/examples/bluetooth/ble_advertising.py
@@ -19,6 +19,8 @@ _ADV_TYPE_UUID32_MORE = const(0x4)
_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):
@@ -50,6 +52,9 @@ def advertising_payload(limited_disc=False, br_edr=False, name=None, services=No
if appearance:
_append(_ADV_TYPE_APPEARANCE, struct.pack("<h", appearance))
+ if len(payload) > _ADV_MAX_PAYLOAD:
+ raise ValueError("advertising payload too large")
+
return payload