2009-11-09 10:00:53

by alok barsode

[permalink] [raw]
Subject: [PATCH 1/5] Moving start_inquiry() from security.c to adapter.c and

From: Alok Barsode <[email protected]>

---
src/adapter.c | 49 ++++++++++++++++++++++++++++++++++++++++++--
src/adapter.h | 6 +----
src/security.c | 61 ++++++-------------------------------------------------
3 files changed, 54 insertions(+), 62 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index fec14dc..18bab3d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -192,7 +192,7 @@ static void dev_info_free(struct remote_dev_info *dev)
g_free(dev);
}

-void clear_found_devices_list(struct btd_adapter *adapter)
+static void clear_found_devices_list(struct btd_adapter *adapter)
{
if (!adapter->found_devices)
return;
@@ -255,7 +255,7 @@ int btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major,
return err;
}

-int pending_remote_name_cancel(struct btd_adapter *adapter)
+static int pending_remote_name_cancel(struct btd_adapter *adapter)
{
struct remote_dev_info *dev, match;
int err = 0;
@@ -2808,7 +2808,7 @@ void adapter_remove_connection(struct btd_adapter *adapter,
}
}

-gboolean adapter_has_discov_sessions(struct btd_adapter *adapter)
+static inline gboolean adapter_has_discov_sessions(struct btd_adapter *adapter)
{
if (!adapter || !adapter->disc_sessions)
return FALSE;
@@ -2816,6 +2816,49 @@ gboolean adapter_has_discov_sessions(struct btd_adapter *adapter)
return TRUE;
}

+void adapter_handle_start_inquiry(bdaddr_t *local, uint8_t status, gboolean periodic)
+{
+ struct btd_adapter *adapter;
+ int state;
+
+ /* Don't send the signal if the cmd failed */
+ if (status) {
+ error("Inquiry Failed with status 0x%02x", status);
+ return;
+ }
+
+ adapter = manager_find_adapter(local);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }
+
+ state = adapter_get_state(adapter);
+
+ /* Disable name resolution for non D-Bus clients */
+ if (!adapter_has_discov_sessions(adapter))
+ state &= ~RESOLVE_NAME;
+
+ if (periodic) {
+ state |= PERIODIC_INQUIRY;
+ adapter_set_state(adapter, state);
+ return;
+ }
+
+ state |= STD_INQUIRY;
+ adapter_set_state(adapter, state);
+
+ /*
+ * Cancel pending remote name request and clean the device list
+ * when inquiry is supported in periodic inquiry idle state.
+ */
+ if (adapter->state & PERIODIC_INQUIRY) {
+ pending_remote_name_cancel(adapter);
+
+ clear_found_devices_list(adapter);
+ }
+}
+
int btd_register_adapter_driver(struct btd_adapter_driver *driver)
{
GSList *adapters;
diff --git a/src/adapter.h b/src/adapter.h
index 0954424..f92fd9e 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -92,12 +92,8 @@ void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
struct btd_device *adapter_create_device(DBusConnection *conn,
struct btd_adapter *adapter, const char *address);

-int pending_remote_name_cancel(struct btd_adapter *adapter);
-
int adapter_resolve_names(struct btd_adapter *adapter);

-void clear_found_devices_list(struct btd_adapter *adapter);
-
struct btd_adapter *adapter_create(DBusConnection *conn, int id,
gboolean devup);
void adapter_remove(struct btd_adapter *adapter);
@@ -121,13 +117,13 @@ void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
void adapter_setname_complete(bdaddr_t *local, uint8_t status);
void adapter_update_local_name(bdaddr_t *bdaddr, uint8_t status, void *ptr);
void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status);
+void adapter_handle_start_inquiry(bdaddr_t *local, uint8_t status, gboolean periodic);

struct agent *adapter_get_agent(struct btd_adapter *adapter);
void adapter_add_connection(struct btd_adapter *adapter,
struct btd_device *device, uint16_t handle);
void adapter_remove_connection(struct btd_adapter *adapter,
struct btd_device *device, uint16_t handle);
-gboolean adapter_has_discov_sessions(struct btd_adapter *adapter);

struct btd_adapter *btd_adapter_ref(struct btd_adapter *adapter);
void btd_adapter_unref(struct btd_adapter *adapter);
diff --git a/src/security.c b/src/security.c
index 843361b..5095218 100644
--- a/src/security.c
+++ b/src/security.c
@@ -554,49 +554,6 @@ reject:
hci_send_cmd(dev, OGF_LINK_CTL, OCF_PIN_CODE_NEG_REPLY, 6, dba);
}

