示例#1
0
static void cmd_char_desc(int argcp, char **argvp)
{
	if (conn_state != STATE_CONNECTED) {
		resp_error(err_BAD_STATE);
		return;
	}

	if (argcp > 1) {
		start = strtohandle(argvp[1]);
		if (start < 0) {
			resp_error(err_BAD_PARAM);
			return;
		}
	} else
		start = 0x0001;

	if (argcp > 2) {
		end = strtohandle(argvp[2]);
		if (end < 0) {
			resp_error(err_BAD_PARAM);
			return;
		}
	} else
		end = 0xffff;

	gatt_discover_char_desc(attrib, start, end, char_desc_cb, NULL);
}
static void refresh_discovered_cb(uint8_t status, GSList *chars,
								void *user_data)
{
	struct scan *scan = user_data;
	struct gatt_char *chr;
	uint16_t start, end;

	if (status) {
		error("Scan Refresh %s", att_ecode2str(status));
		return;
	}

	if (!chars) {
		DBG("Scan Refresh not supported");
		return;
	}

	chr = chars->data;

	DBG("Scan Refresh handle: 0x%04x", chr->value_handle);

	start = chr->value_handle + 1;
	end = scan->range.end;

	if (start > end)
		return;

	scan->refresh_handle = chr->value_handle;

	gatt_discover_char_desc(scan->attrib, start, end,
					discover_descriptor_cb, user_data);
}
static void cmd_char_desc(int argcp, char **argvp)
{
    if (conn_state != STATE_CONNECTED) {
        failed("Disconnected\n");
        return;
    }

    if (argcp > 1) {
        start = strtohandle(argvp[1]);
        if (start < 0) {
            error("Invalid start handle: %s\n", argvp[1]);
            return;
        }
    } else
        start = 0x0001;

    if (argcp > 2) {
        end = strtohandle(argvp[2]);
        if (end < 0) {
            error("Invalid end handle: %s\n", argvp[2]);
            return;
        }
    } else
        end = 0xffff;

    gatt_discover_char_desc(attrib, start, end, char_desc_cb, NULL);
}
static gboolean characteristics_desc(gpointer user_data)
{
	GAttrib *attrib = user_data;

	gatt_discover_char_desc(attrib, opt_start, opt_end, char_desc_cb, NULL);

	return FALSE;
}
示例#5
0
static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
							gpointer user_data)
{
	struct att_data_list *list;
	guint8 format;
	uint16_t handle = 0xffff;
	int i;

	if (status != 0) {
		resp_error(err_COMM_ERR); // Todo: status
		return;
	}

	list = dec_find_info_resp(pdu, plen, &format);
	if (list == NULL) {
		resp_error(err_NOT_FOUND); // Todo: what does this mean?
		return;
	}

	resp_begin(rsp_DESCRIPTORS);
	for (i = 0; i < list->num; i++) {
		char uuidstr[MAX_LEN_UUID_STR];
		uint8_t *value;
		bt_uuid_t uuid;

		value = list->data[i];
		handle = att_get_u16(value);

		if (format == 0x01)
			uuid = att_get_uuid16(&value[2]);
		else
			uuid = att_get_uuid128(&value[2]);

		bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
		send_uint(tag_HANDLE, handle);
                send_str (tag_UUID, uuidstr);
	}
        resp_end();

	att_data_list_free(list);

	if (handle != 0xffff && handle < end)
		gatt_discover_char_desc(attrib, handle + 1, end, char_desc_cb, NULL);
}
static void discover_measurement_ccc(struct heartrate *hr,
				struct gatt_char *c, struct gatt_char *c_next)
{
	uint16_t start, end;

	start = c->value_handle + 1;

	if (c_next != NULL) {
		if (start == c_next->handle)
			return;
		end = c_next->handle - 1;
	} else if (c->value_handle != hr->svc_range->end) {
		end = hr->svc_range->end;
	} else {
		return;
	}

