Skip to content
Snippets Groups Projects
Commit f22e8929 authored by schneider's avatar schneider
Browse files

change(ble): Add epic call to add descriptors

parent 45d856e4
Branches
Tags
1 merge request!446Initial MicroPython BLE support (GATTS)
...@@ -174,6 +174,42 @@ int epic_atts_dyn_add_characteristic( ...@@ -174,6 +174,42 @@ int epic_atts_dyn_add_characteristic(
return 0; 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) int epic_atts_dyn_send_service_changed_ind(void)
{ {
// TODO: This is copied from an upstream stack version // TODO: This is copied from an upstream stack version
......
...@@ -165,8 +165,7 @@ typedef _Bool bool; ...@@ -165,8 +165,7 @@ typedef _Bool bool;
#define API_BLE_ATTS_DYN_CREATE_GROUP 0x160 #define API_BLE_ATTS_DYN_CREATE_GROUP 0x160
//#define API_BLE_ATTS_DYN_DELETE_GROUP 0x161 //#define API_BLE_ATTS_DYN_DELETE_GROUP 0x161
#define API_BLE_ATTS_DYN_REGISTER 0x162 #define API_BLE_ATTS_DYN_REGISTER 0x162
#define API_BLE_ATTS_DYN_ADD_ATTR_DYN 0x163 #define API_BLE_ATTS_DYN_ADD_DESCRIPTOR 0x164
#define API_BLE_ATTS_DYN_ADD_ATTR 0x164
#define API_BLE_ATTS_SET_ATTR 0x165 #define API_BLE_ATTS_SET_ATTR 0x165
#define API_BLE_ATTS_HANDLE_VALUE_NTF 0x166 #define API_BLE_ATTS_HANDLE_VALUE_NTF 0x166
#define API_BLE_ATTS_HANDLE_VALUE_IND 0x167 #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_ ...@@ -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_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_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_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_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_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_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)); API(API_BLE_ATTS_SEND_SERVICE_CHANGED_IND, int epic_atts_dyn_send_service_changed_ind(void));
......
...@@ -4,27 +4,6 @@ ...@@ -4,27 +4,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.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_SUCCESS 0x00 /*!< \brief Operation successful */
#define ATT_ERR_HANDLE 0x01 /*!< \brief Invalid handle */ #define ATT_ERR_HANDLE 0x01 /*!< \brief Invalid handle */
#define ATT_ERR_READ 0x02 /*!< \brief Read not permitted */ #define ATT_ERR_READ 0x02 /*!< \brief Read not permitted */
...@@ -476,22 +455,23 @@ int mp_bluetooth_gatts_register_service( ...@@ -476,22 +455,23 @@ int mp_bluetooth_gatts_register_service(
if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE) { if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_INDICATE) {
initCcc[0] |= 0x02; initCcc[0] |= 0x02;
} }
// TODO: Handle CCC data // TODO: Handle CCC data
// Settings is 0 on purpose. If set to ATTS_SET_CCC the stack starts to try and uint8_t ccc_uuid[] = { 0x02, 0x29 };
// manage the CCC data itself. uint8_t flags = MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ |
uint8_t settings = 0; MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE;
uint8_t permissions = epic_ble_atts_dyn_add_descriptor(
ATTS_PERMIT_READ | ATTS_PERMIT_WRITE;
AttsDynAddAttr(
pSvcHandle, pSvcHandle,
attCliChCfgUuid, ccc_uuid,
sizeof(ccc_uuid),
flags,
initCcc, initCcc,
sizeof(initCcc), sizeof(initCcc),
sizeof(initCcc), sizeof(initCcc)
settings, );
permissions 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); //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); //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)); //int ret = mp_bluetooth_gatts_db_write(GATTS_DB, handles[handle_index] + 1, cccb_buf, sizeof(cccb_buf));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment