Skip to content

Commit

Permalink
Bluetooth: hci_sync: Convert MGMT_OP_SET_PHY_CONFIGURATION
Browse files Browse the repository at this point in the history
mgmt-test paths:
Set PHY 2m Success
Set PHY coded Succcess
Set PHY 1m 2m coded Succcess
Set PHY 2m tx success
Set PHY 2m rx success
Set PHY Invalid Param
Start Discovery - (2m, Scan Param)
Start Discovery - (coded, Scan Param)
Start Discovery - (1m, 2m, coded, Scan Param)

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 6f6ff38 commit 71efbb0
Showing 1 changed file with 66 additions and 50 deletions.
116 changes: 66 additions & 50 deletions net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3414,23 +3414,26 @@ int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip)
sizeof(ev), skip);
}

static void set_default_phy_complete(struct hci_dev *hdev, u8 status,
u16 opcode, struct sk_buff *skb)
static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err)
{
struct mgmt_pending_cmd *cmd;

bt_dev_dbg(hdev, "status 0x%02x", status);
struct mgmt_pending_cmd *cmd = data;
struct sk_buff *skb = cmd->skb;
u8 status = mgmt_status(err);

hci_dev_lock(hdev);
if (!status) {
if (!skb)
status = MGMT_STATUS_FAILED;
else if (IS_ERR(skb))
status = mgmt_status(PTR_ERR(skb));
else
status = mgmt_status(skb->data[0]);
}

cmd = pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev);
if (!cmd)
goto unlock;
bt_dev_dbg(hdev, "status %d", status);

if (status) {
mgmt_cmd_status(cmd->sk, hdev->id,
MGMT_OP_SET_PHY_CONFIGURATION,
mgmt_status(status));
MGMT_OP_SET_PHY_CONFIGURATION, status);
} else {
mgmt_cmd_complete(cmd->sk, hdev->id,
MGMT_OP_SET_PHY_CONFIGURATION, 0,
Expand All @@ -3439,19 +3442,56 @@ static void set_default_phy_complete(struct hci_dev *hdev, u8 status,
mgmt_phy_configuration_changed(hdev, cmd->sk);
}

if (skb && !IS_ERR(skb))
kfree_skb(skb);

mgmt_pending_remove(cmd);
}

unlock:
hci_dev_unlock(hdev);
static int set_default_phy_sync(struct hci_dev *hdev, void *data)
{
struct mgmt_pending_cmd *cmd = data;
struct mgmt_cp_set_phy_configuration *cp = cmd->param;
struct hci_cp_le_set_default_phy cp_phy;
u32 selected_phys = __le32_to_cpu(cp->selected_phys);

memset(&cp_phy, 0, sizeof(cp_phy));

if (!(selected_phys & MGMT_PHY_LE_TX_MASK))
cp_phy.all_phys |= 0x01;

if (!(selected_phys & MGMT_PHY_LE_RX_MASK))
cp_phy.all_phys |= 0x02;

if (selected_phys & MGMT_PHY_LE_1M_TX)
cp_phy.tx_phys |= HCI_LE_SET_PHY_1M;

if (selected_phys & MGMT_PHY_LE_2M_TX)
cp_phy.tx_phys |= HCI_LE_SET_PHY_2M;

if (selected_phys & MGMT_PHY_LE_CODED_TX)
cp_phy.tx_phys |= HCI_LE_SET_PHY_CODED;

if (selected_phys & MGMT_PHY_LE_1M_RX)
cp_phy.rx_phys |= HCI_LE_SET_PHY_1M;

if (selected_phys & MGMT_PHY_LE_2M_RX)
cp_phy.rx_phys |= HCI_LE_SET_PHY_2M;

if (selected_phys & MGMT_PHY_LE_CODED_RX)
cp_phy.rx_phys |= HCI_LE_SET_PHY_CODED;

cmd->skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_DEFAULT_PHY,
sizeof(cp_phy), &cp_phy, HCI_CMD_TIMEOUT);

return 0;
}

static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_cp_set_phy_configuration *cp = data;
struct hci_cp_le_set_default_phy cp_phy;
struct mgmt_pending_cmd *cmd;
struct hci_request req;
u32 selected_phys, configurable_phys, supported_phys, unconfigure_phys;
u16 pkt_type = (HCI_DH1 | HCI_DM1);
bool changed = false;
Expand Down Expand Up @@ -3555,44 +3595,20 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev,

cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data,
len);
if (!cmd) {
if (!cmd)
err = -ENOMEM;
goto unlock;
}

hci_req_init(&req, hdev);

memset(&cp_phy, 0, sizeof(cp_phy));

if (!(selected_phys & MGMT_PHY_LE_TX_MASK))
cp_phy.all_phys |= 0x01;

if (!(selected_phys & MGMT_PHY_LE_RX_MASK))
cp_phy.all_phys |= 0x02;

if (selected_phys & MGMT_PHY_LE_1M_TX)
cp_phy.tx_phys |= HCI_LE_SET_PHY_1M;

if (selected_phys & MGMT_PHY_LE_2M_TX)
cp_phy.tx_phys |= HCI_LE_SET_PHY_2M;

if (selected_phys & MGMT_PHY_LE_CODED_TX)
cp_phy.tx_phys |= HCI_LE_SET_PHY_CODED;

if (selected_phys & MGMT_PHY_LE_1M_RX)
cp_phy.rx_phys |= HCI_LE_SET_PHY_1M;

if (selected_phys & MGMT_PHY_LE_2M_RX)
cp_phy.rx_phys |= HCI_LE_SET_PHY_2M;

if (selected_phys & MGMT_PHY_LE_CODED_RX)
cp_phy.rx_phys |= HCI_LE_SET_PHY_CODED;
else
err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd,
set_default_phy_complete);

hci_req_add(&req, HCI_OP_LE_SET_DEFAULT_PHY, sizeof(cp_phy), &cp_phy);
if (err < 0) {
err = mgmt_cmd_status(sk, hdev->id,
MGMT_OP_SET_PHY_CONFIGURATION,
MGMT_STATUS_FAILED);

err = hci_req_run_skb(&req, set_default_phy_complete);
if (err < 0)
mgmt_pending_remove(cmd);
if (cmd)
mgmt_pending_remove(cmd);
}

unlock:
hci_dev_unlock(hdev);
Expand Down

0 comments on commit 71efbb0

Please sign in to comment.