Bluetooth: Read LE Max data length command
authorSudha Bheemanna <b.sudha@samsung.com>
Fri, 16 Sep 2016 05:08:30 +0000 (10:38 +0530)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 29 Apr 2025 03:38:27 +0000 (12:38 +0900)
This patch adds the MGMT command and code to support reading
the maximum data length supported command for LE.

Change-Id: Ia7e51129c749526c0fd18179ad604cf1a770ebbd
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 f7c926a7021e395caa4be39a4d87db94a59b1ebb..70e3e2ab9f5c9e496edd7a5ee8171fae2aadf951 100644 (file)
@@ -2455,6 +2455,8 @@ void mgmt_multi_adv_state_change_evt(struct hci_dev *hdev, u8 adv_instance,
                u8 state_change_reason, u16 connection_handle);
 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);
 #endif
 
 int hci_abort_conn(struct hci_conn *conn, u8 reason);
index 52a36f91bd01a57b1497bfcaaad55dcf445899e7..444d793fdcde998802272dcf1de75862ef622f57 100644 (file)
@@ -185,6 +185,15 @@ struct mgmt_cp_disconnect_6lowpan {
 } __packed;
 #define MGMT_DISCONNECT_6LOWPAN_SIZE           7
 
+#define MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH    (TIZEN_OP_CODE_BASE + 0x15)
+struct mgmt_rp_le_read_maximum_data_length {
+       __le16  max_tx_octets;
+       __le16  max_tx_time;
+       __le16  max_rx_octets;
+       __le16  max_rx_time;
+} __packed;
+#define MGMT_LE_READ_MAXIMUM_DATA_LENGTH_SIZE  0
+
 /* EVENTS */
 
 /* For device name update changes */
index c6a87456bd19dc69b6850b6086e3ebde4b0f2507..3a9be40325cee303bbb9313b88133cd6d0d304b2 100644 (file)
@@ -2091,14 +2091,23 @@ static u8 hci_cc_le_read_max_data_len(struct hci_dev *hdev, void *data,
 
        bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
 
+#ifndef TIZEN_BT
        if (rp->status)
                return rp->status;
+#else
+       hci_dev_lock(hdev);
+#endif
 
        hdev->le_max_tx_len = le16_to_cpu(rp->tx_len);
        hdev->le_max_tx_time = le16_to_cpu(rp->tx_time);
        hdev->le_max_rx_len = le16_to_cpu(rp->rx_len);
        hdev->le_max_rx_time = le16_to_cpu(rp->rx_time);
 
+#ifdef TIZEN_BT
+       mgmt_le_read_maximum_data_length_complete(hdev, rp->status);
+       hci_dev_unlock(hdev);
+#endif
+
        return rp->status;
 }
 
index 348c552d628bcf61ddd8e85d249c6e34f0aab0d1..c783d6b3a5a0a765e3c09febe41f4d96726b0910 100644 (file)
@@ -9112,6 +9112,83 @@ void mgmt_6lowpan_conn_changed(struct hci_dev *hdev, char if_name[16],
 
        mgmt_event(MGMT_EV_6LOWPAN_CONN_STATE_CHANGED, hdev, ev, ev_size, NULL);
 }
+
+void mgmt_le_read_maximum_data_length_complete(struct hci_dev *hdev, u8 status)
+{
+       struct mgmt_pending_cmd *cmd;
+       struct mgmt_rp_le_read_maximum_data_length rp;
+
+       BT_DBG("%s status %u", hdev->name, status);
+
+       cmd = pending_find(MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH, hdev);
+       if (!cmd)
+               return;
+
+       if (status)
+               mgmt_cmd_status(cmd->sk, hdev->id,
+                               MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH,
+                               mgmt_status(status));
+
+       memset(&rp, 0, sizeof(rp));
+
+       rp.max_tx_octets = cpu_to_le16(hdev->le_max_tx_len);
+       rp.max_tx_time = cpu_to_le16(hdev->le_max_tx_time);
+       rp.max_rx_octets = cpu_to_le16(hdev->le_max_rx_len);
+       rp.max_rx_time = cpu_to_le16(hdev->le_max_rx_time);
+
+       mgmt_cmd_complete(cmd->sk, hdev->id,
+                         MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH, 0,
+                         &rp, sizeof(rp));
+
+       mgmt_pending_remove(cmd);
+}
+
+static int read_maximum_le_data_length(struct sock *sk,
+               struct hci_dev *hdev, void *data, u16 len)
+{
+       struct mgmt_pending_cmd *cmd;
+       int err;
+
+       BT_DBG("read_maximum_le_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_MAXIMUM_DATA_LENGTH,
+                                     MGMT_STATUS_NOT_POWERED);
+               goto unlock;
+       }
+
+       if (!lmp_le_capable(hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                                     MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH,
+                                     MGMT_STATUS_NOT_SUPPORTED);
+               goto unlock;
+       }
+
+       if (pending_find(MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH, hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id,
+                                     MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH,
+                                     MGMT_STATUS_BUSY);
+               goto unlock;
+       }
+
+       cmd = mgmt_pending_add(sk, MGMT_OP_LE_READ_MAXIMUM_DATA_LENGTH,
+                              hdev, data, len);
+       if (!cmd) {
+               err = -ENOMEM;
+               goto unlock;
+       }
+
+       err = hci_send_cmd(hdev, HCI_OP_LE_READ_MAX_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)
@@ -11477,6 +11554,8 @@ static const struct hci_mgmt_handler tizen_mgmt_handlers[] = {
        { enable_bt_6lowpan,       MGMT_ENABLE_BT_6LOWPAN_SIZE },
        { connect_bt_6lowpan,      MGMT_CONNECT_6LOWPAN_SIZE },
        { disconnect_bt_6lowpan,   MGMT_DISCONNECT_6LOWPAN_SIZE },
+       { read_maximum_le_data_length,
+                                  MGMT_LE_READ_MAXIMUM_DATA_LENGTH_SIZE },
 };
 #endif