diff options
author | Luiz Augusto von Dentz <luiz.dentz@indt.org.br> | 2008-07-10 16:05:26 -0300 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@indt.org.br> | 2008-07-28 10:37:24 -0300 |
commit | 31add9474ec23e17b445811ac7491d3571bfc716 (patch) | |
tree | caf842053b8eea073ed9e928bac8acdc904406ac | |
parent | 51e6fcc051fe21c8359dd7d1981a5b38c59a4b9d (diff) |
Integrate struct hci_dev into struct adapter.
-rw-r--r-- | hcid/adapter.c | 2 | ||||
-rw-r--r-- | hcid/adapter.h | 18 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 4 | ||||
-rw-r--r-- | hcid/main.c | 2 | ||||
-rw-r--r-- | hcid/manager.c | 148 |
5 files changed, 60 insertions, 114 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 117536b6..ba313b0a 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -417,7 +417,7 @@ static DBusMessage *set_mode(DBusConnection *conn, DBusMessage *msg, } limited = (new_mode == MODE_LIMITED ? TRUE : FALSE); - err = set_limited_discoverable(dd, adapter->class, limited); + err = set_limited_discoverable(dd, adapter->dev.class, limited); if (err < 0) { hci_close_dev(dd); return failed_strerror(msg, -err); diff --git a/hcid/adapter.h b/hcid/adapter.h index 772f3599..1b9901bd 100644 --- a/hcid/adapter.h +++ b/hcid/adapter.h @@ -84,6 +84,21 @@ struct active_conn_info { uint16_t handle; }; +struct hci_dev { + int ignore; + + bdaddr_t bdaddr; + uint8_t features[8]; + uint8_t lmp_ver; + uint16_t lmp_subver; + uint16_t hci_rev; + uint16_t manufacturer; + + uint8_t ssp_mode; + uint8_t name[248]; + uint8_t class[3]; +}; + struct adapter { uint16_t dev_id; int up; @@ -94,7 +109,6 @@ struct adapter { uint8_t scan_enable; /* scan mode: SCAN_DISABLED, SCAN_PAGE, SCAN_INQUIRY */ uint8_t mode; /* off, connectable, discoverable, limited */ uint8_t global_mode; /* last valid global mode */ - uint8_t class[3]; /* device class */ int discov_active; /* standard discovery active: includes name resolution step */ int pdiscov_active; /* periodic discovery active */ int pinq_idle; /* tracks the idle time for periodic inquiry */ @@ -115,6 +129,8 @@ struct adapter { authentication requests */ GSList *devices; /* Devices structure pointers */ GSList *sessions; /* Request Mode sessions */ + + struct hci_dev dev; /* hci info */ }; dbus_bool_t adapter_init(DBusConnection *conn, diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index be235882..548ba92e 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -1598,7 +1598,7 @@ gboolean discov_timeout_handler(void *data) goto failed; } - set_limited_discoverable(dd, adapter->class, FALSE); + set_limited_discoverable(dd, adapter->dev.class, FALSE); adapter->timeout_id = 0; retval = FALSE; @@ -1735,7 +1735,7 @@ void hcid_dbus_write_class_complete(bdaddr_t *local) write_local_class(local, cls); set_device_class(adapter->dev_id, cls); - memcpy(adapter->class, cls, 3); + memcpy(adapter->dev.class, cls, 3); hci_close_dev(dd); } diff --git a/hcid/main.c b/hcid/main.c index 2dca2065..00f9896d 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -909,8 +909,6 @@ int main(int argc, char *argv[]) child_exit, NULL); g_io_channel_unref(child_io); - init_adapters(); - agent_init(); if (experimental) diff --git a/hcid/manager.c b/hcid/manager.c index 9673b4f4..4d41dc1d 100644 --- a/hcid/manager.c +++ b/hcid/manager.c @@ -63,39 +63,10 @@ #include "manager.h" -#define MAX_DEVICES 16 - static DBusConnection *connection = NULL; static int default_adapter_id = -1; static GSList *adapters = NULL; -struct hci_dev { - int ignore; - - bdaddr_t bdaddr; - uint8_t features[8]; - uint8_t lmp_ver; - uint16_t lmp_subver; - uint16_t hci_rev; - uint16_t manufacturer; - - uint8_t ssp_mode; - uint8_t name[248]; - uint8_t class[3]; -}; - -static struct hci_dev devices[MAX_DEVICES]; - -#define ASSERT_DEV_ID { if (dev_id >= MAX_DEVICES) return -ERANGE; } - -void init_adapters(void) -{ - int i; - - for (i = 0; i < MAX_DEVICES; i++) - memset(devices + i, 0, sizeof(struct hci_dev)); -} - static int device_read_bdaddr(uint16_t dev_id, bdaddr_t *bdaddr) { int dd, err; @@ -123,13 +94,10 @@ static int device_read_bdaddr(uint16_t dev_id, bdaddr_t *bdaddr) int add_adapter(uint16_t dev_id) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; struct hci_dev_info di; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - if (hci_devinfo(dev_id, &di) < 0) { dev->ignore = 1; return -errno; @@ -156,11 +124,8 @@ int add_adapter(uint16_t dev_id) int remove_adapter(uint16_t dev_id) { - struct hci_dev *dev; - - ASSERT_DEV_ID; - - dev = &devices[dev_id]; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; memset(dev, 0, sizeof(struct hci_dev)); @@ -216,17 +181,14 @@ static void update_ext_inquiry_response(int dd, struct hci_dev *dev) int start_adapter(uint16_t dev_id) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; struct hci_version ver; uint8_t features[8], inqmode; uint8_t events[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00 }; char name[249]; int dd, err; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - if (dev->ignore) return 0; @@ -357,8 +319,6 @@ done: int stop_adapter(uint16_t dev_id) { - ASSERT_DEV_ID; - info("Device hci%d has been disabled", dev_id); return 0; @@ -366,13 +326,10 @@ int stop_adapter(uint16_t dev_id) int update_adapter(uint16_t dev_id) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; int dd; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - if (dev->ignore) return 0; @@ -393,25 +350,20 @@ int update_adapter(uint16_t dev_id) int get_device_address(uint16_t dev_id, char *address, size_t size) { - struct hci_dev *dev; - - ASSERT_DEV_ID; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; if (size < 18) return -ENOBUFS; - dev = &devices[dev_id]; - return ba2str(&dev->bdaddr, address); } int get_device_class(uint16_t dev_id, uint8_t *cls) { - struct hci_dev *dev; - - ASSERT_DEV_ID; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; - dev = &devices[dev_id]; memcpy(cls, dev->class, 3); return 0; @@ -419,10 +371,9 @@ int get_device_class(uint16_t dev_id, uint8_t *cls) int set_device_class(uint16_t dev_id, uint8_t *cls) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; - ASSERT_DEV_ID; - dev = &devices[dev_id]; memcpy(dev->class, cls, 3); return 0; @@ -430,17 +381,14 @@ int set_device_class(uint16_t dev_id, uint8_t *cls) int get_device_version(uint16_t dev_id, char *version, size_t size) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; char edr[7], *tmp; int err; - ASSERT_DEV_ID; - if (size < 14) return -ENOBUFS; - dev = &devices[dev_id]; - if ((dev->lmp_ver == 0x03 || dev->lmp_ver == 0x04) && (dev->features[3] & (LMP_EDR_ACL_2M | LMP_EDR_ACL_3M))) sprintf(edr, " + EDR"); @@ -497,13 +445,10 @@ static int digi_revision(uint16_t dev_id, char *revision, size_t size) int get_device_revision(uint16_t dev_id, char *revision, size_t size) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; int err; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - switch (dev->manufacturer) { case 10: err = snprintf(revision, size, "Build %d", dev->lmp_subver); @@ -526,23 +471,23 @@ int get_device_revision(uint16_t dev_id, char *revision, size_t size) int get_device_manufacturer(uint16_t dev_id, char *manufacturer, size_t size) { + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; char *tmp; - ASSERT_DEV_ID; - - tmp = bt_compidtostr(devices[dev_id].manufacturer); + tmp = bt_compidtostr(dev->manufacturer); return snprintf(manufacturer, size, "%s", tmp); } int get_device_company(uint16_t dev_id, char *company, size_t size) { + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; char *tmp, oui[9]; int err; - ASSERT_DEV_ID; - - ba2oui(&devices[dev_id].bdaddr, oui); + ba2oui(&dev->bdaddr, oui); tmp = ouitocomp(oui); err = snprintf(company, size, "%s", tmp); @@ -554,13 +499,10 @@ int get_device_company(uint16_t dev_id, char *company, size_t size) int set_simple_pairing_mode(uint16_t dev_id, uint8_t mode) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; int dd; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - dev->ssp_mode = mode; dd = hci_open_dev(dev_id); @@ -580,11 +522,11 @@ int set_simple_pairing_mode(uint16_t dev_id, uint8_t mode) int get_device_name(uint16_t dev_id, char *name, size_t size) { + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; char tmp[249]; int dd, err; - ASSERT_DEV_ID; - memset(tmp, 0, sizeof(tmp)); dd = hci_open_dev(dev_id); @@ -605,20 +547,17 @@ int get_device_name(uint16_t dev_id, char *name, size_t size) hci_close_dev(dd); - memcpy(devices[dev_id].name, tmp, 248); + memcpy(dev->name, tmp, 248); return snprintf(name, size, "%s", tmp); } int set_device_name(uint16_t dev_id, const char *name) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; int dd, err; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - dd = hci_open_dev(dev_id); if (dd < 0) { err = errno; @@ -646,12 +585,12 @@ int set_device_name(uint16_t dev_id, const char *name) int get_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, char *alias, size_t size) { + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; char filename[PATH_MAX + 1], addr[18], *tmp; int err; - ASSERT_DEV_ID; - - ba2str(&devices[dev_id].bdaddr, addr); + ba2str(&dev->bdaddr, addr); create_name(filename, PATH_MAX, STORAGEDIR, addr, "aliases"); ba2str(bdaddr, addr); @@ -669,11 +608,11 @@ int get_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, char *alias, size_ int set_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, const char *alias) { + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; char filename[PATH_MAX + 1], addr[18]; - ASSERT_DEV_ID; - - ba2str(&devices[dev_id].bdaddr, addr); + ba2str(&dev->bdaddr, addr); create_name(filename, PATH_MAX, STORAGEDIR, addr, "aliases"); create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); @@ -685,13 +624,10 @@ int set_device_alias(uint16_t dev_id, const bdaddr_t *bdaddr, const char *alias) int get_encryption_key_size(uint16_t dev_id, const bdaddr_t *baddr) { - struct hci_dev *dev; + struct adapter *adapter = manager_find_adapter_by_id(dev_id); + struct hci_dev *dev = &adapter->dev; int size; - ASSERT_DEV_ID; - - dev = &devices[dev_id]; - switch (dev->manufacturer) { default: size = -ENOENT; @@ -1269,13 +1205,9 @@ int manager_start_adapter(int id) if (err < 0) goto failed; - err = get_device_class(adapter->dev_id, adapter->class); - if (err < 0) - goto failed; - adapter->mode = get_startup_mode(id); if (adapter->mode == MODE_LIMITED) - set_limited_discoverable(dd, adapter->class, TRUE); + set_limited_discoverable(dd, adapter->dev.class, TRUE); /* * retrieve the active connections: address the scenario where |