Add cts-verifier app for wearable
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 6 Apr 2020 08:26:02 +0000 (17:26 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 6 Apr 2020 08:26:02 +0000 (17:26 +0900)
CMakeLists.txt
cts-verifier/CMakeLists.txt [new file with mode: 0644]
cts-verifier/cts-verifier-common.c [new file with mode: 0644]
cts-verifier/cts-verifier-main.c [new file with mode: 0644]
cts-verifier/cts-verifier-publish-test.c [new file with mode: 0644]
cts-verifier/cts-verifier-subscribe-test.c [new file with mode: 0644]
cts-verifier/cts-verifier.h [new file with mode: 0644]
packaging/capi-network-wifi-aware.spec

index 57d83eb..e5bc6fd 100644 (file)
@@ -53,9 +53,10 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}")
 
 SET(TARGET_WIFI_AWARE "capi-network-wifi-aware")
 SET(TARGET_WIFI_AWARE_TEST "wifi-aware-test")
-
+SET(TARGET_CTS_VERIFIER_TOOL "cts-verifier")
 
 ADD_SUBDIRECTORY(include)
 ADD_SUBDIRECTORY(src)
 ADD_SUBDIRECTORY(pkgconfig)
 ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(cts-verifier)
diff --git a/cts-verifier/CMakeLists.txt b/cts-verifier/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6523fbb
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+# @file        CMakeLists.txt
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+#PROJECT(${TARGET_CTS_VERIFIER_TOOL} C)
+
+#MESSAGE("NAME: ${PROJECT_NAME}")
+
+SET(CTS_VERIFIER_TOOL_INCLUDE_DIR ${CTS_VERIFIER_TOOL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include)
+INCLUDE_DIRECTORIES(${CTS_VERIFIER_TOOL_INCLUDE_DIR})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(TARGET_CTS_VERIFIER_TOOL REQUIRED capi-base-common glib-2.0)
+FOREACH(flag ${TARGET_CTS_VERIFIER_TOOL_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+       MESSAGE(${flag})
+ENDFOREACH()
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+aux_source_directory(. sources)
+
+ADD_EXECUTABLE(${TARGET_CTS_VERIFIER_TOOL} ${sources})
+TARGET_LINK_LIBRARIES(${TARGET_CTS_VERIFIER_TOOL} ${TARGET_WIFI_AWARE} ${TARGET_CTS_VERIFIER_TOOL_LDFLAGS})
+INSTALL(TARGETS ${TARGET_CTS_VERIFIER_TOOL} RUNTIME DESTINATION ${BIN_DIR})
diff --git a/cts-verifier/cts-verifier-common.c b/cts-verifier/cts-verifier-common.c
new file mode 100644 (file)
index 0000000..c391fe5
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "wifi-aware.h"
+
+#include "cts-verifier.h"
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x\n"
+
+#define MAX_INIT_NUM 1024
+#define MAX_LOG_LEN 700
+
+const char *__print_error(int err)
+{
+       switch (err) {
+       case WIFI_AWARE_ERROR_NONE:
+               return "NO ERROR";
+       case WIFI_AWARE_ERROR_NOT_PERMITTED:
+               return "NOT_PERMITTED";
+       case WIFI_AWARE_ERROR_OUT_OF_MEMORY:
+               return "OUT_OF_MEMORY";
+       case WIFI_AWARE_ERROR_PERMISSION_DENIED:
+               return "PERMISSION_DENIED";
+       case WIFI_AWARE_ERROR_RESOURCE_BUSY:
+               return "RESOURCE_BUSY";
+       case WIFI_AWARE_ERROR_INVALID_PARAMETER:
+               return "INVALID_PARAMETER";
+       case WIFI_AWARE_ERROR_NOW_IN_PROGRESS:
+               return "NOW_IN_PROGRESS";
+       case WIFI_AWARE_ERROR_NOT_SUPPORTED:
+               return "NOT_SUPPORTED";
+       case WIFI_AWARE_ERROR_OPERATION_FAILED:
+               return "OPERATION_FAILED";
+       case WIFI_AWARE_ERROR_NOT_INITIALIZED:
+               return "NOT_INITIALIZED";
+       case WIFI_AWARE_ERROR_ALREADY_INITIALIZED:
+               return "ALREADY_INITIALIZED";
+       case WIFI_AWARE_ERROR_REJECTED_BY_PEER:
+               return "REJECTED_BY_PEER";
+       default:
+               return "UNKNOWN";
+       }
+}
+
+static void __print_result(int ret, gchar *msg)
+{
+       if (ret == WIFI_AWARE_ERROR_NONE)
+               printf("success to %s\n", msg);
+       else
+               printf("fail to %s: %s \n", msg, __print_error(ret));
+}
+
+void __print_mac(unsigned char mac[6])
+{
+       printf(MACSTR, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+}
+
+void test_init()
+{
+       printf("Start Test...\n");
+       wifi_aware_initialize();
+}
+
+void test_deinit()
+{
+       int ret = wifi_aware_disable();
+       __print_result(ret, "disable");
+       ret = wifi_aware_deinitialize();
+       __print_result(ret, "deinitialize");
+}
diff --git a/cts-verifier/cts-verifier-main.c b/cts-verifier/cts-verifier-main.c
new file mode 100644 (file)
index 0000000..6ac849f
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "wifi-aware.h"
+
+#include "cts-verifier.h"
+
+static GMainLoop *g_main_loop_p = NULL;
+
+#define RET_IF_LOOP_IS_NULL()\
+       do {\
+               if (!g_main_loop_p) {\
+                       printf("Loop was not initialized\n");\
+                       return;\
+               } \
+       } while (0)
+
+#define RET_IF_SESSION_IS_NULL()\
+       do {\
+               if (!g_wifi_aware_session) {\
+                       printf("wifi-aware-session handle is not created yet\n");\
+                       return;\
+               }\
+       } while (0)
+
+#define RET_IF_NDP_IS_NULL()\
+       do {\
+               if (!g_ndp) {\
+                       printf("wifi_aware_data_path handle is not created yet\n");\
+                       return;\
+               }\
+       } while (0)
+
+enum {
+       CMD_QUIT = 0,
+
+       CMD_OPEN_UNSOL,
+       CMD_OPEN_PASSIVE,
+
+       CMD_PSK_UNSOL,
+       CMD_PSK_PASSIVE,
+
+       CMD_OPEN_SOL,
+       CMD_OPEN_ACT,
+
+       CMD_PSK_SOL,
+       CMD_PSK_ACT,
+
+       CMD_INVALID,
+};
+
+/*****************************************************************************
+ *  Global Variables
+ *****************************************************************************/
+
+static char *g_menu_str[] = {
+       [CMD_QUIT]
+               = "Quit test",
+
+       [CMD_OPEN_UNSOL]
+               = "Publish",
+       [CMD_OPEN_PASSIVE]
+               = "Subscribe",
+
+       [CMD_PSK_UNSOL]
+               = "Publish",
+       [CMD_PSK_PASSIVE]
+               = "Subscribe",
+
+       [CMD_OPEN_SOL]
+               = "Publish",
+       [CMD_OPEN_ACT]
+               ="Subscribe",
+
+       [CMD_PSK_SOL]
+               ="Publish",
+       [CMD_PSK_ACT]
+               ="Subscribe",
+
+       [CMD_INVALID]
+               = NULL,
+};
+
+typedef void (*test_func)(void);
+test_func g_menu_func[] = {
+       //[CMD_QUIT]                            = test_quit,
+       [CMD_QUIT]                              = NULL,
+
+       [CMD_OPEN_UNSOL]                = test_open_unsolicited,
+       [CMD_OPEN_PASSIVE]              = test_open_passive,
+
+       [CMD_PSK_UNSOL]                 = test_psk_unsolicited,
+       [CMD_PSK_PASSIVE]               = test_psk_passive,
+
+       [CMD_OPEN_SOL]                  = test_open_solicited,
+       [CMD_OPEN_ACT]                  = test_open_active,
+
+       [CMD_PSK_SOL]                   = test_psk_solicited,
+       [CMD_PSK_ACT]                   = test_psk_active,
+
+       [CMD_INVALID]                   = NULL,
+};
+
+static inline void __usage_full()
+{
+       int i;
+       printf("Call Test Program\n");
+
+       for (i = CMD_OPEN_UNSOL; i < CMD_INVALID; i++) {
+               if (i == CMD_OPEN_UNSOL)
+                       printf(MAKE_GREEN"Test 1. UnSolicited/Passive/DataPath(Open)"RESET_COLOR"\n");
+               else if (i == CMD_PSK_UNSOL)
+                       printf(MAKE_GREEN"Test 2. UnSolicited/Passive/DataPath(PSK)"RESET_COLOR"\n");
+               else if (i == CMD_OPEN_SOL)
+                       printf(MAKE_GREEN"Test 3. Solicited/Active/DataPath(Open)"RESET_COLOR"\n");
+               else if (i == CMD_PSK_SOL)
+                       printf(MAKE_GREEN"Test 4. Solicited/Active/DataPath(PSK)"RESET_COLOR"\n");
+       
+               printf(" [%02d] %s\n", i, g_menu_str[i]);
+       }
+
+       printf(MAKE_GREEN"Please input '0' if test is finished."RESET_COLOR"\n");
+       printf("\n");
+}
+
+static inline int __is_digit(const char* str)
+{
+       int len;
+       int i;
+
+       if (str == NULL)
+               return -1;
+
+       if (strlen(str) == 0)
+               return -1;
+
+       len = strlen(str);
+       for (i = 0; i < len; i++)   {
+               if (str[i] < '0' || str[i] > '9')
+                       return -2;
+       }
+
+       return 0;
+}
+
+static inline void __process_input(const char *input, gpointer user_data)
+{
+       int cmd = -1;
+
+       cmd = strtol(input, NULL, 0);
+       if (__is_digit(input) < 0 || strlen(input) == 0 || errno == ERANGE || errno
+                       == EINVAL)
+               cmd = CMD_INVALID;
+
+       printf("cmd=[%d]\n", cmd);
+       if (cmd >= CMD_INVALID || cmd < CMD_QUIT) {
+               printf("Invalid CMD\n");
+               return;
+       }
+       g_menu_func[cmd]();
+}
+
+static gboolean __test_terminal_read_std_input(GIOChannel * source,
+               GIOCondition condition, gpointer user_data)
+{
+       int fd = 0;
+
+       static char buf[1024];
+       int n;
+
+       errno = 0;
+       n = read(fd, buf, 1024);
+       if (n == 0) {
+               printf("Error: read() from stdin returns 0.\n");
+       } else if (n < 0) {
+               printf("input: read, err\n");
+       } else if (buf[0] == '0') {
+               test_deinit();
+               printf(MAKE_GREEN"Test is finished.."RESET_COLOR"\n");
+               exit(1);
+       } else if (buf[0] == '\n' || buf[0] == '\r') {
+               __usage_full();
+       } else if (n - 1 > 0 && n < 1024) {
+               buf[n - 1] = '\0'; /* remove new line... */
+               printf("\n\n");
+               __process_input(buf, user_data);
+       } else {
+               printf("invalid input\n");
+       }
+
+       return TRUE;
+}
+
+int main(int argc, char **argv)
+{
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+       g_type_init();
+#endif
+       g_main_loop_p = g_main_loop_new(NULL, FALSE);
+
+       int std_input_fd = 0;
+       GIOChannel *gio2 = g_io_channel_unix_new(std_input_fd);
+       g_io_add_watch(gio2, G_IO_IN, (GIOFunc) __test_terminal_read_std_input, NULL);
+       g_io_channel_unref(gio2);
+
+       __usage_full();
+
+       g_main_loop_run(g_main_loop_p);
+       g_main_loop_unref(g_main_loop_p);
+
+       return 0;
+}
diff --git a/cts-verifier/cts-verifier-publish-test.c b/cts-verifier/cts-verifier-publish-test.c
new file mode 100644 (file)
index 0000000..7d63123
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Wi-Fi Aware
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "wifi-aware.h"
+
+#include "cts-verifier.h"
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+
+#define MAX_INIT_NUM 1024
+#define MAX_LOG_LEN 700
+
+#define PORT 1234
+
+#define MAX_SERVICE_NAME_LEN 255
+#define MAX_SPECIFIC_INFO_LEN 1024
+
+#define MAX_PSK_LEN 63
+#define IPV6_ADDRESS_LEN 39
+
+static wifi_aware_session_h g_wifi_aware_session = NULL;
+static wifi_aware_publish_h g_publish_handle = NULL;
+static wifi_aware_data_path_h g_ndp = NULL;
+static wifi_aware_peer_h g_peer = NULL;
+
+static wifi_aware_publish_type_e g_pub_type;
+static wifi_aware_security_type_e g_security_type;
+
+static void clear_resources();
+
+static void __test_finish(int is_validated)
+{
+       if (is_validated)
+               printf(MAKE_GREEN"Wi-Fi Aware validated!"RESET_COLOR"\n");
+       else
+               printf(MAKE_RED"Wi-Fi Aware invalidated!"RESET_COLOR"\n");
+       test_deinit();
+}
+
+static void __published_cb(wifi_aware_session_h session,
+               wifi_aware_error_e error, void *user_data)
+{
+       if (error == WIFI_AWARE_ERROR_NONE) {
+               printf("Publish discovery session started...\n");
+       } else {
+               printf("Publish is failed...\n");
+               __test_finish(0);
+       }
+
+       return;
+}
+
+static void __data_path_terminated_cb(wifi_aware_data_path_h data_path,
+               wifi_aware_termination_reason_e reason, void *user_data)
+{
+       g_ndp = data_path;
+       __test_finish(1);
+}
+
+static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error, void *user_data)
+{
+       if (error == WIFI_AWARE_ERROR_NONE) {
+               printf("DataPath is confirmed...\n");
+               int ret = WIFI_AWARE_ERROR_NONE;
+               char *interface;
+
+               char *ipv6_address;
+               int port;
+               ret = wifi_aware_data_path_get_peer_ipv6_address(data_path, &ipv6_address);
+               ret = wifi_aware_data_path_get_peer_port(data_path, &port);
+               __test_finish(1);
+       } else {
+               printf("Failed to open Data Path...\n");
+               __test_finish(0);
+       }
+}
+
+static void __open_data_path(wifi_aware_session_h session)
+{
+       printf("Request to open Data Path...\n");
+
+       if (g_peer == NULL) {
+               printf("Peer doesn't exist.\n");
+               __test_finish(0);
+               return;
+       }
+
+       int ret = wifi_aware_data_path_create(session, g_peer, &g_ndp);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_set_terminated_cb(g_ndp, __data_path_terminated_cb, NULL);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_set_security(g_ndp, g_security_type);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       switch (g_security_type) {
+       case WIFI_AWARE_SECURITY_TYPE_OPEN:
+               break;
+       case WIFI_AWARE_SECURITY_TYPE_PSK:
+               ret = wifi_aware_data_path_set_psk(g_ndp, PASSPHRASE);
+               break;
+       case WIFI_AWARE_SECURITY_TYPE_PMK:
+               break;
+       default:
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_set_port(g_ndp, PORT);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_open(g_ndp, __open_cb, NULL);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+}
+
+static void __message_result_cb(wifi_aware_session_h session, wifi_aware_error_e error, void *user_data)
+{
+       if (error == WIFI_AWARE_ERROR_NONE) {
+               printf("Sent message successfully...\n");
+               __open_data_path(session);
+       } else {
+               printf("Sending message is failed...\n");
+               __test_finish(0);
+       }
+}
+
+static void __message_received_cb(wifi_aware_session_h session, wifi_aware_peer_h peer,
+               const unsigned char *message, size_t len, void *user_data)
+{
+       //char buf[1024] = {0, };
+       unsigned char *mac = NULL;
+
+       printf("Received message...\n");
+
+       //memcpy(buf, message, 1024);
+       wifi_aware_peer_get_mac(peer, &mac);
+
+       printf("Peer's NMI: ");
+       if (mac != NULL) {
+               __print_mac(mac);
+               g_free(mac);
+       }
+
+       g_peer = peer;
+       unsigned char send_message[1024] = {0, };
+       size_t message_len = strlen(MSG_PUB_TO_SUB);
+       memcpy(send_message, MSG_PUB_TO_SUB, message_len);
+       wifi_aware_session_send_message(session,
+                       peer, send_message, message_len, __message_result_cb, NULL);
+}
+
+static void __session_terminated_cb(wifi_aware_session_h session,
+               wifi_aware_termination_reason_e reason, void *user_data)
+{
+       printf("Session is terminated\n");
+       if (session != NULL) {
+               wifi_aware_session_destroy(session);
+               wifi_aware_session_unset_message_received_cb(session);
+       }
+}
+
+static bool __set_publish_config(wifi_aware_publish_h publish)
+{
+       int ret = 0;
+       char service_name[MAX_SERVICE_NAME_LEN + 1] = {0, };
+       unsigned char specific_info[MAX_SPECIFIC_INFO_LEN + 1] = {0, };
+       unsigned char match_filter[MAX_SPECIFIC_INFO_LEN + 1] = {0, };
+
+       ret = wifi_aware_publish_set_type(publish, g_pub_type);
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               return false;
+
+       strncpy(service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN);
+       ret = wifi_aware_publish_set_service_name(publish,
+                       service_name);
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               return false;
+
+       size_t len = strlen(PUB_SSI);
+       memcpy(specific_info, PUB_SSI, len);
+       ret = wifi_aware_publish_set_service_specific_info(publish,
+                       specific_info, len);
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               return false;
+
+       len = strlen(MATCH_FILTER);
+       match_filter[0] = len;
+       memcpy(&match_filter[1], MATCH_FILTER, len);
+       ret = wifi_aware_publish_set_match_filter(publish,
+                       match_filter, len + 1);
+       if (ret != WIFI_AWARE_ERROR_NONE)
+               return false;
+
+       return true;
+}
+
+static void __enabled_cb(wifi_aware_error_e error, void *user_data)
+{
+       if (error != WIFI_AWARE_ERROR_NONE) {
+               printf("Wi-Fi Aware is failed.\n");
+               __test_finish(0);
+               return;
+       } else {
+               printf("Wi-Fi Aware is enabled.\n");
+       }
+
+       int ret = wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_wifi_aware_session);
+       ret = wifi_aware_publish_create(&g_publish_handle);
+
+       if (__set_publish_config(g_publish_handle) == false) {
+               __test_finish(0);
+               return;
+       }
+       ret = wifi_aware_session_set_message_received_cb(g_wifi_aware_session,
+                       __message_received_cb, NULL);
+       ret = wifi_aware_session_set_terminated_cb(g_wifi_aware_session, __session_terminated_cb, NULL);
+       ret = wifi_aware_session_publish(g_wifi_aware_session, g_publish_handle, __published_cb, NULL);
+}
+
+static void run_common()
+{
+       int ret = 0;
+       ret = wifi_aware_enable(__enabled_cb, NULL);
+}
+
+static void clear_resources()
+{
+       if (g_ndp) {
+               wifi_aware_data_path_destroy(g_ndp);
+               wifi_aware_data_path_unset_terminated_cb(g_ndp);
+       }
+       g_ndp = NULL;
+
+       if (g_wifi_aware_session) {
+               wifi_aware_session_destroy(g_wifi_aware_session);
+               wifi_aware_session_unset_message_received_cb(g_wifi_aware_session);
+               wifi_aware_session_unset_terminated_cb(g_wifi_aware_session);
+       }
+       g_wifi_aware_session = NULL;
+
+       if (g_publish_handle)
+               wifi_aware_publish_destroy(g_publish_handle);
+       g_publish_handle = NULL;
+
+       g_peer = NULL;
+}
+
+void test_open_unsolicited()
+{
+       clear_resources();
+       test_init();
+       g_pub_type = WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_OPEN;
+       run_common();
+}
+
+void test_open_solicited()
+{
+       clear_resources();
+       test_init();
+       g_pub_type = WIFI_AWARE_PUBLISH_TYPE_SOLICITED;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_OPEN;
+       run_common();
+}
+
+void test_psk_unsolicited()
+{
+       clear_resources();
+       test_init();
+       g_pub_type = WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_PSK;
+       run_common();
+}
+
+void test_psk_solicited()
+{
+       clear_resources();
+       test_init();
+       g_pub_type = WIFI_AWARE_PUBLISH_TYPE_SOLICITED;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_PSK;
+       run_common();
+}
diff --git a/cts-verifier/cts-verifier-subscribe-test.c b/cts-verifier/cts-verifier-subscribe-test.c
new file mode 100644 (file)
index 0000000..091e3dd
--- /dev/null
@@ -0,0 +1,331 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "wifi-aware.h"
+
+#include "cts-verifier.h"
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+
+#define MAX_INIT_NUM 1024
+
+#define MAX_SERVICE_NAME_LEN 255
+#define MAX_SPECIFIC_INFO_LEN 1024
+
+#define MAX_PSK_LEN 63
+#define IPV6_ADDRESS_LEN 39
+
+static wifi_aware_session_h g_wifi_aware_session = NULL;
+static wifi_aware_subscribe_h g_subscribe_handle = NULL;
+static wifi_aware_data_path_h g_ndp = NULL;
+static wifi_aware_peer_h g_peer = NULL;
+
+static wifi_aware_subscribe_type_e g_sub_type;
+static wifi_aware_security_type_e g_security_type;
+static char g_psk[MAX_PSK_LEN + 1];
+
+static void clear_resources();
+
+static void __test_finish(int is_validated)
+{
+       if (is_validated)
+               printf(MAKE_GREEN"Wi-Fi Aware validated!"RESET_COLOR"\n");
+       else
+               printf(MAKE_RED"Wi-Fi Aware invalidated!"RESET_COLOR"\n");
+
+    clear_resources();
+}
+
+static void __subscribed_cb(wifi_aware_session_h session,
+               wifi_aware_error_e error, void *user_data)
+{
+       if (error == WIFI_AWARE_ERROR_NONE) {
+               printf("Subscribe discovery session started...\n");
+       }
+       else {
+               printf("Subscribe is failed...\n");
+               return;
+       }
+}
+
+static void __data_path_terminated_cb(wifi_aware_data_path_h data_path,
+               wifi_aware_termination_reason_e reason, void *user_data)
+{
+       if (data_path != NULL) {
+               wifi_aware_data_path_unset_terminated_cb(data_path);
+               wifi_aware_data_path_destroy(data_path);
+       }
+
+       __test_finish(1);
+}
+
+static void __open_cb(wifi_aware_data_path_h data_path, wifi_aware_error_e error, void *user_data)
+{
+       if (error == WIFI_AWARE_ERROR_NONE) {
+               printf("DataPath is confirmed...\n");
+               int ret = WIFI_AWARE_ERROR_NONE;
+               char *interface;
+
+               char *ipv6_address;
+               int port;
+               ret = wifi_aware_data_path_get_peer_ipv6_address(data_path, &ipv6_address);
+               ret = wifi_aware_data_path_get_peer_port(data_path, &port);
+               __test_finish(1);
+       } else {
+               printf("Failed to open Data Path...\n");
+               __test_finish(0);
+       }
+
+}
+
+static void __open_data_path(wifi_aware_session_h session)
+{
+       printf("Request to open Data Path...\n");
+
+       if (g_peer == NULL) {
+               printf("Peer doesn't exist.\n");
+               __test_finish(0);
+               return;
+       }
+
+       int ret = wifi_aware_data_path_create(session, g_peer, &g_ndp);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_set_terminated_cb(g_ndp, __data_path_terminated_cb, NULL);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_set_security(g_ndp, g_security_type);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+
+       switch (g_security_type) {
+       case WIFI_AWARE_SECURITY_TYPE_OPEN:
+               break;
+       case WIFI_AWARE_SECURITY_TYPE_PSK:
+               ret = wifi_aware_data_path_set_psk(g_ndp, g_psk);
+               break;
+       case WIFI_AWARE_SECURITY_TYPE_PMK:
+               break;
+       default:
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_data_path_open(g_ndp, __open_cb, NULL);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               __test_finish(0);
+               return;
+       }
+}
+
+static void __message_result_cb(wifi_aware_session_h session, wifi_aware_error_e error, void *user_data)
+{
+       if (error != WIFI_AWARE_ERROR_NONE) {
+               printf("Sending message is failed...\n");
+               __test_finish(0);
+       }
+       else {
+               printf("Sent message successfully...\n");
+       }
+}
+
+static void __message_received_cb(wifi_aware_session_h session, wifi_aware_peer_h peer,
+               const unsigned char *message, size_t len, void *user_data)
+{
+       int ret = 0;
+       //char buf[1024] = {0, };
+       unsigned char *mac = NULL;
+
+       printf("Received message...\n");
+
+       //memcpy(buf, message, 1024);
+       printf("Peer's NMI: ");
+       wifi_aware_peer_get_mac(peer, &mac);
+       if (mac != NULL) {
+               __print_mac(mac);
+               g_free(mac);
+       }
+
+       g_peer = peer;
+       __open_data_path(session);
+}
+
+static void __service_discovered_cb(wifi_aware_session_h session,
+               wifi_aware_peer_h peer,
+               const unsigned char *service_specific_info, size_t service_specific_info_len,
+               void *user_data)
+{
+       printf("Service discovered...\n");
+
+       unsigned char send_message[1024] = {0, };
+       size_t message_len = strlen(MSG_SUB_TO_PUB);
+       memcpy(send_message, MSG_SUB_TO_PUB, message_len);
+
+       int ret = wifi_aware_session_send_message(session,
+                       peer, send_message, message_len, __message_result_cb, NULL);
+}
+
+static void __session_terminated_cb(wifi_aware_session_h session,
+               wifi_aware_termination_reason_e reason, void *user_data)
+{
+       printf("Session is terminated\n");
+       if (session != NULL) {
+               wifi_aware_session_destroy(session);
+               wifi_aware_session_unset_message_received_cb(session);
+       }
+}
+
+static bool __set_subscribe_config(wifi_aware_subscribe_h subscribe)
+{
+       int ret = 0;
+       char service_name[MAX_SERVICE_NAME_LEN + 1] = {0, };
+       unsigned char specific_info[MAX_SPECIFIC_INFO_LEN + 1] = {0, };
+
+       ret = wifi_aware_subscribe_set_type(subscribe, g_sub_type);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               printf("Fail to set subscribe type\n");
+               return false;
+       }
+
+       strncpy(service_name, SERVICE_NAME, MAX_SERVICE_NAME_LEN);
+       ret = wifi_aware_subscribe_set_service_name(subscribe,
+                       service_name);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               printf("Fail to set service name\n");
+               return false;
+       }
+
+       size_t len = strlen(PUB_SSI);
+       memcpy(specific_info, PUB_SSI, len);
+       ret = wifi_aware_subscribe_set_service_specific_info(subscribe,
+                       specific_info, len);
+       if (ret != WIFI_AWARE_ERROR_NONE) {
+               printf("Fail to set service specific info\n");
+               return false;
+       }
+
+       return true;
+}
+
+static void __enabled_cb(wifi_aware_error_e error, void *user_data)
+{
+       if (error != WIFI_AWARE_ERROR_NONE) {
+               printf("Wi-Fi Aware is failed.\n");
+               __test_finish(0);
+               return;
+       } else {
+               printf("Wi-Fi Aware is enabled.\n");
+       }
+
+       int ret = wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_wifi_aware_session);
+
+       ret = wifi_aware_subscribe_create(&g_subscribe_handle);
+
+       if (__set_subscribe_config(g_subscribe_handle) == false) {
+               __test_finish(0);
+               return;
+       }
+
+       ret = wifi_aware_session_set_service_discovered_cb(g_wifi_aware_session,
+                       __service_discovered_cb, NULL);
+       ret = wifi_aware_session_set_message_received_cb(g_wifi_aware_session,
+                       __message_received_cb, NULL);
+       ret = wifi_aware_session_set_terminated_cb(g_wifi_aware_session, __session_terminated_cb, NULL);
+       ret = wifi_aware_session_subscribe(g_wifi_aware_session, g_subscribe_handle, __subscribed_cb, NULL);
+}
+
+static void run_common()
+{
+       int ret = 0;
+       ret = wifi_aware_enable(__enabled_cb, NULL);
+}
+
+static void clear_resources()
+{
+       if (g_ndp) {
+               wifi_aware_data_path_destroy(g_ndp);
+               wifi_aware_data_path_unset_terminated_cb(g_ndp);
+       }
+       g_ndp = NULL;
+
+       if (g_wifi_aware_session) {
+               wifi_aware_session_destroy(g_wifi_aware_session);
+               wifi_aware_session_unset_message_received_cb(g_wifi_aware_session);
+               wifi_aware_session_unset_service_discovered_cb(g_wifi_aware_session);
+               wifi_aware_session_unset_terminated_cb(g_wifi_aware_session);
+       }
+       g_wifi_aware_session = NULL;
+
+       if (g_subscribe_handle)
+               wifi_aware_subscribe_destroy(g_subscribe_handle);
+       g_subscribe_handle = NULL;
+
+       g_peer = NULL;
+}
+
+void test_open_passive()
+{
+       clear_resources();
+       test_init();
+       g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_OPEN;
+       run_common();
+}
+
+void test_open_active()
+{
+       clear_resources();
+       test_init();
+       g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_ACTIVE;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_OPEN;
+       run_common();
+}
+
+void test_psk_passive()
+{
+       clear_resources();
+       test_init();
+       g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_PSK;
+       strncpy(g_psk, PASSPHRASE, strlen(PASSPHRASE));
+       run_common();
+}
+
+void test_psk_active()
+{
+       clear_resources();
+       test_init();
+       g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_ACTIVE;
+       g_security_type = WIFI_AWARE_SECURITY_TYPE_PSK;
+       strncpy(g_psk, PASSPHRASE, strlen(PASSPHRASE));
+       run_common();
+}
diff --git a/cts-verifier/cts-verifier.h b/cts-verifier/cts-verifier.h
new file mode 100644 (file)
index 0000000..a52feb8
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Wi-Fi Aware Test Program
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+
+ * This file declares functions for testing Wi-Fi aware CAPIs.
+ *
+ * @file        wifi-aware-test.h
+ * @author      Jiung Yu (jiung.yu@samsung.com)
+ */
+#ifndef __WIFI_AWARE_TEST_H__
+#define __WIFI_AWARE_TEST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SERVICE_NAME "CtsVerifierTestService"
+#define MATCH_FILTER "bytes used for matching"
+#define PUB_SSI "Extra bytes in the publisher discovery"
+#define SUB_SSI "Arbitrary bytes for the subscribe discovery"
+#define MSG_SUB_TO_PUB "Let's talk"
+#define MSG_PUB_TO_SUB "Ready"
+#define PASSPHRASE "Some super secret password"
+
+#define RESET_COLOR "\e[m"
+#define MAKE_RED "\e[31m"
+#define MAKE_GREEN "\e[32m"
+
+// Common
+void __print_mac(unsigned char mac[6]);
+
+void test_init();
+void test_deinit();
+
+// Publish Test
+void test_open_unsolicited();
+void test_psk_unsolicited();
+void test_open_solicited();
+void test_psk_solicited();
+
+// Subscribe Test
+void test_open_passive();
+void test_psk_passive();
+void test_open_active();
+void test_psk_active();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WIFI_AWARE_TEST_H__ */
index 57783bd..41077d2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-network-wifi-aware
 Summary:    An Wi-Fi Aware libraries in Native API
-Version:    0.1.0
+Version:    0.1.1
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
@@ -35,6 +35,13 @@ Summary:    Wi-Fi Aware - Wi-Fi Aware test binaries
 %description test
 Test Application for Wi-Fi Aware
 
+%package cts-verifier
+summary:       cts-verifier command app 
+
+%description cts-verifier
+cts-verifier command app 
+
+
 %prep
 %setup -q
 chmod 644 %{SOURCE0}
@@ -91,3 +98,7 @@ rm -rf %{buildroot}
 %attr(755,root,root) %{_bindir}/wifi-aware-test
 %attr(755,root,root) %{_bindir}/wifi-aware-publish-test
 %attr(755,root,root) %{_bindir}/wifi-aware-subscribe-test
+
+%files cts-verifier
+#%manifest wifi-aware-test.manifest
+%attr(755,root,root) %{_bindir}/cts-verifier