@@ -140,6 +140,13 @@ struct bt_voice {
#define BT_PHY_LE_2M_RX 0x00001000
#define BT_PHY_LE_CODED_TX 0x00002000
#define BT_PHY_LE_CODED_RX 0x00004000
+#define BT_PHY_LE_CODED_S2 0x00008000
+#define BT_PHY_LE_CODED_S8 0x00010000
+
+#define BT_PHY_LE_TX_MASK (BT_PHY_LE_1M_TX | BT_PHY_LE_2M_TX | \
+ BT_PHY_LE_CODED_TX)
+#define BT_PHY_LE_RX_MASK (BT_PHY_LE_1M_RX | BT_PHY_LE_2M_RX | \
+ BT_PHY_LE_CODED_RX)
#define BT_MODE 15
@@ -1677,10 +1677,22 @@ struct hci_cp_le_set_default_phy {
__u8 rx_phys;
} __packed;
+#define HCI_OP_LE_SET_PHY 0x2032
+struct hci_cp_le_set_phy {
+ __le16 handle;
+ __u8 all_phys;
+ __u8 tx_phys;
+ __u8 rx_phys;
+ __le16 phy_opt;
+} __packed;
+
#define HCI_LE_SET_PHY_1M 0x01
#define HCI_LE_SET_PHY_2M 0x02
#define HCI_LE_SET_PHY_CODED 0x04
+#define HCI_LE_PHY_CODED_S2 0x01
+#define HCI_LE_PHY_CODED_S8 0x02
+
#define HCI_LE_READ_PHY_1M 0x01
#define HCI_LE_READ_PHY_2M 0x02
#define HCI_LE_READ_PHY_CODED 0x03
@@ -1702,6 +1702,7 @@ struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
const void *param, u32 timeout);
u32 hci_conn_get_phy(struct hci_conn *conn);
+int hci_conn_set_phy(struct hci_conn *conn, u32 phys);
/* ----- HCI Sockets ----- */
void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
@@ -1935,3 +1935,59 @@ u32 hci_conn_get_phy(struct hci_conn *conn)
return phys;
}
+
+int hci_conn_set_phy(struct hci_conn *conn, u32 phys)
+{
+ struct hci_cp_le_set_phy cp_phy;
+ u16 phy_opt = 0;
+
+ if (conn->type != LE_LINK)
+ return -ENOTCONN;
+
+ /* Check whether HCI_LE_Set_PHY command is supported or not */
+ if (!(conn->hdev->commands[35] & 0x40))
+ return -EOPNOTSUPP;
+
+ hci_dev_lock(conn->hdev);
+
+ memset(&cp_phy, 0, sizeof(cp_phy));
+ cp_phy.handle = cpu_to_le16(conn->handle);
+
+ if (!(phys & BT_PHY_LE_TX_MASK))
+ cp_phy.all_phys |= 0x01;
+
+ if (!(phys & BT_PHY_LE_RX_MASK))
+ cp_phy.all_phys |= 0x02;
+
+ if (phys & BT_PHY_LE_1M_TX)
+ cp_phy.tx_phys |= HCI_LE_SET_PHY_1M;
+
+ if (phys & BT_PHY_LE_2M_TX)
+ cp_phy.tx_phys |= HCI_LE_SET_PHY_2M;
+
+ if (phys & BT_PHY_LE_CODED_TX)
+ cp_phy.tx_phys |= HCI_LE_SET_PHY_CODED;
+
+ if (phys & BT_PHY_LE_1M_RX)
+ cp_phy.rx_phys |= HCI_LE_SET_PHY_1M;
+
+ if (phys & BT_PHY_LE_2M_RX)
+ cp_phy.rx_phys |= HCI_LE_SET_PHY_2M;
+
+ if (phys & BT_PHY_LE_CODED_RX)
+ cp_phy.rx_phys |= HCI_LE_SET_PHY_CODED;
+
+ if (phys & BT_PHY_LE_CODED_S2)
+ phy_opt |= HCI_LE_PHY_CODED_S2;
+
+ if (phys & BT_PHY_LE_CODED_S8)
+ phy_opt |= HCI_LE_PHY_CODED_S8;
+
+ cp_phy.phy_opt = cpu_to_le16(phy_opt);
+
+ hci_send_cmd(conn->hdev, HCI_OP_LE_SET_PHY, sizeof(cp_phy), &cp_phy);
+
+ hci_dev_unlock(conn->hdev);
+
+ return 0;
+}
@@ -875,7 +875,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
struct bt_power pwr;
struct l2cap_conn *conn;
int len, err = 0;
- u32 opt;
+ u32 opt, phys;
BT_DBG("sk %p", sk);
@@ -1071,6 +1071,25 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
break;
+ case BT_PHY:
+ if (sk->sk_state != BT_CONNECTED) {
+ err = -ENOTCONN;
+ break;
+ }
+
+ if (copy_from_sockptr(&phys, optval, sizeof(u32))) {
+ err = -EFAULT;
+ break;
+ }
+
+ err = hci_conn_set_phy(chan->conn->hcon, phys);
+
+ if (err)
+ break;
+
+ BT_DBG("phys %u", phys);
+ break;
+
case BT_MODE:
if (!enable_ecred) {
err = -ENOPROTOOPT;