mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
extmod/modbluetooth: Allow setting char/desc enc/auth options.
This widens the characteristic/descriptor flags to 16-bit, to allow setting encryption/authentication requirements. Sets the required flags for NimBLE and btstack implementations. The BLE.FLAG_* constants will eventually be deprecated in favour of copy and paste Python constants (like the IRQs). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
7a9aa49595
commit
1697ff335d
@@ -461,11 +461,11 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
|
||||
|
||||
// Lists of characteristic uuids and flags.
|
||||
mp_obj_bluetooth_uuid_t **characteristic_uuids = m_new(mp_obj_bluetooth_uuid_t *, len);
|
||||
uint8_t *characteristic_flags = m_new(uint8_t, len);
|
||||
uint16_t *characteristic_flags = m_new(uint16_t, len);
|
||||
|
||||
// Flattened list of descriptor uuids and flags. Grows (realloc) as more descriptors are encountered.
|
||||
mp_obj_bluetooth_uuid_t **descriptor_uuids = NULL;
|
||||
uint8_t *descriptor_flags = NULL;
|
||||
uint16_t *descriptor_flags = NULL;
|
||||
// How many descriptors in the flattened list per characteristic.
|
||||
uint8_t *num_descriptors = m_new(uint8_t, len);
|
||||
|
||||
@@ -506,7 +506,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character
|
||||
|
||||
// Grow the flattened uuids and flags arrays with this many more descriptors.
|
||||
descriptor_uuids = m_renew(mp_obj_bluetooth_uuid_t *, descriptor_uuids, descriptor_index, descriptor_index + num_descriptors[characteristic_index]);
|
||||
descriptor_flags = m_renew(uint8_t, descriptor_flags, descriptor_index, descriptor_index + num_descriptors[characteristic_index]);
|
||||
descriptor_flags = m_renew(uint16_t, descriptor_flags, descriptor_index, descriptor_index + num_descriptors[characteristic_index]);
|
||||
|
||||
// Also grow the handles array.
|
||||
*handles = m_renew(uint16_t, *handles, *num_handles, *num_handles + num_descriptors[characteristic_index]);
|
||||
@@ -894,6 +894,8 @@ STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluetooth) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BLE), MP_ROM_PTR(&mp_type_bluetooth_ble) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&mp_type_bluetooth_uuid) },
|
||||
|
||||
// TODO: Deprecate these flags (recommend copying the constants from modbluetooth.h instead).
|
||||
{ MP_ROM_QSTR(MP_QSTR_FLAG_READ), MP_ROM_INT(MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_FLAG_WRITE), MP_ROM_INT(MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_FLAG_NOTIFY), MP_ROM_INT(MP_BLUETOOTH_CHARACTERISTIC_FLAG_NOTIFY) },
|
||||
|
||||
Reference in New Issue
Block a user