Skip to contentSkip to conversation

Bluetooth: Enable LE Enhanced Connection Complete event.

PATCH In review Marcel Holtmann 2 participants 3 messages Apr 7, 2020 – Apr 9, 2020

Subsystems (2)
lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: Enable LE Enhanced Connection Complete event.

In case LL Privacy is supported by the controller, it is also a good idea to use the LE Enhanced Connection Complete event for getting all information about the new connection and its addresses.

---
 net/bluetooth/hci_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/bluetooth/hci_core.c +8 -0
index fb210f7ab7ab..d8d543e3dc9f 100644
@@ -638,6 +638,14 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 		if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)
 			events[0] |= 0x40;	/* LE Data Length Change */
 
+		/* If the controller supports LL Privacy feature, enable
+		 * the corresponding event.
+		 */
+		if (hdev->le_features[0] & HCI_LE_LL_PRIVACY)
+			events[1] |= 0x02;	/* LE Enhanced Connection
+						 * Complete
+						 */
+
 		/* If the controller supports Extended Scanner Filter
 		 * Policies, enable the correspondig event.
 		 */
Signature · 1 line
2.25.2
author maintainer
#1 lore raw

Hi,

Quoted 15 lines

In case LL Privacy is supported by the controller, it is also a good idea to use the LE Enhanced Connection Complete event for getting all information about the new connection and its addresses.

---
net/bluetooth/hci_core.c | 8 ++++++++

1 file changed, 8 insertions(+)
net/bluetooth/hci_core.c +0 -0
index fb210f7ab7ab..d8d543e3dc9f 100644
@@ -638,6 +638,14 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 		if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)

net/bluetooth/hci_core.c static int hci_init3_req(struct hci_request *req, unsigned long opt) · line 648

Quoted 10 lines
net/bluetooth/hci_core.c +8 -0
 			events[0] |= 0x40;	/* LE Data Length Change */
 
+		/* If the controller supports LL Privacy feature, enable
+		 * the corresponding event.
+		 */
+		if (hdev->le_features[0] & HCI_LE_LL_PRIVACY)
+			events[1] |= 0x02;	/* LE Enhanced Connection
+						 * Complete
+						 */
+

so this is sort of enough to get the events, but they don’t give any extra information if LL Privacy is not used. While the current code handles the non LL Privacy parts of this event, the important local RPA and peer RPA are not handled.

Both RPAs (if used) however need to be stored in hci_conn so that SMP can make use of them if needed.

Regards

Marcel

#2 lore raw
In reply to Marcel Holtmann
I love your patch! Yet something to improve:

Hi Marcel,

I love your patch! Yet something to improve:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on v5.6 next-20200408]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Marcel-Holtmann/Bluetooth-Enable-LE-Enhanced-Connection-Complete-event/20200408-072654
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 19fec004e23adbc43b839ddf1be8bc2e22e58aca)

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> net/bluetooth/hci_core.c:644:30: error: use of undeclared identifier 'HCI_LE_LL_PRIVACY'; did you mean 'HCI_LIMITED_PRIVACY'?
                   if (hdev->le_features[0] & HCI_LE_LL_PRIVACY)
                                              ^~~~~~~~~~~~~~~~~
                                              HCI_LIMITED_PRIVACY
   include/net/bluetooth/hci.h:278:2: note: 'HCI_LIMITED_PRIVACY' declared here
           HCI_LIMITED_PRIVACY,
           ^

1 error generated.

vim +644 net/bluetooth/hci_core.c

586
587 static int hci_init3_req(struct hci_request *req, unsigned long opt)
588 {
589 struct hci_dev *hdev = req->hdev;
590 u8 p;
591
592 hci_setup_event_mask(req);
593
594 if (hdev->commands[6] & 0x20 &&
595 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) {
596 struct hci_cp_read_stored_link_key cp;
597
598 bacpy(&cp.bdaddr, BDADDR_ANY);
599 cp.read_all = 0x01;
600 hci_req_add(req, HCI_OP_READ_STORED_LINK_KEY, sizeof(cp), &cp);
601 }
602
603 if (hdev->commands[5] & 0x10)
604 hci_setup_link_policy(req);
605
606 if (hdev->commands[8] & 0x01)
607 hci_req_add(req, HCI_OP_READ_PAGE_SCAN_ACTIVITY, 0, NULL);
608
609 if (hdev->commands[18] & 0x04)
610 hci_req_add(req, HCI_OP_READ_DEF_ERR_DATA_REPORTING, 0, NULL);
611
612 /* Some older Broadcom based Bluetooth 1.2 controllers do not
613 * support the Read Page Scan Type command. Check support for
614 * this command in the bit mask of supported commands.
615 */
616 if (hdev->commands[13] & 0x01)
617 hci_req_add(req, HCI_OP_READ_PAGE_SCAN_TYPE, 0, NULL);
618
619 if (lmp_le_capable(hdev)) {
620 u8 events[8];
621
622 memset(events, 0, sizeof(events));
623
624 if (hdev->le_features[0] & HCI_LE_ENCRYPTION)
625 events[0] |= 0x10; /* LE Long Term Key Request */
626
627 /* If controller supports the Connection Parameters Request
628 * Link Layer Procedure, enable the corresponding event.
629 */
630 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC)
631 events[0] |= 0x20; /* LE Remote Connection
632 * Parameter Request
633 */
634
635 /* If the controller supports the Data Length Extension
636 * feature, enable the corresponding event.
637 */
638 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)
639 events[0] |= 0x40; /* LE Data Length Change */
640
641 /* If the controller supports LL Privacy feature, enable
642 * the corresponding event.
643 */

 > 644			if (hdev->le_features[0] & HCI_LE_LL_PRIVACY)

