Lines Matching full:conn

61 static int pin_code_reply(struct bt_conn *conn, const char *pin, uint8_t len)  in pin_code_reply()  argument
75 bt_addr_copy(&cp->bdaddr, &conn->br.dst); in pin_code_reply()
82 int bt_conn_auth_pincode_entry(struct bt_conn *conn, const char *pin) in bt_conn_auth_pincode_entry() argument
90 if (conn->type != BT_CONN_TYPE_BR) { in bt_conn_auth_pincode_entry()
99 if (conn->required_sec_level == BT_SECURITY_L3 && len < 16) { in bt_conn_auth_pincode_entry()
100 LOG_WRN("PIN code for %s is not 16 bytes wide", bt_addr_str(&conn->br.dst)); in bt_conn_auth_pincode_entry()
105 if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) { in bt_conn_auth_pincode_entry()
110 atomic_set_bit(conn->flags, BT_CONN_BR_LEGACY_SECURE); in bt_conn_auth_pincode_entry()
113 return pin_code_reply(conn, pin, len); in bt_conn_auth_pincode_entry()
116 static void pin_code_req(struct bt_conn *conn) in pin_code_req() argument
121 if (conn->required_sec_level == BT_SECURITY_L3) { in pin_code_req()
125 atomic_set_bit(conn->flags, BT_CONN_USER); in pin_code_req()
126 atomic_set_bit(conn->flags, BT_CONN_BR_PAIRING); in pin_code_req()
127 bt_auth->pincode_entry(conn, secure); in pin_code_req()
129 pin_code_neg_reply(&conn->br.dst); in pin_code_req()
154 static uint8_t ssp_pair_method(const struct bt_conn *conn) in ssp_pair_method() argument
156 return ssp_method[conn->br.remote_io_capa][get_io_capa()]; in ssp_pair_method()
159 static uint8_t ssp_get_auth(const struct bt_conn *conn) in ssp_get_auth() argument
162 if ((conn->br.remote_auth == BT_HCI_NO_BONDING) || in ssp_get_auth()
163 ((conn->br.remote_auth == BT_HCI_NO_BONDING_MITM) && in ssp_get_auth()
164 (ssp_pair_method(conn) > JUST_WORKS))) { in ssp_get_auth()
165 return conn->br.remote_auth; in ssp_get_auth()
169 if (ssp_pair_method(conn) > JUST_WORKS) { in ssp_get_auth()
170 return conn->br.remote_auth | BT_MITM; in ssp_get_auth()
174 return (conn->br.remote_auth & ~BT_MITM); in ssp_get_auth()
177 static int ssp_confirm_reply(struct bt_conn *conn) in ssp_confirm_reply() argument
190 bt_addr_copy(&cp->bdaddr, &conn->br.dst); in ssp_confirm_reply()
195 static int ssp_confirm_neg_reply(struct bt_conn *conn) in ssp_confirm_neg_reply() argument
208 bt_addr_copy(&cp->bdaddr, &conn->br.dst); in ssp_confirm_neg_reply()
214 static void ssp_pairing_complete(struct bt_conn *conn, uint8_t status) in ssp_pairing_complete() argument
219 atomic_clear_bit(conn->flags, BT_CONN_BR_PAIRING); in ssp_pairing_complete()
220 atomic_set_bit_to(conn->flags, BT_CONN_BR_PAIRED, !status); in ssp_pairing_complete()
225 bool bond = !atomic_test_bit(conn->flags, BT_CONN_BR_NOBOND); in ssp_pairing_complete()
231 listener->pairing_complete(conn, bond); in ssp_pairing_complete()
240 listener->pairing_failed(conn, status); in ssp_pairing_complete()
246 static void ssp_auth(struct bt_conn *conn, uint32_t passkey) in ssp_auth() argument
248 conn->br.pairing_method = ssp_pair_method(conn); in ssp_auth()
254 if (conn->required_sec_level > BT_SECURITY_L2 && in ssp_auth()
255 conn->br.pairing_method == JUST_WORKS) { in ssp_auth()
257 ssp_confirm_neg_reply(conn); in ssp_auth()
261 switch (conn->br.pairing_method) { in ssp_auth()
263 atomic_set_bit(conn->flags, BT_CONN_USER); in ssp_auth()
264 bt_auth->passkey_confirm(conn, passkey); in ssp_auth()
267 atomic_set_bit(conn->flags, BT_CONN_USER); in ssp_auth()
268 bt_auth->passkey_display(conn, passkey); in ssp_auth()
271 atomic_set_bit(conn->flags, BT_CONN_USER); in ssp_auth()
272 bt_auth->passkey_entry(conn); in ssp_auth()
281 !atomic_test_bit(conn->flags, in ssp_auth()
283 atomic_set_bit(conn->flags, BT_CONN_USER); in ssp_auth()
284 bt_auth->pairing_confirm(conn); in ssp_auth()
287 ssp_confirm_reply(conn); in ssp_auth()
294 static int ssp_passkey_reply(struct bt_conn *conn, unsigned int passkey) in ssp_passkey_reply() argument
307 bt_addr_copy(&cp->bdaddr, &conn->br.dst); in ssp_passkey_reply()
313 static int ssp_passkey_neg_reply(struct bt_conn *conn) in ssp_passkey_neg_reply() argument
326 bt_addr_copy(&cp->bdaddr, &conn->br.dst); in ssp_passkey_neg_reply()
332 static int conn_auth(struct bt_conn *conn) in conn_auth() argument
345 auth->handle = sys_cpu_to_le16(conn->handle); in conn_auth()
347 atomic_set_bit(conn->flags, BT_CONN_BR_PAIRING_INITIATOR); in conn_auth()
352 int bt_ssp_start_security(struct bt_conn *conn) in bt_ssp_start_security() argument
354 if (atomic_test_bit(conn->flags, BT_CONN_BR_PAIRING)) { in bt_ssp_start_security()
359 conn->required_sec_level > BT_SECURITY_L2) { in bt_ssp_start_security()
363 return conn_auth(conn); in bt_ssp_start_security()
366 int bt_ssp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey) in bt_ssp_auth_passkey_entry() argument
369 if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) { in bt_ssp_auth_passkey_entry()
373 if (conn->br.pairing_method == PASSKEY_INPUT) { in bt_ssp_auth_passkey_entry()
374 return ssp_passkey_reply(conn, passkey); in bt_ssp_auth_passkey_entry()
380 int bt_ssp_auth_passkey_confirm(struct bt_conn *conn) in bt_ssp_auth_passkey_confirm() argument
383 if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) { in bt_ssp_auth_passkey_confirm()
387 return ssp_confirm_reply(conn); in bt_ssp_auth_passkey_confirm()
390 int bt_ssp_auth_pairing_confirm(struct bt_conn *conn) in bt_ssp_auth_pairing_confirm() argument
392 return ssp_confirm_reply(conn); in bt_ssp_auth_pairing_confirm()
395 int bt_ssp_auth_cancel(struct bt_conn *conn) in bt_ssp_auth_cancel() argument
398 if (!atomic_test_and_clear_bit(conn->flags, BT_CONN_USER)) { in bt_ssp_auth_cancel()
402 switch (conn->br.pairing_method) { in bt_ssp_auth_cancel()
405 return ssp_confirm_neg_reply(conn); in bt_ssp_auth_cancel()
407 return ssp_passkey_neg_reply(conn); in bt_ssp_auth_cancel()
409 return bt_conn_disconnect(conn, in bt_ssp_auth_cancel()
412 return pin_code_neg_reply(&conn->br.dst); in bt_ssp_auth_cancel()
423 struct bt_conn *conn; in bt_hci_pin_code_req() local
427 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_pin_code_req()
428 if (!conn) { in bt_hci_pin_code_req()
429 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_pin_code_req()
433 pin_code_req(conn); in bt_hci_pin_code_req()
434 bt_conn_unref(conn); in bt_hci_pin_code_req()
440 struct bt_conn *conn; in bt_hci_link_key_notify() local
442 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_link_key_notify()
443 if (!conn) { in bt_hci_link_key_notify()
444 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_link_key_notify()
461 ssp_pairing_complete(conn, bt_security_err_get(BT_HCI_ERR_AUTH_FAIL)); in bt_hci_link_key_notify()
462 bt_conn_disconnect(conn, BT_HCI_ERR_AUTH_FAIL); in bt_hci_link_key_notify()
463 bt_conn_unref(conn); in bt_hci_link_key_notify()
467 if (!conn->br.link_key) { in bt_hci_link_key_notify()
468 conn->br.link_key = bt_keys_get_link_key(&evt->bdaddr); in bt_hci_link_key_notify()
470 if (!conn->br.link_key) { in bt_hci_link_key_notify()
472 bt_conn_unref(conn); in bt_hci_link_key_notify()
477 conn->br.link_key->flags = 0U; in bt_hci_link_key_notify()
485 if (atomic_test_and_clear_bit(conn->flags, in bt_hci_link_key_notify()
487 conn->br.link_key->flags |= BT_LINK_KEY_AUTHENTICATED; in bt_hci_link_key_notify()
489 memcpy(conn->br.link_key->val, evt->link_key, 16); in bt_hci_link_key_notify()
492 conn->br.link_key->flags |= BT_LINK_KEY_AUTHENTICATED; in bt_hci_link_key_notify()
495 memcpy(conn->br.link_key->val, evt->link_key, 16); in bt_hci_link_key_notify()
498 conn->br.link_key->flags |= BT_LINK_KEY_AUTHENTICATED; in bt_hci_link_key_notify()
501 conn->br.link_key->flags |= BT_LINK_KEY_SC; in bt_hci_link_key_notify()
503 memcpy(conn->br.link_key->val, evt->link_key, 16); in bt_hci_link_key_notify()
507 (void)memset(conn->br.link_key->val, 0, in bt_hci_link_key_notify()
508 sizeof(conn->br.link_key->val)); in bt_hci_link_key_notify()
513 !atomic_test_bit(conn->flags, BT_CONN_BR_NOBOND)) { in bt_hci_link_key_notify()
514 bt_keys_link_key_store(conn->br.link_key); in bt_hci_link_key_notify()
517 bt_conn_unref(conn); in bt_hci_link_key_notify()
560 struct bt_conn *conn; in bt_hci_link_key_req() local
564 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_link_key_req()
565 if (!conn) { in bt_hci_link_key_req()
566 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_link_key_req()
571 if (!conn->br.link_key) { in bt_hci_link_key_req()
572 conn->br.link_key = bt_keys_find_link_key(&evt->bdaddr); in bt_hci_link_key_req()
575 if (!conn->br.link_key) { in bt_hci_link_key_req()
577 bt_conn_unref(conn); in bt_hci_link_key_req()
585 if (!(conn->br.link_key->flags & BT_LINK_KEY_AUTHENTICATED) && in bt_hci_link_key_req()
586 conn->required_sec_level > BT_SECURITY_L2) { in bt_hci_link_key_req()
588 bt_conn_unref(conn); in bt_hci_link_key_req()
592 link_key_reply(&evt->bdaddr, conn->br.link_key->val); in bt_hci_link_key_req()
593 bt_conn_unref(conn); in bt_hci_link_key_req()
617 struct bt_conn *conn; in bt_hci_io_capa_resp() local
636 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_io_capa_resp()
637 if (!conn) { in bt_hci_io_capa_resp()
638 LOG_ERR("Unable to find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_io_capa_resp()
642 conn->br.remote_io_capa = evt->capability; in bt_hci_io_capa_resp()
643 conn->br.remote_auth = evt->authentication; in bt_hci_io_capa_resp()
644 atomic_set_bit(conn->flags, BT_CONN_BR_PAIRING); in bt_hci_io_capa_resp()
645 bt_conn_unref(conn); in bt_hci_io_capa_resp()
658 struct bt_conn *conn; in bt_hci_io_capa_req() local
664 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_io_capa_req()
665 if (!conn) { in bt_hci_io_capa_req()
666 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_io_capa_req()
674 err = bt_auth->pairing_accept(conn, NULL); in bt_hci_io_capa_req()
687 bt_conn_unref(conn); in bt_hci_io_capa_req()
697 if (atomic_test_bit(conn->flags, BT_CONN_BR_PAIRING_INITIATOR)) { in bt_hci_io_capa_req()
699 if (atomic_test_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING)) { in bt_hci_io_capa_req()
705 if (atomic_test_bit(conn->flags, BT_CONN_BR_GENERAL_BONDING)) { in bt_hci_io_capa_req()
712 if (conn->required_sec_level < BT_SECURITY_L3) { in bt_hci_io_capa_req()
717 auth = ssp_get_auth(conn); in bt_hci_io_capa_req()
720 if (!atomic_test_bit(conn->flags, BT_CONN_BR_BONDABLE)) { in bt_hci_io_capa_req()
731 bt_conn_unref(conn); in bt_hci_io_capa_req()
737 struct bt_conn *conn; in bt_hci_ssp_complete() local
741 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_ssp_complete()
742 if (!conn) { in bt_hci_ssp_complete()
743 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_ssp_complete()
748 if (ssp_get_auth(conn) < BT_HCI_DEDICATED_BONDING) { in bt_hci_ssp_complete()
749 atomic_set_bit(conn->flags, BT_CONN_BR_NOBOND); in bt_hci_ssp_complete()
752 ssp_pairing_complete(conn, bt_security_err_get(evt->status)); in bt_hci_ssp_complete()
754 bt_conn_disconnect(conn, BT_HCI_ERR_AUTH_FAIL); in bt_hci_ssp_complete()
757 bt_conn_unref(conn); in bt_hci_ssp_complete()
763 struct bt_conn *conn; in bt_hci_user_confirm_req() local
765 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_user_confirm_req()
766 if (!conn) { in bt_hci_user_confirm_req()
767 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_user_confirm_req()
771 ssp_auth(conn, sys_le32_to_cpu(evt->passkey)); in bt_hci_user_confirm_req()
772 bt_conn_unref(conn); in bt_hci_user_confirm_req()
778 struct bt_conn *conn; in bt_hci_user_passkey_notify() local
782 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_user_passkey_notify()
783 if (!conn) { in bt_hci_user_passkey_notify()
784 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_user_passkey_notify()
788 ssp_auth(conn, sys_le32_to_cpu(evt->passkey)); in bt_hci_user_passkey_notify()
789 bt_conn_unref(conn); in bt_hci_user_passkey_notify()
795 struct bt_conn *conn; in bt_hci_user_passkey_req() local
797 conn = bt_conn_lookup_addr_br(&evt->bdaddr); in bt_hci_user_passkey_req()
798 if (!conn) { in bt_hci_user_passkey_req()
799 LOG_ERR("Can't find conn for %s", bt_addr_str(&evt->bdaddr)); in bt_hci_user_passkey_req()
803 ssp_auth(conn, 0); in bt_hci_user_passkey_req()
804 bt_conn_unref(conn); in bt_hci_user_passkey_req()
830 struct bt_conn *conn; in bt_hci_auth_complete() local
835 conn = bt_conn_lookup_handle(handle, BT_CONN_TYPE_BR); in bt_hci_auth_complete()
836 if (!conn) { in bt_hci_auth_complete()
837 LOG_ERR("Can't find conn for handle %u", handle); in bt_hci_auth_complete()
846 bt_conn_security_changed(conn, evt->status, in bt_hci_auth_complete()
852 bt_conn_unref(conn); in bt_hci_auth_complete()