summaryrefslogtreecommitdiff
path: root/attrib/att.c
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2011-10-06 15:01:48 -0300
committerJohan Hedberg <johan.hedberg@intel.com>2011-10-07 19:52:32 +0300
commit253f8a7c681ae16710d1384ad700d40cc087e75f (patch)
treea9df9fa6e02392aebc4eabbf7d8c2b4cf3f004f6 /attrib/att.c
parent911f1b1be00fe0dd32bebe72ace93d1f3834f493 (diff)
downloadbluez-253f8a7c681ae16710d1384ad700d40cc087e75f.tar.gz
Fix using the attribute struct for encoding ATT pdus
The enconding and decoding of ATT pdus should be kept as much free of dependences from other parts of the code as possible, so it can be used in many contexts. In this case, for encoding and decoding notifications and indications we did have to pass an instance of an attribute instead of direct values.
Diffstat (limited to 'attrib/att.c')
-rw-r--r--attrib/att.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/attrib/att.c b/attrib/att.c
index c3cbf868a..a3a89472a 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -820,60 +820,65 @@ struct att_data_list *dec_find_info_resp(const uint8_t *pdu, int len,
return list;
}
-uint16_t enc_notification(struct attribute *a, uint8_t *pdu, int len)
+uint16_t enc_notification(uint16_t handle, uint8_t *value, int vlen,
+ uint8_t *pdu, int len)
{
const uint16_t min_len = sizeof(pdu[0]) + sizeof(uint16_t);
if (pdu == NULL)
return 0;
- if (len < (a->len + min_len))
+ if (len < (vlen + min_len))
return 0;
pdu[0] = ATT_OP_HANDLE_NOTIFY;
- att_put_u16(a->handle, &pdu[1]);
- memcpy(&pdu[3], a->data, a->len);
+ att_put_u16(handle, &pdu[1]);
+ memcpy(&pdu[3], value, vlen);
- return a->len + min_len;
+ return vlen + min_len;
}
-uint16_t enc_indication(struct attribute *a, uint8_t *pdu, int len)
+uint16_t enc_indication(uint16_t handle, uint8_t *value, int vlen,
+ uint8_t *pdu, int len)
{
const uint16_t min_len = sizeof(pdu[0]) + sizeof(uint16_t);
if (pdu == NULL)
return 0;
- if (len < (a->len + min_len))
+ if (len < (vlen + min_len))
return 0;
pdu[0] = ATT_OP_HANDLE_IND;
- att_put_u16(a->handle, &pdu[1]);
- memcpy(&pdu[3], a->data, a->len);
+ att_put_u16(handle, &pdu[1]);
+ memcpy(&pdu[3], value, vlen);
- return a->len + min_len;
+ return vlen + min_len;
}
-struct attribute *dec_indication(const uint8_t *pdu, int len)
+uint16_t dec_indication(const uint8_t *pdu, int len, uint16_t *handle,
+ uint8_t *value, int vlen)
{
const uint16_t min_len = sizeof(pdu[0]) + sizeof(uint16_t);
- struct attribute *a;
+ uint16_t dlen;
if (pdu == NULL)
- return NULL;
+ return 0;
if (pdu[0] != ATT_OP_HANDLE_IND)
- return NULL;
+ return 0;
if (len < min_len)
- return NULL;
+ return 0;
+
+ dlen = MIN(len - min_len, vlen);
+
+ if (handle)
+ *handle = att_get_u16(&pdu[1]);
- a = g_new0(struct attribute, 1);
- a->handle = att_get_u16(&pdu[1]);
- a->len = len - min_len;
- a->data = g_memdup(&pdu[3], a->len);
+ memcpy(value, &pdu[3], dlen);
- return a;
+ return dlen;
}
uint16_t enc_confirmation(uint8_t *pdu, int len)