Skip to content

Commit 161510c

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 1
This make use of hci_cmd_sync_queue for the following MGMT commands: Set Device Class Set Device ID Add UUID Remove UUID tools/mgmt-tester -s "Set Device Class" Test Summary ------------ Set Device Class - Success 1 Passed Set Device Class - Success 2 Passed Set Device Class - Invalid parameters 1 Passed Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0599 seconds tools/mgmt-tester -s "Set Device ID" Test Summary ------------ Set Device ID - Success 1 Passed Set Device ID - Success 2 Passed Set Device ID - Disable Passed Set Device ID - Power off and Power on Passed Set Device ID - SSP off and Power on Passed Set Device ID - Invalid Parameter Passed Total: 6, Passed: 6 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.107 seconds tools/mgmt-tester -s "Add UUID" Test Summary ------------ Add UUID - UUID-16 1 Passed Add UUID - UUID-16 multiple 1 Passed Add UUID - UUID-16 partial 1 Passed Add UUID - UUID-32 1 Passed Add UUID - UUID-32 multiple 1 Passed Add UUID - UUID-32 partial 1 Passed Add UUID - UUID-128 1 Passed Add UUID - UUID-128 multiple 1 Passed Add UUID - UUID-128 partial 1 Passed Add UUID - UUID mix Passed Total: 10, Passed: 10 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.198 seconds tools/mgmt-tester -s "Remove UUID" Test Summary ------------ Remove UUID - Success 1 Passed Remove UUID - All UUID - Success 2 Passed Remove UUID - Power Off - Success 3 Passed Remove UUID - Power Off and On - Success 4 Passed Remove UUID - Not Exist - Invalid Params 1 Passed Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0 Overall execution time: 0.0908 seconds Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 6a98e38 commit 161510c

File tree

7 files changed

+193
-102
lines changed

7 files changed

+193
-102
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ void hci_cmd_sync_clear(struct hci_dev *hdev);
4040

4141
int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
4242
void *data, hci_cmd_sync_work_destroy_t destroy);
43+
44+
int hci_update_eir_sync(struct hci_dev *hdev);
45+
int hci_update_class_sync(struct hci_dev *hdev);

net/bluetooth/hci_request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ int hci_req_run_skb(struct hci_request *req, hci_req_complete_skb_t complete)
9797
return req_run(req, NULL, complete);
9898
}
9999

100-
static void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
101-
struct sk_buff *skb)
100+
void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
101+
struct sk_buff *skb)
102102
{
103103
bt_dev_dbg(hdev, "result 0x%2.2x", result);
104104

net/bluetooth/hci_request.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
#include <asm/unaligned.h>
2424

25+
#define HCI_REQ_DONE 0
26+
#define HCI_REQ_PEND 1
27+
#define HCI_REQ_CANCELED 2
28+
2529
#define hci_req_sync_lock(hdev) mutex_lock(&hdev->req_lock)
2630
#define hci_req_sync_unlock(hdev) mutex_unlock(&hdev->req_lock)
2731

@@ -44,6 +48,8 @@ void hci_req_purge(struct hci_request *req);
4448
bool hci_req_status_pend(struct hci_dev *hdev);
4549
int hci_req_run(struct hci_request *req, hci_req_complete_t complete);
4650
int hci_req_run_skb(struct hci_request *req, hci_req_complete_skb_t complete);
51+
void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
52+
struct sk_buff *skb);
4753
void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
4854
const void *param);
4955
void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,

net/bluetooth/hci_sync.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "hci_request.h"
1313
#include "smp.h"
14+
#include "eir.h"
1415

1516
static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
1617
struct sk_buff *skb)
@@ -328,3 +329,74 @@ int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
328329
return 0;
329330
}
330331
EXPORT_SYMBOL(hci_cmd_sync_queue);
332+
333+
int hci_update_eir_sync(struct hci_dev *hdev)
334+
{
335+
struct hci_cp_write_eir cp;
336+
337+
bt_dev_dbg(hdev, "");
338+
339+
if (!hdev_is_powered(hdev))
340+
return 0;
341+
342+
if (!lmp_ext_inq_capable(hdev))
343+
return 0;
344+
345+
if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED))
346+
return 0;
347+
348+
if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE))
349+
return 0;
350+
351+
memset(&cp, 0, sizeof(cp));
352+
353+
eir_create(hdev, cp.data);
354+
355+
if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0)
356+
return 0;
357+
358+
memcpy(hdev->eir, cp.data, sizeof(cp.data));
359+
360+
return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp,
361+
HCI_CMD_TIMEOUT);
362+
}
363+
364+
static u8 get_service_classes(struct hci_dev *hdev)
365+
{
366+
struct bt_uuid *uuid;
367+
u8 val = 0;
368+
369+
list_for_each_entry(uuid, &hdev->uuids, list)
370+
val |= uuid->svc_hint;
371+
372+
return val;
373+
}
374+
375+
int hci_update_class_sync(struct hci_dev *hdev)
376+
{
377+
u8 cod[3];
378+
379+
bt_dev_dbg(hdev, "");
380+
381+
if (!hdev_is_powered(hdev))
382+
return 0;
383+
384+
if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
385+
return 0;
386+
387+
if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE))
388+
return 0;
389+
390+
cod[0] = hdev->minor_class;
391+
cod[1] = hdev->major_class;
392+
cod[2] = get_service_classes(hdev);
393+
394+
if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE))
395+
cod[1] |= 0x20;
396+
397+
if (memcmp(cod, hdev->dev_class, 3) == 0)
398+
return 0;
399+
400+
return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CLASS_OF_DEV,
401+
sizeof(cod), cod, HCI_CMD_TIMEOUT);
402+
}

0 commit comments

Comments
 (0)