Bluetooth: Write host suggested default le data length
authorSudha Bheemanna <b.sudha@samsung.com>
Fri, 16 Sep 2016 06:39:57 +0000 (12:09 +0530)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 12 Nov 2024 04:03:13 +0000 (13:03 +0900)
This patch adds MGMT command and code for supporting write
default le data length command to the controller.

Change-Id: Idd59eba48a6726293ef91804d090ecfd7d46f220
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 e65829ca0056632c18c9bc9e234ed6f84c82cf4c..0ebbe173b620bfa3100308ec59569c4e30c411a4 100644 (file)
@@ -2431,6 +2431,8 @@ void mgmt_6lowpan_conn_changed(struct hci_dev *hdev, char if_name[16],
                bdaddr_t *bdaddr, u8 addr_type, bool connected);
 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);
 #endif
 
 int hci_abort_conn(struct hci_conn *conn, u8 reason);
index 444d793fdcde998802272dcf1de75862ef622f57..0f36ecdcad2b21c4daf768c9f67794d46a70a483 100644 (file)
@@ -194,6 +194,13 @@ struct mgmt_rp_le_read_maximum_data_length {
 } __packed;
 #define MGMT_LE_READ_MAXIMUM_DATA_LENGTH_SIZE  0
 
+#define MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH    (TIZEN_OP_CODE_BASE + 0x16)
+struct mgmt_cp_le_write_host_suggested_data_length {
+       __le16  def_tx_octets;
+       __le16  def_tx_time;
+} __packed;
+#define MGMT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH_SIZE  4
+
 /* EVENTS */
 
 /* For device name update changes */
index 9effa815ff9d07968799df82e303ec867075f23b..296f53485424d7d5e537960e67161d7f79ce3b72 100644 (file)
@@ -1966,16 +1966,29 @@ static u8 hci_cc_le_write_def_data_len(struct hci_dev *hdev, void *data,
        bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
 
        if (rp->status)
+#ifndef TIZEN_BT
                return rp->status;
+#else
+               goto unblock;
+#endif
 
        sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN);
        if (!sent)
+#ifndef TIZEN_BT
                return rp->status;
+#else
+               goto unblock;
+#endif
 
        hdev->le_def_tx_len = le16_to_cpu(sent->tx_len);
        hdev->le_def_tx_time = le16_to_cpu(sent->tx_time);
 
        return rp->status;
+#ifdef TIZEN_BT
+unblock:
+       mgmt_le_write_host_suggested_data_length_complete(hdev, rp->status);
+       return rp->status;
+#endif
 }
 
 static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data,
index 2b909d68df27c3ecf7b01f33e6ca4af2526013b2..ca70551fdcfa2c3fd6bbe98fc5ab952bc39a566b 100644 (file)
@@ -9164,6 +9164,90 @@ unlock:
        hci_dev_unlock(hdev);
        return err;
 }
+
+void mgmt_le_write_host_suggested_data_length_complete(struct hci_dev *hdev,
+               u8 status)
+{
+       struct mgmt_pending_cmd *cmd;
+
+       BT_DBG("status 0x%02x", status);
+
+       hci_dev_lock(hdev);
+
+       cmd = pending_find(MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, hdev);
+       if (!cmd) {
+               BT_ERR("cmd not found in the pending list");
+               goto unlock;
+       }
+
+       if (status)
+               mgmt_cmd_status(cmd->sk, hdev->id,
+                               MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH,
+                               mgmt_status(status));
+       else
+               mgmt_cmd_complete(cmd->sk, hdev->id,
+                                 MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH,
+                                 0, NULL, 0);
+
+       mgmt_pending_remove(cmd);
+
+unlock:
+       hci_dev_unlock(hdev);
+}
+
+static int write_host_suggested_le_data_length(struct sock *sk,
+               struct hci_dev *hdev, void *data, u16 len)
+{
+       struct mgmt_pending_cmd *cmd;
+       struct mgmt_cp_le_write_host_suggested_data_length *cp = data;
+       struct hci_cp_le_write_def_data_len hci_data;
+       int err = 0;
+
+       BT_DBG("Write host suggested data length request for %s", hdev->name);
+
+       hci_dev_lock(hdev);
+
+       if (!hdev_is_powered(hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                               MGMT_OP_LE_WRITE_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_WRITE_HOST_SUGGESTED_DATA_LENGTH,
+                               MGMT_STATUS_NOT_SUPPORTED);
+               goto unlock;
+       }
+
+       if (pending_find(MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                               MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH,
+                               MGMT_STATUS_BUSY);
+               goto unlock;
+       }
+
+       cmd = mgmt_pending_add(sk, MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH,
+                              hdev, data, len);
+       if (!cmd) {
+               err = -ENOMEM;
+               goto unlock;
+       }
+
+       hci_data.tx_len = cp->def_tx_octets;
+       hci_data.tx_time = cp->def_tx_time;
+
+       err = hci_send_cmd(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN,
+                          sizeof(hci_data), &hci_data);
+       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)
@@ -11496,6 +11580,8 @@ static const struct hci_mgmt_handler tizen_mgmt_handlers[] = {
        { disconnect_bt_6lowpan,   MGMT_DISCONNECT_6LOWPAN_SIZE },
        { read_maximum_le_data_length,
                                   MGMT_LE_READ_MAXIMUM_DATA_LENGTH_SIZE },
+       { write_host_suggested_le_data_length,
+                                  MGMT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH_SIZE },
 };
 #endif