Bluetooth: Add support to enable/disable IPSP
authorSudha Bheemanna <b.sudha@samsung.com>
Thu, 15 Sep 2016 04:42:09 +0000 (10:12 +0530)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 12 Nov 2024 04:03:13 +0000 (13:03 +0900)
This patch supports MGMT commands and code to enable or disable
IPSP 6LowPan features.

Change-Id: Ibbed275162ac0539205502747923603a2a581c36
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/l2cap.h
include/net/bluetooth/mgmt_tizen.h
net/bluetooth/6lowpan.c
net/bluetooth/mgmt.c

index d2a1154121d0d581652c86775dd720d247f20310..461ee3cd6599419f53fe528455bcd23dd28598f4 100644 (file)
@@ -973,4 +973,15 @@ void l2cap_conn_put(struct l2cap_conn *conn);
 int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user);
 void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user);
 
+#ifdef TIZEN_BT
+#ifdef CONFIG_BT_6LOWPAN
+/* IPSP : initialize/deinitialize 6lowpan */
+void bt_6lowpan_enable(void);
+void bt_6lowpan_disable(void);
+#else
+static inline void bt_6lowpan_enable(void) { }
+static inline void bt_6lowpan_disable(void) { }
+#endif
+#endif /* TIZEN_BT */
+
 #endif /* __L2CAP_H */
index 982c00d35c9b9bf4fdcab462c330c87f9ba794e4..6549be14bfd938ea055caa5a6d95a28ac013ec3b 100644 (file)
@@ -167,6 +167,12 @@ struct mgmt_rp_get_adv_tx_power {
        __s8    adv_tx_power;
 } __packed;
 
+#define MGMT_OP_ENABLE_6LOWPAN                 (TIZEN_OP_CODE_BASE + 0x12)
+struct mgmt_cp_enable_6lowpan {
+       __u8    enable_6lowpan;
+} __packed;
+#define MGMT_ENABLE_BT_6LOWPAN_SIZE            1
+
 /* EVENTS */
 
 /* For device name update changes */
index 4eb1b3ced0d27eae5eb135d98fe65fcf701dff98..fd15bff34448f12484f8b32251e19b83c3ac5cb5 100644 (file)
@@ -1259,6 +1259,40 @@ static int __init bt_6lowpan_init(void)
        return register_netdevice_notifier(&bt_6lowpan_dev_notifier);
 }
 
+#ifdef TIZEN_BT
+void bt_6lowpan_enable(void)
+{
+       if (!enable_6lowpan) {
+               disconnect_all_peers();
+
+               enable_6lowpan = true;
+
+               if (listen_chan) {
+                       l2cap_chan_close(listen_chan, 0);
+                       l2cap_chan_put(listen_chan);
+               }
+
+               listen_chan = bt_6lowpan_listen();
+
+               register_netdevice_notifier(&bt_6lowpan_dev_notifier);
+       }
+}
+
+void bt_6lowpan_disable(void)
+{
+       if (enable_6lowpan) {
+               if (listen_chan) {
+                       l2cap_chan_close(listen_chan, 0);
+                       l2cap_chan_put(listen_chan);
+                       listen_chan = NULL;
+               }
+               disconnect_devices();
+               unregister_netdevice_notifier(&bt_6lowpan_dev_notifier);
+               enable_6lowpan = false;
+       }
+}
+#endif
+
 static void __exit bt_6lowpan_exit(void)
 {
        debugfs_remove(lowpan_enable_debugfs);
index e7a54bf687bff5e676005a26ec509d0e9b4b02af..ee50c60fd598e57388877ad7087a4e2dd95e3d45 100644 (file)
@@ -8905,6 +8905,40 @@ void mgmt_multi_adv_state_change_evt(struct hci_dev *hdev, u8 adv_instance,
                sizeof(struct mgmt_ev_vendor_specific_multi_adv_state_changed),
                NULL);
 }
+
+static int enable_bt_6lowpan(struct sock *sk, struct hci_dev *hdev,
+               void *data, u16 len)
+{
+       int err;
+       struct mgmt_cp_enable_6lowpan *cp = data;
+
+       BT_DBG("%s", hdev->name);
+
+       hci_dev_lock(hdev);
+
+       if (!hdev_is_powered(hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ENABLE_6LOWPAN,
+                                     MGMT_STATUS_NOT_POWERED);
+               goto unlocked;
+       }
+
+       if (!lmp_le_capable(hdev)) {
+               err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ENABLE_6LOWPAN,
+                                     MGMT_STATUS_NOT_SUPPORTED);
+               goto unlocked;
+       }
+
+       if (cp->enable_6lowpan)
+               bt_6lowpan_enable();
+       else
+               bt_6lowpan_disable();
+
+       err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ENABLE_6LOWPAN,
+                               MGMT_STATUS_SUCCESS, NULL, 0);
+unlocked:
+       hci_dev_unlock(hdev);
+       return err;
+}
 #endif /* TIZEN_BT */
 
 static bool ltk_is_valid(struct mgmt_ltk_info *key)
@@ -11232,6 +11266,7 @@ static const struct hci_mgmt_handler tizen_mgmt_handlers[] = {
        { le_set_scan_params,      MGMT_LE_SET_SCAN_PARAMS_SIZE },
        { set_voice_setting,       MGMT_SET_VOICE_SETTING_SIZE },
        { get_adv_tx_power,        MGMT_GET_ADV_TX_POWER_SIZE },
+       { enable_bt_6lowpan,       MGMT_ENABLE_BT_6LOWPAN_SIZE },
 };
 #endif