summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/hci_lib.h2
-rw-r--r--src/hci.c24
2 files changed, 26 insertions, 0 deletions
diff --git a/include/hci_lib.h b/include/hci_lib.h
index 79866a45..31995411 100644
--- a/include/hci_lib.h
+++ b/include/hci_lib.h
@@ -82,6 +82,8 @@ 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, int on, int to);
+// role == 0 is master, 1 is slave
+int hci_switch_role(int dd, bdaddr_t peer, int role, int to);
int hci_for_each_dev(int flag, int(*func)(int s, int dev_id, long arg), long arg);
int hci_get_route(bdaddr_t *bdaddr);
diff --git a/src/hci.c b/src/hci.c
index e6cf48c4..6d313d21 100644
--- a/src/hci.c
+++ b/src/hci.c
@@ -1125,3 +1125,27 @@ int hci_encrypt_link(int dd, uint16_t handle, int on, int to)
}
return 0;
}
+
+int hci_switch_role(int dd, bdaddr_t peer, int role, int to)
+{
+ switch_role_cp cp;
+ evt_role_change rp;
+ struct hci_request rq;
+
+ cp.bdaddr = peer;
+ cp.role = role;
+ rq.ogf = OGF_LINK_POLICY;
+ rq.ocf = OCF_SWITCH_ROLE;
+ rq.cparam = &cp;
+ rq.clen = SWITCH_ROLE_CP_SIZE;
+ rq.rparam = &rp;
+ rq.rlen = EVT_ROLE_CHANGE_SIZE;
+ rq.event = EVT_ROLE_CHANGE;
+ if (hci_send_req(dd, &rq, to) < 0)
+ return -1;
+ if (rp.status) {
+ errno = EIO;
+ return -1;
+ }
+ return 0;
+}