guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; size_t buflen; guint16 plen; guint id; struct read_long_data *long_read; long_read = g_try_new0(struct read_long_data, 1); if (long_read == NULL) return 0; long_read->attrib = attrib; long_read->func = func; long_read->user_data = user_data; long_read->handle = handle; buf = g_attrib_get_buffer(attrib, &buflen); plen = enc_read_req(handle, buf, buflen); id = g_attrib_send(attrib, 0, buf, plen, read_char_helper, long_read, read_long_destroy); if (id == 0) g_free(long_read); else { __sync_fetch_and_add(&long_read->ref, 1); long_read->id = id; } return id; }
static guint resolve_included_uuid(struct included_discovery *isd, struct gatt_included *incl) { struct included_uuid_query *query; size_t buflen; uint8_t *buf = g_attrib_get_buffer(isd->attrib, &buflen); guint16 oplen = enc_read_req(incl->range.start, buf, buflen); query = g_new0(struct included_uuid_query, 1); query->isd = isd_ref(isd); query->included = incl; return g_attrib_send(isd->attrib, 0, buf, oplen, resolve_included_uuid_cb, query, NULL); }
guint gatt_read_char(GAttrib *attrib, uint16_t handle, uint16_t offset, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; int buflen; guint16 plen; guint id; struct read_long_data *long_read; long_read = g_try_new0(struct read_long_data, 1); if (long_read == NULL) return 0; long_read->attrib = attrib; long_read->func = func; long_read->user_data = user_data; long_read->handle = handle; buf = g_attrib_get_buffer(attrib, &buflen); if (offset > 0) { plen = enc_read_blob_req(long_read->handle, offset, buf, buflen); id = g_attrib_send(attrib, 0, ATT_OP_READ_BLOB_REQ, buf, plen, read_blob_helper, long_read, read_long_destroy); } else { plen = enc_read_req(handle, buf, buflen); id = g_attrib_send(attrib, 0, ATT_OP_READ_REQ, buf, plen, read_char_helper, long_read, read_long_destroy); } if (id == 0) g_free(long_read); else { g_atomic_int_inc(&long_read->ref); long_read->id = id; } return id; }
guint gatt_read_char_single(GAttrib *attrib, uint16_t handle, uint16_t offset, GAttribResultFunc func, gpointer user_data) { uint8_t *buf; size_t buflen; guint16 plen; guint id; struct read_data *read; read = g_try_new0(struct read_data, 1); if (read == NULL) return 0; read->attrib = g_attrib_ref(attrib); read->func = func; read->user_data = user_data; read->handle = handle; read->offset = offset; buf = g_attrib_get_buffer(attrib, &buflen); if (!offset) plen = enc_read_req(handle, buf, buflen); else plen = enc_read_blob_req(handle, offset, buf, buflen); id = g_attrib_send(attrib, 0, buf, plen, read_char_helper, read, read_destroy); if (id == 0) { g_attrib_unref(read->attrib); g_free(read); } else { __sync_fetch_and_add(&read->ref, 1); read->id = id; } return id; }