return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE);
}
+static GVariant *__open_data_path_handler(GVariant *parameters)
+{
+ _emit_gdbus_signal(DATA_PATH_OPENED);
+ return g_variant_new("(i)", WIFI_AWARE_ERROR_NONE);
+}
+
struct {
const gchar *interface_name;
const gchar *method_name;
__cancel_subscribe_handler,
},
{
+ "net.nan.discovery",
+ "OpenDataPath",
+ NULL,
+ __open_data_path_handler,
+ },
+ {
+ "net.nan.discovery",
+ "OpenDataPathPsk",
+ NULL,
+ __open_data_path_handler,
+ },
+ {
+ "net.nan.discovery",
+ "OpenDataPathPmk",
+ NULL,
+ __open_data_path_handler,
+ },
+ {
NULL,
NULL,
NULL,
_signal_data.user_data = user_data;
}
+static void __data_path_open_result(GDBusSignalCallback callback, gpointer user_data)
+{
+ if (!callback)
+ return;
+ _signal_data.callback = callback;
+ strncpy(_signal_data.signal_name, "DataPathOpenResult", 50);
+ _signal_data.parameters = g_variant_new("(ussii)", DUMMY_NDP_ID,
+ DUMMY_NDP_IFACE, DUMMY_PEER_IP, DUMMY_PEER_PORT,
+ WIFI_AWARE_ERROR_NONE);
+ _signal_data.user_data = user_data;
+}
+
struct {
const gchar *interface_name;
const gchar *signal_name;
"MessageReceived",
__message_received,
},
+ [DATA_PATH_OPENED] = {
+ "net.nan.discovery",
+ "DataPathOpenResult",
+ __data_path_open_result,
+ },
{
NULL,
NULL,
#define DUMMY_PUBLISH_ID 1
#define DUMMY_SUBSCRIBE_ID 1
#define DUMMY_PEER_ID 1
+#define DUMMY_NDP_ID 1
+#define DUMMY_NDP_IFACE "ndp0"
+#define DUMMY_PEER_IP "fe80::0"
+#define DUMMY_PEER_PORT 1234
#define DUMMY_DISTANCE 1
#define MAC_ADDR_LEN 6
typedef enum {
SERVICE_DISCOVERED = 0,
MESSAGE_RECEIVED,
+ DATA_PATH_OPENED,
} wifi_aware_gdbus_signal_e;
GDBusConnection *_get_dummy_gdbus_connection();
protected:
virtual void SetUp()
{
+ g_data_path_open = false;
WifiAware::SetUp();
g_session = __create_dummy_session(WIFI_AWARE_SESSION_SUBSCRIBE);
g_peer = __create_dummy_peer();
- g_data_path = __create_dummy_data_path();
+ g_data_path = __create_dummy_data_path(g_session, g_peer);
}
virtual void TearDown()
wifi_aware_peer_h g_peer;
wifi_aware_data_path_h g_data_path;
+public:
+ static bool g_data_path_open;
};
#include "wifi-aware-data-path-unittest-fixture.h"
#include "wifi-aware.h"
+bool WifiAwareDataPath::g_data_path_open;
+
+static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error,
+ void *user_data)
+{
+ WifiAwareDataPath::g_data_path_open = true;
+ QUIT_GMAIN_LOOP;
+}
+
static void __terminated_cb(wifi_aware_data_path_h data_path,
wifi_aware_termination_reason_e reason, void *user_data)
{
CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_destroy");
}
+TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p1)
+{
+ int ret = 0;
+
+ wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+ RUN_GMAIN_LOOP;
+
+ ret = wifi_aware_data_path_open(g_data_path, __open_cb, NULL);
+ CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_open");
+ RUN_GMAIN_LOOP;
+
+ ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open";
+ wifi_aware_disable();
+}
+
+TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p2)
+{
+ int ret = 0;
+
+ wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+ RUN_GMAIN_LOOP;
+
+ wifi_aware_data_path_set_security(g_data_path, WIFI_AWARE_SECURITY_TYPE_PSK);
+ wifi_aware_data_path_set_psk(g_data_path, "12345678");
+
+ ret = wifi_aware_data_path_open(g_data_path, __open_cb, NULL);
+ CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_open");
+ RUN_GMAIN_LOOP;
+
+ ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open";
+ wifi_aware_disable();
+}
+
+TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_p3)
+{
+ int ret = 0;
+ unsigned char pmk[PMK_LEN] = {0, };
+
+ wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+ RUN_GMAIN_LOOP;
+
+ wifi_aware_data_path_set_security(g_data_path, WIFI_AWARE_SECURITY_TYPE_PMK);
+ wifi_aware_data_path_set_pmk(g_data_path, pmk);
+
+ ret = wifi_aware_data_path_open(g_data_path, __open_cb, NULL);
+ CHECK_RESULT(WIFI_AWARE_ERROR_NONE, ret, "wifi_aware_data_path_open");
+ RUN_GMAIN_LOOP;
+
+ ASSERT_TRUE(WifiAwareDataPath::g_data_path_open) << "FAIL Data Path Open";
+ wifi_aware_disable();
+}
+
TEST_F(WifiAwareDataPath, wifi_aware_data_path_open_n)
{
int ret = 0;
- ret = wifi_aware_data_path_open(NULL, NULL, NULL);
+ ret = wifi_aware_data_path_open(g_data_path, NULL, NULL);
CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_OPERATION, ret, "wifi_aware_data_path_open");
+
+ wifi_aware_enable(WifiAware::__enabled_cb, NULL);
+ RUN_GMAIN_LOOP;
+
+ ret = wifi_aware_data_path_open(NULL, NULL, NULL);
+ CHECK_RESULT(WIFI_AWARE_ERROR_INVALID_PARAMETER, ret, "wifi_aware_data_path_open");
+
+ wifi_aware_disable();
}
TEST_F(WifiAwareDataPath, wifi_aware_data_path_close_n)
} __wifi_aware_peer_s;
typedef struct {
+ uint16_t ttl;
+ wifi_aware_publish_type_e publish_type;
+ char service_name[MAX_SERVICE_NAME_LEN + 1];
+ uint8_t specific_info[MAX_SERVICE_SPECIFIC_INFO_LEN];
+ uint16_t specific_info_len;
+ uint8_t match_filter[MAX_MATCH_FILTER_LEN];
+ uint16_t match_filter_len;
+ bool enable_ranging;
+} __wifi_aware_publish_request_s;
+
+typedef struct {
+ uint16_t ttl;
+ wifi_aware_subscribe_type_e subscribe_type;
+ char service_name[MAX_SERVICE_NAME_LEN + 1];
+ uint8_t specific_info[MAX_SERVICE_SPECIFIC_INFO_LEN];
+ uint16_t specific_info_len;
+ uint8_t match_filter[MAX_MATCH_FILTER_LEN];
+ uint16_t match_filter_len;
+ int max_distance;
+ int min_distance;
+} __wifi_aware_subscribe_request_s;
+
+typedef struct {
uint16_t pub_sub_id;
wifi_aware_session_type_e session_type;
wifi_aware_publish_h publish_config;
bool is_open;
} __wifi_aware_data_path_s;
+static wifi_aware_publish_h __create_dummy_publish_config()
+{
+ __wifi_aware_publish_request_s *config =
+ (__wifi_aware_publish_request_s *)g_try_malloc0(sizeof(__wifi_aware_publish_request_s));
+ config->publish_type = WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED;
+ strncpy(config->service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN + 1);
+ return config;
+}
+
+static void __destroy_dummy_publish_config(wifi_aware_publish_h config)
+{
+ g_free(config);
+}
+
+static wifi_aware_subscribe_h __create_dummy_subscribe_config()
+{
+ __wifi_aware_subscribe_request_s *config =
+ (__wifi_aware_subscribe_request_s *)g_try_malloc0(sizeof(__wifi_aware_subscribe_request_s));
+ config->subscribe_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE;
+ strncpy(config->service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN + 1);
+ return config;
+}
+
+static void __destroy_dummy_subscribe_config(wifi_aware_subscribe_h config)
+{
+ g_free(config);
+}
+
wifi_aware_session_h __create_dummy_session(wifi_aware_session_type_e type)
{
__wifi_aware_session_s *session =
(__wifi_aware_session_s *)g_try_malloc0(sizeof(__wifi_aware_session_s));
session->pub_sub_id = 1;
session->session_type = type;
+ if (type == WIFI_AWARE_SESSION_PUBLISH)
+ session->publish_config = __create_dummy_publish_config();
+ else
+ session->subscribe_config = __create_dummy_subscribe_config();
return session;
}
void __destroy_dummy_session(wifi_aware_session_h session)
{
+ __wifi_aware_session_s *s = (__wifi_aware_session_s *)session;
+ if (s->session_type == WIFI_AWARE_SESSION_PUBLISH)
+ __destroy_dummy_publish_config(s->publish_config);
+ else
+ __destroy_dummy_subscribe_config(s->subscribe_config);
g_free(session);
}
g_free(peer);
}
-wifi_aware_data_path_h __create_dummy_data_path()
+wifi_aware_data_path_h __create_dummy_data_path(wifi_aware_session_h session, wifi_aware_peer_h peer)
{
__wifi_aware_data_path_s *data_path =
(__wifi_aware_data_path_s *)g_try_malloc0(sizeof(__wifi_aware_data_path_s));
snprintf(data_path->iface_name, IFNAMSIZ, "ndp0");
snprintf(data_path->peer_ip, IPV6_ADDR_STR_LEN, "fe80::0");
data_path->is_open = true;
+ data_path->session = session;
+ data_path->peer = peer;
return data_path;
}
#define SERVICE_NAME "NanService"
#define SERVICE_INFO "ServiceInfo"
#define MATCH_FILTER "Match Filter"
+#define MAX_SERVICE_NAME_LEN 255
+#define MAX_MATCH_FILTER_LEN 255
+#define MAX_SERVICE_SPECIFIC_INFO_LEN 1024
#define MAX_PSK_LEN 63
#define PMK_LEN 32
#define DATA_PATH_PEER_PORT 1234
void __destroy_dummy_peer(wifi_aware_peer_h peer);
wifi_aware_session_h __create_dummy_session(wifi_aware_session_type_e type);
void __destroy_dummy_session(wifi_aware_session_h session);
-wifi_aware_data_path_h __create_dummy_data_path();
+wifi_aware_data_path_h __create_dummy_data_path(wifi_aware_session_h session, wifi_aware_peer_h peer);
void __destroy_dummy_data_path(wifi_aware_data_path_h data_path);
void WifiAware::__enabled_cb(wifi_aware_error_e error, void *user_data)
{
- if (error == WIFI_AWARE_ERROR_NONE) {
- // LOGI("Successfully Enabled");
+ if (error == WIFI_AWARE_ERROR_NONE)
WifiAware::g_enabled = true;
- }
- else {
- // LOGE("Fail to enable %s(%d)", _wifi_aware_error_to_string(error), error);
- }
QUIT_GMAIN_LOOP;
}