Add test to open/close data path
authorCheoleun Moon <chleun.moon@samsung.com>
Mon, 9 Mar 2020 10:26:31 +0000 (19:26 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Mon, 9 Mar 2020 10:26:31 +0000 (19:26 +0900)
include/wifi-aware.h
test/wifi-aware-test.c

index 220a91a..08fcb27 100644 (file)
@@ -710,7 +710,7 @@ int wifi_aware_data_path_get_peer_port(wifi_aware_data_path_h data_path, int* po
  * @return
  * @retval     #WIFI_AWARE_ERROR_NONE
  */
-int wifi_aware_data_path_get_ipv6_address(wifi_aware_data_path_h data_path, char **ipv6_address);
+int wifi_aware_data_path_get_peer_ipv6_address(wifi_aware_data_path_h data_path, char **ipv6_address);
 
 /**
  * @brief
index fe288eb..5813642 100644 (file)
                }\
        } 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)
+
 #define SERVICE_NAME "CtsVerifierTestService"
 #define MATCH_FILTER "bytes used for matching"
 #define PUB_SSI "Extra bytes in the publisher discovery"
 #define MAX_SPECIFIC_INFO_LEN 1024
 #define MAX_MATCH_FILTER_LEN 255
 
+#define MAX_PSK_LEN 63
+#define PMK_LEN 32
+#define IPV6_ADDRESS_LEN 39
+
 typedef struct {
        int peer_id;
        wifi_aware_peer_h peer;
@@ -117,11 +129,13 @@ enum {
        CMD_UPDATE_PUBLISH,
        CMD_SUBSCRIBE,
        CMD_CANCEL_SUBSCRIBE,
-       CMD_TEST_SPECIFIC_INFO,
 
        CMD_MESSAGE_RECV_CB,
        CMD_SEND_MESSAGE,
 
+       CMD_OPEN_DATA_PATH,
+
+       CMD_TEST_SPECIFIC_INFO,
        CMD_INVALID,
 };
 
@@ -154,13 +168,16 @@ static char *g_menu_str[] = {
                = "SUBSCRIBE",
        [CMD_CANCEL_SUBSCRIBE]
                = "CANCEL SUBSCRIBE",
-       [CMD_TEST_SPECIFIC_INFO]
-               = "TEST SPECIFIC INFO",
 
        [CMD_MESSAGE_RECV_CB]
                = "SET MESSAGE_RECV CB",
        [CMD_SEND_MESSAGE]
                = "SEND MESSAGE",
+       [CMD_OPEN_DATA_PATH]
+               = "OPEN DATA PATH",
+
+       [CMD_TEST_SPECIFIC_INFO]
+               = "TEST SPECIFIC INFO",
        [CMD_INVALID]
                = NULL,
 };
@@ -169,7 +186,9 @@ static GMainLoop *g_main_loop_p;
 static wifi_aware_session_h g_wifi_aware_session = NULL;
 static wifi_aware_publish_h g_publish_handle = NULL;
 static wifi_aware_subscribe_h g_subscribe_handle = NULL;
-unsigned char g_msg[4];
+static wifi_aware_data_path_h g_ndp = NULL;
+static int g_session_type = -1;        // 0: publish, 1: subscribe
+static unsigned char g_msg[4];
 
 /*****************************************************************************
  *  Local Functions Definition
@@ -481,6 +500,7 @@ void test_publish()
        __print_result(ret, "wifi_aware_publish");
 
        memcpy(g_msg, "TEST", 4);
+       g_session_type = 0;
        //ret = wifi_aware_publish_destroy(publish);
        //__print_result(ret, "wifi_aware_publish_destroy");
 }
@@ -692,6 +712,7 @@ void test_subscribe()
        __print_result(ret, "wifi_aware_subscribe");
 
        memcpy(g_msg, "ABCD", 4);
+       g_session_type = 1;
 }
 
 void test_cancel_subscribe()
@@ -806,6 +827,114 @@ void test_send_message()
        printf("Send a message to %p", peer);
 }
 
+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) {
+               int ret = WIFI_AWARE_ERROR_NONE;
+               char *interface;
+               printf("Data path is created. NDP: %p\n", data_path);
+               ret = wifi_aware_data_path_get_interface(data_path, &interface);
+               if (ret == WIFI_AWARE_ERROR_NONE)
+                       printf("Interface: %s\n", interface);
+               else
+                       printf("Fail to get interface\n");
+
+               if (g_session_type == 1) {
+                       char *ipv6_address;
+                       int port;
+                       ret = wifi_aware_data_path_get_peer_ipv6_address(data_path, &ipv6_address);
+                       if (ret == WIFI_AWARE_ERROR_NONE)
+                               printf("IPv6 Address of Peer: %s\n", ipv6_address);
+                       else
+                               printf("Fail to get IPV6 Address\n");
+                       ret = wifi_aware_data_path_get_peer_port(data_path, &port);
+                       if (ret == WIFI_AWARE_ERROR_NONE)
+                               printf("Port number of Peer: %d\n", port);
+                       else
+                               printf("Fail to get Port number\n");
+               }
+       }
+       else {
+               printf("Fail to open Data path. NDP: %p\n", data_path);
+       }
+
+}
+
+void test_open_data_path()
+{
+       int ret = WIFI_AWARE_ERROR_NONE;
+       int peer_id;
+       int security_type;
+
+       RET_IF_LOOP_IS_NULL();
+
+       __display_peer_list();
+       printf("Select a peer to send message: ");
+       if (scanf("%d", &peer_id) < 0)
+               return;
+
+       wifi_aware_peer_h peer = __get_peer_by_id(peer_id);
+       ret = wifi_aware_data_path_create(g_wifi_aware_session, peer, &g_ndp);
+       __print_result(ret, "wifi_aware_data_path_create");
+       printf("NDP %p", g_ndp);
+
+       printf("Choose security type(0-Open, 1-PSK, 2-PMK): ");
+       ret = scanf("%d", &security_type);
+       if (ret < 0)
+               return;
+
+       ret = wifi_aware_data_path_set_security(g_ndp, security_type);
+       __print_result(ret, "wifi_aware_data_path_set_security");
+
+       if (security_type == WIFI_AWARE_SECURITY_TYPE_PSK) {
+               char key[MAX_PSK_LEN] = {0, };
+               printf("Passphrase: ");
+               ret = scanf("%s", key);
+               if (ret < 0)
+                       return;
+               ret = wifi_aware_data_path_set_psk(g_ndp, key);
+               __print_result(ret, "wifi_aware_data_path_set_psk");
+       }
+
+       if (security_type == WIFI_AWARE_SECURITY_TYPE_PMK) {
+               char key[PMK_LEN] = {0, };
+               unsigned char pmk[PMK_LEN] = {0, };
+               printf("PMK: ");
+               ret = scanf("%s", key);
+               if (ret < 0)
+                       return;
+               memcpy(pmk, key, PMK_LEN);
+               ret = wifi_aware_data_path_set_pmk(g_ndp, pmk);
+               __print_result(ret, "wifi_aware_data_path_set_pmk");
+       }
+
+       if (g_session_type == 0) {
+               int port = -1;
+               ret = scanf("%d", &port);
+               if (ret < 0)
+                       return;
+               ret = wifi_aware_data_path_set_port(g_ndp, port);
+               __print_result(ret, "wifi_aware_data_set_port");
+       }
+
+       ret = wifi_aware_data_path_open(g_ndp, __open_cb, NULL);
+       __print_result(ret, "wifi_aware_data_path_open");
+}
+
+void test_close_data_path()
+{
+       int ret = WIFI_AWARE_ERROR_NONE;
+
+       RET_IF_LOOP_IS_NULL();
+       RET_IF_NDP_IS_NULL();
+
+       ret = wifi_aware_data_path_close(g_ndp);
+       __print_result(ret, "wifi_aware_data_path_close");
+
+       ret = wifi_aware_data_path_destroy(g_ndp);
+       __print_result(ret, "wifi_aware_data_path_destroy");
+}
+
 typedef void (*test_func)(void);
 test_func g_menu_func[] = {
        [CMD_QUIT]                              = test_quit,
@@ -819,9 +948,11 @@ test_func g_menu_func[] = {
        [CMD_UPDATE_PUBLISH]    = test_update_publish,
        [CMD_SUBSCRIBE]                 = test_subscribe,
        [CMD_CANCEL_SUBSCRIBE]  = test_cancel_subscribe,
-       [CMD_TEST_SPECIFIC_INFO] = test_specific_info,
        [CMD_MESSAGE_RECV_CB]   = test_message_recv_cb,
        [CMD_SEND_MESSAGE]              = test_send_message,
+       [CMD_OPEN_DATA_PATH]    = test_open_data_path,
+
+       [CMD_TEST_SPECIFIC_INFO] = test_specific_info,
 
        [CMD_INVALID]                   = NULL,
 };