Bluetooth: Read host suggested default le data length 94/306594/1
authorSudha Bheemanna <b.sudha@samsung.com>
Fri, 16 Sep 2016 07:24:31 +0000 (12:54 +0530)
committerJaehoon Chung <jh80.chung@samsung.com>
Fri, 23 Feb 2024 02:15:22 +0000 (11:15 +0900)
This patch adds MGMT command and code for supporting reading
default le data length value set at the controller.

Change-Id: I6194023bf41ef1fe5606f41fdb0776f6ec84cb4f
Signed-off-by: Sudha Bheemanna <b.sudha@samsung.com>
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
include/net/bluetooth/hci_core.h
include/net/bluetooth/mgmt_tizen.h
net/bluetooth/hci_event.c
net/bluetooth/mgmt.c

index 4cd4b7d..957dff5 100644 (file)
@@ -2430,6 +2430,8 @@ void mgmt_le_read_maximum_data_length_complete(struct hci_dev *hdev,
                u8 status);
 void mgmt_le_write_host_suggested_data_length_complete(struct hci_dev *hdev,
                u8 status);
+void mgmt_le_read_host_suggested_data_length_complete(struct hci_dev *hdev,
+               u8 status);
 #endif
 
 int hci_abort_conn(struct hci_conn *conn, u8 reason);
index 0f36ecd..2d11d5b 100644 (file)
@@ -201,6 +201,13 @@ struct mgmt_cp_le_write_host_suggested_data_length {
 } __packed;
 #define MGMT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH_SIZE  4
 
+#define MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH     (TIZEN_OP_CODE_BASE + 0x17)
+struct mgmt_rp_le_read_host_suggested_data_length {
+       __le16  def_tx_octets;
+       __le16  def_tx_time;
+} __packed;
+#define MGMT_LE_READ_HOST_SUGGESTED_DATA_LENGTH_SIZE   0
+
 /* EVENTS */
 
 /* For device name update changes */
index b3ce9f2..0f98ffe 100644 (file)
@@ -2009,12 +2009,22 @@ static u8 hci_cc_le_read_def_data_len(struct hci_dev *hdev, void *data,
 
        bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
 
+#ifdef TIZEN_BT
+       hci_dev_lock(hdev);
+#else
        if (rp->status)
                return rp->status;
+#endif
 
        hdev->le_def_tx_len = le16_to_cpu(rp->tx_len);
        hdev->le_def_tx_time = le16_to_cpu(rp->tx_time);
 
+#ifdef TIZEN_BT
+       mgmt_le_read_host_suggested_data_length_complete(hdev, rp->status);
+
+       hci_dev_unlock(hdev);
+#endif
+
        return rp->status;
 }
 
index f82a5af..f67e73f 100644 (file)
@@ -9294,6 +9294,85 @@ unlock:
 
        return err;
 }
+
+void mgmt_le_read_host_suggested_data_length_complete(struct hci_dev *hdev,
+               u8 status)
+{
+       struct mgmt_pending_cmd *cmd;
+       struct mgmt_rp_le_read_host_suggested_data_length rp;
+
+       BT_DBG("%s status %u", hdev->name, status);
+
+       cmd = pending_find(MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH, hdev);
+       if (!cmd) {
+               BT_ERR("cmd not found in the pending list");
+               return;
+       }
+
+       if (status)
+               mgmt_cmd_status(cmd->sk, hdev->id,
+                       MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH,
+                       mgmt_status(status));
+
+       memset(&rp, 0, sizeof(rp));
+
+       rp.def_tx_octets = cpu_to_le16(hdev->le_def_tx_len);
+       rp.def_tx_time = cpu_to_le16(hdev->le_def_tx_time);
+
+       mgmt_cmd_complete(cmd->sk, hdev->id,
+                         MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH, 0,
+                         &rp, sizeof(rp));
+
+       mgmt_pending_remove(cmd);
+}
+
+static int read_host_suggested_data_length(struct sock *sk,
+               struct hci_dev *hdev, void *data, u16 len)
+{
+       struct mgmt_pending_cmd *cmd;
+       int err;
+
+       BT_DBG("read_host_suggested_data_length %s", hdev->name);
+
+       hci_dev_lock(hdev);
+
+       if (!hdev_is_powered(hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                               MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH,
+                               MGMT_STATUS_NOT_POWERED);
+               goto unlock;
+       }
+
+       if (!lmp_le_capable(hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                               MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH,
+                               MGMT_STATUS_NOT_SUPPORTED);
+               goto unlock;
+       }
+
+       if (pending_find(MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH, hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                               MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH,
+                               MGMT_STATUS_BUSY);
+               goto unlock;
+       }
+
+       cmd = mgmt_pending_add(sk, MGMT_OP_LE_READ_HOST_SUGGESTED_DATA_LENGTH,
+                              hdev, data, len);
+       if (!cmd) {
+               err = -ENOMEM;
+               goto unlock;
+       }
+
+       err = hci_send_cmd(hdev, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL);
+       if (err < 0)
+               mgmt_pending_remove(cmd);
+
+unlock:
+       hci_dev_unlock(hdev);
+
+       return err;
+}
 #endif /* TIZEN_BT */
 
 static bool ltk_is_valid(struct mgmt_ltk_info *key)
@@ -11636,6 +11715,8 @@ static const struct hci_mgmt_handler tizen_mgmt_handlers[] = {
                                   MGMT_LE_READ_MAXIMUM_DATA_LENGTH_SIZE },
        { write_host_suggested_le_data_length,
                                   MGMT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH_SIZE },
+       { read_host_suggested_data_length,
+                                  MGMT_LE_READ_HOST_SUGGESTED_DATA_LENGTH_SIZE },
 };
 #endif