@@ -893,7 +893,30 @@ STATIC inline uint16_t get_uuid16(const mp_obj_bluetooth_uuid_t *uuid) {
893893 return (uuid -> data [1 ] << 8 ) | uuid -> data [0 ];
894894}
895895
896- int mp_bluetooth_gatts_register_service (mp_obj_bluetooth_uuid_t * service_uuid , mp_obj_bluetooth_uuid_t * * characteristic_uuids , uint8_t * characteristic_flags , mp_obj_bluetooth_uuid_t * * descriptor_uuids , uint8_t * descriptor_flags , uint8_t * num_descriptors , uint16_t * handles , size_t num_characteristics ) {
896+ // Map MP_BLUETOOTH_CHARACTERISTIC_FLAG_ values to btstack read/write permission values.
897+ STATIC void get_characteristic_permissions (uint16_t flags , uint16_t * read_permission , uint16_t * write_permission ) {
898+ if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_ENCRYPTED ) {
899+ * read_permission = ATT_SECURITY_ENCRYPTED ;
900+ } else if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_AUTHENTICATED ) {
901+ * read_permission = ATT_SECURITY_AUTHENTICATED ;
902+ } else if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_AUTHORIZED ) {
903+ * read_permission = ATT_SECURITY_AUTHORIZED ;
904+ } else {
905+ * read_permission = ATT_SECURITY_NONE ;
906+ }
907+
908+ if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_ENCRYPTED ) {
909+ * write_permission = ATT_SECURITY_ENCRYPTED ;
910+ } else if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_AUTHENTICATED ) {
911+ * write_permission = ATT_SECURITY_AUTHENTICATED ;
912+ } else if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_AUTHORIZED ) {
913+ * write_permission = ATT_SECURITY_AUTHORIZED ;
914+ } else {
915+ * write_permission = ATT_SECURITY_NONE ;
916+ }
917+ }
918+
919+ int mp_bluetooth_gatts_register_service (mp_obj_bluetooth_uuid_t * service_uuid , mp_obj_bluetooth_uuid_t * * characteristic_uuids , uint16_t * characteristic_flags , mp_obj_bluetooth_uuid_t * * descriptor_uuids , uint16_t * descriptor_flags , uint8_t * num_descriptors , uint16_t * handles , size_t num_characteristics ) {
897920 DEBUG_printf ("mp_bluetooth_gatts_register_service\n" );
898921 // Note: btstack expects BE UUIDs (which it immediately convertes to LE).
899922 // So we have to convert all our modbluetooth LE UUIDs to BE just for the att_db_util_add_* methods (using get_uuid16 above, and reverse_128 from btstackutil.h).
@@ -916,9 +939,9 @@ int mp_bluetooth_gatts_register_service(mp_obj_bluetooth_uuid_t *service_uuid, m
916939 static uint8_t cccb_buf [2 ] = {0 };
917940
918941 for (size_t i = 0 ; i < num_characteristics ; ++ i ) {
919- uint16_t props = characteristic_flags [i ] | ATT_PROPERTY_DYNAMIC ;
920- uint16_t read_permission = ATT_SECURITY_NONE ;
921- uint16_t write_permission = ATT_SECURITY_NONE ;
942+ uint16_t props = ( characteristic_flags [i ] & 0x7f ) | ATT_PROPERTY_DYNAMIC ;
943+ uint16_t read_permission , write_permission ;
944+ get_characteristic_permissions ( characteristic_flags [ i ], & read_permission , & write_permission ) ;
922945 if (characteristic_uuids [i ]-> type == MP_BLUETOOTH_UUID_TYPE_16 ) {
923946 handles [handle_index ] = att_db_util_add_characteristic_uuid16 (get_uuid16 (characteristic_uuids [i ]), props , read_permission , write_permission , NULL , 0 );
924947 } else if (characteristic_uuids [i ]-> type == MP_BLUETOOTH_UUID_TYPE_128 ) {
@@ -942,9 +965,8 @@ int mp_bluetooth_gatts_register_service(mp_obj_bluetooth_uuid_t *service_uuid, m
942965 ++ handle_index ;
943966
944967 for (size_t j = 0 ; j < num_descriptors [i ]; ++ j ) {
945- props = descriptor_flags [descriptor_index ] | ATT_PROPERTY_DYNAMIC ;
946- read_permission = ATT_SECURITY_NONE ;
947- write_permission = ATT_SECURITY_NONE ;
968+ props = (descriptor_flags [descriptor_index ] & 0x7f ) | ATT_PROPERTY_DYNAMIC ;
969+ get_characteristic_permissions (descriptor_flags [descriptor_index ], & read_permission , & write_permission );
948970
949971 if (descriptor_uuids [descriptor_index ]-> type == MP_BLUETOOTH_UUID_TYPE_16 ) {
950972 handles [handle_index ] = att_db_util_add_descriptor_uuid16 (get_uuid16 (descriptor_uuids [descriptor_index ]), props , read_permission , write_permission , NULL , 0 );
0 commit comments