コード例 #1
0
ファイル: interactive.c プロジェクト: Zauberstuhl/ot_6015x
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
    bdaddr_t sba, dba;

    if (err) {
        printf("connect error: %s\n", err->message);
        set_state(STATE_DISCONNECTED);
        return;
    }

    if (!io) {
        printf("connect error io NULL\n");
        set_state(STATE_DISCONNECTED);
        return;
    }

    iochannel = io;
    attrib = g_attrib_new(iochannel);
    g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, events_handler,
                      attrib, NULL);
    g_attrib_register(attrib, ATT_OP_HANDLE_IND, events_handler,
                      attrib, NULL);

    /* LE connections share Client and Server paths */
    if (!opt_psm) {
        str2ba(opt_dst, &dba);
        str2ba(opt_src, &sba);
        attrib_server_attach(attrib, &sba, &dba, ATT_DEFAULT_LE_MTU);
    }

    set_state(STATE_CONNECTED);
}
コード例 #2
0
ファイル: interactive.c プロジェクト: ghent360/bluez
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
	uint16_t mtu;
	uint16_t cid;

	if (err) {
		set_state(STATE_DISCONNECTED);
		error("%s\n", err->message);
		return;
	}

	bt_io_get(io, &err, BT_IO_OPT_IMTU, &mtu,
				BT_IO_OPT_CID, &cid, BT_IO_OPT_INVALID);

	if (err) {
		g_printerr("Can't detect MTU, using default: %s", err->message);
		g_error_free(err);
		mtu = ATT_DEFAULT_LE_MTU;
	}

	if (cid == ATT_CID)
		mtu = ATT_DEFAULT_LE_MTU;

	attrib = g_attrib_new(iochannel, mtu, false);
	g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES,
						events_handler, attrib, NULL);
	g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
						events_handler, attrib, NULL);
	set_state(STATE_CONNECTED);
	rl_printf("Connection successful\n");
}
コード例 #3
0
ファイル: bbconsole.c プロジェクト: 0xFACE/bbconsole
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
    uint16_t mtu;
    uint16_t cid;
    GError *gerr = NULL;
    uint8_t *value;

    if (err) {
        printf("# Connect error: %s\n", err->message);
        g_main_loop_quit(event_loop);
        return;
    }

    bt_io_get(io, &gerr, BT_IO_OPT_IMTU, &mtu,
                BT_IO_OPT_CID, &cid, BT_IO_OPT_INVALID);

    if (gerr) {
        printf("# Can't detect MTU, using default");
        g_error_free(gerr);
        mtu = ATT_DEFAULT_LE_MTU;
    }
    else if (cid == ATT_CID)
        mtu = ATT_DEFAULT_LE_MTU;

    attrib = g_attrib_new(iochannel, mtu, false);

    g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES,
                        events_handler, attrib, NULL);
    g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
                        events_handler, attrib, NULL);
  printf("Connected.\n");
  //Enabling notifying
  gatt_attr_data_from_string("0100", &value);
  gatt_write_cmd(attrib, 0x002f, value, 2, NULL, NULL);
}
コード例 #4
0
static gboolean io_listen_cb(gpointer user_data) {
	gatt_connection_t *conn = user_data;

	g_attrib_register(conn->attrib, ATT_OP_HANDLE_NOTIFY, events_handler, conn, NULL);
	g_attrib_register(conn->attrib, ATT_OP_HANDLE_IND, events_handler, conn, NULL);

	return FALSE;
}
コード例 #5
0
ファイル: gatttool.c プロジェクト: intgr/bluez
static gboolean listen_start(gpointer user_data)
{
	GAttrib *attrib = user_data;

	g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, events_handler,
							attrib, NULL);
	g_attrib_register(attrib, ATT_OP_HANDLE_IND, events_handler,
							attrib, NULL);

	return FALSE;
}
コード例 #6
0
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
  if (err) {
    set_error(ERR_CONNECT_FAILED, err->message, user_data);
    set_state(STATE_DISCONNECTED);

  } else {
    /* attrib is declared as global for now */
    attrib = g_attrib_new(iochannel);
    g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES, events_handler, attrib, NULL);
    g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES, events_handler, attrib, NULL);
    set_state(STATE_CONNECTED);
  }
  g_main_loop_quit(event_loop);
}
コード例 #7
0
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
	if (err) {
		printf("connect error: %s\n", err->message);
		set_state(STATE_DISCONNECTED);
		return;
	}

	attrib = g_attrib_new(iochannel);
	g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, events_handler,
							attrib, NULL);
	g_attrib_register(attrib, ATT_OP_HANDLE_IND, events_handler,
							attrib, NULL);
	set_state(STATE_CONNECTED);
}
コード例 #8
0
ファイル: scpp.c プロジェクト: rymanluk/bluez
bool bt_scpp_attach(struct bt_scpp *scan, void *attrib)
{
	bt_uuid_t iwin_uuid, refresh_uuid;

	if (!scan || scan->attrib || !scan->primary)
		return false;

	scan->attrib = g_attrib_ref(attrib);

	if (scan->iwhandle)
		write_scan_params(scan->attrib, scan->iwhandle, scan->interval,
								scan->window);
	else {
		bt_uuid16_create(&iwin_uuid, SCAN_INTERVAL_WIN_UUID);
		discover_char(scan, scan->attrib, scan->primary->range.start,
					scan->primary->range.end, &iwin_uuid,
					iwin_discovered_cb, scan);
	}

	if (scan->refresh_handle)
		scan->refresh_cb_id = g_attrib_register(scan->attrib,
				ATT_OP_HANDLE_NOTIFY, scan->refresh_handle,
				refresh_value_cb, scan, NULL);
	else {
		bt_uuid16_create(&refresh_uuid, SCAN_REFRESH_UUID);
		discover_char(scan, scan->attrib, scan->primary->range.start,
					scan->primary->range.end, &refresh_uuid,
					refresh_discovered_cb, scan);
	}

	return true;
}
コード例 #9
0
ファイル: hog.c プロジェクト: AlanApter/steamlink-sdk
static void enable_report_notifications(struct report *report,
							bool enable_on_device)
{
	struct hog_device *hogdev = report->hogdev;
	uint8_t value[2];

	if (!hogdev->uhid_created)
		return;

	if (!report->ccc_handle)
		return;

	/* Register callback for HoG report notifications */
	report->notifyid = g_attrib_register(hogdev->attrib,
					ATT_OP_HANDLE_NOTIFY,
					report->decl->value_handle,
					report_value_cb, report, NULL);

	if (!enable_on_device)
		return;

	/* Enable HoG report notifications on the HoG device */
	put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
	gatt_write_char(hogdev->attrib, report->ccc_handle, value,
				sizeof(value), report_ccc_written_cb, report);
}
コード例 #10
0
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
    if (err) {
        set_state(STATE_DISCONNECTED);
        error("%s\n", err->message);
        return;
    }

    attrib = g_attrib_new(iochannel);
    g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES,
                      events_handler, attrib, NULL);
    g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
                      events_handler, attrib, NULL);
    set_state(STATE_CONNECTED);
    rl_printf("Connection successful\n");
}
コード例 #11
0
static void discover_char_cb(uint8_t status, GSList *chars, void *user_data)
{
	struct heartrate *hr = user_data;

	if (status) {
		error("Discover HRS characteristics failed: %s",
							att_ecode2str(status));
		return;
	}

	for (; chars; chars = chars->next) {
		struct gatt_char *c = chars->data;

		if (g_strcmp0(c->uuid, HEART_RATE_MEASUREMENT_UUID) == 0) {
			struct gatt_char *c_next =
				(chars->next ? chars->next->data : NULL);

			hr->attionotid = g_attrib_register(hr->attrib,
						ATT_OP_HANDLE_NOTIFY,
						c->value_handle,
						notify_handler, hr, NULL);

			discover_measurement_ccc(hr, c, c_next);
		} else if (g_strcmp0(c->uuid, BODY_SENSOR_LOCATION_UUID) == 0) {
			DBG("Body Sensor Location supported");

			gatt_read_char(hr->attrib, c->value_handle,
						read_sensor_location_cb, hr);
		} else if (g_strcmp0(c->uuid,
					HEART_RATE_CONTROL_POINT_UUID) == 0) {
			DBG("Heart Rate Control Point supported");
			hr->hrcp_val_handle = c->value_handle;
		}
	}
}
コード例 #12
0
static void discover_char_cb(uint8_t status, GSList *chars, void *user_data)
{
	struct csc *csc = user_data;
	uint16_t feature_val_handle = 0;

	if (status) {
		error("Discover CSCS characteristics: %s",
							att_ecode2str(status));
		return;
	}

	for (; chars; chars = chars->next) {
		struct gatt_char *c = chars->data;
		struct gatt_char *c_next =
				(chars->next ? chars->next->data : NULL);

		if (g_strcmp0(c->uuid, CSC_MEASUREMENT_UUID) == 0) {
			csc->attio_measurement_id =
				g_attrib_register(csc->attrib,
					ATT_OP_HANDLE_NOTIFY, c->value_handle,
					measurement_notify_handler, csc, NULL);

			discover_desc(csc, c, c_next);
		} else if (g_strcmp0(c->uuid, CSC_FEATURE_UUID) == 0) {
			feature_val_handle = c->value_handle;
		} else if (g_strcmp0(c->uuid, SENSOR_LOCATION_UUID) == 0) {
			DBG("Sensor Location supported");
			gatt_read_char(csc->attrib, c->value_handle,
							read_location_cb, csc);
		} else if (g_strcmp0(c->uuid, SC_CONTROL_POINT_UUID) == 0) {
			DBG("SC Control Point supported");
			csc->controlpoint_val_handle = c->value_handle;

			csc->attio_controlpoint_id = g_attrib_register(
					csc->attrib, ATT_OP_HANDLE_IND,
					c->value_handle,
					controlpoint_ind_handler, csc, NULL);

			discover_desc(csc, c, c_next);
		}
	}

	if (feature_val_handle > 0)
		gatt_read_char(csc->attrib, feature_val_handle,
							read_feature_cb, csc);
}
コード例 #13
0
ファイル: client.c プロジェクト: richardxu/panda-a4
static void attio_connected(GAttrib *attrib, gpointer user_data)
{
	struct gatt_service *gatt = user_data;

	gatt->attrib = g_attrib_ref(attrib);

	g_attrib_register(gatt->attrib, ATT_OP_HANDLE_NOTIFY,
					events_handler, gatt, NULL);
	g_attrib_register(gatt->attrib, ATT_OP_HANDLE_IND,
					events_handler, gatt, NULL);

	/*
	 * TODO : we do not support offline writing
	 */
	/*g_slist_foreach(gatt->offline_chars, offline_char_write, attrib);*/

	INFO("%s connected", gatt->path);
}
コード例 #14
0
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) {
	if (err) {
		std::cout <<  err->message << std::endl;
		return;
	}
	user_data_t* ud = static_cast<user_data_t*>(user_data);
	GAttrib* attrib = g_attrib_new(io);
	g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES,
						notify_cb, ud, NULL);
	g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
						indicate_cb, ud, NULL);

	if (ud->mtu < ATT_DEFAULT_LE_MTU) {
		std::cout << "Invalid value. Minimum MTU size is " << ATT_DEFAULT_LE_MTU;
		disconnect(ud->attrib, ud->chan);
		g_main_loop_quit(event_loop);
		return;
	}
	ud->attrib = attrib;
	gatt_exchange_mtu(attrib, ud->mtu, exchange_mtu_cb, ud);
}
コード例 #15
0
ファイル: heartrate.c プロジェクト: intgr/bluez
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
{
	struct heartrate *hr = user_data;

	DBG("");

	hr->attrib = g_attrib_ref(attrib);

	hr->attionotid = g_attrib_register(hr->attrib, ATT_OP_HANDLE_NOTIFY,
						notify_handler, hr, NULL);

	gatt_discover_char(hr->attrib, hr->svc_range->start, hr->svc_range->end,
						NULL, discover_char_cb, hr);
}
コード例 #16
0
ファイル: hog.c プロジェクト: aguedes/bluez
bool bt_hog_attach(struct bt_hog *hog, void *gatt)
{
	struct gatt_primary *primary = hog->primary;
	GSList *l;

	if (hog->attrib)
		return false;

	hog->attrib = g_attrib_ref(gatt);

	if (!primary) {
		gatt_discover_primary(hog->attrib, NULL, primary_cb, hog);
		return true;
	}

	if (hog->scpp)
		bt_scpp_attach(hog->scpp, gatt);

	if (hog->dis)
		bt_dis_attach(hog->dis, gatt);

	if (hog->bas)
		bt_bas_attach(hog->bas, gatt);

	for (l = hog->instances; l; l = l->next) {
		struct bt_hog *instance = l->data;

		bt_hog_attach(instance, gatt);
	}

	if (hog->reports == NULL) {
		gatt_discover_char(hog->attrib, primary->range.start,
						primary->range.end, NULL,
						char_discovered_cb, hog);
		return true;
	}

	for (l = hog->reports; l; l = l->next) {
		struct report *r = l->data;

		r->notifyid = g_attrib_register(hog->attrib,
					ATT_OP_HANDLE_NOTIFY,
					r->decl->value_handle,
					report_value_cb, r, NULL);
	}

	return true;
}
コード例 #17
0
ファイル: scan.c プロジェクト: AlanApter/steamlink-sdk
static void ccc_written_cb(guint8 status, const guint8 *pdu,
					guint16 plen, gpointer user_data)
{
	struct scan *scan = user_data;

	if (status != 0) {
		error("Write Scan Refresh CCC failed: %s",
						att_ecode2str(status));
		return;
	}

	DBG("Scan Refresh: notification enabled");

	scan->refresh_cb_id = g_attrib_register(scan->attrib,
				ATT_OP_HANDLE_NOTIFY, scan->refresh_handle,
				refresh_value_cb, scan, NULL);
}
コード例 #18
0
ファイル: hog.c プロジェクト: anupdw/android-bluez.bluez
static void report_ccc_written_cb(guint8 status, const guint8 *pdu,
					guint16 plen, gpointer user_data)
{
	struct report *report = user_data;
	struct hog_device *hogdev = report->hogdev;

	if (status != 0) {
		error("Write report characteristic descriptor failed: %s",
							att_ecode2str(status));
		return;
	}

	report->notifyid = g_attrib_register(hogdev->attrib,
					ATT_OP_HANDLE_NOTIFY,
					report->decl->value_handle,
					report_value_cb, report, NULL);

	DBG("Report characteristic descriptor written: notifications enabled");
}
コード例 #19
0
ファイル: bas.c プロジェクト: Klamath233/BlueZ
static void ccc_written_cb(guint8 status, const guint8 *pdu,
					guint16 plen, gpointer user_data)
{
	struct gatt_request *req = user_data;
	struct bt_bas *bas = req->user_data;

	destroy_gatt_req(req);

	if (status != 0) {
		error("Write Scan Refresh CCC failed: %s",
						att_ecode2str(status));
		return;
	}

	DBG("Battery Level: notification enabled");

	bas->id = g_attrib_register(bas->attrib, ATT_OP_HANDLE_NOTIFY,
					bas->handle, notification_cb, bas,
					NULL);
}
コード例 #20
0
ファイル: bluepy-helper.c プロジェクト: calandoa/bluepy
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
    uint16_t mtu;
    uint16_t cid;
    GError *gerr = NULL;

    DBG("io = %p, err = %p", io, err);
    if (err) {
        DBG("err = %s", err->message);
        set_state(STATE_DISCONNECTED);
        resp_error(err_CONN_FAIL);
        printf("# Connect error: %s\n", err->message);
        return;
    }

    bt_io_get(io, &gerr, BT_IO_OPT_IMTU, &mtu,
                BT_IO_OPT_CID, &cid, BT_IO_OPT_INVALID);

    if (gerr) {
        printf("# Can't detect MTU, using default");
        g_error_free(gerr);
        mtu = ATT_DEFAULT_LE_MTU;
    }
    else if (cid == ATT_CID)
        mtu = ATT_DEFAULT_LE_MTU;

    attrib = g_attrib_new(iochannel, mtu);

    g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES,
                        events_handler, attrib, NULL);
    g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
                        events_handler, attrib, NULL);
    g_attrib_register(attrib, ATT_OP_FIND_INFO_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_FIND_BY_TYPE_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_READ_BY_TYPE_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_READ_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_READ_BLOB_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_READ_MULTI_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_READ_BY_GROUP_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_WRITE_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_WRITE_CMD, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_SIGNED_WRITE_CMD, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_PREP_WRITE_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);
    g_attrib_register(attrib, ATT_OP_EXEC_WRITE_REQ, GATTRIB_ALL_HANDLES,
                        req_gatts, NULL, NULL);

    set_state(STATE_CONNECTED);
}