diff --git a/epicardium/ble/epic_att_api.c b/epicardium/ble/epic_att_api.c index 97805e28e3e131cc5ec8f3617880836783a810f2..a0da6a219575a44c616679aa3d371d44454cccc8 100644 --- a/epicardium/ble/epic_att_api.c +++ b/epicardium/ble/epic_att_api.c @@ -174,6 +174,42 @@ int epic_atts_dyn_add_characteristic( return 0; } +int epic_ble_atts_dyn_add_descriptor( + void *pSvcHandle, + const uint8_t *uuid, + uint8_t uuid_len, + uint8_t flags, + const uint8_t *value, + uint16_t value_len, + uint16_t maxLen +) { + uint8_t settings = 0; + if (flags & ATT_PROP_WRITE) { + settings |= ATTS_SET_WRITE_CBACK; + } + + uint8_t permissions = 0; + if (flags & ATT_PROP_READ) { + permissions |= ATTS_PERMIT_READ; + } + if (flags & ATT_PROP_WRITE) { + permissions |= ATTS_PERMIT_WRITE; + } + + AttsDynAddAttrDyn( + pSvcHandle, + uuid, + uuid_len, + value, + value_len, + maxLen, + settings, + permissions + ); + + return 0; +} + int epic_atts_dyn_send_service_changed_ind(void) { // TODO: This is copied from an upstream stack version diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index d9973d18822fb83f7d1ae97d78ca9cfddc13bb70..a63784e4020241ae3923ef94a64359ddb17c69fa 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -165,8 +165,7 @@ typedef _Bool bool; #define API_BLE_ATTS_DYN_CREATE_GROUP 0x160 //#define API_BLE_ATTS_DYN_DELETE_GROUP 0x161 #define API_BLE_ATTS_DYN_REGISTER 0x162 -#define API_BLE_ATTS_DYN_ADD_ATTR_DYN 0x163 -#define API_BLE_ATTS_DYN_ADD_ATTR 0x164 +#define API_BLE_ATTS_DYN_ADD_DESCRIPTOR 0x164 #define API_BLE_ATTS_SET_ATTR 0x165 #define API_BLE_ATTS_HANDLE_VALUE_NTF 0x166 #define API_BLE_ATTS_HANDLE_VALUE_IND 0x167 @@ -2593,8 +2592,7 @@ API(API_BLE_ATTS_DYN_CREATE_GROUP, int epic_atts_dyn_create_service(const uint8_ //API(API_BLE_ATTS_DYN_DELETE_GROUP, void AttsDynDeleteGroup(void *pSvcHandle)); API(API_BLE_ATTS_DYN_DELETE_GROUPS, int epic_ble_atts_dyn_delete_groups(void)); -API(API_BLE_ATTS_DYN_ADD_ATTR_DYN, void AttsDynAddAttrDyn(void *pSvcHandle, const uint8_t *pUuid, uint8_t uuidLen, const uint8_t *pValue, uint16_t len, uint16_t maxLen, uint8_t settings, uint8_t permissions)); -API(API_BLE_ATTS_DYN_ADD_ATTR, void AttsDynAddAttr(void *pSvcHandle, const uint8_t *pUuid, const uint8_t *pValue, uint16_t len, uint16_t maxLen, uint8_t settings, uint8_t permissions)); +API(API_BLE_ATTS_DYN_ADD_DESCRIPTOR, int epic_ble_atts_dyn_add_descriptor(void *pSvcHandle, const uint8_t *uuid, uint8_t uuid_len, uint8_t flags, const uint8_t *value, uint16_t value_len, uint16_t maxLen)); API(API_BLE_ATTS_DYN_ADD_CHARACTERISTIC, int epic_atts_dyn_add_characteristic(void *pSvcHandle, const uint8_t *uuid, uint8_t uuid_len, uint8_t flags, uint16_t maxLen, uint16_t current_handle)); API(API_BLE_ATTS_SEND_SERVICE_CHANGED_IND, int epic_atts_dyn_send_service_changed_ind(void)); diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c index 1d3e675937e4f9e2d3e6741673613828f06519bc..3aa760ff5e43084ea77ab3c54b320e5626aa6a05 100644 --- a/pycardium/modules/modbluetooth_card10.c +++ b/pycardium/modules/modbluetooth_card10.c @@ -4,27 +4,6 @@ #include <stdio.h> #include <string.h> -#define ATTS_PERMIT_READ 0x01 /*!< \brief Set if attribute can be read */ -#define ATTS_PERMIT_READ_AUTH \ - 0x02 /*!< \brief Set if attribute read requires authentication */ -#define ATTS_PERMIT_READ_AUTHORIZ \ - 0x04 /*!< \brief Set if attribute read requires authorization */ -#define ATTS_PERMIT_READ_ENC \ - 0x08 /*!< \brief Set if attribute read requires encryption */ -#define ATTS_PERMIT_WRITE 0x10 /*!< \brief Set if attribute can be written */ -#define ATTS_PERMIT_WRITE_AUTH \ - 0x20 /*!< \brief Set if attribute write requires authentication */ -#define ATTS_PERMIT_WRITE_AUTHORIZ \ - 0x40 /*!< \brief Set if attribute write requires authorization */ -#define ATTS_PERMIT_WRITE_ENC \ - 0x80 /*!< \brief Set if attribute write requires encryption */ - -#define UINT16_TO_BYTES(n) ((uint8_t)(n)), ((uint8_t)((n) >> 8)) -#define ATT_UUID_CLIENT_CHAR_CONFIG 0x2902 - -const uint8_t attCliChCfgUuid[] = { UINT16_TO_BYTES( - ATT_UUID_CLIENT_CHAR_CONFIG) }; - #define ATT_SUCCESS 0x00 /*!< \brief Operation successful */ #define ATT_ERR_HANDLE 0x01 /*!< \brief Invalid handle */ #define ATT_ERR_READ 0x02 /*!< \brief Read not permitted */ @@ -476,22 +455,23 @@ int mp_bluetooth_gatts_register_service( if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE) { initCcc[0] |= 0x02; } + // TODO: Handle CCC data - // Settings is 0 on purpose. If set to ATTS_SET_CCC the stack starts to try and - // manage the CCC data itself. - uint8_t settings = 0; - uint8_t permissions = - ATTS_PERMIT_READ | ATTS_PERMIT_WRITE; - AttsDynAddAttr( + uint8_t ccc_uuid[] = { 0x02, 0x29 }; + uint8_t flags = MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ | + MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE; + epic_ble_atts_dyn_add_descriptor( pSvcHandle, - attCliChCfgUuid, + ccc_uuid, + sizeof(ccc_uuid), + flags, initCcc, sizeof(initCcc), - sizeof(initCcc), - settings, - permissions + sizeof(initCcc) + ); + epic_ble_atts_set_attr( + currentHandle, initCcc, sizeof(initCcc) ); - //mp_bluetooth_gatts_db_create_entry(GATTS_DB, handles[handle_index] + 1, MP_BLUETOOTH_CCCB_LEN); //gatts_status_create_entry(GATTS_STATUS, handles[handle_index] + 1); //int ret = mp_bluetooth_gatts_db_write(GATTS_DB, handles[handle_index] + 1, cccb_buf, sizeof(cccb_buf));