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) {
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;
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) {
__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,
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");