diff options
author | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2010-08-18 18:22:17 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2010-09-22 22:34:26 +0300 |
commit | 9041deab6519ccf61b33041cbc2c5b39c1f32650 (patch) | |
tree | a22c86cdb82ccb2d593aba322b34333a83eb3e2a | |
parent | 37e3aa41e8604a67acd03746fbacaeccfb9a8aa3 (diff) | |
download | bluez-9041deab6519ccf61b33041cbc2c5b39c1f32650.tar.gz |
Add encoders/decoders for Indication/Confirmation
-rw-r--r-- | attrib/att.c | 50 | ||||
-rw-r--r-- | attrib/att.h | 3 |
2 files changed, 53 insertions, 0 deletions
diff --git a/attrib/att.c b/attrib/att.c index 905c85428..cb9e0fee5 100644 --- a/attrib/att.c +++ b/attrib/att.c @@ -509,6 +509,56 @@ uint16_t enc_notification(struct attribute *a, uint8_t *pdu, int len) return a->len + 3; } +uint16_t enc_indication(struct attribute *a, uint8_t *pdu, int len) +{ + if (pdu == NULL) + return 0; + + if (len < (a->len + 3)) + return 0; + + pdu[0] = ATT_OP_HANDLE_IND; + att_put_u16(a->handle, &pdu[1]); + memcpy(&pdu[3], a->data, a->len); + + return a->len + 3; +} + +struct attribute *dec_indication(const uint8_t *pdu, int len) +{ + struct attribute *a; + + if (pdu == NULL) + return NULL; + + if (pdu[0] != ATT_OP_HANDLE_IND) + return NULL; + + a = malloc(sizeof(struct attribute) + len - 3); + if (a == NULL) + return NULL; + + a->len = len - 3; + + a->handle = att_get_u16((uint16_t *) &pdu[1]); + memcpy(a->data, &pdu[3], a->len); + + return a; +} + +uint16_t enc_confirmation(uint8_t *pdu, int len) +{ + if (pdu == NULL) + return 0; + + if (len < 1) + return 0; + + pdu[0] = ATT_OP_HANDLE_CNF; + + return 1; +} + uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, int len) { if (pdu == NULL) diff --git a/attrib/att.h b/attrib/att.h index a155f4d88..f3aaa7625 100644 --- a/attrib/att.h +++ b/attrib/att.h @@ -188,6 +188,9 @@ uint16_t enc_find_info_resp(uint8_t format, struct att_data_list *list, struct att_data_list *dec_find_info_resp(const uint8_t *pdu, int len, uint8_t *format); uint16_t enc_notification(struct attribute *a, uint8_t *pdu, int len); +uint16_t enc_indication(struct attribute *a, uint8_t *pdu, int len); +struct attribute *dec_indication(const uint8_t *pdu, int len); +uint16_t enc_confirmation(uint8_t *pdu, int len); uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, int len); uint16_t dec_mtu_req(const uint8_t *pdu, int len, uint16_t *mtu); |