summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@tieto.com>2012-11-19 16:03:56 +0100
committerJohan Hedberg <johan.hedberg@intel.com>2012-11-20 12:22:25 +0200
commitd823bba949ea0305a0ac41b8148a4087a99fd885 (patch)
tree5c290c04db34d403346c9136dee01d0fa83e7c32 /plugins
parent8d7bf14da23a9d98dfa796266738bb7dcda28c70 (diff)
downloadbluez-d823bba949ea0305a0ac41b8148a4087a99fd885.tar.gz
neard: Move device object checking into separate helper
This will also be used by 'nokia.com:bt' handler.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/neard.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/plugins/neard.c b/plugins/neard.c
index 1576be535..831944591 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -248,13 +248,38 @@ static void bonding_complete(struct btd_adapter *adapter,
error("D-Bus send failed");
}
+static int check_device(struct btd_adapter *adapter, const char *address)
+{
+ struct btd_device *device;
+
+ device = adapter_find_device(adapter, address);
+
+ /* If already paired */
+ if (device && device_is_paired(device)) {
+ DBG("already paired");
+ return 1;
+ }
+
+ /* Pairing in progress... */
+ if (device && device_is_bonding(device, NULL)) {
+ DBG("pairing in progress");
+ return -EINPROGRESS;
+ }
+
+ /* If we have unpaired device hanging around, purge it */
+ if (device)
+ adapter_remove_device(adapter, device, TRUE);
+
+ return 0;
+}
+
/* returns 1 if pairing is not needed */
static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
bdaddr_t *remote)
{
- struct btd_device *device;
struct eir_data eir_data;
char remote_address[18];
+ int ret;
DBG("size %zu", size);
@@ -267,26 +292,12 @@ static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
DBG("hci%u remote:%s", adapter_get_dev_id(adapter), remote_address);
- device = adapter_find_device(adapter, remote_address);
-
- /* If already paired do nothing */
- if (device && device_is_paired(device)) {
- DBG("already paired");
+ ret = check_device (adapter, remote_address);
+ if (ret != 0) {
eir_data_free(&eir_data);
- return 1;
+ return ret;
}
- /* Pairing in progress... */
- if (device && device_is_bonding(device, NULL)) {
- DBG("pairing in progress");
- eir_data_free(&eir_data);
- return -EINPROGRESS;
- }
-
- /* If we have unpaired device hanging around, purge it */
- if (device)
- adapter_remove_device(adapter, device, TRUE);
-
/* store OOB data */
if (eir_data.class != 0)
write_remote_class(adapter_get_address(adapter),