Skip to content

Commit

Permalink
Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME
Browse files Browse the repository at this point in the history
Uses existing *_sync functions, but made hci_update_name_sync
non-static.

mgmt-test paths:
Set Advertising on - Local name 1
Set Advertising on - Name + Appear 1
Set Local Name - Success 1
Set Local Name - Success 2
Set Local Name - Success 3
Add Advertising - Success (Empty ScRsp)
Add Advertising - Success (Complete name)
Add Advertising - Success (Shortened name)
Add Advertising - Success (Short name)
Add Advertising - Success (Name + data)
Add Advertising - Invalid Params (Name + data)
Add Advertising - Success (Name+data+appear)
Read Ext Controller Info 3
Read Ext Controller Info 4
Read Ext Controller Info 5
Add Ext Advertising - Success (Empty ScRsp)
Add Ext Advertising - Success (Complete name)
Add Ext Advertising - Success (Shortened name)
Add Ext Advertising - Success (Short name)
Add Ext Advertising - Success (Name + data)
Add Ext Advertising - Invalid Params (Name + data)
Add Ext Advertising - Success (Name+data+appear)

Signed-off-by: Brian Gix <brian.gix@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Brian Gix authored and Marcel Holtmann committed Oct 29, 2021
1 parent 177e77a commit 6f6ff38
Showing 3 changed files with 34 additions and 34 deletions.
1 change: 1 addition & 0 deletions include/net/bluetooth/hci_sync.h
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ int hci_update_class_sync(struct hci_dev *hdev);

int hci_update_eir_sync(struct hci_dev *hdev);
int hci_update_class_sync(struct hci_dev *hdev);
int hci_update_name_sync(struct hci_dev *hdev);

int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy,
bool rpa, u8 *own_addr_type);
2 changes: 1 addition & 1 deletion net/bluetooth/hci_sync.c
Original file line number Diff line number Diff line change
@@ -2341,7 +2341,7 @@ int hci_update_scan_sync(struct hci_dev *hdev)
return hci_write_scan_enable_sync(hdev, scan);
}

static int hci_update_name_sync(struct hci_dev *hdev)
int hci_update_name_sync(struct hci_dev *hdev)
{
struct hci_cp_write_local_name cp;

65 changes: 32 additions & 33 deletions net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
@@ -3246,24 +3246,17 @@ static void adv_expire(struct hci_dev *hdev, u32 flags)
hci_req_run(&req, NULL);
}

static void set_name_complete(struct hci_dev *hdev, u8 status, u16 opcode)
static void set_name_complete(struct hci_dev *hdev, void *data, int err)
{
struct mgmt_cp_set_local_name *cp;
struct mgmt_pending_cmd *cmd;

bt_dev_dbg(hdev, "status 0x%02x", status);

hci_dev_lock(hdev);

cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev);
if (!cmd)
goto unlock;
struct mgmt_pending_cmd *cmd = data;
struct mgmt_cp_set_local_name *cp = cmd->param;
u8 status = mgmt_status(err);

cp = cmd->param;
bt_dev_dbg(hdev, "err %d", err);

if (status) {
mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
mgmt_status(status));
status);
} else {
mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0,
cp, sizeof(*cp));
@@ -3273,17 +3266,29 @@ static void set_name_complete(struct hci_dev *hdev, u8 status, u16 opcode)
}

mgmt_pending_remove(cmd);
}

unlock:
hci_dev_unlock(hdev);
static int set_name_sync(struct hci_dev *hdev, void *data)
{
if (lmp_bredr_capable(hdev)) {
hci_update_name_sync(hdev);
hci_update_eir_sync(hdev);
}

/* The name is stored in the scan response data and so
* no need to update the advertising data here.
*/
if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING))
hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance);

return 0;
}

static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
u16 len)
{
struct mgmt_cp_set_local_name *cp = data;
struct mgmt_pending_cmd *cmd;
struct hci_request req;
int err;

bt_dev_dbg(hdev, "sock %p", sk);
@@ -3319,29 +3324,23 @@ static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
}

cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len);
if (!cmd) {
if (!cmd)
err = -ENOMEM;
goto failed;
}
else
err = hci_cmd_sync_queue(hdev, set_name_sync, cmd,
set_name_complete);

memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name));
if (err < 0) {
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
MGMT_STATUS_FAILED);

hci_req_init(&req, hdev);
if (cmd)
mgmt_pending_remove(cmd);

if (lmp_bredr_capable(hdev)) {
__hci_req_update_name(&req);
__hci_req_update_eir(&req);
goto failed;
}

/* The name is stored in the scan response data and so
* no need to update the advertising data here.
*/
if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING))
__hci_req_update_scan_rsp_data(&req, hdev->cur_adv_instance);

err = hci_req_run(&req, set_name_complete);
if (err < 0)
mgmt_pending_remove(cmd);
memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name));

failed:
hci_dev_unlock(hdev);

0 comments on commit 6f6ff38

Please sign in to comment.