From 0c1deccf69a9448ae58f2af965529e667ab6694d Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Tue, 3 Mar 2020 15:26:17 +0900 Subject: [PATCH] Add APIs for Data Path and basic implementations --- src/CMakeLists.txt | 1 + src/include/wifi-aware-data-path.h | 53 ++++++ src/include/wifi-aware-gdbus.h | 19 ++- src/include/wifi-aware-private.h | 4 +- src/wifi-aware-data-path.c | 319 +++++++++++++++++++++++++++++++++++++ src/wifi-aware-gdbus.c | 36 ++++- src/wifi-aware-private.c | 5 + src/wifi-aware.c | 143 +++++++++++++++++ 8 files changed, 576 insertions(+), 4 deletions(-) create mode 100644 src/include/wifi-aware-data-path.h create mode 100644 src/wifi-aware-data-path.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 777c65f..8ee3d89 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ INCLUDE_DIRECTORIES( SET(WIFI_AWARE_SOURCES ${WIFI_AWARE_PATH}/wifi-aware.c + ${WIFI_AWARE_PATH}/wifi-aware-data-path.c ${WIFI_AWARE_PATH}/wifi-aware-gdbus.c ${WIFI_AWARE_PATH}/wifi-aware-peer.c ${WIFI_AWARE_PATH}/wifi-aware-private.c diff --git a/src/include/wifi-aware-data-path.h b/src/include/wifi-aware-data-path.h new file mode 100644 index 0000000..c2dff6f --- /dev/null +++ b/src/include/wifi-aware-data-path.h @@ -0,0 +1,53 @@ +/* + * 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_DATA_PATH_H__ +#define __TIZEN_NET_WIFI_AWARE_DATA_PATH_H__ + +#include +#include + +#include "wifi-aware.h" +#include "wifi-aware-config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WIFI_AWARE_MAX_PSK_LEN 63 +#define WIFI_AWARE_MAX_PMK_LEN 32 + +int _wifi_aware_data_path_handle_create(wifi_aware_session_h session, wifi_aware_peer_h peer, + wifi_aware_data_path_role_e role, wifi_aware_data_path_h *data_path); +int _wifi_aware_data_path_set_security(wifi_aware_data_path_h data_path, + wifi_aware_security_type_e security_type); +int _wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, const char *key); +int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, + unsigned char *key, size_t key_len); +int _wifi_aware_data_path_set_service_specific_info(wifi_aware_data_path_h data_path, + unsigned char *service_specific_info, size_t service_specific_info_len); +int _wifi_aware_data_path_destroy(wifi_aware_data_path_h data_path); +int _wifi_aware_data_path_open(wifi_aware_data_path_h data_path, + wifi_aware_data_path_open_cb callback, void *user_data); +int _wifi_aware_data_path_close(wifi_aware_data_path_h data_path); +int _wifi_aware_data_path_set_terminated_cb(wifi_aware_data_path_h data_path, + wifi_aware_data_path_terminated_cb callback, void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NET_WIFI_AWARE_DATA_PATH_H__ */ diff --git a/src/include/wifi-aware-gdbus.h b/src/include/wifi-aware-gdbus.h index f1b776c..f983960 100644 --- a/src/include/wifi-aware-gdbus.h +++ b/src/include/wifi-aware-gdbus.h @@ -72,8 +72,25 @@ int wifi_aware_gdbus_update_subscribe(wifi_aware_session_h session, int wifi_aware_gdbus_followup(wifi_aware_session_h session, int client_id, unsigned int pub_sub_id, unsigned int peer_id, - unsigned char *message, size_t len, + const unsigned char *message, size_t len, GAsyncReadyCallback cb, void *user_data); + +int wifi_aware_gdbus_ndp_open(wifi_aware_data_path_h data_path, + unsigned int pub_sub_id, unsigned int peer_id, wifi_aware_data_path_role_e role, + const unsigned char *specific_info, size_t specific_info_len, + GAsyncReadyCallback cb); +int wifi_aware_gdbus_ndp_close(wifi_aware_data_path_h data_path, + unsigned int ndp_id, unsigned int pub_sub_id, unsigned int peer_id); +int wifi_aware_gdbus_ndp_psk(wifi_aware_data_path_h data_path, + unsigned int pub_sub_id, unsigned int peer_id, wifi_aware_data_path_role_e role, + unsigned char *specific_info, size_t specific_info_len, + const char *psk, + GAsyncReadyCallback cb); +int wifi_aware_gdbus_ndp_pmk(wifi_aware_data_path_h data_path, + unsigned int pub_sub_id, unsigned int peer_id, wifi_aware_data_path_role_e role, + unsigned char *specific_info, size_t specific_info_len, + const unsigned char *pmk, size_t pmk_len, + GAsyncReadyCallback cb); #ifdef __cplusplus } #endif diff --git a/src/include/wifi-aware-private.h b/src/include/wifi-aware-private.h index 50861af..0fe1034 100644 --- a/src/include/wifi-aware-private.h +++ b/src/include/wifi-aware-private.h @@ -15,7 +15,7 @@ * */ #ifndef __TIZEN_NET_WIFI_AWARE_PRIVATE_H__ -#define __TIZEN_NET_WIFI_AWARE_PRIAVTE_H__ +#define __TIZEN_NET_WIFI_AWARE_PRIVATE_H__ #include #include @@ -28,6 +28,7 @@ extern "C" { #endif const char *_wifi_aware_convert_error_type_to_string(wifi_aware_error_e err); +wifi_aware_error_e _wifi_aware_convert_error_string_to_enum(const char *error); bool _wifi_aware_is_initialized(); int _wifi_aware_init(); @@ -40,6 +41,7 @@ int _wifi_aware_disable_request(); int _wifi_aware_session_handle_create(wifi_aware_session_type_e session_type, wifi_aware_session_h *session_handle); void _wifi_aware_session_handle_destroy(wifi_aware_session_h session_handle); wifi_aware_session_type_e _wifi_aware_session_get_type(wifi_aware_session_h session_handle); +unsigned int _wifi_aware_session_get_pubsub_id(wifi_aware_session_h session); int _wifi_aware_publish_handle_create(wifi_aware_publish_h *publish); void _wifi_aware_publish_request_set_default_values(wifi_aware_publish_h publish); diff --git a/src/wifi-aware-data-path.c b/src/wifi-aware-data-path.c new file mode 100644 index 0000000..868cdc4 --- /dev/null +++ b/src/wifi-aware-data-path.c @@ -0,0 +1,319 @@ +/* Wi-Fi Aware + * + * 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. + * + */ + +/** + * This file implements Wi-Fi Aware user library. + * + * @file wifi-aware-client.c + * @author Jiung Yu (jiung.yu@samsung.com) + */ + + +#include +#include + +#include "wifi-aware-data-path.h" +#include "wifi-aware-gdbus.h" +#include "wifi-aware-log.h" +#include "wifi-aware-peer.h" +#include "wifi-aware-private.h" +#include "wifi-aware-utils.h" + +typedef struct { + uint32_t ndp_id; + + wifi_aware_session_h session; + wifi_aware_peer_h peer; + + wifi_aware_data_path_role_e role; + wifi_aware_security_type_e security_type; + char psk[WIFI_AWARE_MAX_PSK_LEN + 1]; + unsigned char pmk[WIFI_AWARE_MAX_PMK_LEN]; + size_t pmk_len; + + unsigned char specific_info[WIFI_AWARE_MAX_SERVICE_SPECIFIC_INFO_LEN]; + size_t specific_info_len; + + char iface_name[IFNAMSIZ + 1]; + + wifi_aware_data_path_open_cb open_cb; + void *open_cb_user_data; + wifi_aware_data_path_terminated_cb terminated_cb; + void *terminated_cb_user_data; + + bool is_open; +} wifi_aware_data_path_s; + +static bool __is_valid_data_path_role(wifi_aware_data_path_role_e role) +{ + return role >= WIFI_AWARE_DATA_PATH_INITIATOR && role <= WIFI_AWARE_DATA_PATH_RESPONDER; +} + +static bool __is_valid_wifi_aware_security_type(wifi_aware_security_type_e security_type) +{ + return security_type >= WIFI_AWARE_SECURITY_TYPE_OPEN + && security_type <= WIFI_AWARE_SECURITY_TYPE_PMK; +} + +static uint32_t __data_path_get_ndp_id(wifi_aware_data_path_h data_path) +{ + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + return ndp->ndp_id; +} + +static bool __data_path_is_open(wifi_aware_data_path_h data_path) +{ + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + return ndp->is_open; +} + +static void __data_path_open(wifi_aware_data_path_h data_path) +{ + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + ndp->is_open = true; +} + +static void __data_path_close(wifi_aware_data_path_h data_path) +{ + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + ndp->is_open = false; +} + +int _wifi_aware_data_path_handle_create(wifi_aware_session_h session, wifi_aware_peer_h peer, + wifi_aware_data_path_role_e role, wifi_aware_data_path_h *data_path) +{ + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(session == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "session is NULL"); + RET_VAL_IF(peer == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "peer is NULL"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + + RET_VAL_IF(!__is_valid_data_path_role(role), WIFI_AWARE_ERROR_INVALID_PARAMETER, + "data_path_role is not valid"); + + wifi_aware_data_path_s *ndp = + (wifi_aware_data_path_s *)g_try_malloc0(sizeof(wifi_aware_data_path_s)); + RET_VAL_IF(ndp == NULL, WIFI_AWARE_ERROR_OUT_OF_MEMORY, "Out of memory"); + + *data_path = (wifi_aware_data_path_h)ndp; + ndp->role = role; + + return WIFI_AWARE_ERROR_NONE; +} + +int _wifi_aware_data_path_set_security(wifi_aware_data_path_h data_path, + wifi_aware_security_type_e security_type) +{ + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + RET_VAL_IF(!__is_valid_wifi_aware_security_type(security_type), WIFI_AWARE_ERROR_INVALID_PARAMETER, + "security type is not valid"); + + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + ndp->security_type = security_type; + + return WIFI_AWARE_ERROR_NONE; +} + +int _wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, const char *key) +{ + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + RET_VAL_IF(ndp->security_type != WIFI_AWARE_SECURITY_TYPE_PSK, + WIFI_AWARE_ERROR_INVALID_OPERATION, "security type is not WIFI_AWARE_SECURITY_TYPE_PSK"); + + size_t len = strlen(key); + if (len > WIFI_AWARE_MAX_PSK_LEN) { + WIFI_AWARE_LOGE("Password is too long"); + return WIFI_AWARE_ERROR_INVALID_PARAMETER; + } + + if (len == 0) + return WIFI_AWARE_ERROR_NONE; + + strncpy(ndp->psk, key, WIFI_AWARE_MAX_PSK_LEN); + return WIFI_AWARE_ERROR_NONE; +} + +int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key, size_t key_len) +{ + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(data_path== NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + RET_VAL_IF(ndp->security_type != WIFI_AWARE_SECURITY_TYPE_PMK, + WIFI_AWARE_ERROR_INVALID_OPERATION, "security type is not WIFI_AWARE_SECURITY_TYPE_PMK"); + + if (key_len > WIFI_AWARE_MAX_PMK_LEN) { + WIFI_AWARE_LOGE("PMK is too long"); + return WIFI_AWARE_ERROR_INVALID_PARAMETER; + } + + if (key_len == 0) + return WIFI_AWARE_ERROR_NONE; + + memcpy(ndp->pmk, key, key_len); + return WIFI_AWARE_ERROR_NONE; +} + +int _wifi_aware_data_path_set_service_specific_info(wifi_aware_data_path_h data_path, + unsigned char *service_specific_info, size_t service_specific_info_len) +{ + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(data_path== NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + + if (service_specific_info_len > WIFI_AWARE_MAX_PMK_LEN) { + WIFI_AWARE_LOGE("service_specific_info is too long"); + return WIFI_AWARE_ERROR_INVALID_PARAMETER; + } + + if (service_specific_info_len == 0) + return WIFI_AWARE_ERROR_NONE; + + memcpy(ndp->specific_info, service_specific_info, service_specific_info_len); + ndp->specific_info_len = service_specific_info_len; + return WIFI_AWARE_ERROR_NONE; +} + +int _wifi_aware_data_path_destroy(wifi_aware_data_path_h data_path) +{ + __WIFI_AWARE_FUNC_ENTER__; + return WIFI_AWARE_ERROR_NONE; +} + +static void __data_path_set_open_cb(wifi_aware_data_path_h data_path, + wifi_aware_data_path_open_cb callback, void *user_data) +{ + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + ndp->open_cb = callback; + ndp->open_cb_user_data = user_data; +} + +static void __data_path_invoke_callback(wifi_aware_data_path_h data_path, wifi_aware_error_e error, + unsigned char *mac, unsigned char *specific_info, size_t specific_info_len) +{ + RET_IF(data_path == NULL, "data path handle is NULL"); + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + + if (ndp->open_cb) + ndp->open_cb(data_path, error, mac, specific_info, specific_info_len, ndp->open_cb_user_data); +} + +static void __data_path_open_reply(GObject *src, GAsyncResult *res, gpointer user_data) +{ + //GDBusConnection *conn = NULL; + GError *dbus_error = NULL; + //GVariant *reply = NULL; + wifi_aware_error_e error = WIFI_AWARE_ERROR_NONE; + //int nan_error = 0; + wifi_aware_data_path_h data_path = (wifi_aware_data_path_h)user_data; + // unsigned int ndp_id; + + WIFI_AWARE_LOGI("Reply for Data Path Open request"); + + //conn = G_DBUS_CONNECTION(src); + //reply = g_dbus_connection_call_finish(conn, res, &dbus_error); + + if (dbus_error != NULL) { + WIFI_AWARE_LOGE("Open Request failure: %s", dbus_error->message); + error = _wifi_aware_convert_error_string_to_enum(dbus_error->message); + g_error_free(dbus_error); + } else { + // TODO: Parameter parsing + } + + if (error == WIFI_AWARE_ERROR_NONE) { + __data_path_open(data_path); + } + __data_path_invoke_callback(data_path, error, NULL, NULL, 0); +} + +int _wifi_aware_data_path_open(wifi_aware_data_path_h data_path, + wifi_aware_data_path_open_cb callback, void *user_data) +{ + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(data_path== NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + + __data_path_set_open_cb(data_path, callback, user_data); + switch (ndp->security_type) { + case WIFI_AWARE_SECURITY_TYPE_OPEN: + return wifi_aware_gdbus_ndp_open(data_path, + _wifi_aware_session_get_pubsub_id(ndp->session), + _wifi_aware_peer_get_id(ndp->peer), + ndp->role, + ndp->specific_info, + ndp->specific_info_len, + __data_path_open_reply); + case WIFI_AWARE_SECURITY_TYPE_PSK: + return wifi_aware_gdbus_ndp_psk(data_path, + _wifi_aware_session_get_pubsub_id(ndp->session), + _wifi_aware_peer_get_id(ndp->peer), + ndp->role, + ndp->specific_info, + ndp->specific_info_len, + ndp->psk, + __data_path_open_reply); + case WIFI_AWARE_SECURITY_TYPE_PMK: + return wifi_aware_gdbus_ndp_pmk(data_path, + _wifi_aware_session_get_pubsub_id(ndp->session), + _wifi_aware_peer_get_id(ndp->peer), + ndp->role, + ndp->specific_info, + ndp->specific_info_len, + ndp->pmk, + ndp->pmk_len, + __data_path_open_reply); + } + + WIFI_AWARE_LOGE("Invalid security type"); + __data_path_set_open_cb(data_path, NULL, NULL); + return WIFI_AWARE_ERROR_INVALID_PARAMETER; +} + +int _wifi_aware_data_path_close(wifi_aware_data_path_h data_path) +{ + int ret = WIFI_AWARE_ERROR_NONE; + __WIFI_AWARE_FUNC_ENTER__; + + RET_VAL_IF(data_path== NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL"); + RET_VAL_IF(!__data_path_is_open(data_path), WIFI_AWARE_ERROR_INVALID_OPERATION, "No Data Path"); + + wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path; + ret = wifi_aware_gdbus_ndp_close(data_path, + __data_path_get_ndp_id(data_path), + _wifi_aware_session_get_pubsub_id(ndp->session), + _wifi_aware_peer_get_id(ndp->peer)); + __data_path_close(data_path); + return ret; +} + +int _wifi_aware_data_path_set_terminated_cb(wifi_aware_data_path_h data_path, wifi_aware_data_path_terminated_cb callback, void *user_data) +{ + int ret = WIFI_AWARE_ERROR_NONE; + __WIFI_AWARE_FUNC_ENTER__; + + return ret; +} diff --git a/src/wifi-aware-gdbus.c b/src/wifi-aware-gdbus.c index b52ff19..8a36936 100644 --- a/src/wifi-aware-gdbus.c +++ b/src/wifi-aware-gdbus.c @@ -352,7 +352,7 @@ static GVariant *__create_update_subscribe_request_param(int client_id, } static GVariant *__create_followup_request_param(int client_id, unsigned int pub_sub_id, - unsigned int peer_id, unsigned char *message, size_t len) + unsigned int peer_id, const unsigned char *message, size_t len) { GVariantBuilder *builder = NULL; GVariant *params = NULL; @@ -605,7 +605,7 @@ int wifi_aware_gdbus_update_subscribe(wifi_aware_session_h session, int wifi_aware_gdbus_followup(wifi_aware_session_h session, int client_id, unsigned int pub_sub_id, unsigned int peer_id, - unsigned char *message, size_t len, + const unsigned char *message, size_t len, GAsyncReadyCallback cb, void *user_data) { __WIFI_AWARE_FUNC_ENTER__; @@ -626,3 +626,35 @@ int wifi_aware_gdbus_followup(wifi_aware_session_h session, __WIFI_AWARE_FUNC_EXIT__; return ret; } + +int wifi_aware_gdbus_ndp_open(wifi_aware_data_path_h data_path, + unsigned int pub_sub_id, unsigned int peer_id, wifi_aware_data_path_role_e role, + const unsigned char *specific_info, size_t specific_info_len, + GAsyncReadyCallback cb) +{ + return WIFI_AWARE_ERROR_NONE; +} + +int wifi_aware_gdbus_ndp_close(wifi_aware_data_path_h data_path, + unsigned int ndp_id, unsigned int pub_sub_id, unsigned int peer_id) +{ + return WIFI_AWARE_ERROR_NONE; +} + +int wifi_aware_gdbus_ndp_psk(wifi_aware_data_path_h data_path, + unsigned int pub_sub_id, unsigned int peer_id, wifi_aware_data_path_role_e role, + unsigned char *specific_info, size_t specific_info_len, + const char *psk, + GAsyncReadyCallback cb) +{ + return WIFI_AWARE_ERROR_NONE; +} + +int wifi_aware_gdbus_ndp_pmk(wifi_aware_data_path_h data_path, + unsigned int pub_sub_id, unsigned int peer_id, wifi_aware_data_path_role_e role, + unsigned char *specific_info, size_t specific_info_len, + const unsigned char *pmk, size_t pmk_len, + GAsyncReadyCallback cb) +{ + return WIFI_AWARE_ERROR_NONE; +} diff --git a/src/wifi-aware-private.c b/src/wifi-aware-private.c index cbf9484..75adcb8 100644 --- a/src/wifi-aware-private.c +++ b/src/wifi-aware-private.c @@ -423,6 +423,11 @@ unsigned int _wifi_aware_session_get_subscribe_id(wifi_aware_session_h session) return __session_get_subscribe_config(session)->subscribe_id; } +unsigned int _wifi_aware_session_get_pubsub_id(wifi_aware_session_h session) +{ + return 0; +} + static int __wifi_aware_create() { g_wifi_aware = (wifi_aware_s *)g_try_malloc0(sizeof(wifi_aware_s)); diff --git a/src/wifi-aware.c b/src/wifi-aware.c index ece88b8..8290935 100644 --- a/src/wifi-aware.c +++ b/src/wifi-aware.c @@ -28,6 +28,7 @@ #include "wifi-aware.h" +#include "wifi-aware-data-path.h" #include "wifi-aware-gdbus.h" #include "wifi-aware-log.h" #include "wifi-aware-private.h" @@ -560,3 +561,145 @@ API int wifi_aware_unset_message_received_cb(wifi_aware_session_h session) __WIFI_AWARE_FUNC_EXIT__; return WIFI_AWARE_ERROR_NONE; } + +API int wifi_aware_data_path_create(wifi_aware_session_h session, wifi_aware_peer_h peer, + wifi_aware_data_path_role_e role, wifi_aware_data_path_h *data_path) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(session == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Session is NULL"); + RET_VAL_IF(peer == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Peer is NULL"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_handle_create(session, peer, role, data_path); + RET_VAL_IF(ret != WIFI_AWARE_ERROR_NONE, ret, "Fail to create data path handle"); + WIFI_AWARE_LOGD("data path handle: %p", *data_path); + + __WIFI_AWARE_FUNC_EXIT__; + return WIFI_AWARE_ERROR_NONE; +} + +API int wifi_aware_data_path_set_security(wifi_aware_data_path_h data_path, wifi_aware_security_type_e security_type) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_set_security(data_path, security_type); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + +API int wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, char *key) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_set_psk(data_path, key); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + +API int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key, size_t key_len) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_set_pmk(data_path, key, key_len); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + +API int wifi_aware_data_path_set_service_specific_info(wifi_aware_data_path_h data_path, unsigned char *service_specific_info, size_t service_specific_info_len) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_set_service_specific_info(data_path, + service_specific_info, service_specific_info_len); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + +API int wifi_aware_data_path_destroy(wifi_aware_data_path_h data_path) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_destroy(data_path); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + +API int wifi_aware_data_path_open(wifi_aware_data_path_h data_path, wifi_aware_data_path_open_cb callback, void *user_data) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_open(data_path, callback, user_data); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + +API int wifi_aware_data_path_close(wifi_aware_data_path_h data_path) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_close(data_path); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} + + +API int wifi_aware_data_path_set_terminated_cb(wifi_aware_data_path_h data_path, wifi_aware_data_path_terminated_cb callback, void *user_data) +{ + int ret = WIFI_AWARE_ERROR_NONE; + + __WIFI_AWARE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_WIFI_AWARE); + RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized"); + RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL"); + + ret = _wifi_aware_data_path_set_terminated_cb(data_path, callback, user_data); + + __WIFI_AWARE_FUNC_EXIT__; + return ret; +} -- 2.7.4