diff options
author | Alvaro Silva <alvaro.silva@openbossa.org> | 2013-07-19 13:34:14 -0400 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2013-07-24 08:42:43 -0700 |
commit | 38487a99155988699aa0dc4f3505a2da5980ceee (patch) | |
tree | 389a8202ccbd5c935623a1cc4069205b4561967a /attrib/att.c | |
parent | 9abeec8c11d45e962c5713e4fbe3f9ab83f8cd66 (diff) | |
download | bluez-38487a99155988699aa0dc4f3505a2da5980ceee.tar.gz |
attrib: Add encode/decode prepare write support
Add functions for encoding/decoding Prepare Write Request PDUs.
Diffstat (limited to 'attrib/att.c')
-rw-r--r-- | attrib/att.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/attrib/att.c b/attrib/att.c index 20a299ac0..8fd5ab553 100644 --- a/attrib/att.c +++ b/attrib/att.c @@ -1024,6 +1024,62 @@ uint16_t enc_prep_write_req(uint16_t handle, uint16_t offset, return min_len; } +uint16_t dec_prep_write_req(const uint8_t *pdu, size_t len, uint16_t *handle, + uint16_t *offset, uint8_t *value, size_t *vlen) +{ + const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle) + + sizeof(*offset); + + if (pdu == NULL) + return 0; + + if (handle == NULL || offset == NULL || value == NULL || vlen == NULL) + return 0; + + if (len < min_len) + return 0; + + if (pdu[0] != ATT_OP_PREP_WRITE_REQ) + return 0; + + *handle = att_get_u16(&pdu[1]); + *offset = att_get_u16(&pdu[3]); + + *vlen = len - min_len; + if (*vlen > 0) + memcpy(value, pdu + min_len, *vlen); + + return len; +} + +uint16_t enc_prep_write_resp(uint16_t handle, uint16_t offset, + const uint8_t *value, size_t vlen, + uint8_t *pdu, size_t len) +{ + const uint16_t min_len = sizeof(pdu[0]) + sizeof(handle) + + sizeof(offset); + + if (pdu == NULL) + return 0; + + if (len < min_len) + return 0; + + if (vlen > len - min_len) + vlen = len - min_len; + + pdu[0] = ATT_OP_PREP_WRITE_RESP; + att_put_u16(handle, &pdu[1]); + att_put_u16(offset, &pdu[3]); + + if (vlen > 0) { + memcpy(&pdu[5], value, vlen); + return min_len + vlen; + } + + return min_len; +} + uint16_t dec_prep_write_resp(const uint8_t *pdu, size_t len, uint16_t *handle, uint16_t *offset, uint8_t *value, size_t *vlen) { |