/*
-* Copyright (c) 2011 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.
-*/
+ * Copyright (c) 2011 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 __SOFTAP_PRIVATE_H__
#define __SOFTAP_PRIVATE_H__
int _softap_check_feature_supported(int key);
/**
-* Start of mobileap-agent common values
-* When these values are changed, mobileap-agent should be also changed.
-* But some of those will be removed.
-*/
+ * To lock and unlock Mutex
+ */
+
+#define SOFTAP_LOCK \
+ do { \
+ _softap_lock(); \
+ } while(0)
+
+#define SOFTAP_UNLOCK \
+ do { \
+ _softap_unlock(); \
+ } while(0)
+
+void _softap_lock(void);
+void _softap_unlock(void);
+
+/**
+ * Start of mobileap-agent common values
+ * When these values are changed, mobileap-agent should be also changed.
+ * But some of those will be removed.
+ */
/*
-* from mobileap_lib.h
-*/
+ * from mobileap_lib.h
+ */
/**
-* Common configuration
-*/
+ * Common configuration
+ */
#define SOFTAP_STR_INFO_LEN 20 /**< length of the ip or mac address */
/**
-* Mobile AP error code
-*/
+ * Mobile AP error code
+ */
typedef enum {
MOBILE_AP_ERROR_NONE, /**< No error */
MOBILE_AP_ERROR_RESOURCE, /**< Socket creation error, file open error */
} mobile_ap_error_code_e;
/**
-* Event type on callback
-*/
+ * Event type on callback
+ */
typedef enum {
MOBILE_AP_ENABLE_CFM = 0,
MOBILE_AP_DISABLE_CFM = 1,
#define MAX_ALIAS_LEN 256
/**
-* End of mobileap-agent common values
-*/
+ * End of mobileap-agent common values
+ */
#define SOFTAP_DEFAULT_SSID "Tizen"
#define SOFTAP_DEFAULT_CHANNEL 1
Name: capi-network-softap
Summary: Softap Framework
-Version: 0.0.30
+Version: 0.0.31
Release: 1
Group: System/Network
License: Apache-2.0
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
__softap_h *sa = (__softap_h *)user_data;
bool opened = false;
g_free(ip);
g_free(mac);
g_free(name);
+
+ SOFTAP_UNLOCK;
DBG("-");
}
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL");
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
__softap_h *sa = (__softap_h *)user_data;
bool is_requested = false;
void *data = NULL;
ecb = sa->enabled_cb;
- if (ecb == NULL)
+ if (ecb == NULL) {
+ SOFTAP_UNLOCK;
return;
+ }
+
data = sa->enabled_user_data;
ecb(SOFTAP_ERROR_NONE, is_requested, data);
+
+ SOFTAP_UNLOCK;
DBG("-");
}
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL");
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
__softap_h *sa = (__softap_h *)user_data;
softap_disabled_cause_e code = SOFTAP_DISABLED_BY_OTHERS;
char *buf = NULL;
dcb = sa->disabled_cb;
- if (dcb == NULL)
+ if (dcb == NULL) {
+ SOFTAP_UNLOCK;
return;
+ }
+
data = sa->disabled_user_data;
g_variant_get(parameters, "(s)", &buf);
if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE))
g_free(buf);
dcb(SOFTAP_ERROR_NONE, code, data);
+ SOFTAP_UNLOCK;
DBG("-");
}
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL");
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
__softap_h *sa = (__softap_h *)user_data;
softap_disabled_cb dcb = NULL;
softap_disabled_cause_e code = SOFTAP_DISABLED_BY_LOW_BATTERY;
dcb = sa->disabled_cb;
- if (dcb == NULL)
+ if (dcb == NULL) {
+ SOFTAP_UNLOCK;
return;
+ }
data = sa->disabled_user_data;
dcb(SOFTAP_ERROR_NONE, code, data);
+
+ SOFTAP_UNLOCK;
DBG("-");
}
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
__softap_h *sa = (__softap_h *)user_data;
softap_disabled_cb dcb = NULL;
softap_disabled_cause_e code = SOFTAP_DISABLED_BY_FLIGHT_MODE;
dcb = sa->disabled_cb;
- if (dcb == NULL)
+ if (dcb == NULL) {
+ SOFTAP_UNLOCK;
return;
+ }
+
data = sa->disabled_user_data;
dcb(SOFTAP_ERROR_NONE, code, data);
+
+ SOFTAP_UNLOCK;
DBG("-");
}
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL");
- __softap_h *sa = (__softap_h *)user_data;
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
+ __softap_h *sa = (__softap_h *)user_data;
softap_security_type_changed_cb scb = NULL;
void *data = NULL;
int security_type;
scb = sa->security_type_changed_cb;
- if (scb == NULL)
+ if (scb == NULL) {
+ SOFTAP_UNLOCK;
return;
+ }
g_variant_get(parameters, "(i)", &security_type);
data = sa->security_type_user_data;
scb((softap_security_type_e)security_type, data);
+ SOFTAP_UNLOCK;
return;
}
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL");
- __softap_h *sa = (__softap_h *)user_data;
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
+ __softap_h *sa = (__softap_h *)user_data;
softap_ssid_visibility_changed_cb scb = NULL;
void *data = NULL;
int visible = 0;
scb = sa->ssid_visibility_changed_cb;
if (scb == NULL) {
+ SOFTAP_UNLOCK;
DBG("-");
return;
}
g_variant_get(parameters, "(i)", &visible);
data = sa->ssid_visibility_user_data;
scb(visible, data);
+
+ SOFTAP_UNLOCK;
DBG("-");
}
GVariant *parameters, gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
- __softap_h *sa = (__softap_h *)user_data;
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
+ __softap_h *sa = (__softap_h *)user_data;
softap_passphrase_changed_cb pcb = NULL;
void *data = NULL;
pcb = sa->passphrase_changed_cb;
- if (pcb == NULL)
+ if (pcb == NULL) {
+ SOFTAP_UNLOCK;
return;
+ }
data = sa->passphrase_user_data;
pcb(data);
+
+ SOFTAP_UNLOCK;
DBG("-");
}
static void __enabled_cfm_cb(GObject *source_object, GAsyncResult *res,
gpointer user_data)
{
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
+ DBG("+");
+ SOFTAP_LOCK;
+
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
+
__softap_h *sa = (__softap_h *)user_data;
GError *g_error = NULL;
GVariant *g_var;
if (!_softap_check_handle((softap_h)user_data)) {
DBG("Softap handle is already destroyed");
+ SOFTAP_UNLOCK;
return;
}
++retry < SOFTAP_ERROR_RECOVERY_MAX) {
g_error_free(g_error);
softap_enable((softap_h)sa);
+ SOFTAP_UNLOCK;
DBG("-");
return;
}
if (ecb)
ecb(error, true, data);
+ SOFTAP_UNLOCK;
+ DBG("-");
return;
}
gpointer user_data)
{
DBG("+");
+ SOFTAP_LOCK;
+
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
+
__softap_h *sa = (__softap_h *)user_data;
GError *g_error = NULL;
GVariant *g_var;
if (!_softap_check_handle((softap_h) sa)) {
DBG("Softap handle is already destroyed");
+ SOFTAP_UNLOCK;
return;
}
if (g_error) {
ERR("DBus error [%s]", g_error->message);
g_error_free(g_error);
+ SOFTAP_UNLOCK;
DBG("-");
return;
} else {
if (dcb)
dcb(error, code, data);
+ SOFTAP_UNLOCK;
DBG("-");
return;
}
gpointer user_data)
{
DBG("+\n");
+ SOFTAP_LOCK;
+
+ if (user_data == NULL) {
+ ERR("parameter(user_data) is NULL");
+ SOFTAP_UNLOCK;
+ return;
+ }
- _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
GError *g_error = NULL;
GVariant *g_var;
guint info;
if (sa->settings_reloaded_cb == NULL) {
DBG("There is no settings_reloaded_cb\n");
+ SOFTAP_UNLOCK;
return;
}
sa->settings_reloaded_cb = NULL;
sa->settings_reloaded_user_data = NULL;
+
+ SOFTAP_UNLOCK;
DBG("-\n");
}
/*
-* Copyright (c) 2011 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.
-*/
-
+ * Copyright (c) 2011 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.
+ */
+
+#define _GNU_SOURCE
+#include <pthread.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#define SOFTAP_FEATURE "http://tizen.org/feature/network.wifi.softap"
#define MODEL_NAME_FEATURE "http://tizen.org/system/model_name"
-static __thread bool is_feature_checked[SUPPORTED_FEATURE_MAX] = { 0, };
-static __thread bool feature_supported[SUPPORTED_FEATURE_MAX] = { 0, };
-static __thread GSList *softap_handle_list = NULL;
+static pthread_mutex_t g_softap_thread_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static bool is_feature_checked[SUPPORTED_FEATURE_MAX] = { 0, };
+static bool feature_supported[SUPPORTED_FEATURE_MAX] = { 0, };
+static GSList *softap_handle_list = NULL;
-static __thread bool is_privilege_checked = 0;
-static __thread bool access_allowed = 0;
+static bool is_privilege_checked = 0;
+static bool access_allowed = 0;
static void __get_feature_info(int feature)
{
free(model_name);
}
+void _softap_lock(void)
+{
+ pthread_mutex_lock(&g_softap_thread_mutex);
+}
+
+void _softap_unlock(void)
+{
+ pthread_mutex_unlock(&g_softap_thread_mutex);
+}
+
int _softap_check_feature_supported(int feature)
{
+ SOFTAP_LOCK;
+
if (!is_feature_checked[feature])
__get_feature_info(feature);
if (!feature_supported[feature]) {
ERR("Not supported feature!");
+ SOFTAP_UNLOCK;
return SOFTAP_ERROR_NOT_SUPPORTED;
}
+ SOFTAP_UNLOCK;
return SOFTAP_ERROR_NONE;
}
int _softap_check_permission(void)
{
+ SOFTAP_LOCK;
+
FILE *fd;
int ret;
char smack_label[SMACK_LABEL_LEN + 1] = {0, };
char uid[10] = {0, };
char *client_session = "";
cynara *p_cynara;
+ int is_access_allowed = 0;
- if (is_privilege_checked)
- return access_allowed ? SOFTAP_ERROR_NONE : SOFTAP_ERROR_PERMISSION_DENIED;
+ if (is_privilege_checked) {
+ is_access_allowed = access_allowed ? SOFTAP_ERROR_NONE : SOFTAP_ERROR_PERMISSION_DENIED;
+ SOFTAP_UNLOCK;
+ return is_access_allowed;
+ }
- if (CYNARA_API_SUCCESS != cynara_initialize(&p_cynara, NULL))
+ if (CYNARA_API_SUCCESS != cynara_initialize(&p_cynara, NULL)) {
+ SOFTAP_UNLOCK;
return SOFTAP_ERROR_PERMISSION_DENIED;
+ }
bzero(smack_label, SMACK_LABEL_LEN + 1);
fd = fopen("/proc/self/attr/current", "r");
- if (fd == NULL)
+ if (fd == NULL) {
+ SOFTAP_UNLOCK;
return SOFTAP_ERROR_PERMISSION_DENIED;
+ }
ret = fread(smack_label, SMACK_LABEL_LEN, 1, fd);
if (ret < 0) {
ERR("Failed[%d] to read /proc/self/attr/current\n", ferror(fd));
fclose(fd);
+ SOFTAP_UNLOCK;
return SOFTAP_ERROR_PERMISSION_DENIED;
}
fclose(fd);
is_privilege_checked = true;
access_allowed = (ret == CYNARA_API_ACCESS_ALLOWED) ? true : false;
+ is_access_allowed = access_allowed ? SOFTAP_ERROR_NONE : SOFTAP_ERROR_PERMISSION_DENIED;
DBG("check permission[%s/%d]", SOFTAP_PRIVILEGE, access_allowed);
- return access_allowed ? SOFTAP_ERROR_NONE : SOFTAP_ERROR_PERMISSION_DENIED;
+ SOFTAP_UNLOCK;
+ return is_access_allowed;
}
void _softap_add_handle(softap_h handle)
{
+ SOFTAP_LOCK;
softap_handle_list = g_slist_append(softap_handle_list, handle);
+ SOFTAP_UNLOCK;
}
void _softap_remove_handle(softap_h handle)
{
+ SOFTAP_LOCK;
softap_handle_list = g_slist_remove(softap_handle_list, handle);
+ SOFTAP_UNLOCK;
}
bool _softap_check_handle(softap_h handle)
{
- if (g_slist_find(softap_handle_list, handle) != NULL)
+ SOFTAP_LOCK;
+ if (g_slist_find(softap_handle_list, handle) != NULL) {
+ SOFTAP_UNLOCK;
return true;
- else
- return false;
+ }
+
+ SOFTAP_UNLOCK;
+ return false;
}