From 9427f5dc51c6962692eecd7250f2a1130dbc49ad Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 4 Nov 2004 11:21:34 +0000 Subject: Add hci_change_link_key() function --- include/hci.h | 13 +++++++++++++ include/hci_lib.h | 1 + src/hci.c | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/include/hci.h b/include/hci.h index 00f2d21a..c8c3aa16 100644 --- a/include/hci.h +++ b/include/hci.h @@ -370,6 +370,12 @@ typedef struct { } __attribute__ ((packed)) set_conn_encrypt_cp; #define SET_CONN_ENCRYPT_CP_SIZE 3 +#define OCF_CHANGE_CONN_LINK_KEY 0x0015 +typedef struct { + uint16_t handle; +} __attribute__ ((packed)) change_conn_link_key_cp; +#define CHANGE_CONN_LINK_KEY_CP_SIZE 2 + #define OCF_REMOTE_NAME_REQ 0x0019 typedef struct { bdaddr_t bdaddr; @@ -860,6 +866,13 @@ typedef struct { } __attribute__ ((packed)) evt_encrypt_change; #define EVT_ENCRYPT_CHANGE_SIZE 5 +#define EVT_CHANGE_CONN_LINK_KEY_COMPLETE 0x09 +typedef struct { + uint8_t status; + uint16_t handle; +} __attribute__ ((packed)) evt_change_conn_link_key_complete; +#define EVT_CHANGE_CONN_LINK_KEY_COMPLETE_SIZE 3 + #define EVT_READ_REMOTE_FEATURES_COMPLETE 0x0B typedef struct { uint8_t status; diff --git a/include/hci_lib.h b/include/hci_lib.h index e40a1afd..0d9867f9 100644 --- a/include/hci_lib.h +++ b/include/hci_lib.h @@ -84,6 +84,7 @@ int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to); int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to); int hci_authenticate_link(int dd, uint16_t handle, int to); int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to); +int hci_change_link_key(int dd, uint16_t handle, int to); /* role == 0 is master, 1 is slave */ int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to); int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval, uint16_t min_interval, int to); diff --git a/src/hci.c b/src/hci.c index d3892bbc..23f890a6 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1174,12 +1174,13 @@ int hci_authenticate_link(int dd, uint16_t handle, int to) struct hci_request rq; cp.handle = handle; + rq.ogf = OGF_LINK_CTL; rq.ocf = OCF_AUTH_REQUESTED; + rq.event = EVT_AUTH_COMPLETE; rq.cparam = &cp; rq.clen = AUTH_REQUESTED_CP_SIZE; rq.rparam = &rp; - rq.event = EVT_AUTH_COMPLETE; rq.rlen = EVT_AUTH_COMPLETE_SIZE; if (hci_send_req(dd, &rq, to) < 0) @@ -1201,13 +1202,14 @@ int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to) cp.handle = handle; cp.encrypt = encrypt; + rq.ogf = OGF_LINK_CTL; rq.ocf = OCF_SET_CONN_ENCRYPT; + rq.event = EVT_ENCRYPT_CHANGE; rq.cparam = &cp; rq.clen = SET_CONN_ENCRYPT_CP_SIZE; - rq.event = EVT_ENCRYPT_CHANGE; - rq.rlen = EVT_ENCRYPT_CHANGE_SIZE; rq.rparam = &rp; + rq.rlen = EVT_ENCRYPT_CHANGE_SIZE; if (hci_send_req(dd, &rq, to) < 0) return -1; @@ -1216,6 +1218,34 @@ int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to) errno = EIO; return -1; } + + return 0; +} + +int hci_change_link_key(int dd, uint16_t handle, int to) +{ + change_conn_link_key_cp cp; + evt_change_conn_link_key_complete rp; + struct hci_request rq; + + cp.handle = handle; + + rq.ogf = OGF_LINK_CTL; + rq.ocf = OCF_CHANGE_CONN_LINK_KEY; + rq.event = EVT_CHANGE_CONN_LINK_KEY_COMPLETE; + rq.cparam = &cp; + rq.clen = CHANGE_CONN_LINK_KEY_CP_SIZE; + rq.rparam = &rp; + rq.rlen = EVT_CHANGE_CONN_LINK_KEY_COMPLETE_SIZE; + + if (hci_send_req(dd, &rq, to) < 0) + return -1; + + if (rp.status) { + errno = EIO; + return -1; + } + return 0; } -- cgit