diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index 81e499d..98318b9 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
struct characteristic {
struct gatt_char attr; /* Characteristic */
- GSList *desc; /* Descriptors */
struct thermometer *t; /* Thermometer where the char belongs */
};
-struct descriptor {
- struct characteristic *ch;
- uint16_t handle;
- bt_uuid_t uuid;
-};
-
struct watcher {
struct thermometer_adapter *tadapter;
guint id;
{
struct characteristic *c = user_data;
- g_slist_free_full(c->desc, g_free);
g_free(c);
}
static void valid_range_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
gpointer user_data)
{
- struct descriptor *desc = user_data;
+ struct thermometer *t = user_data;
uint8_t value[VALID_RANGE_DESC_SIZE];
uint16_t max, min;
ssize_t vlen;
return;
}
- change_property(desc->ch->t, "Maximum", &max);
- change_property(desc->ch->t, "Minimum", &min);
+ change_property(t, "Maximum", &max);
+ change_property(t, "Minimum", &min);
}
static void write_ccc_cb(guint8 status, const guint8 *pdu,
g_free(msg);
}
-static void process_thermometer_desc(struct descriptor *desc)
+static void process_thermometer_desc(struct characteristic *ch, uint16_t uuid,
+ uint16_t handle)
{
- struct characteristic *ch = desc->ch;
- char uuidstr[MAX_LEN_UUID_STR];
- bt_uuid_t btuuid;
+ uint8_t atval[2];
+ uint16_t val;
+ char *msg;
- bt_uuid16_create(&btuuid, GATT_CLIENT_CHARAC_CFG_UUID);
+ if (uuid == GATT_CHARAC_VALID_RANGE_UUID) {
+ if (g_strcmp0(ch->attr.uuid, MEASUREMENT_INTERVAL_UUID) == 0)
+ gatt_read_char(ch->t->attrib, handle,
+ valid_range_desc_cb, ch->t);
+ return;
+ }
- if (bt_uuid_cmp(&desc->uuid, &btuuid) == 0) {
- uint8_t atval[2];
- uint16_t val;
- char *msg;
+ if (uuid != GATT_CLIENT_CHARAC_CFG_UUID)
+ return;
- if (g_strcmp0(ch->attr.uuid,
- TEMPERATURE_MEASUREMENT_UUID) == 0) {
- desc->ch->t->measurement_ccc_handle = desc->handle;
+ if (g_strcmp0(ch->attr.uuid, TEMPERATURE_MEASUREMENT_UUID) == 0) {
+ ch->t->measurement_ccc_handle = handle;
- if (g_slist_length(ch->t->tadapter->fwatchers) == 0)
- return;
+ if (g_slist_length(ch->t->tadapter->fwatchers) == 0)
+ return;
- val = GATT_CLIENT_CHARAC_CFG_IND_BIT;
- msg = g_strdup("Enable Temperature Measurement "
- "indication");
- } else if (g_strcmp0(ch->attr.uuid,
+ val = GATT_CLIENT_CHARAC_CFG_IND_BIT;
+ msg = g_strdup("Enable Temperature Measurement indication");
+ } else if (g_strcmp0(ch->attr.uuid,
INTERMEDIATE_TEMPERATURE_UUID) == 0) {
- desc->ch->t->intermediate_ccc_handle = desc->handle;
-
- if (g_slist_length(ch->t->tadapter->iwatchers) == 0)
- return;
-
- val = GATT_CLIENT_CHARAC_CFG_NOTIF_BIT;
- msg = g_strdup("Enable Intermediate Temperature "
- "notification");
- } else if (g_strcmp0(ch->attr.uuid,
- MEASUREMENT_INTERVAL_UUID) == 0) {
- val = GATT_CLIENT_CHARAC_CFG_IND_BIT;
- msg = g_strdup("Enable Measurement Interval "
- "indication");
- } else {
- goto done;
- }
+ ch->t->intermediate_ccc_handle = handle;
- att_put_u16(val, atval);
- gatt_write_char(ch->t->attrib, desc->handle, atval, 2,
- write_ccc_cb, msg);
- return;
- }
-
- bt_uuid16_create(&btuuid, GATT_CHARAC_VALID_RANGE_UUID);
+ if (g_slist_length(ch->t->tadapter->iwatchers) == 0)
+ return;
- if (bt_uuid_cmp(&desc->uuid, &btuuid) == 0 && g_strcmp0(ch->attr.uuid,
- MEASUREMENT_INTERVAL_UUID) == 0) {
- gatt_read_char(ch->t->attrib, desc->handle, valid_range_desc_cb,
- desc);
+ val = GATT_CLIENT_CHARAC_CFG_NOTIF_BIT;
+ msg = g_strdup("Enable Intermediate Temperature notification");
+ } else if (g_strcmp0(ch->attr.uuid, MEASUREMENT_INTERVAL_UUID) == 0) {
+ val = GATT_CLIENT_CHARAC_CFG_IND_BIT;
+ msg = g_strdup("Enable Measurement Interval indication");
+ } else {
return;
}
-done:
- bt_uuid_to_string(&desc->uuid, uuidstr, MAX_LEN_UUID_STR);
- DBG("Ignored descriptor %s in characteristic %s", uuidstr,
- ch->attr.uuid);
+ att_put_u16(val, atval);
+ gatt_write_char(ch->t->attrib, handle, atval, sizeof(atval),
+ write_ccc_cb, msg);
}
static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
if (list == NULL)
return;
+ if (format != ATT_FIND_INFO_RESP_FMT_16BIT)
+ goto done;
+
for (i = 0; i < list->num; i++) {
- struct descriptor *desc;
uint8_t *value;
+ uint16_t handle, uuid;
value = list->data[i];
- desc = g_new0(struct descriptor, 1);
- desc->handle = att_get_u16(value);
- desc->ch = ch;
-
- if (format == ATT_FIND_INFO_RESP_FMT_16BIT)
- desc->uuid = att_get_uuid16(&value[2]);
- else
- desc->uuid = att_get_uuid128(&value[2]);
+ handle = att_get_u16(value);
+ uuid = att_get_u16(value + 2);
- ch->desc = g_slist_append(ch->desc, desc);
- process_thermometer_desc(desc);
+ process_thermometer_desc(ch, uuid, handle);
}
+done:
att_data_list_free(list);
}