diff --git a/src/adapter.c b/src/adapter.c
index b682753..8831e23 100644
--- a/src/adapter.c
+++ b/src/adapter.c
static gboolean process_auth_queue(gpointer user_data);
-static void adapter_class_changed(struct btd_adapter *adapter,
- const uint8_t *new_class)
+static void dev_class_changed_callback(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
{
+ struct btd_adapter *adapter = user_data;
+ const struct mgmt_cod *rp = param;
+ uint8_t appearance[3];
uint32_t dev_class;
- uint8_t cls[3];
-
- dev_class = new_class[0] | (new_class[1] << 8) | (new_class[2] << 16);
- if (dev_class == adapter->dev_class)
+ if (length < sizeof(*rp)) {
+ error("Wrong size of class of device changed parameters");
return;
+ }
- DBG("class 0x%06x", dev_class);
+ dev_class = rp->val[0] | (rp->val[1] << 8) | (rp->val[2] << 16);
- adapter->dev_class = dev_class;
+ DBG("Class: 0x%06x", dev_class);
- memcpy(cls, new_class, sizeof(cls));
+ if (dev_class == adapter->dev_class)
+ return;
- /* Removes service class */
- cls[1] = cls[1] & 0x1f;
- attrib_gap_set(adapter, GATT_CHARAC_APPEARANCE, cls, 2);
+ adapter->dev_class = dev_class;
- g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
+ g_dbus_emit_property_changed(dbus_conn, adapter->path,
ADAPTER_INTERFACE, "Class");
-}
-
-static void class_of_dev_changed_callback(uint16_t index, uint16_t length,
- const void *param, void *user_data)
-{
- struct btd_adapter *adapter = user_data;
- const struct mgmt_cod *rp = param;
-
- if (length < sizeof(*rp)) {
- error("Wrong size of class of device changed parameters");
- return;
- }
- DBG("Class: 0x%02x%02x%02x", rp->val[2], rp->val[1], rp->val[0]);
+ appearance[0] = rp->val[0];
+ appearance[1] = rp->val[1] & 0x1f; /* removes service class */
+ appearance[2] = rp->val[2];
- adapter_class_changed(adapter, rp->val);
+ attrib_gap_set(adapter, GATT_CHARAC_APPEARANCE, appearance, 2);
}
static void set_dev_class_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
struct btd_adapter *adapter = user_data;
- const struct mgmt_cod *rp = param;
if (status != MGMT_STATUS_SUCCESS) {
error("Failed to set device class: %s (0x%02x)",
return;
}
- if (length < sizeof(*rp)) {
- error("Wrong size of set device class response");
- return;
- }
-
- DBG("Class: 0x%02x%02x%02x", rp->val[2], rp->val[1], rp->val[0]);
-
- adapter_class_changed(adapter, rp->val);
+ /*
+ * The parameters are idential and also the task that is
+ * required in both cases. So it is safe to just call the
+ * event handling functions here.
+ */
+ dev_class_changed_callback(adapter->dev_id, length, param, adapter);
}
static int set_dev_class(struct btd_adapter *adapter, uint8_t major,
const void *param, void *user_data)
{
struct btd_adapter *adapter = user_data;
- const struct mgmt_cod *rp = param;
if (status != MGMT_STATUS_SUCCESS) {
error("Failed to add UUID: %s (0x%02x)",
return;
}
- if (length < sizeof(*rp)) {
- error("Wrong size of add UUID response");
- return;
- }
-
- DBG("Class: 0x%02x%02x%02x", rp->val[2], rp->val[1], rp->val[0]);
-
- adapter_class_changed(adapter, rp->val);
+ /*
+ * The parameters are idential and also the task that is
+ * required in both cases. So it is safe to just call the
+ * event handling functions here.
+ */
+ dev_class_changed_callback(adapter->dev_id, length, param, adapter);
if (adapter->initialized)
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- adapter->path, ADAPTER_INTERFACE, "UUIDs");
+ g_dbus_emit_property_changed(dbus_conn, adapter->path,
+ ADAPTER_INTERFACE, "UUIDs");
}
static int add_uuid(struct btd_adapter *adapter, uuid_t *uuid, uint8_t svc_hint)
const void *param, void *user_data)
{
struct btd_adapter *adapter = user_data;
- const struct mgmt_cod *rp = param;
if (status != MGMT_STATUS_SUCCESS) {
error("Failed to remove UUID: %s (0x%02x)",
return;
}
- if (length < sizeof(*rp)) {
- error("Wrong size of remove UUID response");
- return;
- }
-
- DBG("Class: 0x%02x%02x%02x", rp->val[2], rp->val[1], rp->val[0]);
-
- adapter_class_changed(adapter, rp->val);
+ /*
+ * The parameters are idential and also the task that is
+ * required in both cases. So it is safe to just call the
+ * event handling functions here.
+ */
+ dev_class_changed_callback(adapter->dev_id, length, param, adapter);
if (adapter->initialized)
g_dbus_emit_property_changed(btd_get_dbus_connection(),
const void *param, void *user_data)
{
struct btd_adapter *adapter = user_data;
- const struct mgmt_cod *rp = param;
if (status != MGMT_STATUS_SUCCESS) {
error("Failed to clear UUIDs: %s (0x%02x)",
return;
}
- if (length < sizeof(*rp)) {
- error("Wrong size of remove UUID response");
- return;
- }
-
- DBG("Class: 0x%02x%02x%02x", rp->val[2], rp->val[1], rp->val[0]);
-
- adapter_class_changed(adapter, rp->val);
+ /*
+ * The parameters are idential and also the task that is
+ * required in both cases. So it is safe to just call the
+ * event handling functions here.
+ */
+ dev_class_changed_callback(adapter->dev_id, length, param, adapter);
}
static int clear_uuids(struct btd_adapter *adapter)
mgmt_register(adapter->mgmt, MGMT_EV_CLASS_OF_DEV_CHANGED,
adapter->dev_id,
- class_of_dev_changed_callback,
+ dev_class_changed_callback,
adapter, NULL);
mgmt_register(adapter->mgmt, MGMT_EV_LOCAL_NAME_CHANGED,
adapter->dev_id,