DPM: Add basic code for device policy manager for BT. 75/57375/5
authorh.sandeep <h.sandeep@samsung.com>
Tue, 19 Jan 2016 12:44:48 +0000 (18:14 +0530)
committerh.sandeep <h.sandeep@samsung.com>
Thu, 21 Jan 2016 04:04:56 +0000 (09:34 +0530)
Change-Id: I708a7f0e013b7fa5b298050518e59852686d5a0f
Signed-off-by: h.sandeep <h.sandeep@samsung.com>
bt-service/CMakeLists.txt
bt-service/bt-service-dpm.c [new file with mode: 0644]
bt-service/include/bt-service-dpm.h [new file with mode: 0644]

index 230f100..9f5a259 100644 (file)
@@ -27,6 +27,7 @@ bt-request-handler.c
 bt-service-agent.c
 bt-service-gap-agent.c
 bt-service-pbap.c
+bt-service-dpm.c
 )
 
 IF(LIBNOTIFY_SUPPORT)
diff --git a/bt-service/bt-service-dpm.c b/bt-service/bt-service-dpm.c
new file mode 100644 (file)
index 0000000..fd7a118
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * 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.
+ *
+ */
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <dlog.h>
+#include <string.h>
+#include <syspopup_caller.h>
+#include <bundle_internal.h>
+
+#include "bluetooth-api.h"
+#include "bt-internal-types.h"
+
+#include "bt-service-common.h"
+#include "bt-service-dpm.h"
+
+static dpm_policy_t policy_table[DPM_POLICY_END] = {
+       /* policy-group : BLUETOOTH */
+       [DPM_POLICY_ALLOW_BLUETOOTH] = {DPM_BT_ERROR},
+       [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = {NULL},
+       [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = {NULL},
+       [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = {NULL},
+       [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = {NULL},
+       [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = {DPM_STATUS_ERROR},
+};
+
+dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
+{
+       BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
+       policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value  = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void)
+{
+       BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
+       return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
+}
+
+dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value  = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void)
+{
+       BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
+}
+
+dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value  = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void)
+{
+       BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
+}
+
+dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(char *device_address)
+{
+       GSList *l = NULL;
+       char *dev_addr;
+       BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       dev_addr = g_strdup(device_address);
+       if (!dev_addr)
+               return DPM_RESULT_FAIL;
+       policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
+       return DPM_RESULT_SUCCESS;
+}
+
+GSList *_bt_dpm_get_bluetooth_devices_from_blacklist(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return NULL;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
+}
+
+dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(char *device_address)
+{
+       GSList *l = NULL;
+       char *dev_addr;
+       BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       dev_addr = g_strdup(device_address);
+       if (!dev_addr)
+               return DPM_RESULT_FAIL;
+       policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
+       return DPM_RESULT_SUCCESS;
+}
+
+GSList *_bt_dpm_get_bluetooth_devices_from_whitelist(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return NULL;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
+}
+
+dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(char *uuid)
+{
+       GSList *l = NULL;
+       char *l_uuid;
+       BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       l_uuid = g_strdup(uuid);
+       if (!l_uuid)
+               return DPM_RESULT_FAIL;
+       policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
+       return DPM_RESULT_SUCCESS;
+}
+
+GSList *_bt_dpm_get_bluetooth_uuids_from_blacklist(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return NULL;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
+}
+
+dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(char *uuid)
+{
+       GSList *l = NULL;
+       char *l_uuid;
+       BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       l_uuid = g_strdup(uuid);
+       if (!l_uuid)
+               return DPM_RESULT_FAIL;
+       policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list  = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
+       return DPM_RESULT_SUCCESS;
+}
+
+
+GSList *_bt_dpm_get_bluetooth_uuids_from_whitelist(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return NULL;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
+}
+
+dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value  = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void)
+{
+       BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
+}
+
+dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
+{
+       GSList *l = NULL;
+       BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
+               char *address = l->data;
+               if (address) {
+                       policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
+                       g_free(address);
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
+{
+       GSList *l = NULL;
+       BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
+               char *address = l->data;
+               if (address) {
+                       policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
+                       g_free(address);
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
+{
+       GSList *l = NULL;
+       BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
+               char *l_uuid = l->data;
+               if (l_uuid)
+                       policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
+                       g_free(l_uuid);
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
+{
+       GSList *l = NULL;
+       BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
+               char *l_uuid = l->data;
+               if (l_uuid) {
+                       policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
+                       g_free(l_uuid);
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
diff --git a/bt-service/include/bt-service-dpm.h b/bt-service/include/bt-service-dpm.h
new file mode 100644 (file)
index 0000000..57bc7c0
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * 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 _BT_SERVICE_DPM_H_
+#define _BT_SERVICE_DPM_H_
+
+#include <glib.h>
+#include <sys/types.h>
+#include "bluetooth-api.h"
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+
+ /**
+ * @brief DPM BT allowance state
+ * @see
+ */
+ typedef enum {
+        DPM_BT_ERROR    = -1,   /**< bluetooth allowance error */
+        DPM_BT_ALLOWED,                 /**< bluetooth allowance allowed */
+        DPM_BT_HANDSFREE_ONLY,  /**< bluetooth allowance handsfree only */
+        DPM_BT_RESTRICTED,      /**< bluetooth allowance restricted */
+ } dpm_bt_allow_t;
+
+ /**
+ * @brief DPM API result
+ * @see
+ */
+typedef enum _dpm_result {
+       DPM_RESULT_SERVICE_NOT_ENABLED = -5,    /**< DPM API result service not enabled. */
+       DPM_RESULT_ACCESS_DENIED = -4,                  /**< DPM API result access denied. */
+       DPM_RESULT_INVALID_PARAM = -3,                  /**< DPM API result invalid parameter. */
+       DPM_RESULT_NOT_SUPPORTED = -2,                  /**< DPM API result not supported. */
+       DPM_RESULT_FAIL          = -1,                          /**< DPM API result fail. */
+       DPM_RESULT_SUCCESS       = 0,                           /**< DPM API result success. */
+} dpm_result_t;
+
+/**
+ * @brief DPM Policy status
+ * @see
+ */
+typedef enum _dpm_status {
+       DPM_STATUS_ERROR        = -1,
+
+       DPM_ALLOWED                     = 0,    /**< DPM Policy status allowed. */
+       DPM_RESTRICTED          = 1,    /**< DPM Policy status restricted. */
+
+       DPM_ENABLED                     = 0,    /**< DPM Policy status enabled. */
+       DPm_DISABLED            = 1,    /**< DPM Policy status disabled. */
+
+       DPM_FALSE                       = 0,    /**< DPM Policy status false. */
+       DPM_TRUE                        = 1,    /**< DPM Policy status true. */
+} dpm_status_t;
+
+typedef enum _dpm_policy_cmd {
+       /* policy-group : BLUETOOTH */
+       DPM_POLICY_ALLOW_BLUETOOTH,
+       DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION,
+       DPM_POLICY_BLUETOOTH_UUID_RESTRICTION,
+       DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST,
+       DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST,
+       DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST,
+       DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST,
+       DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL,
+       DPM_POLICY_END,
+} dpm_policy_cmd_t;
+
+struct dpm_policy {
+       union {
+               int value;
+               GSList *list;
+       };
+};
+typedef struct dpm_policy dpm_policy_t;
+
+dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value);
+dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void);
+dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value);
+dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void);
+dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value);
+dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void);
+dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(char *device_address);
+dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(char *device_address);
+dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(char *uuid);
+dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(char *uuid);
+dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value);
+dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void);
+dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void);
+dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void);
+dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void);
+dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void);
+GSList *_bt_dpm_get_bluetooth_devices_from_blacklist(void);
+GSList *_bt_dpm_get_bluetooth_devices_from_whitelist(void);
+GSList *_bt_dpm_get_bluetooth_uuids_from_blacklist(void);
+GSList *_bt_dpm_get_bluetooth_uuids_from_whitelist(void);
+dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void);
+dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_BT_SERVICE_DPM_H_*/
+