2009-11-09 14:25:04

by alok barsode

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

From: Alok Barsode <[email protected]>

---
src/adapter.c | 43 ++++++++++++++++++++++++++++++--
src/adapter.h | 7 +----
src/security.c | 74 +++++++++++++++----------------------------------------
3 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index fec14dc..aedf50a 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,43 @@ gboolean adapter_has_discov_sessions(struct btd_adapter *adapter)
return TRUE;
}

+void adapter_handle_start_inquiry(struct btd_adapter *adapter,
+ uint8_t status, gboolean periodic)
+{
+ int state;
+
+ /* Don't send the signal if the cmd failed */
+ if (status) {
+ error("Inquiry Failed with status 0x%02x", status);
+ 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..44e1cc2 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,14 @@ 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(struct btd_adapter *adapter,
+ 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..06f9d1a 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,24 +620,21 @@ 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;
uint16_t opcode = btohs(evt->opcode);
uint8_t status = *((uint8_t *) ptr + EVT_CMD_COMPLETE_SIZE);
+ struct btd_adapter *adapter = manager_find_adapter(sba);
+
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return;
+ }

switch (opcode) {
case cmd_opcode_pack(OGF_LINK_CTL, OCF_PERIODIC_INQUIRY):
- start_inquiry(sba, status, TRUE);
+ adapter_handle_start_inquiry(adapter, status, TRUE);
break;
case cmd_opcode_pack(OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY):
inquiry_complete(sba, status, TRUE);
@@ -943,11 +897,13 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer
{
unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr = buf;
struct hci_dev_info *di = data;
+ struct btd_adapter *adapter;
int type, dev;
size_t len;
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);
@@ -976,9 +932,19 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer
if (hci_test_bit(HCI_RAW, &di->flags))
return TRUE;

+ adapter = manager_find_adapter(&di->bdaddr);
+ if (!adapter) {
+ error("Unable to find matching adapter");
+ return TRUE;
+ }
+
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(adapter, evt->status,
+ FALSE);
break;

case EVT_CMD_COMPLETE:
--
1.5.6.3