-static void start_inquiry(bdaddr_t *local, uint8_t status, gboolean periodic)
-{
- struct btd_adapter *adapter;
- int state;
-
- /* Don't send the signal if the cmd failed */
- if (status) {
- error("Inquiry Failed with status 0x%02x", status);
- return;
- }
-
- adapter = manager_find_adapter(local);
- if (!adapter) {
- error("Unable to find matching adapter");
- return;
- }
-
- state = adapter_get_state(adapter);
-
- /* Disable name resolution for non D-Bus clients */
- if (!adapter_has_discov_sessions(adapter))
- state &= ~RESOLVE_NAME;
-
- if (periodic) {
- state |= PERIODIC_INQUIRY;
- adapter_set_state(adapter, state);
- return;
- }
-
- state |= STD_INQUIRY;
- adapter_set_state(adapter, state);
-
- /*
- * Cancel pending remote name request and clean the device list
- * when inquiry is supported in periodic inquiry idle state.
- */
- if (adapter_get_state(adapter) & PERIODIC_INQUIRY) {
- pending_remote_name_cancel(adapter);
-
- clear_found_devices_list(adapter);
- }
-}
-
static void inquiry_complete(bdaddr_t *local, uint8_t status, gboolean periodic)
{
struct btd_adapter *adapter;
@@ -663,15 +620,6 @@ static inline void remote_features_notify(int dev, bdaddr_t *sba, void *ptr)
hcid_dbus_set_legacy_pairing(sba, &evt->bdaddr, TRUE);
}

-static inline void cmd_status(int dev, bdaddr_t *sba, void *ptr)
-{
- evt_cmd_status *evt = ptr;
- uint16_t opcode = btohs(evt->opcode);
-
- if (opcode == cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY))
- start_inquiry(sba, evt->status, FALSE);
-}
-
static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
{
evt_cmd_complete *evt = ptr;
@@ -680,7 +628,7 @@ static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)

switch (opcode) {
case cmd_opcode_pack(OGF_LINK_CTL, OCF_PERIODIC_INQUIRY):
- start_inquiry(sba, status, TRUE);
+ adapter_handle_start_inquiry(sba, status, TRUE);
break;
case cmd_opcode_pack(OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY):
inquiry_complete(sba, status, TRUE);
@@ -948,6 +896,7 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer
hci_event_hdr *eh;
GIOError err;
evt_cmd_status *evt;
+ uint16_t opcode;

if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
delete_channel(chan);
@@ -978,7 +927,11 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer

switch (eh->evt) {
case EVT_CMD_STATUS:
- cmd_status(dev, &di->bdaddr, ptr);
+ evt = (evt_cmd_status *) ptr;
+ opcode = btohs(evt->opcode);
+ if (opcode == cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY))
+ adapter_handle_start_inquiry(&di->bdaddr, evt->status,
+ FALSE);
break;

case EVT_CMD_COMPLETE:
--
1.5.6.3



2009-11-09 10:00:54

by alok barsode

[permalink] [raw]
Subject: [PATCH 2/5] Moving inquiry_complete() from security.c to adapter.c and

From: Alok Barsode <[email protected]>

---
src/adapter.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/adapter.h | 2 +
src/security.c | 62 ++-----------------------------------------------------
3 files changed, 62 insertions(+), 59 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 18bab3d..e03ebbf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2859,6 +2859,63 @@ void adapter_handle_start_inquiry(bdaddr_t *local, uint8_t status, gboolean peri
}
}

