diff options
-rw-r--r-- | hcid/adapter.c | 85 | ||||
-rw-r--r-- | hcid/adapter.h | 7 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 72 | ||||
-rw-r--r-- | hcid/dbus-hci.h | 1 |
4 files changed, 88 insertions, 77 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 6b44ec48..1e22c510 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -254,6 +254,62 @@ static inline DBusMessage *unsupported_major_class(DBusMessage *msg) "Unsupported Major Class"); } +static int auth_req_cmp(const void *p1, const void *p2) +{ + const struct pending_auth_info *pb1 = p1; + const bdaddr_t *bda = p2; + + return bda ? bacmp(&pb1->bdaddr, bda) : -1; +} + +struct pending_auth_info *adapter_find_auth_request(struct adapter *adapter, + bdaddr_t *dba) +{ + GSList *l; + + l = g_slist_find_custom(adapter->auth_reqs, dba, auth_req_cmp); + if (l) + return l->data; + + return NULL; +} + +void adapter_remove_auth_request(struct adapter *adapter, bdaddr_t *dba) +{ + GSList *l; + struct pending_auth_info *auth; + + l = g_slist_find_custom(adapter->auth_reqs, dba, auth_req_cmp); + if (!l) + return; + + auth = l->data; + + adapter->auth_reqs = g_slist_remove(adapter->auth_reqs, auth); + + g_free(auth); +} + +struct pending_auth_info *adapter_new_auth_request(struct adapter *adapter, + bdaddr_t *dba, + auth_type_t type) +{ + struct pending_auth_info *info; + + debug("hcid_dbus_new_auth_request"); + + info = g_new0(struct pending_auth_info, 1); + + bacpy(&info->bdaddr, dba); + info->type = type; + adapter->auth_reqs = g_slist_append(adapter->auth_reqs, info); + + if (adapter->bonding && !bacmp(dba, &adapter->bonding->bdaddr)) + adapter->bonding->auth_active = 1; + + return info; +} + int pending_remote_name_cancel(struct adapter *adapter) { struct remote_dev_info *dev, match; @@ -2644,8 +2700,8 @@ static void cancel_auth_request(int dd, auth_type_t type, bdaddr_t *bda) static void create_bond_req_exit(void *user_data) { struct adapter *adapter = user_data; + struct pending_auth_info *auth; char path[MAX_PATH_LENGTH]; - GSList *l; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, adapter->dev_id); @@ -2655,23 +2711,19 @@ static void create_bond_req_exit(void *user_data) &adapter->bonding->bdaddr); release_passkey_agents(adapter, &adapter->bonding->bdaddr); - l = g_slist_find_custom(adapter->auth_reqs, &adapter->bonding->bdaddr, - auth_req_cmp); - if (l) { - struct pending_auth_info *p = l->data; - - if (!p->replied) { + auth = adapter_find_auth_request(adapter, &adapter->bonding->bdaddr); + if (auth) { + if (!auth->replied) { int dd; dd = hci_open_dev(adapter->dev_id); if (dd >= 0) { - cancel_auth_request(dd, p->type, &p->bdaddr); + cancel_auth_request(dd, auth->type, &auth->bdaddr); hci_close_dev(dd); } } - adapter->auth_reqs = g_slist_remove(adapter->auth_reqs, p); - g_free(p); + adapter_remove_auth_request(adapter, &adapter->bonding->bdaddr); } remove_pending_device(adapter); @@ -2705,7 +2757,7 @@ static DBusMessage *create_bonding(DBusConnection *conn, DBusMessage *msg, if (adapter->bonding) return in_progress(msg, "Bonding in progress"); - if (g_slist_find_custom(adapter->auth_reqs, &bdaddr, auth_req_cmp)) + if (adapter_find_auth_request(adapter, &bdaddr)) return in_progress(msg, "Bonding in progress"); /* check if a link key already exists */ @@ -2775,8 +2827,8 @@ static DBusMessage *adapter_cancel_bonding(DBusConnection *conn, struct adapter *adapter = data; const char *address; bdaddr_t bdaddr; - GSList *l; struct bonding_request_info *bonding = adapter->bonding; + struct pending_auth_info *auth_req; if (!adapter->up) return adapter_not_ready(msg); @@ -2799,10 +2851,8 @@ static DBusMessage *adapter_cancel_bonding(DBusConnection *conn, adapter->bonding->cancel = 1; - l = g_slist_find_custom(adapter->auth_reqs, &bdaddr, auth_req_cmp); - if (l) { - struct pending_auth_info *auth_req = l->data; - + auth_req = adapter_find_auth_request(adapter, &bdaddr); + if (auth_req) { if (auth_req->replied) { /* * If disconnect can't be applied and the PIN code @@ -2825,8 +2875,7 @@ static DBusMessage *adapter_cancel_bonding(DBusConnection *conn, hci_close_dev(dd); } - adapter->auth_reqs = g_slist_remove(adapter->auth_reqs, auth_req); - g_free(auth_req); + adapter_remove_auth_request(adapter, &bdaddr); } g_io_channel_close(adapter->bonding->io); diff --git a/hcid/adapter.h b/hcid/adapter.h index 5e023f3c..2e14bfc0 100644 --- a/hcid/adapter.h +++ b/hcid/adapter.h @@ -154,3 +154,10 @@ int pending_remote_name_cancel(struct adapter *adapter); void dc_pending_timeout_cleanup(struct adapter *adapter); void remove_pending_device(struct adapter *adapter); + +struct pending_auth_info *adapter_find_auth_request(struct adapter *adapter, + bdaddr_t *dba); +void adapter_remove_auth_request(struct adapter *adapter, bdaddr_t *dba); +struct pending_auth_info *adapter_new_auth_request(struct adapter *adapter, + bdaddr_t *dba, + auth_type_t type); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index c9880445..32a6c788 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -833,31 +833,6 @@ int hcid_dbus_stop_device(uint16_t id) return 0; } -int auth_req_cmp(const void *p1, const void *p2) -{ - const struct pending_auth_info *pb1 = p1; - const bdaddr_t *bda = p2; - - return bda ? bacmp(&pb1->bdaddr, bda) : -1; -} - -static void hcid_dbus_new_auth_request(struct adapter *adapter, bdaddr_t *dba, - auth_type_t type) -{ - struct pending_auth_info *info; - - debug("hcid_dbus_new_auth_request"); - - info = g_new0(struct pending_auth_info, 1); - - bacpy(&info->bdaddr, dba); - info->type = type; - adapter->auth_reqs = g_slist_append(adapter->auth_reqs, info); - - if (adapter->bonding && !bacmp(dba, &adapter->bonding->bdaddr)) - adapter->bonding->auth_active = 1; -} - static void pincode_cb(struct agent *agent, DBusError *err, const char *pincode, struct device *device) { @@ -935,7 +910,7 @@ int hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) (agent_pincode_cb) pincode_cb, device); if (ret == 0) - hcid_dbus_new_auth_request(adapter, &ci->bdaddr, + adapter_new_auth_request(adapter, &ci->bdaddr, AUTH_TYPE_PINCODE); return ret; @@ -944,7 +919,7 @@ old_fallback: ret = handle_passkey_request_old(connection, dev, adapter, sba, &ci->bdaddr); if (ret == 0) - hcid_dbus_new_auth_request(adapter, &ci->bdaddr, + adapter_new_auth_request(adapter, &ci->bdaddr, AUTH_TYPE_PINCODE); return ret; @@ -1104,7 +1079,7 @@ int hcid_dbus_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey) return -1; } - hcid_dbus_new_auth_request(adapter, dba, AUTH_TYPE_CONFIRM); + adapter_new_auth_request(adapter, dba, AUTH_TYPE_CONFIRM); return 0; } @@ -1140,7 +1115,7 @@ int hcid_dbus_user_passkey(bdaddr_t *sba, bdaddr_t *dba) return -1; } - hcid_dbus_new_auth_request(adapter, dba, AUTH_TYPE_PASSKEY); + adapter_new_auth_request(adapter, dba, AUTH_TYPE_PASSKEY); return 0; } @@ -1176,7 +1151,7 @@ int hcid_dbus_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey) return -1; } - hcid_dbus_new_auth_request(adapter, dba, AUTH_TYPE_NOTIFY); + adapter_new_auth_request(adapter, dba, AUTH_TYPE_NOTIFY); return 0; } @@ -1187,11 +1162,9 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, struct adapter *adapter; char peer_addr[18]; const char *paddr = peer_addr; - GSList *l; DBusMessage *reply; struct device *device; struct bonding_request_info *bonding; - void *d; gboolean paired = TRUE; debug("hcid_dbus_bonding_process_complete: status=%02x", status); @@ -1211,15 +1184,12 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, adapter->path, peer); } - l = g_slist_find_custom(adapter->auth_reqs, peer, auth_req_cmp); - if (!l) { - debug("hcid_dbus_bonding_process_complete: no pending PIN request"); + if (!adapter_find_auth_request(adapter, peer)) { + debug("hcid_dbus_bonding_process_complete: no pending auth request"); goto proceed; } - d = l->data; - adapter->auth_reqs = g_slist_remove(adapter->auth_reqs, l->data); - g_free(d); + adapter_remove_auth_request(adapter, peer); if (status) goto proceed; @@ -1990,7 +1960,6 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, char peer_addr[18]; const char *paddr = peer_addr; struct adapter *adapter; - GSList *l; adapter = manager_find_adapter(local); if (!adapter) { @@ -2005,12 +1974,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, adapter->path, peer); release_passkey_agents(adapter, peer); - l = g_slist_find_custom(adapter->auth_reqs, peer, auth_req_cmp); - if (l) { - struct pending_auth_req *p = l->data; - adapter->auth_reqs = g_slist_remove(adapter->auth_reqs, p); - g_free(p); - } + adapter_remove_auth_request(adapter, peer); if (adapter->bonding) adapter->bonding->hci_status = status; @@ -2081,12 +2045,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, &dev->bdaddr); release_passkey_agents(adapter, &dev->bdaddr); - l = g_slist_find_custom(adapter->auth_reqs, &dev->bdaddr, auth_req_cmp); - if (l) { - struct pending_auth_req *p = l->data; - adapter->auth_reqs = g_slist_remove(adapter->auth_reqs, p); - g_free(p); - } + adapter_remove_auth_request(adapter, &dev->bdaddr); /* Check if there is a pending CreateBonding request */ if (adapter->bonding && (bacmp(&adapter->bonding->bdaddr, &dev->bdaddr) == 0)) { @@ -2421,15 +2380,14 @@ void hcid_dbus_write_simple_pairing_mode_complete(bdaddr_t *local) void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) { - typedef struct { uint8_t status; bdaddr_t bdaddr; } __attribute__ ((packed)) ret_pin_code_req_reply; + struct pending_auth_info *auth; struct adapter *adapter; ret_pin_code_req_reply *ret = ptr + EVT_CMD_COMPLETE_SIZE; - GSList *l; adapter = manager_find_adapter(local); if (!adapter) { @@ -2437,11 +2395,9 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) return; } - l = g_slist_find_custom(adapter->auth_reqs, &ret->bdaddr, auth_req_cmp); - if (l) { - struct pending_auth_info *p = l->data; - p->replied = 1; - } + auth = adapter_find_auth_request(adapter, &ret->bdaddr); + if (auth) + auth->replied = 1; } int hcid_dbus_get_io_cap(bdaddr_t *local, bdaddr_t *remote, diff --git a/hcid/dbus-hci.h b/hcid/dbus-hci.h index f4dfa018..87aa8a46 100644 --- a/hcid/dbus-hci.h +++ b/hcid/dbus-hci.h @@ -72,7 +72,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 auth_req_cmp(const void *p1, const void *p2); int found_device_cmp(const struct remote_dev_info *d1, const struct remote_dev_info *d2); int found_device_add(GSList **list, bdaddr_t *bdaddr, int8_t rssi, |