645 events[1] |= 0x02; /* LE Enhanced Connection
646 * Complete
647 */
648
649 /* If the controller supports Extended Scanner Filter
650 * Policies, enable the correspondig event.
651 */
652 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)
653 events[1] |= 0x04; /* LE Direct Advertising
654 * Report
655 */
656
657 /* If the controller supports Channel Selection Algorithm #2
658 * feature, enable the corresponding event.
659 */
660 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2)
661 events[2] |= 0x08; /* LE Channel Selection
662 * Algorithm
663 */
664
665 /* If the controller supports the LE Set Scan Enable command,
666 * enable the corresponding advertising report event.
667 */
668 if (hdev->commands[26] & 0x08)
669 events[0] |= 0x02; /* LE Advertising Report */
670
671 /* If the controller supports the LE Create Connection
672 * command, enable the corresponding event.
673 */
674 if (hdev->commands[26] & 0x10)
675 events[0] |= 0x01; /* LE Connection Complete */
676
677 /* If the controller supports the LE Connection Update
678 * command, enable the corresponding event.
679 */
680 if (hdev->commands[27] & 0x04)
681 events[0] |= 0x04; /* LE Connection Update
682 * Complete
683 */
684
685 /* If the controller supports the LE Read Remote Used Features
686 * command, enable the corresponding event.
687 */
688 if (hdev->commands[27] & 0x20)
689 events[0] |= 0x08; /* LE Read Remote Used
690 * Features Complete
691 */
692
693 /* If the controller supports the LE Read Local P-256
694 * Public Key command, enable the corresponding event.
695 */
696 if (hdev->commands[34] & 0x02)
697 events[0] |= 0x80; /* LE Read Local P-256
698 * Public Key Complete
699 */
700
701 /* If the controller supports the LE Generate DHKey
702 * command, enable the corresponding event.
703 */
704 if (hdev->commands[34] & 0x04)
705 events[1] |= 0x01; /* LE Generate DHKey Complete */
706
707 /* If the controller supports the LE Set Default PHY or
708 * LE Set PHY commands, enable the corresponding event.
709 */
710 if (hdev->commands[35] & (0x20 | 0x40))
711 events[1] |= 0x08; /* LE PHY Update Complete */
712
713 /* If the controller supports LE Set Extended Scan Parameters
714 * and LE Set Extended Scan Enable commands, enable the
715 * corresponding event.
716 */
717 if (use_ext_scan(hdev))
718 events[1] |= 0x10; /* LE Extended Advertising
719 * Report
720 */
721
722 /* If the controller supports the LE Extended Create Connection
723 * command, enable the corresponding event.
724 */
725 if (use_ext_conn(hdev))
726 events[1] |= 0x02; /* LE Enhanced Connection
727 * Complete
728 */
729
730 /* If the controller supports the LE Extended Advertising
731 * command, enable the corresponding event.
732 */
733 if (ext_adv_capable(hdev))
734 events[2] |= 0x02; /* LE Advertising Set
735 * Terminated
736 */
737
738 hci_req_add(req, HCI_OP_LE_SET_EVENT_MASK, sizeof(events),
739 events);
740
741 /* Read LE Advertising Channel TX Power */
742 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) {
743 /* HCI TS spec forbids mixing of legacy and extended
744 * advertising commands wherein READ_ADV_TX_POWER is
745 * also included. So do not call it if extended adv
746 * is supported otherwise controller will return
747 * COMMAND_DISALLOWED for extended commands.
748 */
749 hci_req_add(req, HCI_OP_LE_READ_ADV_TX_POWER, 0, NULL);
750 }
751
752 if (hdev->commands[26] & 0x40) {
753 /* Read LE White List Size */
754 hci_req_add(req, HCI_OP_LE_READ_WHITE_LIST_SIZE,
755 0, NULL);
756 }
757
758 if (hdev->commands[26] & 0x80) {
759 /* Clear LE White List */
760 hci_req_add(req, HCI_OP_LE_CLEAR_WHITE_LIST, 0, NULL);
761 }
762
763 if (hdev->commands[34] & 0x40) {
764 /* Read LE Resolving List Size */
765 hci_req_add(req, HCI_OP_LE_READ_RESOLV_LIST_SIZE,
766 0, NULL);
767 }
768
769 if (hdev->commands[34] & 0x20) {
770 /* Clear LE Resolving List */
771 hci_req_add(req, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL);
772 }
773
774 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) {
775 /* Read LE Maximum Data Length */
776 hci_req_add(req, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL);
777
778 /* Read LE Suggested Default Data Length */
779 hci_req_add(req, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL);
780 }
781
782 if (ext_adv_capable(hdev)) {
783 /* Read LE Number of Supported Advertising Sets */
784 hci_req_add(req, HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS,
785 0, NULL);
786 }
787
788 hci_set_le_support(req);
789 }
790
791 /* Read features beyond page 1 if available */
792 for (p = 2; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) {
793 struct hci_cp_read_local_ext_features cp;
794
795 cp.page = p;
796 hci_req_add(req, HCI_OP_READ_LOCAL_EXT_FEATURES,
797 sizeof(cp), &cp);
798 }
799
800 return 0;
801 }
802

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org