+void adapter_handle_inquiry_complete(bdaddr_t *local, uint8_t status,
+ gboolean periodic)
+{
+ struct btd_adapter *adapter;
+ int state;
+
+ /* Don't send the signal if the cmd failed */
+ if (status) {
+ error("Inquiry Failed with status 0x%02x", status);
+ return;
+ }
+
+ adapter = manager_find_adapter(local);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }
+
+ /*
+ * The following scenarios can happen:
+ * 1. standard inquiry: always send discovery completed signal
+ * 2. standard inquiry + name resolving: send discovery completed
+ * after name resolving
+ * 3. periodic inquiry: skip discovery completed signal
+ * 4. periodic inquiry + standard inquiry: always send discovery
+ * completed signal
+ *
+ * Keep in mind that non D-Bus requests can arrive.
+ */
+ if (periodic) {
+ state = adapter_get_state(adapter);
+ state &= ~PERIODIC_INQUIRY;
+ adapter_set_state(adapter, state);
+ return;
+ }
+
+ if (adapter_resolve_names(adapter) == 0)
+ return;
+
+ state = adapter_get_state(adapter);
+ /*
+ * workaround to identify situation when there is no devices around
+ * but periodic inquiry is active.
+ */
+ if (!(state & STD_INQUIRY) && !(state & PERIODIC_INQUIRY)) {
+ state |= PERIODIC_INQUIRY;
+ adapter_set_state(adapter, state);
+ return;
+ }
+
+ /* reset the discover type to be able to handle D-Bus and non D-Bus
+ * requests */
+ state &= ~STD_INQUIRY;
+ state &= ~PERIODIC_INQUIRY;
+ adapter_set_state(adapter, state);
+}
+
int btd_register_adapter_driver(struct btd_adapter_driver *driver)
{
GSList *adapters;
diff --git a/src/adapter.h b/src/adapter.h
index f92fd9e..3f15ddd 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -118,6 +118,8 @@ void adapter_setname_complete(bdaddr_t *local, uint8_t status);
void adapter_update_local_name(bdaddr_t *bdaddr, uint8_t status, void *ptr);
void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status);
void adapter_handle_start_inquiry(bdaddr_t *local, uint8_t status, gboolean periodic);
+void adapter_handle_inquiry_complete(bdaddr_t *local, uint8_t status,
+ gboolean periodic);

struct agent *adapter_get_agent(struct btd_adapter *adapter);
void adapter_add_connection(struct btd_adapter *adapter,
diff --git a/src/security.c b/src/security.c
index 5095218..df72e6a 100644
--- a/src/security.c
+++ b/src/security.c
@@ -554,62 +554,6 @@ reject:
hci_send_cmd(dev, OGF_LINK_CTL, OCF_PIN_CODE_NEG_REPLY, 6, dba);
}

-static void inquiry_complete(bdaddr_t *local, uint8_t status, gboolean periodic)
-{
- struct btd_adapter *adapter;
- int state;
-
- /* Don't send the signal if the cmd failed */
- if (status) {
- error("Inquiry Failed with status 0x%02x", status);
- return;
- }
-
- adapter = manager_find_adapter(local);
- if (!adapter) {
- error("Unable to find matching adapter");
- return;
- }
-
- /*
- * The following scenarios can happen:
- * 1. standard inquiry: always send discovery completed signal
- * 2. standard inquiry + name resolving: send discovery completed
- * after name resolving
- * 3. periodic inquiry: skip discovery completed signal
- * 4. periodic inquiry + standard inquiry: always send discovery
- * completed signal
- *
- * Keep in mind that non D-Bus requests can arrive.
- */
- if (periodic) {
- state = adapter_get_state(adapter);
- state &= ~PERIODIC_INQUIRY;
- adapter_set_state(adapter, state);
- return;
- }
-
- if (adapter_resolve_names(adapter) == 0)
- return;
-
- state = adapter_get_state(adapter);
- /*
- * workaround to identify situation when there is no devices around
- * but periodic inquiry is active.
- */
- if (!(state & STD_INQUIRY) && !(state & PERIODIC_INQUIRY)) {
- state |= PERIODIC_INQUIRY;
- adapter_set_state(adapter, state);
- return;
- }
-
- /* reset the discover type to be able to handle D-Bus and non D-Bus
- * requests */
- state &= ~STD_INQUIRY;
- state &= ~PERIODIC_INQUIRY;
- adapter_set_state(adapter, state);
-}
-
static inline void remote_features_notify(int dev, bdaddr_t *sba, void *ptr)
{
evt_remote_host_features_notify *evt = ptr;
@@ -631,10 +575,10 @@ static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
adapter_handle_start_inquiry(sba, status, TRUE);
break;
case cmd_opcode_pack(OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY):
- inquiry_complete(sba, status, TRUE);
+ adapter_handle_inquiry_complete(sba, status, TRUE);
break;
case cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY_CANCEL):
- inquiry_complete(sba, status, FALSE);
+ adapter_handle_inquiry_complete(sba, status, FALSE);
break;
case cmd_opcode_pack(OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME):
adapter_setname_complete(sba, status);
@@ -956,7 +900,7 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer

