static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
guint16 plen, gpointer user_data)
{
- struct characteristic_data *char_data = user_data;
struct att_data_list *list;
int i;
- if (status == ATT_ECODE_ATTR_NOT_FOUND &&
- char_data->start != opt_start)
- goto done;
-
if (status != 0) {
g_printerr("Read characteristics by UUID failed: %s\n",
att_ecode2str(status));
uint8_t *value = list->data[i];
int j;
- char_data->start = att_get_u16(value) + 1;
-
g_print("handle: 0x%04x \t value: ", att_get_u16(value));
value += 2;
for (j = 0; j < list->len - 2; j++, value++)
att_data_list_free(list);
done:
- g_free(char_data);
g_main_loop_quit(event_loop);
}
GAttrib *attrib = user_data;
if (opt_uuid != NULL) {
- struct characteristic_data *char_data;
-
- char_data = g_new(struct characteristic_data, 1);
- char_data->attrib = attrib;
- char_data->start = opt_start;
- char_data->end = opt_end;
gatt_read_char_by_uuid(attrib, opt_start, opt_end, opt_uuid,
- char_read_by_uuid_cb, char_data);
+ char_read_by_uuid_cb, NULL);
return FALSE;
}
static int start;
static int end;
-struct characteristic_data {
- uint16_t orig_start;
- uint16_t start;
- uint16_t end;
- bt_uuid_t uuid;
-};
-
static void cmd_help(int argcp, char **argvp);
static enum state {
static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
guint16 plen, gpointer user_data)
{
- struct characteristic_data *char_data = user_data;
struct att_data_list *list;
int i;
GString *s;
- if (status == ATT_ECODE_ATTR_NOT_FOUND &&
- char_data->start != char_data->orig_start)
- goto done;
-
if (status != 0) {
error("Read characteristics by UUID failed: %s\n",
att_ecode2str(status));
- goto done;
+ return;
}
list = dec_read_by_type_resp(pdu, plen);
if (list == NULL)
- goto done;
+ return;
s = g_string_new(NULL);
for (i = 0; i < list->num; i++) {
uint8_t *value = list->data[i];
int j;
- char_data->start = att_get_u16(value) + 1;
g_string_printf(s, "handle: 0x%04x \t value: ",
att_get_u16(value));
value += 2;
att_data_list_free(list);
g_string_free(s, TRUE);
-
-done:
- g_free(char_data);
}
static void cmd_exit(int argcp, char **argvp)
static void cmd_read_uuid(int argcp, char **argvp)
{
- struct characteristic_data *char_data;
int start = 0x0001;
int end = 0xffff;
bt_uuid_t uuid;
}
}
- char_data = g_new(struct characteristic_data, 1);
- char_data->orig_start = start;
- char_data->start = start;
- char_data->end = end;
- char_data->uuid = uuid;
-
- gatt_read_char_by_uuid(attrib, start, end, &char_data->uuid,
- char_read_by_uuid_cb, char_data);
+ gatt_read_char_by_uuid(attrib, start, end, &uuid, char_read_by_uuid_cb,
+ NULL);
}
static void char_write_req_cb(guint8 status, const guint8 *pdu, guint16 plen,