Example #1
0
static void gatts_send_indication_p(int argc, const char *argv[])
{
	int server_if;
	int attr_handle;
	int conn_id;
	int confirm;
	char data[200];
	int len = 0;

	RETURN_IF_NULL(if_gatt);
	VERIFY_SERVER_IF(2, server_if);
	VERIFY_HANDLE(3, attr_handle);
	VERIFY_CONN_ID(4, conn_id);

	/* confirm */
	if (argc <= 5) {
		haltest_error("No transport specified\n");
		return;
	}
	confirm = atoi(argv[5]);

	if (argc > 6) {
		len = strlen(argv[6]);
		scan_field(argv[6], len, (uint8_t *) data, sizeof(data));
	}

	EXEC(if_gatt->server->send_indication, server_if, attr_handle, conn_id,
							len, confirm, data);
}
Example #2
0
/*
 * converts string to uuid
 * it accepts uuid in following forms:
 *	123
 *	0000123
 *	0000123-0014-1234-0000-000056789abc
 *	0000123001412340000000056789abc
 *	123-14-1234-0-56789abc
 */
static void gatt_str2bt_uuid_t(const char *str, int len, bt_uuid_t *uuid)
{
	int dash_cnt = 0;
	int dashes[6] = {-1}; /* indexes of '-' or \0 */
	static uint8_t filed_offset[] = { 16, 12, 10, 8, 6, 0 };
	const char *p = str;
	const char *e;
	int i;

	e = str + ((len >= 0) ? len : (int) strlen(str));

	while (p != NULL && dash_cnt < 5) {
		const char *f = strchrlimit(p, e, '-');

		if (f != NULL)
			dashes[++dash_cnt] = f++ - str;
		p = f;
	}

	/* get index of \0 to dashes table */
	if (dash_cnt < 5)
		dashes[++dash_cnt] = e - str;

	memcpy(uuid, GATT_BASE_UUID, sizeof(bt_uuid_t));

	/* whole uuid in one string without dashes */
	if (dash_cnt == 1 && dashes[1] > 8) {
		if (dashes[1] > 32)
			dashes[1] = 32;
		scan_field(str, dashes[1],
				&uuid->uu[16 - (dashes[1] + 1) / 2],
				(dashes[1] + 1) / 2);
	} else {
		for (i = 0; i < dash_cnt; ++i) {
			scan_field(str + dashes[i] + 1,
					dashes[i + 1] - dashes[i] - 1,
					&uuid->uu[filed_offset[i + 1]],
					filed_offset[i] - filed_offset[i + 1]);
		}
	}
}
Example #3
0
static void write_descriptor_p(int argc, const char **argv)
{
	int conn_id;
	btgatt_srvc_id_t srvc_id;
	btgatt_gatt_id_t char_id;
	btgatt_descr_id_t descr_id;
	int write_type;
	int len;
	int auth_req = 0;
	uint8_t value[200] = {0};

	RETURN_IF_NULL(if_gatt);
	VERIFY_CONN_ID(2, conn_id);
	VERIFY_SRVC_ID(3, &srvc_id);
	VERIFY_CHAR_ID(4, &char_id);
	VERIFY_DESCR_ID(5, &descr_id);

	/* write type */
	if (argc <= 6) {
		haltest_error("No write type specified\n");
		return;
	}
	write_type = atoi(argv[6]);

	/* value */
	if (argc <= 7) {
		haltest_error("No value specified\n");
		return;
	}

	/* len in chars */
	len = strlen(argv[7]);
	scan_field(argv[7], len, value, sizeof(value));
	/* len in bytes converted from ascii chars */
	len = (len + 1) / 2;

	/* auth_req */
	if (argc > 8)
		auth_req = atoi(argv[8]);

	EXEC(if_gatt->client->write_descriptor, conn_id, &srvc_id, &char_id,
			&descr_id, write_type, len, auth_req, (char *) value);
}
Example #4
0
static void
db_reader(struct cdt_node *np)
{
  size_t local_lnum = np->lnum;
  unsigned char *ftext = np->text;
  struct cdt_record *rp = NULL;
  struct cdt_database *db = NULL;
  db = malloc(sizeof(struct cdt_database));
  db->type = np->name;
  db->records = list_create(LIST_SINGLE);
  np->children = list_create(LIST_SINGLE);
  list_add(np->children,db);
  while (*ftext)
    {
      ftext = skip_white(ftext,&local_lnum);
      if (*ftext == '@')
	{
	  unsigned char *tok, save;
	  tok = scan_token(ftext, &ftext, &save);
	  if (':' == *tok)
	    {
	      if (rp)
		{
		  struct cdt_field *fld;
		  list_add(rp->fields, fld = malloc(sizeof(struct cdt_field)));
		  *ftext = save;
		  tok = ftext;
		  fld->name = (const char *)tok;
		  while (!isspace(*tok))
		    ++tok;
		  if (*tok)
		    *tok++ = '\0';
		  while (isspace(*ftext))
		    ++ftext;
		  fld->text = scan_field(tok,&ftext);
		  if (fld->text && strchr(fld->text, '@'))
		    {
		      /* fprintf(stderr, "found @ in %s\n", fld->text); */
		      struct cdt_node *sp = cdt_string_node(NULL,fld->text,np->file,local_lnum);
		      cdt_inline(sp,NULL,NULL);
		      fld->inp = sp;
		    }
		  else
		    fld->inp = NULL;
		}
	    }
	  else if (!strcmp((const char *)tok,"record"))
	    {
	      list_add(db->records,rp = malloc(sizeof(struct cdt_record)));
	      rp->fields = list_create(LIST_SINGLE);
	      *ftext = save;
	    }
	  else if (!strcmp((const char *)tok,"end"))
	    {
	      *ftext = save;
	      tok = ++ftext;
	      while (' ' == *tok || '\t' == *tok)
		++tok;
	      if (!strncmp((const char *)tok,"record",6))
		{
		  if (rp)
		    rp = NULL;
		  else
		    cdt_warning(np->file,np->lnum,"misplaced '@end record'");
		}
	      else if (!strncmp((const char *)tok,np->name,strlen(np->name)))
		{
		  ftext = tok + strlen(np->name);
		  *ftext = '\0';
		}
	      else
		cdt_warning(np->file,np->lnum,"misplaced @end %s command", tok);
	    }
	  else
	    {
	      *ftext = save;
	      ++ftext;
	    }
	}
      else
	++ftext;
    }
}