case EVT_INQUIRY_COMPLETE:
evt = (evt_cmd_status *) ptr;
- inquiry_complete(&di->bdaddr, evt->status, FALSE);
+ adapter_handle_inquiry_complete(&di->bdaddr, evt->status, FALSE);
break;

case EVT_INQUIRY_RESULT:
--
1.5.6.3


2009-11-09 10:00:55

by alok barsode

[permalink] [raw]
Subject: [PATCH 3/5] Merging remote_name_information() and hcid_dbus_remote_name()

From: Alok Barsode <[email protected]>

---
src/adapter.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/adapter.h | 1 +
src/dbus-hci.c | 45 -------------------------------------
src/dbus-hci.h | 1 -
src/security.c | 24 +-------------------
5 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e03ebbf..5f8eadb 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2916,6 +2916,73 @@ void adapter_handle_inquiry_complete(bdaddr_t *local, uint8_t status,
adapter_set_state(adapter, state);
}

+void adapter_update_remote_name(bdaddr_t *local, void *ptr)
+{
+ evt_remote_name_req_complete *evt = ptr;
+ char name[MAX_NAME_LENGTH + 1];
+ char srcaddr[18], dstaddr[18];
+ int state;
+ bdaddr_t peer;
+ struct btd_device *device;
+ struct btd_adapter *adapter;
+ struct remote_dev_info match, *dev_info;
+
+ memset(name, 0, sizeof(name));
+ bacpy(&peer, &evt->bdaddr);
+
+ if (!evt->status) {
+ char *end;
+ memcpy(name, evt->name, MAX_NAME_LENGTH);
+ /* It's ok to cast end between const and non-const since
+ * we know it points to inside of name which is non-const */
+ if (!g_utf8_validate(name, -1, (const char **) &end))
+ *end = '\0';
+ write_device_name(local, &peer, name);
+ }
+
+ ba2str(local, srcaddr);
+ ba2str(&peer, dstaddr);
+
+ adapter = manager_find_adapter(local);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }
+
+ device = adapter_find_device(adapter, dstaddr);
+ if (!device)
+ return;
+
+ if (evt->status != 0)
+ goto proceed;
+
+ bacpy(&match.bdaddr, &peer);
+ match.name_status = NAME_ANY;
+
+ dev_info = adapter_search_found_devices(adapter, &match);
+ if (dev_info) {
+ g_free(dev_info->name);
+ dev_info->name = g_strdup(name);
+ adapter_emit_device_found(adapter, dev_info);
+ }
+
+ if (device)
+ device_set_name(device, name);
+
+proceed:
+ /* remove from remote name request list */
+ adapter_remove_found_device(adapter, &peer);
+
+ /* check if there is more devices to request names */
+ if (adapter_resolve_names(adapter) == 0)
+ return;
+
+ state = adapter_get_state(adapter);
+ state &= ~PERIODIC_INQUIRY;
+ state &= ~STD_INQUIRY;
+ adapter_set_state(adapter, state);
+}
+
int btd_register_adapter_driver(struct btd_adapter_driver *driver)
{
GSList *adapters;
diff --git a/src/adapter.h b/src/adapter.h
index 3f15ddd..853bb37 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -120,6 +120,7 @@ void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status);
void adapter_handle_start_inquiry(bdaddr_t *local, uint8_t status, gboolean periodic);
void adapter_handle_inquiry_complete(bdaddr_t *local, uint8_t status,
gboolean periodic);
+void adapter_update_remote_name(bdaddr_t *local, void *ptr);

struct agent *adapter_get_agent(struct btd_adapter *adapter);
void adapter_add_connection(struct btd_adapter *adapter,
diff --git a/src/dbus-hci.c b/src/dbus-hci.c
index 6af8246..0197a0d 100644
--- a/src/dbus-hci.c
+++ b/src/dbus-hci.c
@@ -594,51 +594,6 @@ void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class)
DBUS_TYPE_UINT32, &class);
}

