Skip to content
Snippets Groups Projects

feat(mp-ble): add support for ATT client operation

Merged schneider requested to merge schneider/mp-ble-gattc into master
Files
5
@@ -25,15 +25,29 @@ static int next_handle = ATTS_DYN_START_HANDLE;
void ble_epic_att_api_event(attEvt_t *att_event)
{
if (att_event->handle >= ATTS_DYN_START_HANDLE &&
att_event->handle < next_handle) {
attEvt_t *e = WsfBufAlloc(sizeof(*e));
if (att_event->hdr.event != ATTS_HANDLE_VALUE_CNF ||
(att_event->handle >= ATTS_DYN_START_HANDLE &&
att_event->handle < next_handle)) {
size_t value_len = 0;
if (att_event->hdr.event == ATTC_READ_BY_GROUP_TYPE_RSP ||
att_event->hdr.event == ATTC_READ_BY_TYPE_RSP ||
att_event->hdr.event == ATTC_FIND_INFO_RSP ||
att_event->hdr.event == ATTC_HANDLE_VALUE_NTF ||
att_event->hdr.event == ATTC_HANDLE_VALUE_IND) {
value_len = att_event->valueLen;
}
attEvt_t *e = WsfBufAlloc(sizeof(*e) + value_len);
if (e) {
memcpy(e, att_event, sizeof(*e));
memcpy(e + 1, att_event->pValue, value_len);
ble_epic_ble_api_trigger_event(BLE_EVENT_ATT_EVENT, e);
} else {
LOG_WARN("ble", "could not allocate att event");
LOG_WARN(
"ble",
"could not allocate att event of size %d",
sizeof(*e) + att_event->valueLen
);
}
}
}
@@ -278,3 +292,70 @@ int epic_ble_atts_set_attr(
uint8_t ret = AttsSetAttr(handle, value_len, (uint8_t *)value);
return ret;
}
int epic_ble_attc_discover_primary_services(
uint8_t connId, const uint8_t *uuid, uint8_t uuid_len
) {
if (uuid_len == 0 || uuid == NULL) {
AttcReadByGroupTypeReq(
connId, 1, 0xFFFF, 2, (uint8_t *)attPrimSvcUuid, TRUE
);
} else {
AttcFindByTypeValueReq(
connId,
ATT_HANDLE_START,
ATT_HANDLE_MAX,
ATT_UUID_PRIMARY_SERVICE,
uuid_len,
(uint8_t *)uuid,
FALSE
);
}
return 0;
}
int epic_ble_attc_discover_characteristics(
uint8_t connId, uint16_t start_handle, uint16_t end_handle
) {
AttcReadByTypeReq(
connId,
start_handle,
end_handle,
ATT_16_UUID_LEN,
(uint8_t *)attChUuid,
TRUE
);
return 0;
}
int epic_ble_attc_discover_descriptors(
uint8_t connId, uint16_t start_handle, uint16_t end_handle
) {
AttcFindInfoReq(connId, start_handle, end_handle, TRUE);
return 0;
}
int epic_ble_attc_read(uint8_t connId, uint16_t value_handle)
{
AttcReadReq(connId, value_handle);
return 0;
}
int epic_ble_attc_write_no_rsp(
uint8_t connId,
uint16_t value_handle,
const uint8_t *value,
uint16_t value_len
) {
AttcWriteCmd(connId, value_handle, value_len, (uint8_t *)value);
return 0;
}
int epic_ble_attc_write(
uint8_t connId,
uint16_t value_handle,
const uint8_t *value,
uint16_t value_len
) {
AttcWriteReq(connId, value_handle, value_len, (uint8_t *)value);
return 0;
}
Loading