diff --git a/epicardium/ble/epic_att_api.c b/epicardium/ble/epic_att_api.c index f1475eb41df51625ff8af6cd3b8c7378dfbb8b38..97805e28e3e131cc5ec8f3617880836783a810f2 100644 --- a/epicardium/ble/epic_att_api.c +++ b/epicardium/ble/epic_att_api.c @@ -78,8 +78,12 @@ static int next_start_handle = ATTS_DYN_START_HANDLE; static void *dyn_groups[ATTS_DYN_GROUP_COUNT] = {}; static int next_dyn_group = 0; -int epic_atts_dyn_create_group( - uint16_t group_size, void **pSvcHandle, uint16_t *start_handle +int epic_atts_dyn_create_service( + const uint8_t *uuid, + uint8_t uuid_len, + uint16_t group_size, + void **pSvcHandle, + uint16_t *start_handle ) { *start_handle = next_start_handle; int end_handle = *start_handle + group_size - 1; @@ -91,6 +95,16 @@ int epic_atts_dyn_create_group( //AttsDynRegister(pSvcHandle, DynAttsReadCback, DynAttsWriteCback); AttsDynRegister(*pSvcHandle, NULL, DynAttsWriteCback); + AttsDynAddAttr( + *pSvcHandle, + attPrimSvcUuid, + uuid, + uuid_len, + uuid_len, + 0, + ATTS_PERMIT_READ + ); + // TODO: validate parameters and pointer and current service count return 0; } diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 7ea3efbae64efc3ef4c65fa6cffb7a6720e1ffff..d9973d18822fb83f7d1ae97d78ca9cfddc13bb70 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -2589,13 +2589,13 @@ API(API_BLE_GET_SCAN_REPORT, int epic_ble_get_scan_report(struct epic_scan_repor */ API(API_BLE_HID_SEND_REPORT, int epic_ble_hid_send_report(uint8_t report_id, uint8_t *data, uint8_t len)); -API(API_BLE_ATTS_DYN_CREATE_GROUP, int epic_atts_dyn_create_group(uint16_t group_size, void **pSvcHandle, uint16_t *start_handle)); +API(API_BLE_ATTS_DYN_CREATE_GROUP, int epic_atts_dyn_create_service(const uint8_t *uuid, uint8_t uuid_len, uint16_t group_size, void **pSvcHandle, uint16_t *start_handle)); //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_CHARACTERISTIC, int epic_atts_dyn_add_characteristic(void *pSvcHandle, const uint8_t *pUuid, uint8_t uuidLen, 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)); diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c index 48837f216aeffb2d63a8ee82090b9c12f185b8fb..1d3e675937e4f9e2d3e6741673613828f06519bc 100644 --- a/pycardium/modules/modbluetooth_card10.c +++ b/pycardium/modules/modbluetooth_card10.c @@ -20,10 +20,8 @@ 0x80 /*!< \brief Set if attribute write requires encryption */ #define UINT16_TO_BYTES(n) ((uint8_t)(n)), ((uint8_t)((n) >> 8)) -#define ATT_UUID_PRIMARY_SERVICE 0x2800 #define ATT_UUID_CLIENT_CHAR_CONFIG 0x2902 -const uint8_t attPrimSvcUuid[] = { UINT16_TO_BYTES(ATT_UUID_PRIMARY_SERVICE) }; const uint8_t attCliChCfgUuid[] = { UINT16_TO_BYTES( ATT_UUID_CLIENT_CHAR_CONFIG) }; @@ -426,23 +424,20 @@ int mp_bluetooth_gatts_register_service( 1 + num_characteristics * 2 + num_ccds + num_descriptors_total; uint16_t startHandle; - // TODO: handle error - epic_atts_dyn_create_group(numHandles, &pSvcHandle, &startHandle); - - /* Primary service */ uint16_t uuid_len = service_uuid->type == MP_BLUETOOTH_UUID_TYPE_16 ? 2 : 16; - uint16_t currentHandle = startHandle; - AttsDynAddAttr( - pSvcHandle, - attPrimSvcUuid, + + // TODO: handle error + epic_atts_dyn_create_service( service_uuid->data, uuid_len, - uuid_len, - 0, - ATTS_PERMIT_READ + numHandles, + &pSvcHandle, + &startHandle ); + uint16_t currentHandle = startHandle; + size_t handle_index = 0; for (size_t i = 0; i < num_characteristics; ++i) { uint8_t flags = characteristic_flags[i];