mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-12-14 22:44:35 +08:00
Add support to deal with Read by Type PDUs
This adds att_read_by_type_{encode,decode}, so we can create Read by Type Requests and parse Read by Type Responses.
This commit is contained in:
parent
17b9256fbd
commit
dafe0b2820
52
attrib/att.c
52
attrib/att.c
@ -142,3 +142,55 @@ uint16_t att_find_by_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t att_read_by_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len)
|
||||
{
|
||||
uint16_t *p16;
|
||||
|
||||
/* FIXME: UUID128 is not supported */
|
||||
|
||||
if (!uuid)
|
||||
return 0;
|
||||
|
||||
if (uuid->type != SDP_UUID16)
|
||||
return 0;
|
||||
|
||||
if (len < 7)
|
||||
return 0;
|
||||
|
||||
pdu[0] = ATT_OP_READ_BY_TYPE_REQ;
|
||||
p16 = (void *) &pdu[1];
|
||||
*p16 = htobs(start);
|
||||
p16++;
|
||||
*p16 = htobs(end);
|
||||
p16++;
|
||||
*p16 = htobs(uuid->value.uuid16);
|
||||
|
||||
return 7;
|
||||
}
|
||||
|
||||
struct att_data_list *add_read_by_type_decode(const uint8_t *pdu, int len)
|
||||
{
|
||||
struct att_data_list *list;
|
||||
const uint8_t *ptr;
|
||||
int i;
|
||||
|
||||
if (pdu[0] != ATT_OP_READ_BY_TYPE_RESP)
|
||||
return NULL;
|
||||
|
||||
list = malloc(sizeof(struct att_data_list));
|
||||
list->len = pdu[1];
|
||||
list->num = len / list->len;
|
||||
|
||||
list->data = malloc(sizeof(uint8_t *) * list->num);
|
||||
ptr = &pdu[2];
|
||||
|
||||
for (i = 0; i < list->num; i++) {
|
||||
list->data[i] = malloc(sizeof(uint8_t) * list->len);
|
||||
memcpy(list->data[i], ptr, list->len);
|
||||
ptr += list->len;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
@ -128,6 +128,9 @@ uint16_t att_read_by_grp_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint16_t att_find_by_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len);
|
||||
struct att_data_list *att_read_by_grp_type_decode(const uint8_t *pdu, int len);
|
||||
uint16_t att_read_by_type_encode(uint16_t start, uint16_t end, uuid_t *uuid,
|
||||
uint8_t *pdu, int len);
|
||||
struct att_data_list *add_read_by_type_decode(const uint8_t *pdu, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user