From 2f429c1f8e7e7c8e9bbac8dafcae1d3ee7fbe916 Mon Sep 17 00:00:00 2001 From: Sudha Bheemanna Date: Mon, 3 Oct 2016 16:26:38 +0530 Subject: [PATCH] Bluetooth: Write host suggested default le data length This patch adds MGMT command and code for supporting write default le data length command to the controller. Change-Id: Icc3509186261831cad7be98708a13bfa49730d93 Signed-off-by: Sudha Bheemanna --- include/net/bluetooth/hci_core.h | 2 + include/net/bluetooth/mgmt_tizen.h | 7 ++++ net/bluetooth/hci_event.c | 13 ++++++ net/bluetooth/mgmt.c | 86 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 4d71f69..8141aae 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1566,6 +1566,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 u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, diff --git a/include/net/bluetooth/mgmt_tizen.h b/include/net/bluetooth/mgmt_tizen.h index 336ec36..9609b0b 100644 --- a/include/net/bluetooth/mgmt_tizen.h +++ b/include/net/bluetooth/mgmt_tizen.h @@ -192,6 +192,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 + /* BEGIN TIZEN_Bluetooth :: name update changes */ #define MGMT_EV_DEVICE_NAME_UPDATE (TIZEN_EV_BASE + 0x01) struct mgmt_ev_device_name_update { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 6c87fa5..b05d07c 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1370,14 +1370,27 @@ static void hci_cc_le_write_def_data_len(struct hci_dev *hdev, BT_DBG("%s status 0x%2.2x", hdev->name, status); if (status) +#ifndef CONFIG_TIZEN_WIP return; +#else + goto unblock; +#endif sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN); if (!sent) +#ifndef CONFIG_TIZEN_WIP return; +#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); + +#ifdef CONFIG_TIZEN_WIP +unblock: + mgmt_le_write_host_suggested_data_length_complete(hdev, status); +#endif } static void hci_cc_le_read_max_data_len(struct hci_dev *hdev, diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 2892254..bcb5448 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -7064,6 +7064,90 @@ unlock: hci_dev_unlock(hdev); return err; } + +void mgmt_le_write_host_suggested_data_length_complete(struct hci_dev *hdev, + u8 status) +{ + struct pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = mgmt_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) + cmd_status(cmd->sk, hdev->id, + MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, + mgmt_status(status)); + else + 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 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 = 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 = cmd_status(sk, hdev->id, + MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, + MGMT_STATUS_NOT_SUPPORTED); + goto unlock; + } + + if (mgmt_pending_find(MGMT_OP_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, hdev)) { + err = 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; +} /* END TIZEN_Bluetooth */ #endif @@ -8169,6 +8253,8 @@ static const struct mgmt_handler tizen_mgmt_handlers[] = { { enable_bt_6lowpan, false, MGMT_ENABLE_BT_6LOWPAN_SIZE }, { disconnect_bt_6lowpan, false, MGMT_DISCONNECT_6LOWPAN_SIZE }, { read_maximum_le_data_length, false, MGMT_LE_READ_MAXIMUM_DATA_LENGTH_SIZE }, + { write_host_suggested_le_data_length, false, + MGMT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH_SIZE }, }; #endif -- 2.7.4