#define MAX_PSK_LEN 63
#define PSK "AABBCCDDEE"
+#define PMK_LEN 32
+#define PMK "12345678901234567890123456789012"
#define IPV6_ADDRESS_LEN 39
enum {
CMD_OPEN_SOLICITED,
CMD_PSK_UNSOLICITED,
CMD_PSK_SOLICITED,
+ CMD_PMK_UNSOLICITED,
+ CMD_PMK_SOLICITED,
CMD_OPEN_UNSOLICITED_RANGING,
CMD_OPEN_SOLICITED_RANGING,
= "PSK + Unsolicited",
[CMD_PSK_SOLICITED]
= "PSK + Solicited",
+ [CMD_PMK_UNSOLICITED]
+ = "PMK + Unsolicited",
+ [CMD_PMK_SOLICITED]
+ = "PMK + Solicited",
[CMD_OPEN_UNSOLICITED_RANGING]
= "Open + Unsolicited + Ranging",
[CMD_OPEN_SOLICITED_RANGING]
static GMainLoop *g_main_loop_p;
static bool g_ranging = false;
+static bool g_initialized = false;
+static bool g_enabled = false;
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_publish_type_e g_pub_type;
static wifi_aware_security_type_e g_security_type;
+static unsigned char g_pmk[PMK_LEN];
+
+void test_init();
void test_deinit();
static void __test_finish(int is_validated)
if (error == WIFI_AWARE_ERROR_NONE) {
int ret = WIFI_AWARE_ERROR_NONE;
char *interface;
- PRINT_SUCCESS("[CB][OpenDataPath] Requested %p", data_path);
+ PRINT_SUCCESS("[CB][OpenDataPath] Connected %p", data_path);
ret = wifi_aware_data_path_get_interface(data_path, &interface);
if (ret == WIFI_AWARE_ERROR_NONE)
printf("\tInterface: %s\n", interface);
wifi_aware_data_path_set_psk(g_ndp, PSK);
break;
case WIFI_AWARE_SECURITY_TYPE_PMK:
+ wifi_aware_data_path_set_pmk(g_ndp, g_pmk);
printf("PMK\n");
break;
default:
return true;
}
-static void __enabled_cb(wifi_aware_error_e error, void *user_data)
+static void start_publish()
{
- if (error == WIFI_AWARE_ERROR_NONE) {
- PRINT_SUCCESS("[CB][Enable] Enabled");
- }
- else {
- PRINT_FAILURE_ERROR("[CB][Enable]", error);
- return;
- }
-
printf("[Session][Publish] Create\n");
int ret = wifi_aware_session_create(WIFI_AWARE_SESSION_PUBLISH, &g_wifi_aware_session);
if (ret == WIFI_AWARE_ERROR_NONE) {
}
}
+static void __enabled_cb(wifi_aware_error_e error, void *user_data)
+{
+ if (error == WIFI_AWARE_ERROR_NONE) {
+ PRINT_SUCCESS("[CB][Enable] Enabled");
+ }
+ else {
+ PRINT_FAILURE_ERROR("[CB][Enable]", error);
+ return;
+ }
+
+ start_publish();
+}
+
void run_common()
{
int ret = 0;
RET_IF_LOOP_IS_NULL();
test_init();
- ret = wifi_aware_enable(__enabled_cb, NULL);
- if (ret != WIFI_AWARE_ERROR_NONE) {
- PRINT_FAILURE_ERROR("[Enable]", ret);
- __test_finish(0);
+ if (g_enabled == false) {
+ ret = wifi_aware_enable(__enabled_cb, NULL);
+ if (ret != WIFI_AWARE_ERROR_NONE) {
+ PRINT_FAILURE_ERROR("[Enable]", ret);
+ __test_finish(0);
+ return;
+ }
+ g_enabled = true;
+ } else {
+ start_publish();
}
}
run_common();
}
+void test_pmk_unsolicited()
+{
+ clear_resources();
+ g_pub_type = WIFI_AWARE_PUBLISH_TYPE_UNSOLICITED;
+ g_security_type = WIFI_AWARE_SECURITY_TYPE_PMK;
+ g_ranging = false;
+ memcpy(g_pmk, PMK, PMK_LEN);
+ run_common();
+}
+
+void test_pmk_solicited()
+{
+ clear_resources();
+ g_pub_type = WIFI_AWARE_PUBLISH_TYPE_SOLICITED;
+ g_security_type = WIFI_AWARE_SECURITY_TYPE_PMK;
+ g_ranging = false;
+ memcpy(g_pmk, PMK, PMK_LEN);
+ run_common();
+}
+
void test_open_unsolicited_ranging()
{
clear_resources();
RET_IF_LOOP_IS_NULL();
- ret = wifi_aware_initialize();
- if (ret == WIFI_AWARE_ERROR_NONE)
- PRINT_SUCCESS("[Initialize] Success");
- else
- PRINT_FAILURE_ERROR("[Initialize]", ret);
+ if (g_initialized == false) {
+ ret = wifi_aware_initialize();
+ if (ret == WIFI_AWARE_ERROR_NONE)
+ PRINT_SUCCESS("[Initialize] Success");
+ else
+ PRINT_FAILURE_ERROR("[Initialize]", ret);
+ g_initialized = true;
+ }
}
void test_deinit()
{
- wifi_aware_disable();
- int ret = wifi_aware_deinitialize();
- if (ret == WIFI_AWARE_ERROR_NONE)
- PRINT_SUCCESS("[Deinitialize] Success");
- else
- PRINT_FAILURE_ERROR("[Deinitialize]", ret);
}
typedef void (*test_func)(void);
[CMD_OPEN_SOLICITED] = test_open_solicited,
[CMD_PSK_UNSOLICITED] = test_psk_unsolicited,
[CMD_PSK_SOLICITED] = test_psk_solicited,
+ [CMD_PMK_UNSOLICITED] = test_pmk_unsolicited,
+ [CMD_PMK_SOLICITED] = test_pmk_solicited,
[CMD_OPEN_UNSOLICITED_RANGING] = test_open_unsolicited_ranging,
[CMD_OPEN_SOLICITED_RANGING] = test_open_solicited_ranging,
#define MAX_PSK_LEN 63
#define PSK "AABBCCDDEE"
#define WRONG_PSK "11223344"
+#define PMK_LEN 32
+#define PMK "12345678901234567890123456789012"
+#define WRONG_PMK "11223344556677889900123456789012"
#define IPV6_ADDRESS_LEN 39
enum {
CMD_OPEN_ACTIVE,
CMD_PSK_PASSIVE,
CMD_PSK_ACTIVE,
- CMD_PSK_PASSIVE2,
- CMD_PSK_ACTIVE2,
+ CMD_PMK_PASSIVE,
+ CMD_PMK_ACTIVE,
+ CMD_WRONG_PSK_PASSIVE,
+ CMD_WRONG_PSK_ACTIVE,
+ CMD_WRONG_PMK_PASSIVE,
+ CMD_WRONG_PMK_ACTIVE,
CMD_OPEN_PASSIVE_RANGING,
CMD_OPEN_ACTIVE_RANGING,
= "PSK + Passive",
[CMD_PSK_ACTIVE]
= "PSK + Active",
- [CMD_PSK_PASSIVE2]
+ [CMD_PMK_PASSIVE]
+ = "PMK + Passive",
+ [CMD_PMK_ACTIVE]
+ = "PMK + Active",
+ [CMD_WRONG_PSK_PASSIVE]
= "PSK + Passive (Wrong password)",
- [CMD_PSK_ACTIVE2]
+ [CMD_WRONG_PSK_ACTIVE]
= "PSK + Active (Wrong password)",
+ [CMD_WRONG_PMK_PASSIVE]
+ = "PMK + Passive (Wrong password)",
+ [CMD_WRONG_PMK_ACTIVE]
+ = "PMK + Active (Wrong password)",
[CMD_OPEN_PASSIVE_RANGING]
= "Open + Passive + Ranging",
[CMD_OPEN_ACTIVE_RANGING]
};
static GMainLoop *g_main_loop_p;
-static bool g_initialized = false;
static int g_min_distance = -1;
static int g_max_distance = -1;
+static bool g_initialized = false;
+static bool g_enabled = false;
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_subscribe_type_e g_sub_type;
static wifi_aware_security_type_e g_security_type;
static char g_psk[MAX_PSK_LEN + 1];
+static unsigned char g_pmk[PMK_LEN];
static bool g_service_discovered = false;
+void test_init();
void test_deinit();
static void __test_finish(int is_validated)
if (error == WIFI_AWARE_ERROR_NONE) {
int ret = WIFI_AWARE_ERROR_NONE;
char *interface;
- PRINT_SUCCESS("[CB][OpenDataPath] Requested %p", data_path);
+ PRINT_SUCCESS("[CB][OpenDataPath] Connected %p", data_path);
ret = wifi_aware_data_path_get_interface(data_path, &interface);
if (ret == WIFI_AWARE_ERROR_NONE)
printf("\tInterface: %s\n", interface);
wifi_aware_data_path_set_psk(g_ndp, g_psk);
break;
case WIFI_AWARE_SECURITY_TYPE_PMK:
+ wifi_aware_data_path_set_pmk(g_ndp, g_pmk);
printf("PMK\n");
break;
default:
return true;
}
-static void __enabled_cb(wifi_aware_error_e error, void *user_data)
+static void start_subscribe()
{
- if (error == WIFI_AWARE_ERROR_NONE) {
- PRINT_SUCCESS("[CB][Enable] Enabled");
- }
- else {
- PRINT_FAILURE_ERROR("[CB][Enable]", error);
- return;
- }
-
printf("[Session][Subscribe] Create\n");
int ret = wifi_aware_session_create(WIFI_AWARE_SESSION_SUBSCRIBE, &g_wifi_aware_session);
if (ret == WIFI_AWARE_ERROR_NONE) {
}
}
+static void __enabled_cb(wifi_aware_error_e error, void *user_data)
+{
+ if (error == WIFI_AWARE_ERROR_NONE) {
+ PRINT_SUCCESS("[CB][Enable] Enabled");
+ }
+ else {
+ PRINT_FAILURE_ERROR("[CB][Enable]", error);
+ return;
+ }
+
+ start_subscribe();
+}
+
void run_common()
{
int ret = 0;
RET_IF_LOOP_IS_NULL();
test_init();
- ret = wifi_aware_enable(__enabled_cb, NULL);
- if (ret != WIFI_AWARE_ERROR_NONE) {
- PRINT_FAILURE_ERROR("[Enable]", ret);
- __test_finish(0);
+ if (g_enabled == false) {
+ ret = wifi_aware_enable(__enabled_cb, NULL);
+ if (ret != WIFI_AWARE_ERROR_NONE) {
+ PRINT_FAILURE_ERROR("[Enable]", ret);
+ __test_finish(0);
+ return;
+ }
+ g_enabled = true;
+ } else {
+ start_subscribe();
}
}
run_common();
}
-void test_psk_passive2()
+void test_pmk_passive()
+{
+ clear_resources();
+ g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE;
+ g_security_type = WIFI_AWARE_SECURITY_TYPE_PMK;
+ memcpy(g_pmk, PMK, PMK_LEN);
+ run_common();
+}
+
+void test_pmk_active()
+{
+ clear_resources();
+ g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_ACTIVE;
+ g_security_type = WIFI_AWARE_SECURITY_TYPE_PMK;
+ memcpy(g_pmk, PMK, PMK_LEN);
+ run_common();
+}
+
+void test_wrong_psk_passive()
{
clear_resources();
g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE;
run_common();
}
-void test_psk_active2()
+void test_wrong_psk_active()
{
clear_resources();
g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_ACTIVE;
run_common();
}
+void test_wrong_pmk_passive()
+{
+ clear_resources();
+ g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_PASSIVE;
+ g_security_type = WIFI_AWARE_SECURITY_TYPE_PMK;
+ memcpy(g_pmk, WRONG_PMK, PMK_LEN);
+ run_common();
+}
+
+void test_wrong_pmk_active()
+{
+ clear_resources();
+ g_sub_type = WIFI_AWARE_SUBSCRIBE_TYPE_ACTIVE;
+ g_security_type = WIFI_AWARE_SECURITY_TYPE_PMK;
+ memcpy(g_pmk, WRONG_PMK, PMK_LEN);
+ run_common();
+}
+
void test_open_passive_ranging()
{
clear_resources();
RET_IF_LOOP_IS_NULL();
- ret = wifi_aware_initialize();
- if (ret == WIFI_AWARE_ERROR_NONE)
- PRINT_SUCCESS("[Initialize] Success");
- else
- PRINT_FAILURE_ERROR("[Initialize]", ret);
+ if (g_initialized == false) {
+ ret = wifi_aware_initialize();
+ if (ret == WIFI_AWARE_ERROR_NONE)
+ PRINT_SUCCESS("[Initialize] Success");
+ else
+ PRINT_FAILURE_ERROR("[Initialize]", ret);
+ g_initialized = true;
+ }
}
void test_deinit()
{
- wifi_aware_disable();
- int ret = wifi_aware_deinitialize();
- if (ret == WIFI_AWARE_ERROR_NONE)
- PRINT_SUCCESS("[Deinitialize] Success");
- else
- PRINT_FAILURE_ERROR("[Deinitialize]", ret);
}
typedef void (*test_func)(void);
test_func g_menu_func[] = {
- [CMD_QUIT] = test_quit,
- [CMD_OPEN_PASSIVE] = test_open_passive,
- [CMD_OPEN_ACTIVE] = test_open_active,
- [CMD_PSK_PASSIVE] = test_psk_passive,
- [CMD_PSK_ACTIVE] = test_psk_active,
- [CMD_PSK_PASSIVE2] = test_psk_passive2,
- [CMD_PSK_ACTIVE2] = test_psk_active2,
- [CMD_OPEN_PASSIVE_RANGING] = test_open_passive_ranging,
- [CMD_OPEN_ACTIVE_RANGING] = test_open_active_ranging,
+ [CMD_QUIT] = test_quit,
+ [CMD_OPEN_PASSIVE] = test_open_passive,
+ [CMD_OPEN_ACTIVE] = test_open_active,
+ [CMD_PSK_PASSIVE] = test_psk_passive,
+ [CMD_PSK_ACTIVE] = test_psk_active,
+ [CMD_PMK_PASSIVE] = test_pmk_passive,
+ [CMD_PMK_ACTIVE] = test_pmk_active,
+ [CMD_WRONG_PSK_PASSIVE] = test_wrong_psk_passive,
+ [CMD_WRONG_PSK_ACTIVE] = test_wrong_psk_active,
+ [CMD_WRONG_PMK_PASSIVE] = test_wrong_pmk_passive,
+ [CMD_WRONG_PMK_ACTIVE] = test_wrong_pmk_active,
+ [CMD_OPEN_PASSIVE_RANGING] = test_open_passive_ranging,
+ [CMD_OPEN_ACTIVE_RANGING] = test_open_active_ranging,
[CMD_INVALID] = NULL,
};
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");