Added API to set and get PMF for Mesh Network 61/175661/1 accepted/tizen/unified/20180413.073542 submit/tizen/20180412.075158
authorNishant Chaprana <n.chaprana@samsung.com>
Fri, 6 Apr 2018 09:10:29 +0000 (14:40 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Wed, 11 Apr 2018 10:15:13 +0000 (15:45 +0530)
Change-Id: I9d852d5580a8acc128e7ccc3f69aa18f1c32e33c
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/wifi-mesh.h
include/wifi-mesh_private.h
src/wifi-mesh-dbus.c
src/wifi-mesh.c
test/wifi-mesh-network.c

index ec13a3b55fa8f735b7a26c0fd169985dda09e2a1..093066d41bcb78961cdf33e075a35416e72ebc10 100644 (file)
@@ -113,6 +113,16 @@ typedef enum {
        MESH_SECURITY_SAE, /**< Simultaneous Authentication of Equals */
 } wifi_mesh_security_type_e;
 
+/**
+ * @brief Enumeration for the pmf(Protected management Frames) type of the Wi-Fi Mesh network.
+ * @since_tizen 5.0
+ */
+typedef enum {
+       MESH_PMF_NONE = 0, /**< PMF in not available */
+       MESH_PMF_OPTIONAL, /**< PMF is optional */
+       MESH_PMF_REQUIRED, /**< PMF is mandatory */
+} wifi_mesh_pmf_type_e;
+
 /**
  * @brief Enumeration for the connection state of the Wi-Fi Mesh network.
  * @since_tizen 5.0
@@ -922,6 +932,7 @@ int wifi_mesh_network_clone(wifi_mesh_network_h* dst, wifi_mesh_network_h src);
  * @param[in] rssi The Received Signal Strength Indicator
  * @param[in] security The security type for network
  * @param[in] passphrase The passphrase for network connection
+ * @param[in] pmf The pmf type for network connection
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #WIFI_MESH_ERROR_NONE Successful
@@ -935,7 +946,7 @@ int wifi_mesh_network_clone(wifi_mesh_network_h* dst, wifi_mesh_network_h src);
  */
 int wifi_mesh_network_new_with(wifi_mesh_network_h* network, const char *meshid,
        const char *bssid, int channel, int rssi, wifi_mesh_security_type_e security,
-       const char *passphrase);
+       const char *passphrase, wifi_mesh_pmf_type_e pmf);
 
 /**
  * @brief Destroys network handle.
@@ -1144,6 +1155,44 @@ int wifi_mesh_network_get_security(wifi_mesh_network_h network,
 int wifi_mesh_network_set_security(wifi_mesh_network_h network,
                wifi_mesh_security_type_e security);
 
+/**
+ * @brief Gets the pmf type.
+ * @details This function is to get the pmf type.
+ *
+ * @since_tizen 5.0
+ *
+ * @param[in] network The Wi-Fi mesh network information handle.
+ * @param[out] pmf The pmf type for network.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_MESH_ERROR_NONE Successful
+ * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see wifi_mesh_network_set_pmf()
+ *
+ */
+int wifi_mesh_network_get_pmf(wifi_mesh_network_h network,
+               wifi_mesh_pmf_type_e *pmf);
+
+/**
+ * @brief Sets the pmf type.
+ * @details This function is to set the pmf type.
+ *
+ * @since_tizen 5.0
+ *
+ * @param[in] network The Wi-Fi mesh network information handle.
+ * @param[in] pmf The pmf type for network.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_MESH_ERROR_NONE Successful
+ * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see wifi_mesh_network_get_pmf()
+ *
+ */
+int wifi_mesh_network_set_pmf(wifi_mesh_network_h network,
+               wifi_mesh_pmf_type_e pmf);
+
 /**
  * @brief Sets the passphrase for network connection.
  * @details This function is to set the passphrase.
index d257aaa295b7cf6881a175611b333cf83d338aa3..bf05428fcd4e0f7d120efa7aebe44087a93dc065 100644 (file)
@@ -80,6 +80,7 @@ struct mesh_network_s {
        int rssi; /**< RSSI */
        int data_rate; /**< Data rate */
        wifi_mesh_security_type_e security; /**< Security type */
+       wifi_mesh_pmf_type_e pmf; /**< Pmf type */
        char passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase */
        wifi_mesh_connection_state_e state; /**< Connection state */
        wifi_mesh_ip_config_type_e ipv4_type; /**< IPv4 Config Type */
index 191529bc5b251147331a4a33792107ecaf674efe..c3ed3964bec2ab8948c3994e6a5634f7827403d1 100644 (file)
@@ -1523,7 +1523,7 @@ int _mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h _network)
        }
 
        variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "create_mesh_network",
-                               g_variant_new("(sii)", n->meshid, n->channel, n->security),
+                               g_variant_new("(siii)", n->meshid, n->channel, n->security, n->pmf),
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
                                NULL, &error);