-void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
- char *name)
-{
- struct btd_adapter *adapter;
- char srcaddr[18], dstaddr[18];
- int state;
- struct btd_device *device;
- struct remote_dev_info match, *dev_info;
-
- if (!get_adapter_and_device(local, peer, &adapter, &device, FALSE))
- return;
-
- ba2str(local, srcaddr);
- ba2str(peer, dstaddr);
-
- if (status != 0)
- goto proceed;
-
- bacpy(&match.bdaddr, peer);
- match.name_status = NAME_ANY;
-
- dev_info = adapter_search_found_devices(adapter, &match);
- if (dev_info) {
- g_free(dev_info->name);
- dev_info->name = g_strdup(name);
- adapter_emit_device_found(adapter, dev_info);
- }
-
- if (device)
- device_set_name(device, name);
-
-proceed:
- /* remove from remote name request list */
- adapter_remove_found_device(adapter, peer);
-
- /* check if there is more devices to request names */
- if (adapter_resolve_names(adapter) == 0)
- return;
-
- state = adapter_get_state(adapter);
- state &= ~PERIODIC_INQUIRY;
- state &= ~STD_INQUIRY;
- adapter_set_state(adapter, state);
-}
-
int hcid_dbus_link_key_notify(bdaddr_t *local, bdaddr_t *peer,
uint8_t *key, uint8_t key_type,
int pin_length, uint8_t old_key_type)
diff --git a/src/dbus-hci.h b/src/dbus-hci.h
index c85f227..8e21cdc 100644
--- a/src/dbus-hci.h
+++ b/src/dbus-hci.h
@@ -26,7 +26,6 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci);
void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, int8_t rssi, uint8_t *data);
void hcid_dbus_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
void hcid_dbus_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
-void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char *name);
void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, bdaddr_t *peer);
void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, uint8_t reason);
void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
diff --git a/src/security.c b/src/security.c
index df72e6a..e92c8f2 100644
--- a/src/security.c
+++ b/src/security.c
@@ -599,28 +599,6 @@ static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
};
}

-static inline void remote_name_information(int dev, bdaddr_t *sba, void *ptr)
-{
- evt_remote_name_req_complete *evt = ptr;
- bdaddr_t dba;
- char name[MAX_NAME_LENGTH + 1];
-
- memset(name, 0, sizeof(name));
- bacpy(&dba, &evt->bdaddr);
-
- if (!evt->status) {
- char *end;
- memcpy(name, evt->name, MAX_NAME_LENGTH);
- /* It's ok to cast end between const and non-const since
- * we know it points to inside of name which is non-const */
- if (!g_utf8_validate(name, -1, (const char **) &end))
- *end = '\0';
- write_device_name(sba, &dba, name);
- }
-
- hcid_dbus_remote_name(sba, &dba, evt->status, name);
-}
-
static inline void remote_version_information(int dev, bdaddr_t *sba, void *ptr)
{
evt_read_remote_version_complete *evt = ptr;
@@ -883,7 +861,7 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer
break;

case EVT_REMOTE_NAME_REQ_COMPLETE:
- remote_name_information(dev, &di->bdaddr, ptr);
+ adapter_update_remote_name(&di->bdaddr, ptr);
break;

case EVT_READ_REMOTE_VERSION_COMPLETE:
--
1.5.6.3


2009-11-09 10:00:57

by alok barsode

[permalink] [raw]
Subject: [PATCH 5/5] Add adapter_update_remote_features to adapter.c

From: Alok Barsode <[email protected]>

---
src/adapter.c | 27 +++++++++++++++++++++++++++
src/adapter.h | 1 +
src/security.c | 16 +---------------
3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5171e97..4c649de 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3011,6 +3011,33 @@ void adapter_update_remote_version(bdaddr_t *local, void *ptr)
evt->lmp_ver, btohs(evt->lmp_subver));
}

