diff options
author | Alok Barsode <alok.barsode@azingo.com> | 2008-07-22 20:20:34 +0530 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@indt.org.br> | 2008-07-28 10:48:22 -0300 |
commit | 661a10565362c5ae0aad6a2ebf6513390cba868e (patch) | |
tree | aa4296ef19a88a35c67e778ff34ff9560b11aa28 /hcid | |
parent | d9ff801460ee610f98b97571311e4af13bb8e1a1 (diff) |
Adding adapter_get_dev_id.
Signed-off-by: Alok Barsode <alok.barsode@azingo.com>
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/adapter.c | 5 | ||||
-rw-r--r-- | hcid/adapter.h | 1 | ||||
-rw-r--r-- | hcid/dbus-common.c | 4 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 68 | ||||
-rw-r--r-- | hcid/device.c | 14 | ||||
-rw-r--r-- | hcid/manager.c | 11 |
6 files changed, 71 insertions, 32 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index f760ebd0..0d257ae1 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -2560,3 +2560,8 @@ struct adapter *adapter_create(int id) return adapter; } + +uint16_t adapter_get_dev_id(struct adapter *adapter) +{ + return adapter->dev_id; +} diff --git a/hcid/adapter.h b/hcid/adapter.h index d4d962f5..3446f73d 100644 --- a/hcid/adapter.h +++ b/hcid/adapter.h @@ -175,3 +175,4 @@ struct pending_auth_info *adapter_new_auth_request(struct adapter *adapter, bdaddr_t *dba, auth_type_t type); struct adapter *adapter_create(int id); +uint16_t adapter_get_dev_id(struct adapter *adapter); diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index e779549c..02edd683 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -183,6 +183,7 @@ void hcid_dbus_unregister(void) DBusConnection *conn = get_dbus_connection(); char **children; int i; + uint16_t dev_id; if (!conn || !dbus_connection_get_is_connected(conn)) return; @@ -204,7 +205,8 @@ void hcid_dbus_unregister(void) if (!adapter) continue; - manager_unregister_adapter(adapter->dev_id); + dev_id = adapter_get_dev_id(adapter); + manager_unregister_adapter(dev_id); } dbus_free_string_array(children); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index d0cc0aaa..c7f63f5d 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -322,14 +322,15 @@ static void pincode_cb(struct agent *agent, DBusError *err, const char *pincode, int dev; struct pending_auth_info *auth; const gchar *destination = device_get_address(device); + uint16_t dev_id = adapter_get_dev_id(adapter); /* No need to reply anything if the authentication already failed */ if (adapter->bonding && adapter->bonding->hci_status) return; - dev = hci_open_dev(adapter->dev_id); + dev = hci_open_dev(dev_id); if (dev < 0) { - error("hci_open_dev(%d): %s (%d)", adapter->dev_id, + error("hci_open_dev(%d): %s (%d)", dev_id, strerror(errno), errno); return; } @@ -417,14 +418,15 @@ static void confirm_cb(struct agent *agent, DBusError *err, void *user_data) int dd; struct pending_auth_info *auth; const gchar *destination = device_get_address(device); + uint16_t dev_id = adapter_get_dev_id(adapter); /* No need to reply anything if the authentication already failed */ if (adapter->bonding && adapter->bonding->hci_status) return; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { - error("Unable to open hci%d", adapter->dev_id); + error("Unable to open hci%d", dev_id); return; } @@ -458,14 +460,15 @@ static void passkey_cb(struct agent *agent, DBusError *err, uint32_t passkey, int dd; struct pending_auth_info *auth; const gchar *destination = device_get_address(device); + uint16_t dev_id = adapter_get_dev_id(adapter); /* No need to reply anything if the authentication already failed */ if (adapter->bonding && adapter->bonding->hci_status) return; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { - error("Unable to open hci%d", adapter->dev_id); + error("Unable to open hci%d", dev_id); return; } @@ -536,6 +539,7 @@ int hcid_dbus_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey) char addr[18]; uint8_t type; struct pending_auth_info *auth; + uint16_t dev_id; adapter = manager_find_adapter(sba); if (!adapter) { @@ -543,12 +547,14 @@ int hcid_dbus_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey) return -1; } + dev_id = adapter_get_dev_id(adapter); + if (get_auth_requirements(sba, dba, &type) < 0) { int dd; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { - error("Unable to open hci%d", adapter->dev_id); + error("Unable to open hci%d", dev_id); return -1; } @@ -572,9 +578,9 @@ int hcid_dbus_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey) if (!(device_get_auth(device) & 0x01) && !(type & 0x01)) { int dd; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { - error("Unable to open hci%d", adapter->dev_id); + error("Unable to open hci%d", dev_id); return -1; } @@ -826,6 +832,7 @@ int found_device_req_name(struct adapter *adapter) struct remote_dev_info match; GSList *l; int dd, req_sent = 0; + uint16_t dev_id = adapter_get_dev_id(adapter); /* get the next remote address */ if (!adapter->found_devices) @@ -840,7 +847,7 @@ int found_device_req_name(struct adapter *adapter) if (!l) return -ENODATA; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) return -errno; @@ -1428,6 +1435,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, struct pending_auth_info *auth; const gchar *destination; const gchar *dev_path; + uint16_t dev_id; if (status) { error("Disconnection failed: 0x%02x", status); @@ -1450,8 +1458,10 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, ba2str(&dev->bdaddr, peer_addr); + dev_id = adapter_get_dev_id(adapter); + /* clean pending HCI cmds */ - hci_req_queue_remove(adapter->dev_id, &dev->bdaddr); + hci_req_queue_remove(dev_id, &dev->bdaddr); /* Cancel D-Bus/non D-Bus requests */ auth = adapter_find_auth_request(adapter, &dev->bdaddr); @@ -1570,12 +1580,13 @@ gboolean discov_timeout_handler(void *data) uint8_t scan_enable = adapter->scan_enable; uint8_t status = 0; gboolean retval = TRUE; + uint16_t dev_id = adapter_get_dev_id(adapter); scan_enable &= ~SCAN_INQUIRY; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { - error("HCI device open failed: hci%d", adapter->dev_id); + error("HCI device open failed: hci%d", dev_id); return TRUE; } @@ -1590,7 +1601,7 @@ gboolean discov_timeout_handler(void *data) if (hci_send_req(dd, &rq, 1000) < 0) { error("Sending write scan enable command to hci%d failed: %s (%d)", - adapter->dev_id, strerror(errno), errno); + dev_id, strerror(errno), errno); goto failed; } if (status) { @@ -1663,6 +1674,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) read_scan_enable_rp rp; struct hci_request rq; int dd = -1; + uint16_t dev_id; adapter = manager_find_adapter(local); if (!adapter) { @@ -1670,9 +1682,11 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) return; } - dd = hci_open_dev(adapter->dev_id); + dev_id = adapter_get_dev_id(adapter); + + dd = hci_open_dev(dev_id); if (dd < 0) { - error("HCI device open failed: hci%d", adapter->dev_id); + error("HCI device open failed: hci%d", dev_id); return; } @@ -1713,6 +1727,7 @@ void hcid_dbus_write_class_complete(bdaddr_t *local) struct adapter *adapter; int dd; uint8_t cls[3]; + uint16_t dev_id; adapter = manager_find_adapter(local); if (!adapter) { @@ -1720,15 +1735,17 @@ void hcid_dbus_write_class_complete(bdaddr_t *local) return; } - dd = hci_open_dev(adapter->dev_id); + dev_id = adapter_get_dev_id(adapter); + + dd = hci_open_dev(dev_id); if (dd < 0) { - error("HCI device open failed: hci%d", adapter->dev_id); + error("HCI device open failed: hci%d", dev_id); return; } if (hci_read_class_of_dev(dd, cls, 1000) < 0) { error("Can't read class of device on hci%d: %s (%d)", - adapter->dev_id, strerror(errno), errno); + dev_id, strerror(errno), errno); hci_close_dev(dd); return; } @@ -1744,6 +1761,7 @@ void hcid_dbus_write_simple_pairing_mode_complete(bdaddr_t *local) struct adapter *adapter; int dd; uint8_t mode; + uint16_t dev_id; adapter = manager_find_adapter(local); if (!adapter) { @@ -1751,7 +1769,9 @@ void hcid_dbus_write_simple_pairing_mode_complete(bdaddr_t *local) return; } - dd = hci_open_dev(adapter->dev_id); + dev_id = adapter_get_dev_id(adapter); + + dd = hci_open_dev(dev_id); if (dd < 0) { error("HCI adapter open failed: %s", adapter->path); return; @@ -1894,11 +1914,12 @@ int cancel_discovery(struct adapter *adapter) struct remote_dev_info *dev, match; GSList *l; int dd, err = 0; + uint16_t dev_id = adapter_get_dev_id(adapter); if (!adapter->discov_active) goto cleanup; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { err = -ENODEV; goto cleanup; @@ -1975,11 +1996,12 @@ int cancel_periodic_discovery(struct adapter *adapter) struct remote_dev_info *dev, match; GSList *l; int dd, err = 0; + uint16_t dev_id = adapter_get_dev_id(adapter); if (!adapter->pdiscov_active) goto cleanup; - dd = hci_open_dev(adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) { err = -ENODEV; goto cleanup; diff --git a/hcid/device.c b/hcid/device.c index f83801a4..6aae85ff 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -171,6 +171,7 @@ static DBusMessage *get_properties(DBusConnection *conn, uint32_t class; int i; GSList *l; + uint16_t dev_id = adapter_get_dev_id(adapter); reply = dbus_message_new_method_return(msg); if (!reply) @@ -204,7 +205,7 @@ static DBusMessage *get_properties(DBusConnection *conn, } /* Alias */ - if (get_device_alias(adapter->dev_id, &dst, buf, sizeof(buf)) > 0) { + if (get_device_alias(dev_id, &dst, buf, sizeof(buf)) > 0) { ptr = buf; dbus_message_iter_append_dict_entry(&dict, "Alias", DBUS_TYPE_STRING, &ptr); @@ -243,7 +244,7 @@ static DBusMessage *get_properties(DBusConnection *conn, g_free(uuids); /* Adapter */ - snprintf(path, sizeof(path), "/hci%d", adapter->dev_id); + snprintf(path, sizeof(path), "/hci%d", dev_id); ppath = path; dbus_message_iter_append_dict_entry(&dict, "Adapter", DBUS_TYPE_OBJECT_PATH, &ppath); @@ -271,6 +272,7 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg, bdaddr_t bdaddr; int ecode; char *str, filename[PATH_MAX + 1]; + uint16_t dev_id = adapter_get_dev_id(adapter); str2ba(device->address, &bdaddr); @@ -282,7 +284,7 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg, ecode = remove_device_alias(adapter->address, device->address); } else { str = g_strdup(alias); - ecode = set_device_alias(adapter->dev_id, &bdaddr, alias); + ecode = set_device_alias(dev_id, &bdaddr, alias); } if (ecode < 0) @@ -454,6 +456,7 @@ static gboolean disconnect_timeout(gpointer user_data) disconnect_cp cp; bdaddr_t bda; int dd; + uint16_t dev_id = adapter_get_dev_id(device->adapter); device->disconn_timer = 0; @@ -464,7 +467,7 @@ static gboolean disconnect_timeout(gpointer user_data) return FALSE; ci = l->data; - dd = hci_open_dev(device->adapter->dev_id); + dd = hci_open_dev(dev_id); if (dd < 0) goto fail; @@ -527,6 +530,7 @@ struct btd_device *device_create(DBusConnection *conn, struct adapter *adapter, { gchar *address_up; struct btd_device *device; + uint16_t dev_id = adapter_get_dev_id(adapter); device = g_try_malloc0(sizeof(struct btd_device)); if (device == NULL) @@ -534,7 +538,7 @@ struct btd_device *device_create(DBusConnection *conn, struct adapter *adapter, address_up = g_ascii_strup(address, -1); device->path = g_strdup_printf("/hci%d/dev_%s", - adapter->dev_id, address_up); + dev_id, address_up); g_strdelimit(device->path, ":", '_'); g_free(address_up); diff --git a/hcid/manager.c b/hcid/manager.c index 91cb93bc..64d3d465 100644 --- a/hcid/manager.c +++ b/hcid/manager.c @@ -277,6 +277,7 @@ static DBusMessage *list_adapters(DBusConnection *conn, DBusMessageIter array_iter; DBusMessage *reply; GSList *l; + uint16_t dev_id; reply = dbus_message_new_method_return(msg); if (!reply) @@ -290,8 +291,9 @@ static DBusMessage *list_adapters(DBusConnection *conn, for (l = adapters; l; l = l->next) { struct adapter *adapter = l->data; struct hci_dev_info di; + dev_id = adapter_get_dev_id(adapter); - if (hci_devinfo(adapter->dev_id, &di) < 0) + if (hci_devinfo(dev_id, &di) < 0) continue; if (hci_test_bit(HCI_RAW, &di.flags)) @@ -338,8 +340,9 @@ static gint adapter_id_cmp(gconstpointer a, gconstpointer b) { const struct adapter *adapter = a; uint16_t id = GPOINTER_TO_UINT(b); + uint16_t dev_id = adapter_get_dev_id(adapter); - return adapter->dev_id == id ? 0 : -1; + return dev_id == id ? 0 : -1; } static gint adapter_path_cmp(gconstpointer a, gconstpointer b) @@ -406,12 +409,14 @@ static void manager_add_adapter(struct adapter *adapter) static void manager_remove_adapter(struct adapter *adapter) { + uint16_t dev_id = adapter_get_dev_id(adapter); + g_dbus_emit_signal(connection, "/", MANAGER_INTERFACE, "AdapterRemoved", DBUS_TYPE_OBJECT_PATH, &adapter->path, DBUS_TYPE_INVALID); - if ((default_adapter_id == adapter->dev_id || default_adapter_id < 0)) { + if ((default_adapter_id == dev_id || default_adapter_id < 0)) { int new_default = hci_get_route(NULL); if (new_default >= 0) |