From 344789216712689037f57cb7bc2dc7a333a95333 Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Tue, 26 Aug 2008 16:41:43 +0530 Subject: Removing pinq_idle from struct adapter. --- src/adapter.c | 1 - src/adapter.h | 1 - src/dbus-hci.c | 5 ----- 3 files changed, 7 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 16d03958..bc49090c 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2492,7 +2492,6 @@ int adapter_stop(struct adapter *adapter) adapter->up = 0; adapter->scan_mode = SCAN_DISABLED; adapter->mode = MODE_OFF; - adapter->pinq_idle = 0; adapter->state = DISCOVER_TYPE_NONE; unload_drivers(adapter); diff --git a/src/adapter.h b/src/adapter.h index 7d6ca9cb..d643f40d 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -102,7 +102,6 @@ struct adapter { uint8_t scan_mode; /* scan mode: SCAN_DISABLED, SCAN_PAGE, SCAN_INQUIRY */ uint8_t mode; /* off, connectable, discoverable, limited */ uint8_t global_mode; /* last valid global mode */ - int pinq_idle; /* tracks the idle time for periodic inquiry */ int state; /* standard inq, periodic inq, name resloving */ GSList *found_devices; GSList *oor_devices; /* out of range device list */ diff --git a/src/dbus-hci.c b/src/dbus-hci.c index b713b16f..5e6285ac 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -969,8 +969,6 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) } } - adapter->pinq_idle = 1; - /* * Enable resolution again: standard inquiry can be * received in the periodic inquiry idle state. @@ -1242,10 +1240,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, adapter_set_state(adapter, state); } - /* reset the idle flag when the inquiry complete event arrives */ if (adapter_get_state(adapter) & PERIODIC_INQUIRY) { - adapter->pinq_idle = 0; - /* Out of range list update */ l = g_slist_find_custom(adapter->oor_devices, peer_addr, (GCompareFunc) strcmp); -- cgit From 67696e910549b77004bf7f68003a46728c891f05 Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 14:47:04 +0530 Subject: Freeing found_devices list on end of standard/periodic inquiry. --- src/adapter.c | 15 +++++++++++++++ src/dbus-hci.c | 41 ++++------------------------------------- 2 files changed, 19 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index bc49090c..43f0521f 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2739,6 +2739,21 @@ void adapter_set_state(struct adapter *adapter, int state) if (!adapter) return; + /* Both Standard and periodic Inquiry are in progress */ + if ((state & STD_INQUIRY) && (state & PERIODIC_INQUIRY)) + goto set; + + if (!adapter->found_devices) + goto set; + + /* Free list if standard/periodic inquiry is done */ + if ((adapter->state & (STD_INQUIRY | PERIODIC_INQUIRY)) && + (state & (~STD_INQUIRY | ~PERIODIC_INQUIRY))) { + g_slist_foreach(adapter->found_devices, (GFunc) g_free, NULL); + g_slist_free(adapter->found_devices); + adapter->found_devices = NULL; + } +set: adapter->state = state; } diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 5e6285ac..e349cacf 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -1003,11 +1003,6 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) adapter_set_state(adapter, state); } - /* free discovered devices list */ - g_slist_foreach(adapter->found_devices, (GFunc) g_free, NULL); - g_slist_free(adapter->found_devices); - adapter->found_devices = NULL; - if (adapter->discov_requestor) { g_dbus_remove_watch(connection, adapter->discov_listener); adapter->discov_listener = 0; @@ -1091,11 +1086,6 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status) state &= ~(PERIODIC_INQUIRY | RESOLVE_NAME); adapter_set_state(adapter, state); - /* free discovered devices list */ - g_slist_foreach(adapter->found_devices, (GFunc) g_free, NULL); - g_slist_free(adapter->found_devices); - adapter->found_devices = NULL; - /* free out of range devices list */ g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); g_slist_free(adapter->oor_devices); @@ -1390,11 +1380,6 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, if (!found_device_req_name(adapter)) return; /* skip if a new request has been sent */ - /* free discovered devices list */ - g_slist_foreach(adapter->found_devices, (GFunc) g_free, NULL); - g_slist_free(adapter->found_devices); - adapter->found_devices = NULL; - /* The discovery completed signal must be sent only for discover * devices request WITH name resolving */ if (adapter->discov_requestor) { @@ -1971,14 +1956,6 @@ int cancel_discovery(struct adapter *adapter) hci_close_dev(dd); cleanup: - /* - * Reset discov_requestor and discover_state in the remote name - * request event handler or in the inquiry complete handler. - */ - g_slist_foreach(adapter->found_devices, (GFunc) g_free, NULL); - g_slist_free(adapter->found_devices); - adapter->found_devices = NULL; - /* Disable name resolution for non D-Bus clients */ if (!adapter->pdiscov_requestor) { state = adapter_get_state(adapter); @@ -2020,13 +1997,12 @@ int cancel_periodic_discovery(struct adapter *adapter) uint16_t dev_id = adapter_get_dev_id(adapter); if (!(adapter_get_state(adapter) & PERIODIC_INQUIRY)) - goto cleanup; + return err; dd = hci_open_dev(dev_id); - if (dd < 0) { - err = -ENODEV; - goto cleanup; - } + if (dd < 0) + return -ENODEV; + /* find the pending remote name request */ memset(&match, 0, sizeof(struct remote_dev_info)); bacpy(&match.bdaddr, BDADDR_ANY); @@ -2053,15 +2029,6 @@ int cancel_periodic_discovery(struct adapter *adapter) hci_close_dev(dd); -cleanup: - /* - * Reset pdiscov_requestor and pdiscov_active is done when the - * cmd complete event for exit periodic inquiry mode cmd arrives. - */ - g_slist_foreach(adapter->found_devices, (GFunc) g_free, NULL); - g_slist_free(adapter->found_devices); - adapter->found_devices = NULL; - return err; } -- cgit From e6253167b709768e457e7ccce1f64afc44aef1c2 Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 14:04:25 +0530 Subject: Adding adapter_search_found_devices. --- src/adapter.c | 13 +++++++++++++ src/adapter.h | 2 ++ src/dbus-hci.c | 43 +++++++++++++------------------------------ 3 files changed, 28 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 43f0521f..e2504f7a 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2762,6 +2762,19 @@ int adapter_get_state(struct adapter *adapter) return adapter->state; } +struct remote_dev_info *adapter_search_found_devices(struct adapter *adapter, + struct remote_dev_info *match) +{ + GSList *l; + + l = g_slist_find_custom(adapter->found_devices, match, + (GCompareFunc) found_device_cmp); + if (l) + return l->data; + + return NULL; +} + int btd_register_adapter_driver(struct btd_adapter_driver *driver) { adapter_drivers = g_slist_append(adapter_drivers, driver); diff --git a/src/adapter.h b/src/adapter.h index d643f40d..f9cc607d 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -172,6 +172,8 @@ void adapter_set_mode(struct adapter *adapter, uint8_t mode); uint8_t adapter_get_mode(struct adapter *adapter); void adapter_set_state(struct adapter *adapter, int state); int adapter_get_state(struct adapter *adapter); +struct remote_dev_info *adapter_search_found_devices(struct adapter *adapter, + struct remote_dev_info *match); struct btd_adapter_driver { const char *name; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index e349cacf..255c71e3 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -844,22 +844,16 @@ static int found_device_req_name(struct adapter *adapter) struct hci_request rq; evt_cmd_status rp; remote_name_req_cp cp; - struct remote_dev_info match; - GSList *l; + struct remote_dev_info *dev, match; int dd, req_sent = 0; uint16_t dev_id = adapter_get_dev_id(adapter); - /* get the next remote address */ - if (!adapter->found_devices) - return -ENODATA; - memset(&match, 0, sizeof(struct remote_dev_info)); bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUIRED; - l = g_slist_find_custom(adapter->found_devices, &match, - (GCompareFunc) found_device_cmp); - if (!l) + dev = adapter_search_found_devices(adapter, &match); + if (!dev) return -ENODATA; dd = hci_open_dev(dev_id); @@ -877,9 +871,7 @@ static int found_device_req_name(struct adapter *adapter) /* send at least one request or return failed if the list is empty */ do { - struct remote_dev_info *dev = l->data; - - /* flag to indicate the current remote name requested */ + /* flag to indicate the current remote name requested */ dev->name_status = NAME_REQUESTED; memset(&rp, 0, sizeof(rp)); @@ -905,10 +897,8 @@ static int found_device_req_name(struct adapter *adapter) g_free(dev); /* get the next element */ - l = g_slist_find_custom(adapter->found_devices, &match, - (GCompareFunc) found_device_cmp); - - } while (l); + dev = adapter_search_found_devices(adapter, &match); + } while (dev); hci_close_dev(dd); @@ -1198,7 +1188,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, GSList *l; char local_addr[18], peer_addr[18], *name, *tmp_name; const char *paddr = peer_addr; - struct remote_dev_info match; + struct remote_dev_info *dev, match; dbus_int16_t tmp_rssi = rssi; uint8_t name_type = 0x00; name_status_t name_status; @@ -1246,9 +1236,8 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, bacpy(&match.bdaddr, peer); match.name_status = NAME_SENT; /* if found: don't send the name again */ - l = g_slist_find_custom(adapter->found_devices, &match, - (GCompareFunc) found_device_cmp); - if (l) + dev = adapter_search_found_devices(adapter, &match); + if (dev) return; /* the inquiry result can be triggered by NON D-Bus client */ @@ -1914,7 +1903,6 @@ static int remote_name_cancel(int dd, bdaddr_t *dba, int to) 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); int state; @@ -1936,10 +1924,8 @@ int cancel_discovery(struct adapter *adapter) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = g_slist_find_custom(adapter->found_devices, &match, - (GCompareFunc) found_device_cmp); - if (l) { - dev = l->data; + dev = adapter_search_found_devices(adapter, &match); + if (dev) { if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) { error("Read remote name cancel failed: %s, (%d)", strerror(errno), errno); @@ -1992,7 +1978,6 @@ static int periodic_inquiry_exit(int dd, int to) 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); @@ -2008,10 +1993,8 @@ int cancel_periodic_discovery(struct adapter *adapter) bacpy(&match.bdaddr, BDADDR_ANY); match.name_status = NAME_REQUESTED; - l = g_slist_find_custom(adapter->found_devices, &match, - (GCompareFunc) found_device_cmp); - if (l) { - dev = l->data; + dev = adapter_search_found_devices(adapter, &match); + if (dev) { if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) { error("Read remote name cancel failed: %s, (%d)", strerror(errno), errno); -- cgit From 57e67f6802fc718057fddcd3b155c2d4b0adb68f Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 15:15:10 +0530 Subject: Renaming found_device_add to adapter_add_found_device and moving it to adapter.c --- src/adapter.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/adapter.h | 2 ++ src/dbus-hci.c | 54 +----------------------------------------------------- 3 files changed, 54 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index e2504f7a..24c1518d 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2775,6 +2775,57 @@ struct remote_dev_info *adapter_search_found_devices(struct adapter *adapter, return NULL; } +int dev_rssi_cmp(struct remote_dev_info *d1, struct remote_dev_info *d2) +{ + int rssi1, rssi2; + + rssi1 = d1->rssi < 0 ? -d1->rssi : d1->rssi; + rssi2 = d2->rssi < 0 ? -d2->rssi : d2->rssi; + + return rssi1 - rssi2; +} + +int adapter_add_found_device(struct adapter *adapter, bdaddr_t *bdaddr, + int8_t rssi, name_status_t name_status) +{ + struct remote_dev_info *dev, match; + + memset(&match, 0, sizeof(struct remote_dev_info)); + bacpy(&match.bdaddr, bdaddr); + match.name_status = NAME_ANY; + + /* ignore repeated entries */ + dev = adapter_search_found_devices(adapter, &match); + if (dev) { + /* device found, update the attributes */ + if (rssi != 0) + dev->rssi = rssi; + + /* Get remote name can be received while inquiring. + * Keep in mind that multiple inquiry result events can + * be received from the same remote device. + */ + if (name_status != NAME_NOT_REQUIRED) + dev->name_status = name_status; + + adapter->found_devices = g_slist_sort(adapter->found_devices, + (GCompareFunc) dev_rssi_cmp); + + return -EALREADY; + } + + dev = g_new0(struct remote_dev_info, 1); + + bacpy(&dev->bdaddr, bdaddr); + dev->rssi = rssi; + dev->name_status = name_status; + + adapter->found_devices = g_slist_insert_sorted(adapter->found_devices, + dev, (GCompareFunc) dev_rssi_cmp); + + return 0; +} + int btd_register_adapter_driver(struct btd_adapter_driver *driver) { adapter_drivers = g_slist_append(adapter_drivers, driver); diff --git a/src/adapter.h b/src/adapter.h index f9cc607d..0e2dbdb6 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -174,6 +174,8 @@ void adapter_set_state(struct adapter *adapter, int state); int adapter_get_state(struct adapter *adapter); struct remote_dev_info *adapter_search_found_devices(struct adapter *adapter, struct remote_dev_info *match); +int adapter_add_found_device(struct adapter *adapter, bdaddr_t *bdaddr, + int8_t rssi, name_status_t name_status); struct btd_adapter_driver { const char *name; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 255c71e3..b79318d2 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -110,58 +110,6 @@ int found_device_cmp(const struct remote_dev_info *d1, return 0; } -int dev_rssi_cmp(struct remote_dev_info *d1, struct remote_dev_info *d2) -{ - int rssi1, rssi2; - - rssi1 = d1->rssi < 0 ? -d1->rssi : d1->rssi; - rssi2 = d2->rssi < 0 ? -d2->rssi : d2->rssi; - - return rssi1 - rssi2; -} - -static int found_device_add(GSList **list, bdaddr_t *bdaddr, int8_t rssi, - name_status_t name_status) -{ - struct remote_dev_info *dev, match; - GSList *l; - - memset(&match, 0, sizeof(struct remote_dev_info)); - bacpy(&match.bdaddr, bdaddr); - match.name_status = NAME_ANY; - - /* ignore repeated entries */ - l = g_slist_find_custom(*list, &match, (GCompareFunc) found_device_cmp); - if (l) { - /* device found, update the attributes */ - dev = l->data; - - if (rssi != 0) - dev->rssi = rssi; - - /* Get remote name can be received while inquiring. - * Keep in mind that multiple inquiry result events can - * be received from the same remote device. - */ - if (name_status != NAME_NOT_REQUIRED) - dev->name_status = name_status; - - *list = g_slist_sort(*list, (GCompareFunc) dev_rssi_cmp); - - return -EALREADY; - } - - dev = g_new0(struct remote_dev_info, 1); - - bacpy(&dev->bdaddr, bdaddr); - dev->rssi = rssi; - dev->name_status = name_status; - - *list = g_slist_insert_sorted(*list, dev, (GCompareFunc) dev_rssi_cmp); - - return 0; -} - static int found_device_remove(GSList **list, bdaddr_t *bdaddr) { struct remote_dev_info *dev, match; @@ -1290,7 +1238,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, } /* add in the list to track name sent/pending */ - found_device_add(&adapter->found_devices, peer, rssi, name_status); + adapter_add_found_device(adapter, peer, rssi, name_status); } void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class) -- cgit From a4cbf5540b53cf4b0558c5d420354aa1b3421d61 Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 15:22:40 +0530 Subject: Renaming found_device_remove to adapter_remove_found_device and moving it to adapter.c --- src/adapter.c | 17 +++++++++++++++++ src/adapter.h | 1 + src/dbus-hci.c | 21 +-------------------- 3 files changed, 19 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 24c1518d..0c85fe52 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2826,6 +2826,23 @@ int adapter_add_found_device(struct adapter *adapter, bdaddr_t *bdaddr, return 0; } +int adapter_remove_found_device(struct adapter *adapter, bdaddr_t *bdaddr) +{ + struct remote_dev_info *dev, match; + + memset(&match, 0, sizeof(struct remote_dev_info)); + bacpy(&match.bdaddr, bdaddr); + + dev = adapter_search_found_devices(adapter, &match); + if (!dev) + return -1; + + adapter->found_devices = g_slist_remove(adapter->found_devices, dev); + g_free(dev); + + return 0; +} + int btd_register_adapter_driver(struct btd_adapter_driver *driver) { adapter_drivers = g_slist_append(adapter_drivers, driver); diff --git a/src/adapter.h b/src/adapter.h index 0e2dbdb6..dfc377ed 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -176,6 +176,7 @@ struct remote_dev_info *adapter_search_found_devices(struct adapter *adapter, struct remote_dev_info *match); int adapter_add_found_device(struct adapter *adapter, bdaddr_t *bdaddr, int8_t rssi, name_status_t name_status); +int adapter_remove_found_device(struct adapter *adapter, bdaddr_t *bdaddr); struct btd_adapter_driver { const char *name; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index b79318d2..f0129005 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -110,25 +110,6 @@ int found_device_cmp(const struct remote_dev_info *d1, return 0; } -static int found_device_remove(GSList **list, bdaddr_t *bdaddr) -{ - struct remote_dev_info *dev, match; - GSList *l; - - memset(&match, 0, sizeof(struct remote_dev_info)); - bacpy(&match.bdaddr, bdaddr); - - l = g_slist_find_custom(*list, &match, (GCompareFunc) found_device_cmp); - if (!l) - return -1; - - dev = l->data; - *list = g_slist_remove(*list, dev); - g_free(dev); - - return 0; -} - int active_conn_find_by_bdaddr(const void *data, const void *user_data) { const struct active_conn_info *con = data; @@ -1311,7 +1292,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, } /* remove from remote name request list */ - found_device_remove(&adapter->found_devices, peer); + adapter_remove_found_device(adapter, peer); /* check if there is more devices to request names */ if (!found_device_req_name(adapter)) -- cgit From 5d936ee9bb433445272d3c2a377e42ae4ba5e5ec Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 15:25:40 +0530 Subject: Moving found_device_cmp to adapter.c --- src/adapter.c | 20 ++++++++++++++++++++ src/dbus-hci.c | 20 -------------------- src/dbus-hci.h | 2 -- 3 files changed, 20 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 0c85fe52..53a06101 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -167,6 +167,26 @@ static DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, err > 0 ? strerror(err) : "Connection attempt failed"); } +static int found_device_cmp(const struct remote_dev_info *d1, + const struct remote_dev_info *d2) +{ + int ret; + + if (bacmp(&d2->bdaddr, BDADDR_ANY)) { + ret = bacmp(&d1->bdaddr, &d2->bdaddr); + if (ret) + return ret; + } + + if (d2->name_status != NAME_ANY) { + ret = (d1->name_status - d2->name_status); + if (ret) + return ret; + } + + return 0; +} + static int auth_req_cmp(const void *p1, const void *p2) { const struct pending_auth_info *pb1 = p1; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index f0129005..465a1072 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -90,26 +90,6 @@ void bonding_request_free(struct bonding_request_info *bonding) g_free(bonding); } -int found_device_cmp(const struct remote_dev_info *d1, - const struct remote_dev_info *d2) -{ - int ret; - - if (bacmp(&d2->bdaddr, BDADDR_ANY)) { - ret = bacmp(&d1->bdaddr, &d2->bdaddr); - if (ret) - return ret; - } - - if (d2->name_status != NAME_ANY) { - ret = (d1->name_status - d2->name_status); - if (ret) - return ret; - } - - return 0; -} - int active_conn_find_by_bdaddr(const void *data, const void *user_data) { const struct active_conn_info *con = data; diff --git a/src/dbus-hci.h b/src/dbus-hci.h index 621657d0..72b22741 100644 --- a/src/dbus-hci.h +++ b/src/dbus-hci.h @@ -55,8 +55,6 @@ int cancel_periodic_discovery(struct adapter *adapter); int active_conn_find_by_bdaddr(const void *data, const void *user_data); void bonding_request_free(struct bonding_request_info *dev); -int found_device_cmp(const struct remote_dev_info *d1, - const struct remote_dev_info *d2); int set_limited_discoverable(int dd, const uint8_t *cls, gboolean limited); int set_service_classes(int dd, const uint8_t *cls, uint8_t value); -- cgit From 271183bccb0ac55f7fe3ae6b76211251387e3b5c Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 18:03:55 +0530 Subject: Adding adapter_update_oor_devices. --- src/adapter.c | 19 +++++++++++++++++++ src/adapter.h | 1 + src/dbus-hci.c | 20 ++------------------ 3 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 53a06101..701f49a1 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2863,6 +2863,25 @@ int adapter_remove_found_device(struct adapter *adapter, bdaddr_t *bdaddr) return 0; } +void adapter_update_oor_devices(struct adapter *adapter) +{ + GSList *l = adapter->found_devices; + struct remote_dev_info *dev; + bdaddr_t tmp; + + g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); + g_slist_free(adapter->oor_devices); + adapter->oor_devices = NULL; + + while (l) { + dev = l->data; + baswap(&tmp, &dev->bdaddr); + adapter->oor_devices = g_slist_append(adapter->oor_devices, + batostr(&tmp)); + l = l->next; + } +} + int btd_register_adapter_driver(struct btd_adapter_driver *driver) { adapter_drivers = g_slist_append(adapter_drivers, driver); diff --git a/src/adapter.h b/src/adapter.h index dfc377ed..8b42dbad 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -177,6 +177,7 @@ struct remote_dev_info *adapter_search_found_devices(struct adapter *adapter, int adapter_add_found_device(struct adapter *adapter, bdaddr_t *bdaddr, int8_t rssi, name_status_t name_status); int adapter_remove_found_device(struct adapter *adapter, bdaddr_t *bdaddr); +void adapter_update_oor_devices(struct adapter *adapter); struct btd_adapter_driver { const char *name; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 465a1072..63978d84 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -802,8 +802,7 @@ static int found_device_req_name(struct adapter *adapter) /* if failed, request the next element */ /* remove the element from the list */ - adapter->found_devices = g_slist_remove(adapter->found_devices, dev); - g_free(dev); + adapter_remove_found_device(adapter, &dev->bdaddr); /* get the next element */ dev = adapter_search_found_devices(adapter, &match); @@ -834,8 +833,6 @@ static void send_out_of_range(const char *path, GSList *l) void hcid_dbus_inquiry_complete(bdaddr_t *local) { struct adapter *adapter; - struct remote_dev_info *dev; - bdaddr_t tmp; const gchar *path; int state; @@ -850,22 +847,9 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) /* Out of range verification */ if ((adapter_get_state(adapter) & PERIODIC_INQUIRY) && !(adapter_get_state(adapter) & STD_INQUIRY)) { - GSList *l; send_out_of_range(path, adapter->oor_devices); - - g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); - g_slist_free(adapter->oor_devices); - adapter->oor_devices = NULL; - - l = adapter->found_devices; - while (l) { - dev = l->data; - baswap(&tmp, &dev->bdaddr); - adapter->oor_devices = g_slist_append(adapter->oor_devices, - batostr(&tmp)); - l = l->next; - } + adapter_update_oor_devices(adapter); } /* -- cgit From aeecbf7e45383c48ccb4fd70417500e568cda3bb Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Fri, 29 Aug 2008 14:22:01 +0530 Subject: Moving send_out_of_range to adapter.c --- src/adapter.c | 16 ++++++++++++++++ src/dbus-hci.c | 20 +------------------- 2 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 701f49a1..4926d14f 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -167,6 +167,20 @@ static DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, err > 0 ? strerror(err) : "Connection attempt failed"); } +static void send_out_of_range(const char *path, GSList *l) +{ + while (l) { + const char *peer_addr = l->data; + + g_dbus_emit_signal(connection, path, + ADAPTER_INTERFACE, "DeviceDisappeared", + DBUS_TYPE_STRING, &peer_addr, + DBUS_TYPE_INVALID); + + l = l->next; + } +} + static int found_device_cmp(const struct remote_dev_info *d1, const struct remote_dev_info *d2) { @@ -2869,6 +2883,8 @@ void adapter_update_oor_devices(struct adapter *adapter) struct remote_dev_info *dev; bdaddr_t tmp; + send_out_of_range(adapter->path, adapter->oor_devices); + g_slist_foreach(adapter->oor_devices, (GFunc) free, NULL); g_slist_free(adapter->oor_devices); adapter->oor_devices = NULL; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 63978d84..175a69e4 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -816,20 +816,6 @@ static int found_device_req_name(struct adapter *adapter) return 0; } -static void send_out_of_range(const char *path, GSList *l) -{ - while (l) { - const char *peer_addr = l->data; - - g_dbus_emit_signal(connection, path, - ADAPTER_INTERFACE, "DeviceDisappeared", - DBUS_TYPE_STRING, &peer_addr, - DBUS_TYPE_INVALID); - - l = l->next; - } -} - void hcid_dbus_inquiry_complete(bdaddr_t *local) { struct adapter *adapter; @@ -846,12 +832,8 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) /* Out of range verification */ if ((adapter_get_state(adapter) & PERIODIC_INQUIRY) && - !(adapter_get_state(adapter) & STD_INQUIRY)) { - - send_out_of_range(path, adapter->oor_devices); + !(adapter_get_state(adapter) & STD_INQUIRY)) adapter_update_oor_devices(adapter); - } - /* * Enable resolution again: standard inquiry can be * received in the periodic inquiry idle state. -- cgit From 93750261a6093a8d987cd23327fd3d90467b5739 Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Thu, 28 Aug 2008 20:00:01 +0530 Subject: Adding adapter_remove_oor_devices. --- src/adapter.c | 14 ++++++++++++++ src/adapter.h | 1 + src/dbus-hci.c | 14 ++------------ 3 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/adapter.c b/src/adapter.c index 4926d14f..04c219ca 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2898,6 +2898,20 @@ void adapter_update_oor_devices(struct adapter *adapter) } } +void adapter_remove_oor_device(struct adapter *adapter, char *peer_addr) +{ + GSList *l; + + l = g_slist_find_custom(adapter->oor_devices, peer_addr, + (GCompareFunc) strcmp); + if (l) { + char *dev = l->data; + adapter->oor_devices = g_slist_remove(adapter->oor_devices, + dev); + g_free(dev); + } +} + int btd_register_adapter_driver(struct btd_adapter_driver *driver) { adapter_drivers = g_slist_append(adapter_drivers, driver); diff --git a/src/adapter.h b/src/adapter.h index 8b42dbad..d256b546 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -178,6 +178,7 @@ int adapter_add_found_device(struct adapter *adapter, bdaddr_t *bdaddr, int8_t rssi, name_status_t name_status); int adapter_remove_found_device(struct adapter *adapter, bdaddr_t *bdaddr); void adapter_update_oor_devices(struct adapter *adapter); +void adapter_remove_oor_device(struct adapter *adapter, char *peer_addr); struct btd_adapter_driver { const char *name; diff --git a/src/dbus-hci.c b/src/dbus-hci.c index 175a69e4..57449cbb 100644 --- a/src/dbus-hci.c +++ b/src/dbus-hci.c @@ -1060,7 +1060,6 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, { char filename[PATH_MAX + 1]; struct adapter *adapter; - GSList *l; char local_addr[18], peer_addr[18], *name, *tmp_name; const char *paddr = peer_addr; struct remote_dev_info *dev, match; @@ -1094,18 +1093,9 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, state |= PERIODIC_INQUIRY; adapter_set_state(adapter, state); } - - if (adapter_get_state(adapter) & PERIODIC_INQUIRY) { /* Out of range list update */ - l = g_slist_find_custom(adapter->oor_devices, peer_addr, - (GCompareFunc) strcmp); - if (l) { - char *dev = l->data; - adapter->oor_devices = g_slist_remove(adapter->oor_devices, - dev); - g_free(dev); - } - } + if (adapter_get_state(adapter) & PERIODIC_INQUIRY) + adapter_remove_oor_device(adapter, peer_addr); memset(&match, 0, sizeof(struct remote_dev_info)); bacpy(&match.bdaddr, peer); -- cgit