diff options
author | Brian Gix <bgix@codeaurora.org> | 2011-01-19 14:00:53 -0800 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2011-01-20 15:04:15 +0530 |
commit | 8648c3b198f7585d49b89b43b2780ec80aaef72a (patch) | |
tree | 289bfefd44c52d0d293a50ef199f220fd0c4e831 /attrib | |
parent | e3ba32da9613734647597f2b50e4ce7f3ca9faf7 (diff) |
Add READ_BLOB_REQUEST support to attribute server
Diffstat (limited to 'attrib')
-rw-r--r-- | attrib/att.c | 44 | ||||
-rw-r--r-- | attrib/att.h | 6 |
2 files changed, 49 insertions, 1 deletions
diff --git a/attrib/att.c b/attrib/att.c index f8dbc02f1..dff859723 100644 --- a/attrib/att.c +++ b/attrib/att.c @@ -582,6 +582,33 @@ uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle) return min_len; } +uint16_t dec_read_blob_req(const uint8_t *pdu, int len, uint16_t *handle, + uint16_t *offset) +{ + const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle) + + sizeof(*offset); + + if (pdu == NULL) + return 0; + + if (handle == NULL) + return 0; + + if (offset == NULL) + return 0; + + if (len < min_len) + return 0; + + if (pdu[0] != ATT_OP_READ_BLOB_REQ) + return 0; + + *handle = att_get_u16(&pdu[1]); + *offset = att_get_u16(&pdu[3]); + + return min_len; +} + uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len) { if (pdu == NULL) @@ -600,6 +627,23 @@ uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len) return vlen + 1; } +uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset, + uint8_t *pdu, int len) +{ + if (pdu == NULL) + return 0; + + vlen -= offset; + if (vlen > len - 1) + vlen = len - 1; + + pdu[0] = ATT_OP_READ_BLOB_RESP; + + memcpy(pdu + 1, &value[offset], vlen); + + return vlen + 1; +} + uint16_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int *vlen) { if (pdu == NULL) diff --git a/attrib/att.h b/attrib/att.h index a1e0b62bb..29ab0e64e 100644 --- a/attrib/att.h +++ b/attrib/att.h @@ -216,9 +216,13 @@ uint16_t dec_write_req(const uint8_t *pdu, int len, uint16_t *handle, uint8_t *value, int *vlen); uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len); uint16_t enc_read_blob_req(uint16_t handle, uint16_t offset, uint8_t *pdu, - int len); + int len); uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle); +uint16_t dec_read_blob_req(const uint8_t *pdu, int len, uint16_t *handle, + uint16_t *offset); uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len); +uint16_t enc_read_blob_resp(uint8_t *value, int vlen, uint16_t offset, + uint8_t *pdu, int len); uint16_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int *vlen); uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status, uint8_t *pdu, int len); |