Implement 'Get Phy Configuration' MGMT command 18/186018/6
authorAnupam Roy <anupam.r@samsung.com>
Mon, 6 Aug 2018 17:16:01 +0000 (22:46 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Tue, 7 Aug 2018 00:27:55 +0000 (00:27 +0000)
This patch implements MGMT_OP_GET_PHY_CONFIGURATION
operation if MGMT interface supports PHY Configuration
setting. It introduces two new adapter properties
(l2 2m phy and le coded phy). These properties are filled
upon getting response from kernel about supported phys's.
which are then exported to user by 'SupportedLEFeatures'
adapter property.

This mgmt command supports reading above parameters in bit fields,
based on LE PHY (1M, 2M & CODED) and also
BREDR packet types as following-

 - BR 1M  (1 SLOT, 3 SLOT, 5 SLOT)
 - EDR 2M (1 SLOT, 3 SLOT, 5 SLOT)
 - EDR 3M (1 SLOT, 3 SLOT, 5 SLOT)
 - 1M TX, 1M RX
 - 2M TX, 2M RX
 - CODED TX, CODED RX

Verification logs based on BT 5.0 controller -

bluetoothd[637]: src/adapter.c:get_phy_configuration_resp() Supported phys: [0x7e00]
bluetoothd[637]: src/adapter.c:get_phy_configuration_resp() Configurable phys: [0x7800]
bluetoothd[637]: src/adapter.c:get_phy_configuration_resp() Selected phys: [0x600]
bluetoothd[637]: src/adapter.c:get_phy_configuration_resp() Adapter supports LE 2M PHY
bluetoothd[637]: src/adapter.c:get_phy_configuration_resp() Adapter supports LE CODED PHY

Change-Id: I9ec3565b5d1b9a0de3daea666d34754958bb1550
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
src/adapter.c

index 4ff2711..dfff35e 100644 (file)
@@ -343,6 +343,11 @@ struct btd_adapter {
 #endif
 #endif
        bool is_default;                /* true if adapter is default one */
+
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       bool le_2m_phy_supported;
+       bool le_coded_phy_supported;
+#endif
 };
 
 typedef enum {
@@ -6696,9 +6701,10 @@ static gboolean property_get_supported_le_features(
        const char *str, *val;
        int value;
        DBusMessageIter entry;
+       struct btd_adapter *adapter = user_data;
 
        dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
-                                       DBUS_TYPE_STRING_AS_STRING, &entry);
+                       DBUS_TYPE_STRING_AS_STRING, &entry);
 
        value = adapter_le_get_max_adv_instance();
        if (value > 0) {
@@ -6740,6 +6746,36 @@ static gboolean property_get_supported_le_features(
                g_free((void *)val);
        }
 
+       if (adapter->supported_settings & MGMT_SETTING_PHY_CONFIGURATION) {
+               /* 2M PHY Support */
+               str = g_strdup("2m_phy");
+               dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &str);
+
+               if (adapter->le_2m_phy_supported)
+                       val = g_strdup("true");
+               else
+                       val = g_strdup("false");
+
+               dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &val);
+
+               g_free((void *)str);
+               g_free((void *)val);
+
+               /* CODED PHY Support */
+               str = g_strdup("coded_phy");
+               dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &str);
+
+               if (adapter->le_coded_phy_supported)
+                       val = g_strdup("true");
+               else
+                       val = g_strdup("false");
+
+               dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &val);
+
+               g_free((void *)str);
+               g_free((void *)val);
+       }
+
        dbus_message_iter_close_container(iter, &entry);
 
        return TRUE;
@@ -8771,8 +8807,62 @@ void adapter_auto_connect_remove(struct btd_adapter *adapter,
        adapter->connect_list = g_slist_remove(adapter->connect_list, device);
 }
 
+#if defined (TIZEN_FEATURE_BLUEZ_MODIFY)
+static void get_phy_configuration_resp(uint8_t status, uint16_t len, const void *param,
+                                                        void *user_data)
+{
+       uint32_t supported_phys;
+       uint32_t configurable_phys;
+       uint32_t selected_phys;
+
+       const struct mgmt_rp_get_phy_confguration *rp = param;
+       struct btd_adapter *adapter = user_data;
+
+       if (status != MGMT_STATUS_SUCCESS) {
+               error("Get PHY Configuration failed with status 0x%02x (%s)",
+                               status, mgmt_errstr(status));
+               return;
+       }
+
+       if (len < sizeof(*rp)) {
+               error("Too small get-phy reply (%u bytes)", len);
+               return;
+       }
+
+       supported_phys = get_le32(&rp->supported_phys);
+       configurable_phys = get_le32(&rp-> configurable_phys);
+       selected_phys = get_le16(&rp->selected_phys);
+
+       DBG("Supported phys: [0x%x]", supported_phys);
+       DBG("Configurable phys: [0x%x]", configurable_phys);
+       DBG("Selected phys: [0x%x]", selected_phys);
+
+       if (adapter->supported_settings & MGMT_SETTING_LE) {
+               if ((supported_phys & MGMT_PHY_LE_2M_TX) &&
+                               (supported_phys & MGMT_PHY_LE_2M_RX)) {
+                       DBG("Adapter supports LE 2M PHY");
+                       adapter->le_2m_phy_supported = TRUE;
+               } else
+                       DBG("Adapter does not support LE 2M PHY");
+
+               if ((supported_phys & MGMT_PHY_LE_CODED_TX) &&
+                               (supported_phys & MGMT_PHY_LE_CODED_RX)) {
+                       adapter->le_coded_phy_supported = TRUE;
+                       DBG("Adapter supports LE CODED PHY");
+               } else
+                       DBG("Adapter does not support LE CODED PHY");
+       }
+
+       /* Emit Property Changed Signal */
+        g_dbus_emit_property_changed(dbus_conn, adapter->path,
+                        ADAPTER_INTERFACE, "SupportedLEFeatures");
+
+}
+#endif
+
 static void adapter_start(struct btd_adapter *adapter)
 {
+
 #if defined(TIZEN_FEATURE_BLUEZ_MODIFY) && !defined(__SPRD_PATCH__)
        if (adapter_le_read_ble_feature_info())
                g_dbus_emit_property_changed(dbus_conn, adapter->path,
@@ -13743,7 +13833,6 @@ static void read_info_complete(uint8_t status, uint16_t length,
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        adapter_check_version(adapter, rp->version);
 #endif
-
        clear_uuids(adapter);
        clear_devices(adapter);
 
@@ -13765,6 +13854,15 @@ static void read_info_complete(uint8_t status, uint16_t length,
        missing_settings = adapter->current_settings ^
                                                adapter->supported_settings;
 
+/* If adapter supports PHY CONFIGURATION SETTING, then read PHY configuration and save them */
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (adapter->supported_settings & MGMT_SETTING_PHY_CONFIGURATION) {
+               if (mgmt_send(adapter->mgmt, MGMT_OP_GET_PHY_CONFIGURATION, adapter->dev_id, 0, NULL,
+                                       get_phy_configuration_resp, adapter, NULL) == 0)
+                       error("Unable to send %s cmd",
+                                       mgmt_opstr(MGMT_OP_GET_PHY_CONFIGURATION));
+       }
+#endif
        switch (main_opts.mode) {
        case BT_MODE_DUAL:
                if (missing_settings & MGMT_SETTING_SSP) {