diff options
Diffstat (limited to 'net/bluetooth/hci_conn.c')
-rw-r--r-- | net/bluetooth/hci_conn.c | 106 |
1 files changed, 80 insertions, 26 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index ba5366c320da..bd66c52eff95 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c | |||
@@ -225,8 +225,8 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, | |||
225 | cp.conn_interval_max = cpu_to_le16(max); | 225 | cp.conn_interval_max = cpu_to_le16(max); |
226 | cp.conn_latency = cpu_to_le16(latency); | 226 | cp.conn_latency = cpu_to_le16(latency); |
227 | cp.supervision_timeout = cpu_to_le16(to_multiplier); | 227 | cp.supervision_timeout = cpu_to_le16(to_multiplier); |
228 | cp.min_ce_len = __constant_cpu_to_le16(0x0001); | 228 | cp.min_ce_len = __constant_cpu_to_le16(0x0000); |
229 | cp.max_ce_len = __constant_cpu_to_le16(0x0001); | 229 | cp.max_ce_len = __constant_cpu_to_le16(0x0000); |
230 | 230 | ||
231 | hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp); | 231 | hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp); |
232 | } | 232 | } |
@@ -514,6 +514,21 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src) | |||
514 | } | 514 | } |
515 | EXPORT_SYMBOL(hci_get_route); | 515 | EXPORT_SYMBOL(hci_get_route); |
516 | 516 | ||
517 | /* This function requires the caller holds hdev->lock */ | ||
518 | static void le_conn_failed(struct hci_conn *conn, u8 status) | ||
519 | { | ||
520 | struct hci_dev *hdev = conn->hdev; | ||
521 | |||
522 | conn->state = BT_CLOSED; | ||
523 | |||
524 | mgmt_connect_failed(hdev, &conn->dst, conn->type, conn->dst_type, | ||
525 | status); | ||
526 | |||
527 | hci_proto_connect_cfm(conn, status); | ||
528 | |||
529 | hci_conn_del(conn); | ||
530 | } | ||
531 | |||
517 | static void create_le_conn_complete(struct hci_dev *hdev, u8 status) | 532 | static void create_le_conn_complete(struct hci_dev *hdev, u8 status) |
518 | { | 533 | { |
519 | struct hci_conn *conn; | 534 | struct hci_conn *conn; |
@@ -530,14 +545,7 @@ static void create_le_conn_complete(struct hci_dev *hdev, u8 status) | |||
530 | if (!conn) | 545 | if (!conn) |
531 | goto done; | 546 | goto done; |
532 | 547 | ||
533 | conn->state = BT_CLOSED; | 548 | le_conn_failed(conn, status); |
534 | |||
535 | mgmt_connect_failed(hdev, &conn->dst, conn->type, conn->dst_type, | ||
536 | status); | ||
537 | |||
538 | hci_proto_connect_cfm(conn, status); | ||
539 | |||
540 | hci_conn_del(conn); | ||
541 | 549 | ||
542 | done: | 550 | done: |
543 | hci_dev_unlock(hdev); | 551 | hci_dev_unlock(hdev); |
@@ -558,8 +566,8 @@ static int hci_create_le_conn(struct hci_conn *conn) | |||
558 | bacpy(&cp.peer_addr, &conn->dst); | 566 | bacpy(&cp.peer_addr, &conn->dst); |
559 | cp.peer_addr_type = conn->dst_type; | 567 | cp.peer_addr_type = conn->dst_type; |
560 | cp.own_address_type = conn->src_type; | 568 | cp.own_address_type = conn->src_type; |
561 | cp.conn_interval_min = cpu_to_le16(hdev->le_conn_min_interval); | 569 | cp.conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); |
562 | cp.conn_interval_max = cpu_to_le16(hdev->le_conn_max_interval); | 570 | cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); |
563 | cp.supervision_timeout = __constant_cpu_to_le16(0x002a); | 571 | cp.supervision_timeout = __constant_cpu_to_le16(0x002a); |
564 | cp.min_ce_len = __constant_cpu_to_le16(0x0000); | 572 | cp.min_ce_len = __constant_cpu_to_le16(0x0000); |
565 | cp.max_ce_len = __constant_cpu_to_le16(0x0000); | 573 | cp.max_ce_len = __constant_cpu_to_le16(0x0000); |
@@ -578,7 +586,9 @@ static int hci_create_le_conn(struct hci_conn *conn) | |||
578 | static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, | 586 | static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, |
579 | u8 dst_type, u8 sec_level, u8 auth_type) | 587 | u8 dst_type, u8 sec_level, u8 auth_type) |
580 | { | 588 | { |
589 | struct hci_conn_params *params; | ||
581 | struct hci_conn *conn; | 590 | struct hci_conn *conn; |
591 | struct smp_irk *irk; | ||
582 | int err; | 592 | int err; |
583 | 593 | ||
584 | if (test_bit(HCI_ADVERTISING, &hdev->flags)) | 594 | if (test_bit(HCI_ADVERTISING, &hdev->flags)) |
@@ -607,15 +617,36 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, | |||
607 | if (conn) | 617 | if (conn) |
608 | return ERR_PTR(-EBUSY); | 618 | return ERR_PTR(-EBUSY); |
609 | 619 | ||
620 | /* Convert from L2CAP channel address type to HCI address type */ | ||
621 | if (dst_type == BDADDR_LE_PUBLIC) | ||
622 | dst_type = ADDR_LE_DEV_PUBLIC; | ||
623 | else | ||
624 | dst_type = ADDR_LE_DEV_RANDOM; | ||
625 | |||
626 | /* When given an identity address with existing identity | ||
627 | * resolving key, the connection needs to be established | ||
628 | * to a resolvable random address. | ||
629 | * | ||
630 | * This uses the cached random resolvable address from | ||
631 | * a previous scan. When no cached address is available, | ||
632 | * try connecting to the identity address instead. | ||
633 | * | ||
634 | * Storing the resolvable random address is required here | ||
635 | * to handle connection failures. The address will later | ||
636 | * be resolved back into the original identity address | ||
637 | * from the connect request. | ||
638 | */ | ||
639 | irk = hci_find_irk_by_addr(hdev, dst, dst_type); | ||
640 | if (irk && bacmp(&irk->rpa, BDADDR_ANY)) { | ||
641 | dst = &irk->rpa; | ||
642 | dst_type = ADDR_LE_DEV_RANDOM; | ||
643 | } | ||
644 | |||
610 | conn = hci_conn_add(hdev, LE_LINK, dst); | 645 | conn = hci_conn_add(hdev, LE_LINK, dst); |
611 | if (!conn) | 646 | if (!conn) |
612 | return ERR_PTR(-ENOMEM); | 647 | return ERR_PTR(-ENOMEM); |
613 | 648 | ||
614 | if (dst_type == BDADDR_LE_PUBLIC) | 649 | conn->dst_type = dst_type; |
615 | conn->dst_type = ADDR_LE_DEV_PUBLIC; | ||
616 | else | ||
617 | conn->dst_type = ADDR_LE_DEV_RANDOM; | ||
618 | |||
619 | conn->src_type = hdev->own_addr_type; | 650 | conn->src_type = hdev->own_addr_type; |
620 | 651 | ||
621 | conn->state = BT_CONNECT; | 652 | conn->state = BT_CONNECT; |
@@ -625,6 +656,15 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, | |||
625 | conn->pending_sec_level = sec_level; | 656 | conn->pending_sec_level = sec_level; |
626 | conn->auth_type = auth_type; | 657 | conn->auth_type = auth_type; |
627 | 658 | ||
659 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); | ||
660 | if (params) { | ||
661 | conn->le_conn_min_interval = params->conn_min_interval; | ||
662 | conn->le_conn_max_interval = params->conn_max_interval; | ||
663 | } else { | ||
664 | conn->le_conn_min_interval = hdev->le_conn_min_interval; | ||
665 | conn->le_conn_max_interval = hdev->le_conn_max_interval; | ||
666 | } | ||
667 | |||
628 | err = hci_create_le_conn(conn); | 668 | err = hci_create_le_conn(conn); |
629 | if (err) | 669 | if (err) |
630 | return ERR_PTR(err); | 670 | return ERR_PTR(err); |
@@ -800,14 +840,23 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) | |||
800 | if (!(conn->link_mode & HCI_LM_AUTH)) | 840 | if (!(conn->link_mode & HCI_LM_AUTH)) |
801 | goto auth; | 841 | goto auth; |
802 | 842 | ||
803 | /* An authenticated combination key has sufficient security for any | 843 | /* An authenticated FIPS approved combination key has sufficient |
804 | security level. */ | 844 | * security for security level 4. */ |
805 | if (conn->key_type == HCI_LK_AUTH_COMBINATION) | 845 | if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256 && |
846 | sec_level == BT_SECURITY_FIPS) | ||
847 | goto encrypt; | ||
848 | |||
849 | /* An authenticated combination key has sufficient security for | ||
850 | security level 3. */ | ||
851 | if ((conn->key_type == HCI_LK_AUTH_COMBINATION_P192 || | ||
852 | conn->key_type == HCI_LK_AUTH_COMBINATION_P256) && | ||
853 | sec_level == BT_SECURITY_HIGH) | ||
806 | goto encrypt; | 854 | goto encrypt; |
807 | 855 | ||
808 | /* An unauthenticated combination key has sufficient security for | 856 | /* An unauthenticated combination key has sufficient security for |
809 | security level 1 and 2. */ | 857 | security level 1 and 2. */ |
810 | if (conn->key_type == HCI_LK_UNAUTH_COMBINATION && | 858 | if ((conn->key_type == HCI_LK_UNAUTH_COMBINATION_P192 || |
859 | conn->key_type == HCI_LK_UNAUTH_COMBINATION_P256) && | ||
811 | (sec_level == BT_SECURITY_MEDIUM || sec_level == BT_SECURITY_LOW)) | 860 | (sec_level == BT_SECURITY_MEDIUM || sec_level == BT_SECURITY_LOW)) |
812 | goto encrypt; | 861 | goto encrypt; |
813 | 862 | ||
@@ -816,7 +865,8 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) | |||
816 | is generated using maximum PIN code length (16). | 865 | is generated using maximum PIN code length (16). |
817 | For pre 2.1 units. */ | 866 | For pre 2.1 units. */ |
818 | if (conn->key_type == HCI_LK_COMBINATION && | 867 | if (conn->key_type == HCI_LK_COMBINATION && |
819 | (sec_level != BT_SECURITY_HIGH || conn->pin_length == 16)) | 868 | (sec_level == BT_SECURITY_MEDIUM || sec_level == BT_SECURITY_LOW || |
869 | conn->pin_length == 16)) | ||
820 | goto encrypt; | 870 | goto encrypt; |
821 | 871 | ||
822 | auth: | 872 | auth: |
@@ -840,13 +890,17 @@ int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level) | |||
840 | { | 890 | { |
841 | BT_DBG("hcon %p", conn); | 891 | BT_DBG("hcon %p", conn); |
842 | 892 | ||
843 | if (sec_level != BT_SECURITY_HIGH) | 893 | /* Accept if non-secure or higher security level is required */ |
844 | return 1; /* Accept if non-secure is required */ | 894 | if (sec_level != BT_SECURITY_HIGH && sec_level != BT_SECURITY_FIPS) |
895 | return 1; | ||
845 | 896 | ||
846 | if (conn->sec_level == BT_SECURITY_HIGH) | 897 | /* Accept if secure or higher security level is already present */ |
898 | if (conn->sec_level == BT_SECURITY_HIGH || | ||
899 | conn->sec_level == BT_SECURITY_FIPS) | ||
847 | return 1; | 900 | return 1; |
848 | 901 | ||
849 | return 0; /* Reject not secure link */ | 902 | /* Reject not secure link */ |
903 | return 0; | ||
850 | } | 904 | } |
851 | EXPORT_SYMBOL(hci_conn_check_secure); | 905 | EXPORT_SYMBOL(hci_conn_check_secure); |
852 | 906 | ||