TDLS: Implement the Channel Switch support in net-config 52/125952/3
authorManeesh Jain <maneesh.jain@samsung.com>
Wed, 19 Apr 2017 11:01:06 +0000 (16:31 +0530)
committerManeesh Jain <maneesh.jain@samsung.com>
Thu, 20 Apr 2017 10:57:26 +0000 (16:27 +0530)
Change-Id: I390d3c4089deacb2b8296502545fc2812f6429a8
Signed-off-by: Maneesh Jain <maneesh.jain@samsung.com>
include/wifi-tdls.h
interfaces/netconfig-iface-wifi.xml
packaging/net-config.spec
src/.wifi-tdls.c.swp [new file with mode: 0644]
src/wifi-tdls.c
src/wifi.c

index 616e540..db8acc7 100755 (executable)
 typedef enum {
        NETCONFIG_ERROR_TDLS_NO_ERROR                           = 0x00,
        NETCONFIG_ERROR_TDLS_FAIL_DISCOVER                      = 0x01,
-       NETCONFIG_ERROR_TDLS_FAIL_DISCONNECT            = 0x02,
+       NETCONFIG_ERROR_TDLS_FAIL_DISCONNECT                    = 0x02,
        NETCONFIG_ERROR_TDLS_FAIL_CONNECT                       = 0x03,
-       NETCONFIG_ERROR_TDLS_ALREADY_DONE                       = 0x04,
+       NETCONFIG_ERROR_TDLS_ALREADY_DONE                       = 0x04,
+       NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH                = 0x05,
 } netconfig_tdls_error_e;
 
 void netconfig_wifi_tdls_peer_found_event(GVariant *message);
@@ -43,6 +44,12 @@ gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, gcha
 gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context);
 gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr);
 gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr);
+gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
+                       gchar *peer_mac_Addr, int freq);
+gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
+                       gchar *peer_mac_Addr);
+
+
 
 #ifdef __cplusplus
 }
index 4edb933..719a572 100755 (executable)
                        <arg type="s" name="peer_mac_addr" direction="in"/>
                        <arg  type="i" name="result" direction="out" />
                </method>
+               <method name="TdlsChannelSwitch">
+                       <arg  type="s" name="peer_mac_addr" direction="in" />
+                       <arg  type="i" name="freq" direction="in" />
+                       <arg  type="i" name="result" direction="out" />
+               </method>
+               <method name="TdlsCancelChannelSwitch">
+                       <arg  type="s" name="peer_mac_addr" direction="in" />
+                       <arg  type="i" name="result" direction="out" />
+               </method>
                <signal name="PowerOnCompleted"></signal>
                <signal name="PowerOffCompleted"></signal>
                <signal name="PowerOperationFailed"></signal>
index 4b722a6..d473173 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          net-config
 Summary:       TIZEN Network Configuration service
-Version:       1.1.108
+Version:       1.1.109
 Release:       2
 Group:         System/Network
 License:       Apache-2.0
diff --git a/src/.wifi-tdls.c.swp b/src/.wifi-tdls.c.swp
new file mode 100644 (file)
index 0000000..3efa7db
Binary files /dev/null and b/src/.wifi-tdls.c.swp differ
index cd09f21..6e331fc 100755 (executable)
@@ -125,6 +125,47 @@ static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const
        return message;
 }
 
+static unsigned char _netconfig_freq_to_channel(int freq)
+{
+       if (freq < 2412 || freq > 5825 ||
+               (freq > 2484 && freq < 5180)) {
+               ERR("Invalid Frequence Range");
+               return 0;
+       }
+       if (freq >= 5180)
+               return 36 + (freq - 5180)/5;
+       else if (freq <= 2472)
+               return 1 + (freq - 2412)/5;
+       else if (freq == 2484)
+               return 14;
+       else
+               return 0;
+}
+
+static unsigned char _netconfig_get_operating_class(int freq)
+{
+       unsigned char channel = 0;
+       unsigned char oper_class = 0;
+
+       channel = _netconfig_freq_to_channel(freq);
+
+       if (channel) {
+               /* Operating class 81 - 2.4 GHz band channels 1..13 */
+               if (channel >= 1 && channel <= 13)
+                       oper_class = 81;
+               /* Operating class 115 - 5 GHz, channels 36-48 */
+               else if (channel >= 36 && channel <= 48)
+                       oper_class = 115;
+               /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
+               else
+                       oper_class = 124;
+
+               INFO("TDLS: Operating Class  is [%d]", oper_class);
+               return oper_class;
+       }
+       return 0;
+}
+
 gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context,
                        gchar *peer_mac_Addr)
 {
@@ -250,6 +291,90 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context)
        return TRUE;
 }
 
+gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
+                       gchar *peer_mac_Addr, int freq)
+{
+       GVariant *message = NULL;
+       GVariantBuilder *builder;
+       GVariant *params;
+       const char *if_path = NULL;
+       unsigned char oper_class = 0;
+
+       if (peer_mac_Addr == NULL) {
+               ERR("TDLS: Invalid Parameter");
+               wifi_complete_tdls_channel_switch(wifi, context,
+                                                       NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+               return TRUE;
+       }
+
+       oper_class = _netconfig_get_operating_class(freq);
+
+       if (!oper_class) {
+               ERR("TDLS: Invalid Parameter");
+               wifi_complete_tdls_channel_switch(wifi, context,
+                                                       NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+               return TRUE;
+       }
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       g_variant_builder_add(builder, "{sv}", "PeerAddress", g_variant_new_string(peer_mac_Addr));
+       g_variant_builder_add(builder, "{sv}", "Frequency", g_variant_new_int32(freq));
+       g_variant_builder_add(builder, "{sv}", "OperClass", g_variant_new_byte(oper_class));
+       params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+       g_variant_builder_unref(builder);
+
+       if_path = netconfig_wifi_get_supplicant_interface();
+
+       if (if_path == NULL) {
+               ERR("Fail to get wpa_supplicant DBus path");
+               wifi_complete_tdls_channel_switch(wifi, context,
+                                               NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+               return TRUE;
+       }
+
+       message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+                               if_path, SUPPLICANT_INTERFACE ".Interface", "TDLSChannelSwitch", params);
+
+       if (message == NULL) {
+               ERR(" TDLS : Fail to Process TDLS Channel Switch Request !!!");
+               wifi_complete_tdls_channel_switch(wifi, context,
+                                               NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+               return TRUE;
+       }
+
+       INFO("TDLS Channel Change Request: Success");
+       wifi_complete_tdls_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR);
+
+       g_variant_unref(message);
+       return TRUE;
+}
+
+
+gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
+                       gchar *peer_mac_Addr)
+{
+       GVariant *message = NULL;
+
+       if (peer_mac_Addr == NULL) {
+               INFO("TDLS: Invalid Parameter");
+               wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+               return TRUE;
+       }
+       message = __netconfig_wifi_tdls_send_dbus_str("TDLSCancelChannelSwitch", (const char*)peer_mac_Addr);
+       if (message == NULL) {
+               ERR(" TDLS : Fail to TDLS Cancel Channel Swicth Request !!!");
+               wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+               return TRUE;
+       }
+
+       INFO("TDLS Cancel Channel Swicth Request : Success");
+       wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR);
+
+       g_variant_unref(message);
+       return TRUE;
+}
+
 void netconfig_wifi_tdls_connected_event(GVariant *message)
 {
 
index d2aa830..18f0d39 100755 (executable)
@@ -245,6 +245,10 @@ void wifi_object_create_and_init(void)
                        G_CALLBACK(handle_tdls_discover), NULL);
        g_signal_connect(wifi_object, "handle-tdls-connect",
                        G_CALLBACK(handle_tdls_connect), NULL);
+       g_signal_connect(wifi_object, "handle-tdls-channel-switch",
+                       G_CALLBACK(handle_tdls_channel_switch), NULL);
+       g_signal_connect(wifi_object, "handle-tdls-cancel-channel-switch",
+                       G_CALLBACK(handle_tdls_cancel_channel_switch), NULL);
 
        if (!g_dbus_interface_skeleton_export(interface_wifi, connection,
                        NETCONFIG_WIFI_PATH, NULL)) {