diff options
Diffstat (limited to 'test/wifi-aware-subscribe-test.c')
-rw-r--r-- | test/wifi-aware-subscribe-test.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/test/wifi-aware-subscribe-test.c b/test/wifi-aware-subscribe-test.c index 8f70443..2331522 100644 --- a/test/wifi-aware-subscribe-test.c +++ b/test/wifi-aware-subscribe-test.c @@ -132,6 +132,8 @@ 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 bool g_service_discovered = false; + static inline void __usage_full() { int i; @@ -187,6 +189,8 @@ const char *__print_error(wifi_aware_error_e err) return "ALREADY_INITIALIZED"; case WIFI_AWARE_ERROR_REJECTED_BY_PEER: return "REJECTED_BY_PEER"; + case WIFI_AWARE_ERROR_INTERFACE_DOWN: + return "INTERFACE_IS_DOWN"; default: return "UNKNOWN"; } @@ -356,10 +360,11 @@ static void __message_received_cb(wifi_aware_session_h session, wifi_aware_peer_ printf("\n>>Receive message from a Wi-Fi Aware Peer\n"); - memcpy(buf, message, 1024); if (wifi_aware_peer_get_mac(peer, &mac) != WIFI_AWARE_ERROR_NONE) printf("Fail to get Peer's NMI: %s\n", __print_error(ret)); + memcpy(buf, message, 1024); + buf[len] = '\0'; printf("Message: %s\n", buf); printf("Peer's NMI: "); if (mac != NULL) { @@ -382,13 +387,16 @@ static void __service_discovered_cb(wifi_aware_session_h session, __print_byte_array(service_specific_info, service_specific_info_len); printf("\n"); - printf("\n>>Send message\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); - if (ret != WIFI_AWARE_ERROR_NONE) - printf("Fail to send message: %s\n", __print_error(ret)); + if (g_service_discovered == false) { + g_service_discovered = true; + printf("\n>>Send message\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); + if (ret != WIFI_AWARE_ERROR_NONE) + printf("Fail to send message: %s\n", __print_error(ret)); + } } static void __session_terminated_cb(wifi_aware_session_h session, @@ -469,6 +477,7 @@ static void __enabled_cb(wifi_aware_error_e error, void *user_data) return; } + g_service_discovered = false; ret = wifi_aware_session_set_service_discovered_cb(g_wifi_aware_session, __service_discovered_cb, NULL); __print_result(ret, "set service_discovered_cb"); |