diff options
author | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2010-07-21 14:01:02 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2010-08-09 18:06:44 -0400 |
commit | dafe0b2820611bf40851eb6b551ccb80e6b42deb (patch) | |
tree | 719265ad41fa4d3fa068d1a9d718eddcb2bde423 | |
parent | 17b9256fbd64bab88901b056f2998bda772d9957 (diff) | |
download | bluez-dafe0b2820611bf40851eb6b551ccb80e6b42deb.tar.gz bluez-dafe0b2820611bf40851eb6b551ccb80e6b42deb.tar.xz bluez-dafe0b2820611bf40851eb6b551ccb80e6b42deb.zip |
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.
-rw-r--r-- | attrib/att.c | 52 | ||||
-rw-r--r-- | attrib/att.h | 3 |
2 files changed, 55 insertions, 0 deletions
diff --git a/attrib/att.c b/attrib/att.c index b0feeff9..47926488 100644 --- a/attrib/att.c +++ b/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; +} diff --git a/attrib/att.h b/attrib/att.h index 7d31a652..b7c975e7 100644 --- a/attrib/att.h +++ b/attrib/att.h @@ -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 } |