}\
} 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;
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,
};
= "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,
};
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
__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");
}
__print_result(ret, "wifi_aware_subscribe");
memcpy(g_msg, "ABCD", 4);
+ g_session_type = 1;
}
void test_cancel_subscribe()
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,
[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,
};