@@ -650,6 +650,96 @@ static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev)
650650 return false;
651651}
652652
653+ static void set_random_addr (struct hci_request * req , bdaddr_t * rpa );
654+ static int hci_update_random_address (struct hci_request * req ,
655+ bool require_privacy , bool use_rpa ,
656+ u8 * own_addr_type )
657+ {
658+ struct hci_dev * hdev = req -> hdev ;
659+ int err ;
660+
661+ /* If privacy is enabled use a resolvable private address. If
662+ * current RPA has expired or there is something else than
663+ * the current RPA in use, then generate a new one.
664+ */
665+ if (use_rpa ) {
666+ /* If Controller supports LL Privacy use own address type is
667+ * 0x03
668+ */
669+ if (use_ll_privacy (hdev ))
670+ * own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED ;
671+ else
672+ * own_addr_type = ADDR_LE_DEV_RANDOM ;
673+
674+ if (rpa_valid (hdev ))
675+ return 0 ;
676+
677+ err = smp_generate_rpa (hdev , hdev -> irk , & hdev -> rpa );
678+ if (err < 0 ) {
679+ bt_dev_err (hdev , "failed to generate new RPA" );
680+ return err ;
681+ }
682+
683+ set_random_addr (req , & hdev -> rpa );
684+
685+ return 0 ;
686+ }
687+
688+ /* In case of required privacy without resolvable private address,
689+ * use an non-resolvable private address. This is useful for active
690+ * scanning and non-connectable advertising.
691+ */
692+ if (require_privacy ) {
693+ bdaddr_t nrpa ;
694+
695+ while (true) {
696+ /* The non-resolvable private address is generated
697+ * from random six bytes with the two most significant
698+ * bits cleared.
699+ */
700+ get_random_bytes (& nrpa , 6 );
701+ nrpa .b [5 ] &= 0x3f ;
702+
703+ /* The non-resolvable private address shall not be
704+ * equal to the public address.
705+ */
706+ if (bacmp (& hdev -> bdaddr , & nrpa ))
707+ break ;
708+ }
709+
710+ * own_addr_type = ADDR_LE_DEV_RANDOM ;
711+ set_random_addr (req , & nrpa );
712+ return 0 ;
713+ }
714+
715+ /* If forcing static address is in use or there is no public
716+ * address use the static address as random address (but skip
717+ * the HCI command if the current random address is already the
718+ * static one.
719+ *
720+ * In case BR/EDR has been disabled on a dual-mode controller
721+ * and a static address has been configured, then use that
722+ * address instead of the public BR/EDR address.
723+ */
724+ if (hci_dev_test_flag (hdev , HCI_FORCE_STATIC_ADDR ) ||
725+ !bacmp (& hdev -> bdaddr , BDADDR_ANY ) ||
726+ (!hci_dev_test_flag (hdev , HCI_BREDR_ENABLED ) &&
727+ bacmp (& hdev -> static_addr , BDADDR_ANY ))) {
728+ * own_addr_type = ADDR_LE_DEV_RANDOM ;
729+ if (bacmp (& hdev -> static_addr , & hdev -> random_addr ))
730+ hci_req_add (req , HCI_OP_LE_SET_RANDOM_ADDR , 6 ,
731+ & hdev -> static_addr );
732+ return 0 ;
733+ }
734+
735+ /* Neither privacy nor static address is being used so use a
736+ * public address.
737+ */
738+ * own_addr_type = ADDR_LE_DEV_PUBLIC ;
739+
740+ return 0 ;
741+ }
742+
653743/* Ensure to call hci_req_add_le_scan_disable() first to disable the
654744 * controller based address resolution to be able to reconfigure
655745 * resolving list.
@@ -859,79 +949,6 @@ static void interleave_scan_work(struct work_struct *work)
859949 & hdev -> interleave_scan , timeout );
860950}
861951
862- int hci_get_random_address (struct hci_dev * hdev , bool require_privacy ,
863- bool use_rpa , struct adv_info * adv_instance ,
864- u8 * own_addr_type , bdaddr_t * rand_addr )
865- {
866- int err ;
867-
868- bacpy (rand_addr , BDADDR_ANY );
869-
870- /* If privacy is enabled use a resolvable private address. If
871- * current RPA has expired then generate a new one.
872- */
873- if (use_rpa ) {
874- /* If Controller supports LL Privacy use own address type is
875- * 0x03
876- */
877- if (use_ll_privacy (hdev ))
878- * own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED ;
879- else
880- * own_addr_type = ADDR_LE_DEV_RANDOM ;
881-
882- if (adv_instance ) {
883- if (adv_rpa_valid (adv_instance ))
884- return 0 ;
885- } else {
886- if (rpa_valid (hdev ))
887- return 0 ;
888- }
889-
890- err = smp_generate_rpa (hdev , hdev -> irk , & hdev -> rpa );
891- if (err < 0 ) {
892- bt_dev_err (hdev , "failed to generate new RPA" );
893- return err ;
894- }
895-
896- bacpy (rand_addr , & hdev -> rpa );
897-
898- return 0 ;
899- }
900-
901- /* In case of required privacy without resolvable private address,
902- * use an non-resolvable private address. This is useful for
903- * non-connectable advertising.
904- */
905- if (require_privacy ) {
906- bdaddr_t nrpa ;
907-
908- while (true) {
909- /* The non-resolvable private address is generated
910- * from random six bytes with the two most significant
911- * bits cleared.
912- */
913- get_random_bytes (& nrpa , 6 );
914- nrpa .b [5 ] &= 0x3f ;
915-
916- /* The non-resolvable private address shall not be
917- * equal to the public address.
918- */
919- if (bacmp (& hdev -> bdaddr , & nrpa ))
920- break ;
921- }
922-
923- * own_addr_type = ADDR_LE_DEV_RANDOM ;
924- bacpy (rand_addr , & nrpa );
925-
926- return 0 ;
927- }
928-
929- /* No privacy so use a public address. */
930- * own_addr_type = ADDR_LE_DEV_PUBLIC ;
931-
932- return 0 ;
933- }
934-
935952static void set_random_addr (struct hci_request * req , bdaddr_t * rpa )
936953{
937954 struct hci_dev * hdev = req -> hdev ;
@@ -956,96 +973,8 @@ static void set_random_addr(struct hci_request *req, bdaddr_t *rpa)
956973 hci_req_add (req , HCI_OP_LE_SET_RANDOM_ADDR , 6 , rpa );
957974}
958975
959- int hci_update_random_address (struct hci_request * req , bool require_privacy ,
960- bool use_rpa , u8 * own_addr_type )
961- {
962- struct hci_dev * hdev = req -> hdev ;
963- int err ;
964-
965- /* If privacy is enabled use a resolvable private address. If
966- * current RPA has expired or there is something else than
967- * the current RPA in use, then generate a new one.
968- */
969- if (use_rpa ) {
970- /* If Controller supports LL Privacy use own address type is
971- * 0x03
972- */
973- if (use_ll_privacy (hdev ))
974- * own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED ;
975- else
976- * own_addr_type = ADDR_LE_DEV_RANDOM ;
977-
978- if (rpa_valid (hdev ))
979- return 0 ;
980-
981- err = smp_generate_rpa (hdev , hdev -> irk , & hdev -> rpa );
982- if (err < 0 ) {
983- bt_dev_err (hdev , "failed to generate new RPA" );
984- return err ;
985- }
986-
987- set_random_addr (req , & hdev -> rpa );
988-
989- return 0 ;
990- }
991-
992- /* In case of required privacy without resolvable private address,
993- * use an non-resolvable private address. This is useful for active
994- * scanning and non-connectable advertising.
995- */
996- if (require_privacy ) {
997- bdaddr_t nrpa ;
998-
999- while (true) {
1000- /* The non-resolvable private address is generated
1001- * from random six bytes with the two most significant
1002- * bits cleared.
1003- */
1004- get_random_bytes (& nrpa , 6 );
1005- nrpa .b [5 ] &= 0x3f ;
1006-
1007- /* The non-resolvable private address shall not be
1008- * equal to the public address.
1009- */
1010- if (bacmp (& hdev -> bdaddr , & nrpa ))
1011- break ;
1012- }
1013-
1014- * own_addr_type = ADDR_LE_DEV_RANDOM ;
1015- set_random_addr (req , & nrpa );
1016- return 0 ;
1017- }
1018-
1019- /* If forcing static address is in use or there is no public
1020- * address use the static address as random address (but skip
1021- * the HCI command if the current random address is already the
1022- * static one.
1023- *
1024- * In case BR/EDR has been disabled on a dual-mode controller
1025- * and a static address has been configured, then use that
1026- * address instead of the public BR/EDR address.
1027- */
1028- if (hci_dev_test_flag (hdev , HCI_FORCE_STATIC_ADDR ) ||
1029- !bacmp (& hdev -> bdaddr , BDADDR_ANY ) ||
1030- (!hci_dev_test_flag (hdev , HCI_BREDR_ENABLED ) &&
1031- bacmp (& hdev -> static_addr , BDADDR_ANY ))) {
1032- * own_addr_type = ADDR_LE_DEV_RANDOM ;
1033- if (bacmp (& hdev -> static_addr , & hdev -> random_addr ))
1034- hci_req_add (req , HCI_OP_LE_SET_RANDOM_ADDR , 6 ,
1035- & hdev -> static_addr );
1036- return 0 ;
1037- }
1038-
1039- /* Neither privacy nor static address is being used so use a
1040- * public address.
1041- */
1042- * own_addr_type = ADDR_LE_DEV_PUBLIC ;
1043-
1044- return 0 ;
1045- }
1046-
1047- void __hci_abort_conn (struct hci_request * req , struct hci_conn * conn ,
1048- u8 reason )
976+ static void __hci_abort_conn (struct hci_request * req , struct hci_conn * conn ,
977+ u8 reason )
1049978{
1050979 switch (conn -> state ) {
1051980 case BT_CONNECTED :
0 commit comments