summaryrefslogtreecommitdiffstats
path: root/common/glib-helper.c
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 /common/glib-helper.c
parent89f7e6f27acfa9402a5125264f6b5641409ea079 (diff)
Pass Bluetooth address instead of handle for async encryption func
Diffstat (limited to 'common/glib-helper.c')
-rw-r--r--common/glib-helper.c28
1 files changed, 25 insertions, 3 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;
}