index d59495ecb9cfb00f0ba1aef3d696dda63d9cb374..eeb2ec3218ad1df52c80b51121c6b0c7303c52c9 100644 (file)
@@ -78,6 +78,7 @@ EXPORT_API int wifi_mesh_network_clone(wifi_mesh_network_h* dst, wifi_mesh_netwo
        net->rssi = _src->rssi;
        net->data_rate = _src->data_rate;
        net->security = _src->security;
+       net->pmf = _src->pmf;
        if (strlen(_src->passphrase) > 0)
                snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", _src->passphrase);
 
@@ -88,7 +89,7 @@ EXPORT_API int wifi_mesh_network_clone(wifi_mesh_network_h* dst, wifi_mesh_netwo
 
 EXPORT_API int wifi_mesh_network_new_with(wifi_mesh_network_h* network, const char *meshid,
        const char *bssid, int channel, int rssi, wifi_mesh_security_type_e security,
-       const char *passphrase)
+       const char *passphrase, wifi_mesh_pmf_type_e pmf)
 {
        struct mesh_network_s *net;
 
@@ -109,6 +110,7 @@ EXPORT_API int wifi_mesh_network_new_with(wifi_mesh_network_h* network, const ch
        net->channel = channel;
        net->rssi = rssi;
        net->security = security;
+       net->pmf = pmf;
        if (passphrase)
                snprintf(net->passphrase, MAX_PASSPHRASE_LEN, "%s", passphrase);
 
@@ -314,6 +316,42 @@ EXPORT_API int wifi_mesh_network_set_security(wifi_mesh_network_h network, wifi_
        return WIFI_MESH_ERROR_NONE;
 }
 
+EXPORT_API int wifi_mesh_network_get_pmf(wifi_mesh_network_h network, wifi_mesh_pmf_type_e *pmf)
+{
+       struct mesh_network_s *net = (struct mesh_network_s *)network;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (NULL == network || NULL == pmf) {
+               /* LCOV_EXCL_START */
+               LOGE("Invalid parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       *pmf = net->pmf;
+
+       return WIFI_MESH_ERROR_NONE;
+}
+
+EXPORT_API int wifi_mesh_network_set_pmf(wifi_mesh_network_h network, wifi_mesh_pmf_type_e pmf)
+{
+       struct mesh_network_s *net = (struct mesh_network_s *)network;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (NULL == network) {
+               /* LCOV_EXCL_START */
+               LOGE("Invalid parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       net->pmf = pmf;
+
+       return WIFI_MESH_ERROR_NONE;
+}
+
 EXPORT_API int wifi_mesh_network_set_passphrase(wifi_mesh_network_h network, const char* passphrase)
 {
        struct mesh_network_s *net = (struct mesh_network_s *)network;
index bb7f7ebe7ed85c130a7a2201ac630072c44461f5..55f2d056e280fa3f73f8665302b6ccd7f5e14262 100644 (file)
@@ -44,6 +44,7 @@ static char security[MENU_DATA_SIZE + 1] = "2";
 static char meshid[MENU_DATA_SIZE + 1] = "meshnet";
 static char mesh_channel[MENU_DATA_SIZE + 1] = "161";
 static char mesh_security[MENU_DATA_SIZE + 1] = "0";
+static char mesh_pmf[MENU_DATA_SIZE + 1] = "0";
 static char mesh_passphrase[MENU_DATA_SIZE + 1] = "";
 
 static char network_idx[MENU_DATA_SIZE + 1] = "1";
@@ -720,6 +721,7 @@ static int run_create_network(MManager *mm, struct menu_data *menu)
        int ret;
        int _mesh_channel = 1;
        wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
+       wifi_mesh_pmf_type_e pmf = MESH_PMF_NONE;
        wifi_mesh_network_h net = NULL;
 
        msg("Create a new Mesh Network");
@@ -732,8 +734,13 @@ static int run_create_network(MManager *mm, struct menu_data *menu)
                security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE);
        }
 
+       if (strlen(mesh_pmf)) {
+               ret = (unsigned short)strtol(mesh_pmf, NULL, 10);
+               pmf = ((2 < ret) ? MESH_PMF_NONE : ret);
+       }
+
        wifi_mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0,
-               security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL);
+               security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL, pmf);
        ret = wifi_mesh_create_network(mesh, net);
        wifi_mesh_network_destroy(net);
        if (WIFI_MESH_ERROR_NONE != ret) {
@@ -1043,8 +1050,9 @@ static struct menu_data menu_create_network[] = {
        { "1", "Mesh ID", NULL, NULL, meshid },
        { "2", "Channel", NULL, NULL, mesh_channel },
        { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security },
-       { "4", "Passphrase", NULL, NULL, mesh_passphrase },
-       { "5", "Run", NULL, run_create_network, NULL },
+       { "4", "PMF (0=None,1=OPTIONAL,2=REQUIRED)", NULL, NULL, mesh_pmf },
+       { "5", "Passphrase", NULL, NULL, mesh_passphrase },
+       { "6", "Run", NULL, run_create_network, NULL },
        { NULL, NULL, },
 };