summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-09-12 20:18:49 -0300
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-09-12 20:34:43 -0300
commitad81c796ad12b4ecb4436dd28e5cbdc1f5c5414e (patch)
tree6aa22726bd2dd08d56c8ec4de928533dcb349016
parent89f7e6f27acfa9402a5125264f6b5641409ea079 (diff)
Pass Bluetooth address instead of handle for async encryption func
-rw-r--r--common/glib-helper.c28
-rw-r--r--common/glib-helper.h2
2 files changed, 26 insertions, 4 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c
index 3454fe21..3ccadbcf 100644
--- a/common/glib-helper.c
+++ b/common/glib-helper.c
@@ -1110,15 +1110,18 @@ failed:
return FALSE;
}
-int bt_acl_encrypt(const bdaddr_t *src, uint16_t handle,
+int bt_acl_encrypt(const bdaddr_t *src, const bdaddr_t *dst,
bt_hci_result_t cb, gpointer user_data)
{
GIOChannel *io;
struct hci_cmd_data *cmd;
+ struct hci_conn_info_req *cr;
auth_requested_cp cp;
struct hci_filter nf;
- int dd, dev_id, err = 0;
+ int dd, dev_id, err;
char src_addr[18];
+ uint32_t link_mode;
+ uint16_t handle;
ba2str(src, src_addr);
dev_id = hci_devid(src_addr);
@@ -1129,7 +1132,25 @@ int bt_acl_encrypt(const bdaddr_t *src, uint16_t handle,
if (dd < 0)
return -errno;
- /* FIXME: Check if it is already encrypted */
+ cr = g_malloc0(sizeof(*cr) + sizeof(struct hci_conn_info));
+ cr->type = ACL_LINK;
+ bacpy(&cr->bdaddr, dst);
+
+ err = ioctl(dd, HCIGETCONNINFO, cr);
+ link_mode = cr->conn_info->link_mode;
+ handle = cr->conn_info->handle;
+ g_free(cr);
+
+ if (err < 0) {
+ err = errno;
+ goto failed;
+ }
+
+ if (link_mode & HCI_LM_ENCRYPT) {
+ /* Already encrypted */
+ err = EALREADY;
+ goto failed;
+ }
memset(&cp, 0, sizeof(cp));
cp.handle = htobs(handle);
@@ -1168,6 +1189,7 @@ int bt_acl_encrypt(const bdaddr_t *src, uint16_t handle,
failed:
close(dd);
+
return -err;
}
diff --git a/common/glib-helper.h b/common/glib-helper.h
index 74ba7dfa..ee63b2d7 100644
--- a/common/glib-helper.h
+++ b/common/glib-helper.h
@@ -60,7 +60,7 @@ int bt_sco_connect(const bdaddr_t *src, const bdaddr_t *dst,
GIOChannel *bt_sco_listen(const bdaddr_t *src, uint16_t mtu,
bt_io_callback_t cb, void *user_data);
-int bt_acl_encrypt(const bdaddr_t *src, uint16_t handle,
+int bt_acl_encrypt(const bdaddr_t *src, const bdaddr_t *dst,
bt_hci_result_t cb, gpointer user_data);
/* Experiemental bt_io API */