+void adapter_update_remote_features(bdaddr_t *local, void *ptr)
+{
+ evt_read_remote_features_complete *evt = ptr;
+ bdaddr_t peer;
+ struct btd_device *device;
+ struct btd_adapter *adapter;
+
+ if (evt->status)
+ return;
+
+ adapter = manager_find_adapter(local);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }
+
+ device = adapter_find_connection(adapter, btohs(evt->handle));
+ if (!device) {
+ error("Unable to find matching device");
+ return;
+ }
+
+ device_get_address(device, &peer);
+
+ write_features_info(&adapter->bdaddr, &peer, evt->features);
+}
+
int btd_register_adapter_driver(struct btd_adapter_driver *driver)
{
GSList *adapters;
diff --git a/src/adapter.h b/src/adapter.h
index 421b19e..63b505b 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -122,6 +122,7 @@ void adapter_handle_inquiry_complete(bdaddr_t *local, uint8_t status,
gboolean periodic);
void adapter_update_remote_name(bdaddr_t *local, void *ptr);
void adapter_update_remote_version(bdaddr_t *local, void *ptr);
+void adapter_update_remote_features(bdaddr_t *local, void *ptr);

struct agent *adapter_get_agent(struct btd_adapter *adapter);
void adapter_add_connection(struct btd_adapter *adapter,
diff --git a/src/security.c b/src/security.c
index 1608b1b..24bf8e6 100644
--- a/src/security.c
+++ b/src/security.c
@@ -677,20 +677,6 @@ static inline void extended_inquiry_result(int dev, bdaddr_t *sba, int plen, voi
}
}

-static inline void remote_features_information(int dev, bdaddr_t *sba, void *ptr)
-{
- evt_read_remote_features_complete *evt = ptr;
- bdaddr_t dba;
-
- if (evt->status)
- return;
-
- if (get_bdaddr(dev, sba, btohs(evt->handle), &dba) < 0)
- return;
-
- write_features_info(sba, &dba, evt->features);
-}
-
static inline void conn_complete(int dev, int dev_id, bdaddr_t *sba, void *ptr)
{
evt_conn_complete *evt = ptr;
@@ -854,7 +840,7 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer
break;

case EVT_READ_REMOTE_FEATURES_COMPLETE:
- remote_features_information(dev, &di->bdaddr, ptr);
+ adapter_update_remote_features(&di->bdaddr, ptr);
break;

case EVT_REMOTE_HOST_FEATURES_NOTIFY:
--
1.5.6.3


2009-11-09 10:00:56

by alok barsode

[permalink] [raw]
Subject: [PATCH 4/5] Add adapter_update_remote_version to adapter.c

From: Alok Barsode <[email protected]>

---
src/adapter.c | 28 ++++++++++++++++++++++++++++
src/adapter.h | 1 +
src/security.c | 17 +----------------
3 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5f8eadb..5171e97 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2983,6 +2983,34 @@ proceed:
adapter_set_state(adapter, state);
}

+void adapter_update_remote_version(bdaddr_t *local, void *ptr)
+{
+ evt_read_remote_version_complete *evt = ptr;
+ bdaddr_t peer;
+ struct btd_device *device;
+ struct btd_adapter *adapter;
+
+ if (evt->status)
+ return;
+
+ adapter = manager_find_adapter(local);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }
+
+ device = adapter_find_connection(adapter, btohs(evt->handle));
+ if (!device) {
+ error("Unable to find matching device");
+ return;
+ }
+
+ device_get_address(device, &peer);
+
+ write_version_info(&adapter->bdaddr, &peer, btohs(evt->manufacturer),
+ evt->lmp_ver, btohs(evt->lmp_subver));
+}
+
int btd_register_adapter_driver(struct btd_adapter_driver *driver)
{
GSList *adapters;
diff --git a/src/adapter.h b/src/adapter.h
index 853bb37..421b19e 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -121,6 +121,7 @@ void adapter_handle_start_inquiry(bdaddr_t *local, uint8_t status, gboolean peri
void adapter_handle_inquiry_complete(bdaddr_t *local, uint8_t status,
gboolean periodic);
void adapter_update_remote_name(bdaddr_t *local, void *ptr);
+void adapter_update_remote_version(bdaddr_t *local, void *ptr);

struct agent *adapter_get_agent(struct btd_adapter *adapter);
void adapter_add_connection(struct btd_adapter *adapter,
diff --git a/src/security.c b/src/security.c
index e92c8f2..1608b1b 100644
--- a/src/security.c
+++ b/src/security.c
@@ -599,21 +599,6 @@ static inline void cmd_complete(int dev, bdaddr_t *sba, void *ptr)
};
}

-static inline void remote_version_information(int dev, bdaddr_t *sba, void *ptr)
-{
- evt_read_remote_version_complete *evt = ptr;
- bdaddr_t dba;
-
- if (evt->status)
- return;
-
- if (get_bdaddr(dev, sba, btohs(evt->handle), &dba) < 0)
- return;
-
- write_version_info(sba, &dba, btohs(evt->manufacturer),
- evt->lmp_ver, btohs(evt->lmp_subver));
-}
-
static inline void inquiry_result(int dev, bdaddr_t *sba, int plen, void *ptr)
{
uint8_t num = *(uint8_t *) ptr++;
@@ -865,7 +850,7 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer
break;

case EVT_READ_REMOTE_VERSION_COMPLETE:
- remote_version_information(dev, &di->bdaddr, ptr);
+ adapter_update_remote_version(&di->bdaddr, ptr);
break;

case EVT_READ_REMOTE_FEATURES_COMPLETE:
--
1.5.6.3