// Can APIs to get peer information using wifi_aware_peer_h?
+// wifi_aware_peer_get_mac_address(): Which mac address should this API show, NMI or NDI?
//
* limitations under the License.
*
*/
-#ifndef __TIZEN_NET_WIFI_AWARE_CONN_H__
-#define __TIZEN_NET_WIFI_AWARE_CONN_H__
+#ifndef __TIZEN_NET_WIFI_AWARE_CONFIG_H__
+#define __TIZEN_NET_WIFI_AWARE_CONFIG_H__
#include <stdint.h>
#ifdef __cplusplus
}
#endif
-#endif /* __TIZEN_NET_WIFI_AWARE_CONN_H__ */
+#endif /* __TIZEN_NET_WIFI_AWARE_CONFIG_H__ */
#include <gio/gio.h>
#include <tizen.h>
+#include "wifi-aware.h"
#include "wifi-aware-config.h"
#ifdef __cplusplus
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-*/
-#ifndef __TIZEN_NET_WIFI_AWARE_HANDLE_H__
-#define __TIZEN_NET_WIFI_AWARE_HANDLE_H__
-
-#include <tizen.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_NET_WIFI_AWARE_HANDLE_H__ */
#include <tizen.h>
+#include "wifi-aware.h"
+
#ifdef __cplusplus
extern "C" {
#endif
int _wifi_aware_peer_create(wifi_aware_peer_h *peer, unsigned int peer_id);
+int _wifi_aware_peer_add(wifi_aware_h wifi_aware, wifi_aware_peer_h peer);
+int _wifi_aware_peer_remove(wifi_aware_h wifi_aware, wifi_aware_peer_h peer);
+wifi_aware_peer_h _wifi_aware_peer_get_handle(wifi_aware_h wifi_aware, unsigned int peer_id);
#ifdef __cplusplus
}
#include "wifi-aware.h"
#include "wifi-aware-config.h"
-#include "wifi-aware-log.h"
#ifdef __cplusplus
extern "C" {
#define WIFI_AWARE_HANDLE_LOCK
#define WIFI_AWARE_HANDLE_UNLOCK
+typedef struct {
+ int client_id;
+ wifi_aware_enabled_cb enabled_cb;
+ void *enabled_cb_data;
+ GHashTable *peer_map;
+} wifi_aware_s;
+
const char *_wifi_aware_convert_error_type_to_string(wifi_aware_error_e err);
int _wifi_aware_handle_create(wifi_aware_h *wifi_aware);
#include <dlog.h>
#include "wifi-aware-log.h"
-#include "wifi-aware-private.h"
#ifdef __cplusplus
extern "C" {
#include <system_info.h>
#include "wifi-aware-log.h"
-#include "wifi-aware.h"
#include "wifi-aware-private.h"
#include "wifi-aware-utils.h"
#include "wifi-aware-gdbus.h"
#include <glib.h>
-#include "wifi-aware.h"
#include "wifi-aware-log.h"
+#include "wifi-aware-private.h"
#include "wifi-aware-peer.h"
+#include "wifi-aware-utils.h"
+
+typedef struct {
+ unsigned int id;
+} wifi_aware_peer_s;
int _wifi_aware_peer_create(wifi_aware_peer_h *peer, unsigned int peer_id)
{
+ *peer = (wifi_aware_peer_s *)g_try_malloc0(sizeof(wifi_aware_peer_s));
+ RET_VAL_IF(*peer == NULL, WIFI_AWARE_ERROR_OUT_OF_MEMORY, "g_try_malloc0 failed");
+ return WIFI_AWARE_ERROR_NONE;
+}
+
+int _wifi_aware_peer_add(wifi_aware_h wifi_aware, wifi_aware_peer_h peer)
+{
+ wifi_aware_s *aware_handle = (wifi_aware_s *)wifi_aware;
+ GHashTable *peer_map = aware_handle->peer_map;
+ wifi_aware_peer_s *peer_handle = (wifi_aware_peer_s *)peer;
+ RET_VAL_IF(peer_handle == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "peer is NULL");
+
+ WIFI_AWARE_HANDLE_LOCK;
+ if (g_hash_table_contains(peer_map, GINT_TO_POINTER(peer_handle->id))) {
+ WIFI_AWARE_LOGE("peer_id %d alread exists", peer_handle->id);
+ WIFI_AWARE_HANDLE_UNLOCK;
+ return WIFI_AWARE_ERROR_INVALID_PARAMETER;
+ }
+ WIFI_AWARE_HANDLE_UNLOCK;
+
+ WIFI_AWARE_HANDLE_LOCK;
+ g_hash_table_insert(peer_map, GINT_TO_POINTER(peer_handle->id), peer);
+ WIFI_AWARE_HANDLE_UNLOCK;
// Check peer_id validation
return WIFI_AWARE_ERROR_NONE;
}
+
+int _wifi_aware_peer_remove(wifi_aware_h wifi_aware, wifi_aware_peer_h peer)
+{
+ wifi_aware_s *aware_handle = (wifi_aware_s *)wifi_aware;
+ GHashTable *peer_map = aware_handle->peer_map;
+ wifi_aware_peer_s *peer_handle = (wifi_aware_peer_s *)peer;
+ RET_VAL_IF(peer_handle == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "peer is NULL");
+
+ if (peer_handle == NULL) {
+ WIFI_AWARE_LOGE("peer is NULL");
+ return WIFI_AWARE_ERROR_INVALID_PARAMETER;
+ }
+
+ WIFI_AWARE_HANDLE_LOCK;
+ if (!g_hash_table_remove(peer_map, GINT_TO_POINTER(peer_handle->id))) {
+ WIFI_AWARE_LOGE("peer %d doesn't exist", peer_handle->id);
+ }
+ WIFI_AWARE_HANDLE_UNLOCK;
+
+ return WIFI_AWARE_ERROR_NONE;
+}
+
+wifi_aware_peer_h _wifi_aware_peer_get_handle(wifi_aware_h wifi_aware, unsigned int peer_id)
+{
+ wifi_aware_s *aware_handle = (wifi_aware_s *)wifi_aware;
+ GHashTable *peer_map = aware_handle->peer_map;
+ wifi_aware_peer_s *peer = NULL;
+
+ WIFI_AWARE_HANDLE_LOCK;
+ peer = g_hash_table_lookup(peer_map, GINT_TO_POINTER(peer_id));
+ WIFI_AWARE_HANDLE_UNLOCK;
+ return peer;
+}
#include <glib.h>
-#include "wifi-aware.h"
-
#include "wifi-aware-gdbus.h"
#include "wifi-aware-log.h"
#include "wifi-aware-peer.h"
} nan_manager_error_e;
typedef struct {
- int client_id;
- wifi_aware_enabled_cb enabled_cb;
- void *enabled_cb_data;
-} wifi_aware_s;
-
-typedef struct {
wifi_aware_s *aware_handle;
uint32_t publish_id;
wifi_aware_publish_request_s req;
int _wifi_aware_handle_create(wifi_aware_h *wifi_aware)
{
- *wifi_aware = g_try_malloc0(sizeof(wifi_aware_s));
- if (*wifi_aware == NULL) {
+ wifi_aware_s *aware = (wifi_aware_s *)g_try_malloc0(sizeof(wifi_aware_s));
+ if (aware == NULL) {
WIFI_AWARE_LOGE("g_try_malloc0 failed");
return WIFI_AWARE_ERROR_OUT_OF_MEMORY;
}
+ aware->peer_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
WIFI_AWARE_HANDLE_LOCK;
- __wifi_aware_handle_list = g_list_append(__wifi_aware_handle_list, wifi_aware);
+ __wifi_aware_handle_list = g_list_append(__wifi_aware_handle_list, aware);
WIFI_AWARE_HANDLE_UNLOCK;
+ *wifi_aware = aware;
+
WIFI_AWARE_LOGI("Crate new handle [%p]", *wifi_aware);
return WIFI_AWARE_ERROR_NONE;
}
g_free(info_value);
}
+static int __handle_new_peer(wifi_aware_s *aware_handle, unsigned int peer_id, wifi_aware_peer_h *peer)
+{
+ int ret = WIFI_AWARE_ERROR_NONE;
+ if (_wifi_aware_peer_get_handle(aware_handle, peer_id) != NULL) {
+ WIFI_AWARE_LOGI("Peer %u already exists", peer_id);
+ return WIFI_AWARE_ERROR_NONE;
+ }
+
+ ret = _wifi_aware_peer_create(peer, peer_id);
+ RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Fail to create peer");
+
+ ret = _wifi_aware_peer_add(aware_handle, *peer);
+ RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Fail to add peer");
+
+ return ret;
+}
+
static void __service_discovered_cb(GDBusConnection *connection,
const gchar *sender, const gchar *object_path,
const gchar *interface, const gchar *signal,
}
WIFI_AWARE_LOGD("subscribe ID: %u, Peer ID: %u", sub_id, peer_id);
- if (_wifi_aware_peer_create(&peer, peer_id) != WIFI_AWARE_ERROR_NONE) {
- WIFI_AWARE_LOGE("Fail to create peer");
+ if (__handle_new_peer(handle->aware_handle, peer_id, &peer) != WIFI_AWARE_ERROR_NONE) {
+ WIFI_AWARE_LOGE("Invalid peer %u", peer_id);
return;
}
- // TODO: Add peer list to wifi_aware_s
-
if (handle->discovered_cb)
handle->discovered_cb(handle, peer,
specific_info, specific_info_len,
RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "_wifi_aware_handle_create failed [%s]",
_wifi_aware_convert_error_type_to_string(ret));
- ret = _wifi_aware_init(wifi_aware);
+ ret = _wifi_aware_init();
RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "_wifi_aware_init failed [%s]",
_wifi_aware_convert_error_type_to_string(ret));
ret = _wifi_aware_publish_handle_create(wifi_aware, publish);
RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Fail to create publish handle");
+ WIFI_AWARE_LOGD("publish handle: %p", *publish);
- _wifi_aware_publish_request_set_default_values(publish);
+ _wifi_aware_publish_request_set_default_values(*publish);
__WIFI_AWARE_FUNC_EXIT__;
return WIFI_AWARE_ERROR_NONE;
ret = _wifi_aware_subscribe_handle_create(wifi_aware, subscribe);
RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Fail to create subscribe handle");
+ WIFI_AWARE_LOGD("subscribe handle: %p", *subscribe);
- _wifi_aware_subscribe_set_default_values(subscribe);
+ _wifi_aware_subscribe_set_default_values(*subscribe);
__WIFI_AWARE_FUNC_EXIT__;
return WIFI_AWARE_ERROR_NONE;