	gatt_discover_char_desc(hr->attrib, start, end, discover_ccc_cb, hr);
}
static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
                         gpointer user_data)
{
    struct att_data_list *list;
    guint8 format;
    uint16_t handle = 0xffff;
    int i;

    if (status != 0) {
        rl_printf("Discover descriptors finished: %s\n",
                  att_ecode2str(status));
        return;
    }

    list = dec_find_info_resp(pdu, plen, &format);
    if (list == NULL)
        return;

    for (i = 0; i < list->num; i++) {
        char uuidstr[MAX_LEN_UUID_STR];
        uint8_t *value;
        bt_uuid_t uuid;

        value = list->data[i];
        handle = att_get_u16(value);

        if (format == 0x01)
            uuid = att_get_uuid16(&value[2]);
        else
            uuid = att_get_uuid128(&value[2]);

        bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
        rl_printf("handle: 0x%04x, uuid: %s\n", handle, uuidstr);
    }

    att_data_list_free(list);

    if (handle != 0xffff && handle < end)
        gatt_discover_char_desc(attrib, handle + 1, end, char_desc_cb,
                                NULL);
}
示例#8
0
void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
                  gpointer user_data) {
  struct att_data_list *list   = NULL;
  guint8                format;
  uint16_t              handle = 0xffff;
  int                   i;
  char                  uuid_str[MAX_LEN_UUID_STR];
  uint8_t              *value;

  printf_dbg("[CB] IN char_desc_cb\n");
  if (status) {
    cb_ret_val = BL_REQUEST_FAIL_ERROR;
    sprintf(cb_ret_msg, "Characteristic descriptor "
        "callback: Failure: %s\n", att_ecode2str(status));
    goto exit;
  }

  list = dec_find_info_resp(pdu, plen, &format);
  if (list == NULL) {
    cb_ret_val = BL_NO_ERROR;
    strcpy(cb_ret_msg, "Characteristic descriptor callback: Nothing found\n");
    goto exit;
  }

  for (i = 0; i < list->num; i++) {
    bt_uuid_t uuid;

    value = list->data[i];
    handle = att_get_u16(value);

    if (format == 0x01)
      uuid = att_get_uuid16(&value[2]);
    else
      uuid = att_get_uuid128(&value[2]);

    bt_uuid_to_string(&uuid, uuid_str, MAX_LEN_UUID_STR);
    if (strcmp(uuid_str, GATT_PRIM_SVC_UUID_STR) &&
        strcmp(uuid_str, GATT_SND_SVC_UUID_STR)  &&
        strcmp(uuid_str, GATT_INCLUDE_UUID_STR)  &&
        strcmp(uuid_str, GATT_CHARAC_UUID_STR)) {
      bl_desc_t *bl_desc = bl_desc_new(uuid_str, handle);
      if (bl_desc == NULL) {
        cb_ret_val = BL_MALLOC_ERROR;
        strcpy(cb_ret_msg, "Characteristic descriptor callback: Malloc "
            "error\n");
        goto exit;
      }
      if (bl_desc_list == NULL) {
        bl_desc_list = g_slist_alloc();
        if (bl_desc_list == NULL) {
          cb_ret_val = BL_MALLOC_ERROR;
          strcpy(cb_ret_msg, "Characteristic descriptor callback: Malloc "
              "error\n");
          goto exit;
        }
        bl_desc_list->data = bl_desc;
      } else {
        bl_desc_list = g_slist_append(bl_desc_list, bl_desc);
      }
    } else {
      printf_dbg("Reach end of descriptor list\n");
      goto exit;
    }
  }
  if ((handle != 0xffff) && (handle < end_handle_cb)) {
    printf_dbg("[CB] OUT with asking for a new request\n");
    if (gatt_discover_char_desc(attrib, handle + 1, end_handle_cb,
          char_desc_cb, NULL)) {
      goto next;
    }
    cb_ret_val = BL_SEND_REQUEST_ERROR;
    strcpy(cb_ret_msg, "Unable to send request\n");
  }

exit:
  if (bl_desc_list) {
    // Return what we got if we add something
    cb_ret_val = BL_NO_ERROR;
    cb_ret_pointer = bl_desc_list;
  }
  bl_desc_list = NULL;
  g_mutex_unlock(pending_callback);
next:
  if (list)
    att_data_list_free(list);
  printf_dbg("[CB] OUT char_desc_cb\n");
}