···38753875 "advertised, but not supported.")38763876};3877387738783878-int hci_dev_open_sync(struct hci_dev *hdev)38783878+/* This function handles hdev setup stage:38793879+ *38803880+ * Calls hdev->setup38813881+ * Setup address if HCI_QUIRK_USE_BDADDR_PROPERTY is set.38823882+ */38833883+static int hci_dev_setup_sync(struct hci_dev *hdev)38793884{38803885 int ret = 0;38863886+ bool invalid_bdaddr;38873887+ size_t i;38883888+38893889+ if (!hci_dev_test_flag(hdev, HCI_SETUP) &&38903890+ !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks))38913891+ return 0;38923892+38933893+ bt_dev_dbg(hdev, "");38943894+38953895+ hci_sock_dev_event(hdev, HCI_DEV_SETUP);38963896+38973897+ if (hdev->setup)38983898+ ret = hdev->setup(hdev);38993899+39003900+ for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) {39013901+ if (test_bit(hci_broken_table[i].quirk, &hdev->quirks))39023902+ bt_dev_warn(hdev, "%s", hci_broken_table[i].desc);39033903+ }39043904+39053905+ /* The transport driver can set the quirk to mark the39063906+ * BD_ADDR invalid before creating the HCI device or in39073907+ * its setup callback.39083908+ */39093909+ invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);39103910+39113911+ if (!ret) {39123912+ if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) {39133913+ if (!bacmp(&hdev->public_addr, BDADDR_ANY))39143914+ hci_dev_get_bd_addr_from_property(hdev);39153915+39163916+ if (bacmp(&hdev->public_addr, BDADDR_ANY) &&39173917+ hdev->set_bdaddr) {39183918+ ret = hdev->set_bdaddr(hdev,39193919+ &hdev->public_addr);39203920+39213921+ /* If setting of the BD_ADDR from the device39223922+ * property succeeds, then treat the address39233923+ * as valid even if the invalid BD_ADDR39243924+ * quirk indicates otherwise.39253925+ */39263926+ if (!ret)39273927+ invalid_bdaddr = false;39283928+ }39293929+ }39303930+ }39313931+39323932+ /* The transport driver can set these quirks before39333933+ * creating the HCI device or in its setup callback.39343934+ *39353935+ * For the invalid BD_ADDR quirk it is possible that39363936+ * it becomes a valid address if the bootloader does39373937+ * provide it (see above).39383938+ *39393939+ * In case any of them is set, the controller has to39403940+ * start up as unconfigured.39413941+ */39423942+ if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) ||39433943+ invalid_bdaddr)39443944+ hci_dev_set_flag(hdev, HCI_UNCONFIGURED);39453945+39463946+ /* For an unconfigured controller it is required to39473947+ * read at least the version information provided by39483948+ * the Read Local Version Information command.39493949+ *39503950+ * If the set_bdaddr driver callback is provided, then39513951+ * also the original Bluetooth public device address39523952+ * will be read using the Read BD Address command.39533953+ */39543954+ if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))39553955+ return hci_unconf_init_sync(hdev);39563956+39573957+ return ret;39583958+}39593959+39603960+/* This function handles hdev init stage:39613961+ *39623962+ * Calls hci_dev_setup_sync to perform setup stage39633963+ * Calls hci_init_sync to perform HCI command init sequence39643964+ */39653965+static int hci_dev_init_sync(struct hci_dev *hdev)39663966+{39673967+ int ret;39683968+39693969+ bt_dev_dbg(hdev, "");39703970+39713971+ atomic_set(&hdev->cmd_cnt, 1);39723972+ set_bit(HCI_INIT, &hdev->flags);39733973+39743974+ ret = hci_dev_setup_sync(hdev);39753975+39763976+ if (hci_dev_test_flag(hdev, HCI_CONFIG)) {39773977+ /* If public address change is configured, ensure that39783978+ * the address gets programmed. If the driver does not39793979+ * support changing the public address, fail the power39803980+ * on procedure.39813981+ */39823982+ if (bacmp(&hdev->public_addr, BDADDR_ANY) &&39833983+ hdev->set_bdaddr)39843984+ ret = hdev->set_bdaddr(hdev, &hdev->public_addr);39853985+ else39863986+ ret = -EADDRNOTAVAIL;39873987+ }39883988+39893989+ if (!ret) {39903990+ if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&39913991+ !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {39923992+ ret = hci_init_sync(hdev);39933993+ if (!ret && hdev->post_init)39943994+ ret = hdev->post_init(hdev);39953995+ }39963996+ }39973997+39983998+ /* If the HCI Reset command is clearing all diagnostic settings,39993999+ * then they need to be reprogrammed after the init procedure40004000+ * completed.40014001+ */40024002+ if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) &&40034003+ !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&40044004+ hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag)40054005+ ret = hdev->set_diag(hdev, true);40064006+40074007+ if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {40084008+ msft_do_open(hdev);40094009+ aosp_do_open(hdev);40104010+ }40114011+40124012+ clear_bit(HCI_INIT, &hdev->flags);40134013+40144014+ return ret;40154015+}40164016+40174017+int hci_dev_open_sync(struct hci_dev *hdev)40184018+{40194019+ int ret;3881402038824021 bt_dev_dbg(hdev, "");38834022···40693930 set_bit(HCI_RUNNING, &hdev->flags);40703931 hci_sock_dev_event(hdev, HCI_DEV_OPEN);4071393240724072- atomic_set(&hdev->cmd_cnt, 1);40734073- set_bit(HCI_INIT, &hdev->flags);40744074-40754075- if (hci_dev_test_flag(hdev, HCI_SETUP) ||40764076- test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) {40774077- bool invalid_bdaddr;40784078- size_t i;40794079-40804080- hci_sock_dev_event(hdev, HCI_DEV_SETUP);40814081-40824082- if (hdev->setup)40834083- ret = hdev->setup(hdev);40844084-40854085- for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) {40864086- if (test_bit(hci_broken_table[i].quirk, &hdev->quirks))40874087- bt_dev_warn(hdev, "%s",40884088- hci_broken_table[i].desc);40894089- }40904090-40914091- /* The transport driver can set the quirk to mark the40924092- * BD_ADDR invalid before creating the HCI device or in40934093- * its setup callback.40944094- */40954095- invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR,40964096- &hdev->quirks);40974097-40984098- if (ret)40994099- goto setup_failed;41004100-41014101- if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) {41024102- if (!bacmp(&hdev->public_addr, BDADDR_ANY))41034103- hci_dev_get_bd_addr_from_property(hdev);41044104-41054105- if (bacmp(&hdev->public_addr, BDADDR_ANY) &&41064106- hdev->set_bdaddr) {41074107- ret = hdev->set_bdaddr(hdev,41084108- &hdev->public_addr);41094109-41104110- /* If setting of the BD_ADDR from the device41114111- * property succeeds, then treat the address41124112- * as valid even if the invalid BD_ADDR41134113- * quirk indicates otherwise.41144114- */41154115- if (!ret)41164116- invalid_bdaddr = false;41174117- }41184118- }41194119-41204120-setup_failed:41214121- /* The transport driver can set these quirks before41224122- * creating the HCI device or in its setup callback.41234123- *41244124- * For the invalid BD_ADDR quirk it is possible that41254125- * it becomes a valid address if the bootloader does41264126- * provide it (see above).41274127- *41284128- * In case any of them is set, the controller has to41294129- * start up as unconfigured.41304130- */41314131- if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) ||41324132- invalid_bdaddr)41334133- hci_dev_set_flag(hdev, HCI_UNCONFIGURED);41344134-41354135- /* For an unconfigured controller it is required to41364136- * read at least the version information provided by41374137- * the Read Local Version Information command.41384138- *41394139- * If the set_bdaddr driver callback is provided, then41404140- * also the original Bluetooth public device address41414141- * will be read using the Read BD Address command.41424142- */41434143- if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))41444144- ret = hci_unconf_init_sync(hdev);41454145- }41464146-41474147- if (hci_dev_test_flag(hdev, HCI_CONFIG)) {41484148- /* If public address change is configured, ensure that41494149- * the address gets programmed. If the driver does not41504150- * support changing the public address, fail the power41514151- * on procedure.41524152- */41534153- if (bacmp(&hdev->public_addr, BDADDR_ANY) &&41544154- hdev->set_bdaddr)41554155- ret = hdev->set_bdaddr(hdev, &hdev->public_addr);41564156- else41574157- ret = -EADDRNOTAVAIL;41584158- }41594159-41604160- if (!ret) {41614161- if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&41624162- !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {41634163- ret = hci_init_sync(hdev);41644164- if (!ret && hdev->post_init)41654165- ret = hdev->post_init(hdev);41664166- }41674167- }41684168-41694169- /* If the HCI Reset command is clearing all diagnostic settings,41704170- * then they need to be reprogrammed after the init procedure41714171- * completed.41724172- */41734173- if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) &&41744174- !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&41754175- hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag)41764176- ret = hdev->set_diag(hdev, true);41774177-41784178- if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {41794179- msft_do_open(hdev);41804180- aosp_do_open(hdev);41814181- }41824182-41834183- clear_bit(HCI_INIT, &hdev->flags);41844184-39333933+ ret = hci_dev_init_sync(hdev);41853934 if (!ret) {41863935 hci_dev_hold(hdev);41873936 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);