Skip to content

Commit 6f6ff38

Browse files
bgixholtmann
authored andcommitted
Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME
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>
1 parent 177e77a commit 6f6ff38

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ int hci_update_class_sync(struct hci_dev *hdev);
4646

4747
int hci_update_eir_sync(struct hci_dev *hdev);
4848
int hci_update_class_sync(struct hci_dev *hdev);
49+
int hci_update_name_sync(struct hci_dev *hdev);
4950

5051
int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy,
5152
bool rpa, u8 *own_addr_type);

net/bluetooth/hci_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ int hci_update_scan_sync(struct hci_dev *hdev)
23412341
return hci_write_scan_enable_sync(hdev, scan);
23422342
}
23432343

2344-
static int hci_update_name_sync(struct hci_dev *hdev)
2344+
int hci_update_name_sync(struct hci_dev *hdev)
23452345
{
23462346
struct hci_cp_write_local_name cp;
23472347

net/bluetooth/mgmt.c

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,24 +3246,17 @@ static void adv_expire(struct hci_dev *hdev, u32 flags)
32463246
hci_req_run(&req, NULL);
32473247
}
32483248

3249-
static void set_name_complete(struct hci_dev *hdev, u8 status, u16 opcode)
3249+
static void set_name_complete(struct hci_dev *hdev, void *data, int err)
32503250
{
3251-
struct mgmt_cp_set_local_name *cp;
3252-
struct mgmt_pending_cmd *cmd;
3253-
3254-
bt_dev_dbg(hdev, "status 0x%02x", status);
3255-
3256-
hci_dev_lock(hdev);
3257-
3258-
cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev);
3259-
if (!cmd)
3260-
goto unlock;
3251+
struct mgmt_pending_cmd *cmd = data;
3252+
struct mgmt_cp_set_local_name *cp = cmd->param;
3253+
u8 status = mgmt_status(err);
32613254

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

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

32753268
mgmt_pending_remove(cmd);
3269+
}
32763270

3277-
unlock:
3278-
hci_dev_unlock(hdev);
3271+
static int set_name_sync(struct hci_dev *hdev, void *data)
3272+
{
3273+
if (lmp_bredr_capable(hdev)) {
3274+
hci_update_name_sync(hdev);
3275+
hci_update_eir_sync(hdev);
3276+
}
3277+
3278+
/* The name is stored in the scan response data and so
3279+
* no need to update the advertising data here.
3280+
*/
3281+
if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING))
3282+
hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance);
3283+
3284+
return 0;
32793285
}
32803286

32813287
static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
32823288
u16 len)
32833289
{
32843290
struct mgmt_cp_set_local_name *cp = data;
32853291
struct mgmt_pending_cmd *cmd;
3286-
struct hci_request req;
32873292
int err;
32883293

32893294
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,
33193324
}
33203325

33213326
cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len);
3322-
if (!cmd) {
3327+
if (!cmd)
33233328
err = -ENOMEM;
3324-
goto failed;
3325-
}
3329+
else
3330+
err = hci_cmd_sync_queue(hdev, set_name_sync, cmd,
3331+
set_name_complete);
33263332

3327-
memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name));
3333+
if (err < 0) {
3334+
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
3335+
MGMT_STATUS_FAILED);
33283336

3329-
hci_req_init(&req, hdev);
3337+
if (cmd)
3338+
mgmt_pending_remove(cmd);
33303339

3331-
if (lmp_bredr_capable(hdev)) {
3332-
__hci_req_update_name(&req);
3333-
__hci_req_update_eir(&req);
3340+
goto failed;
33343341
}
33353342

3336-
/* The name is stored in the scan response data and so
3337-
* no need to update the advertising data here.
3338-
*/
3339-
if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING))
3340-
__hci_req_update_scan_rsp_data(&req, hdev->cur_adv_instance);
3341-
3342-
err = hci_req_run(&req, set_name_complete);
3343-
if (err < 0)
3344-
mgmt_pending_remove(cmd);
3343+
memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name));
33453344

33463345
failed:
33473346
hci_dev_unlock(hdev);

0 commit comments

Comments
 (0)