OSDN Git Service

Add encoders/decoders for Indication/Confirmation
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>
Wed, 18 Aug 2010 21:22:17 +0000 (18:22 -0300)
committerJohan Hedberg <johan.hedberg@nokia.com>
Wed, 22 Sep 2010 19:34:26 +0000 (22:34 +0300)
attrib/att.c
attrib/att.h

index 905c854..cb9e0fe 100644 (file)
@@ -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)
index a155f4d..f3aaa76 100644 (file)
@@ -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);