@@ -91,6 +91,7 @@ static const u16 mgmt_commands[] = {
9191 MGMT_OP_LOAD_CONN_PARAM ,
9292 MGMT_OP_READ_UNCONF_INDEX_LIST ,
9393 MGMT_OP_READ_CONFIG_INFO ,
94+ MGMT_OP_SET_EXTERNAL_CONFIG ,
9495};
9596
9697static const u16 mgmt_events [] = {
@@ -441,11 +442,25 @@ static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev,
441442 return err ;
442443}
443444
445+ static bool is_configured (struct hci_dev * hdev )
446+ {
447+ if (test_bit (HCI_QUIRK_EXTERNAL_CONFIG , & hdev -> quirks ) &&
448+ !test_bit (HCI_EXT_CONFIGURED , & hdev -> dev_flags ))
449+ return false;
450+
451+ if (test_bit (HCI_QUIRK_INVALID_BDADDR , & hdev -> quirks ) &&
452+ !bacmp (& hdev -> public_addr , BDADDR_ANY ))
453+ return false;
454+
455+ return true;
456+ }
457+
444458static __le32 get_missing_options (struct hci_dev * hdev )
445459{
446460 u32 options = 0 ;
447461
448- if (test_bit (HCI_QUIRK_EXTERNAL_CONFIG , & hdev -> quirks ))
462+ if (test_bit (HCI_QUIRK_EXTERNAL_CONFIG , & hdev -> quirks ) &&
463+ !test_bit (HCI_EXT_CONFIGURED , & hdev -> dev_flags ))
449464 options |= MGMT_OPTION_EXTERNAL_CONFIG ;
450465
451466 if (test_bit (HCI_QUIRK_INVALID_BDADDR , & hdev -> quirks ) &&
@@ -455,6 +470,14 @@ static __le32 get_missing_options(struct hci_dev *hdev)
455470 return cpu_to_le32 (options );
456471}
457472
473+ static int send_options_rsp (struct sock * sk , u16 opcode , struct hci_dev * hdev )
474+ {
475+ __le32 options = get_missing_options (hdev );
476+
477+ return cmd_complete (sk , hdev -> id , opcode , 0 , & options ,
478+ sizeof (options ));
479+ }
480+
458481static int read_config_info (struct sock * sk , struct hci_dev * hdev ,
459482 void * data , u16 data_len )
460483{
@@ -5355,6 +5378,54 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
53555378 return cmd_complete (sk , hdev -> id , MGMT_OP_LOAD_CONN_PARAM , 0 , NULL , 0 );
53565379}
53575380
5381+ static int set_external_config (struct sock * sk , struct hci_dev * hdev ,
5382+ void * data , u16 len )
5383+ {
5384+ struct mgmt_cp_set_external_config * cp = data ;
5385+ bool changed ;
5386+ int err ;
5387+
5388+ BT_DBG ("%s" , hdev -> name );
5389+
5390+ if (hdev_is_powered (hdev ))
5391+ return cmd_status (sk , hdev -> id , MGMT_OP_SET_EXTERNAL_CONFIG ,
5392+ MGMT_STATUS_REJECTED );
5393+
5394+ if (cp -> config != 0x00 && cp -> config != 0x01 )
5395+ return cmd_status (sk , hdev -> id , MGMT_OP_SET_EXTERNAL_CONFIG ,
5396+ MGMT_STATUS_INVALID_PARAMS );
5397+
5398+ if (!test_bit (HCI_QUIRK_EXTERNAL_CONFIG , & hdev -> quirks ))
5399+ return cmd_status (sk , hdev -> id , MGMT_OP_SET_EXTERNAL_CONFIG ,
5400+ MGMT_STATUS_NOT_SUPPORTED );
5401+
5402+ hci_dev_lock (hdev );
5403+
5404+ if (cp -> config )
5405+ changed = !test_and_set_bit (HCI_EXT_CONFIGURED ,
5406+ & hdev -> dev_flags );
5407+ else
5408+ changed = test_and_clear_bit (HCI_EXT_CONFIGURED ,
5409+ & hdev -> dev_flags );
5410+
5411+ err = send_options_rsp (sk , MGMT_OP_SET_EXTERNAL_CONFIG , hdev );
5412+ if (err < 0 )
5413+ goto unlock ;
5414+
5415+ if (!changed )
5416+ goto unlock ;
5417+
5418+ if (test_bit (HCI_UNCONFIGURED , & hdev -> dev_flags ) == is_configured (hdev )) {
5419+ mgmt_index_removed (hdev );
5420+ change_bit (HCI_UNCONFIGURED , & hdev -> dev_flags );
5421+ mgmt_index_added (hdev );
5422+ }
5423+
5424+ unlock :
5425+ hci_dev_unlock (hdev );
5426+ return err ;
5427+ }
5428+
53585429static const struct mgmt_handler {
53595430 int (* func ) (struct sock * sk , struct hci_dev * hdev , void * data ,
53605431 u16 data_len );
@@ -5417,6 +5488,7 @@ static const struct mgmt_handler {
54175488 { load_conn_param , true, MGMT_LOAD_CONN_PARAM_SIZE },
54185489 { read_unconf_index_list , false, MGMT_READ_UNCONF_INDEX_LIST_SIZE },
54195490 { read_config_info , false, MGMT_READ_CONFIG_INFO_SIZE },
5491+ { set_external_config , false, MGMT_SET_EXTERNAL_CONFIG_SIZE },
54205492};
54215493
54225494int mgmt_control (struct sock * sk , struct msghdr * msg , size_t msglen )
@@ -5469,7 +5541,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
54695541 }
54705542
54715543 if (test_bit (HCI_UNCONFIGURED , & hdev -> dev_flags ) &&
5472- opcode != MGMT_OP_READ_CONFIG_INFO ) {
5544+ opcode != MGMT_OP_READ_CONFIG_INFO &&
5545+ opcode != MGMT_OP_SET_EXTERNAL_CONFIG ) {
54735546 err = cmd_status (sk , index , opcode ,
54745547 MGMT_STATUS_INVALID_INDEX );
54755548 goto done ;
0 commit comments