[DPM] Add apis for the device policy manager in BT 10/58310/2
authorSudha Bheemanna <b.sudha@samsung.com>
Fri, 29 Jan 2016 07:15:14 +0000 (12:45 +0530)
committerSudha Bheemanna <b.sudha@samsung.com>
Fri, 29 Jan 2016 07:22:51 +0000 (12:52 +0530)
Added some more BT api implementation in the base code.

Change-Id: I38690eeb8a4e467ea2e92904f1e0acb3fae5f305
Signed-off-by: Sudha Bheemanna <b.sudha@samsung.com>
bt-service/bt-service-dpm.c [changed mode: 0644->0755]
bt-service/include/bt-service-dpm.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index fd7a118..daa4947
@@ -38,6 +38,29 @@ static dpm_policy_t policy_table[DPM_POLICY_END] = {
        [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = {NULL},
        [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = {NULL},
        [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = {DPM_STATUS_ERROR},
+};
+
+
+/**
+ * @brief DPM profile state
+ * @see
+ */
+static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE]  = {
+       [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
+       [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
 };
 
 dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
@@ -292,3 +315,265 @@ dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
        }
        return DPM_RESULT_SUCCESS;
 }
+
+dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
+}
+
+dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_set_bluetooth_profile_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       dpm_profile_state[profile].value = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_profile_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return dpm_profile_state[profile].value;
+}
+
+dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
+}
+
+dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
+}
+
+dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
+
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void)
+{
+       BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
+}
+
+dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
+}
+
+dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(dpm_status_t value)
+{
+       BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESTRICTED;
+
+       return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
+}
+
+dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(GSList *device_addresses)
+{
+       GSList *l = NULL;
+       GSList *device_list = NULL;
+       BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (device_list = device_addresses; device_list; device_list = g_slist_next(device_list)) {
+               for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
+                       if (l->data == device_list->data) {
+                               char *addr = device_list->data;
+                               if (addr) {
+                                       policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list =
+                                               g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, addr);
+                                       g_free(addr);
+                                       break;
+                               }
+                       }
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(GSList *device_addresses)
+{
+       GSList *l = NULL;
+       GSList *device_list = NULL;
+       BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (device_list = device_addresses; device_list; device_list = g_slist_next(device_list)) {
+               for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
+                       if (l->data == device_list->data) {
+                               char *addr = device_list->data;
+                               if (addr) {
+                                       policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list =
+                                               g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, addr);
+                                       g_free(addr);
+                                       break;
+                               }
+                       }
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(GSList *uuids)
+{
+       GSList *l = NULL;
+       GSList *uuids_list = NULL;
+       BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (uuids_list = uuids; uuids_list; uuids_list = g_slist_next(uuids_list)) {
+               for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
+                       if (l->data == uuids_list->data) {
+                               char *uuid = uuids_list->data;
+                               if (uuid) {
+                                       policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list =
+                                               g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, uuid);
+                                       g_free(uuid);
+                                       break;
+                               }
+                       }
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(GSList *uuids)
+{
+       GSList *l = NULL;
+       GSList *uuids_list = NULL;
+       BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       for (uuids_list = uuids; uuids_list; uuids_list = g_slist_next(uuids_list)) {
+               for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
+                       if (l->data == uuids_list->data) {
+                               char *uuid = uuids_list->data;
+                               if (uuid) {
+                                       policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list =
+                                               g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, uuid);
+                                       g_free(uuid);
+                                       break;
+                               }
+                       }
+               }
+       }
+       return DPM_RESULT_SUCCESS;
+}
+
+dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void)
+{
+       BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
+       dpm_result_t err = DPM_RESULT_FAIL;
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
+       if (!err){
+               err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
+       }
+
+       return err;
+}
+
+dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void)
+{
+       BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
+       dpm_result_t err = DPM_RESULT_FAIL;
+
+       if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
+               return DPM_RESULT_ACCESS_DENIED;
+
+       err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
+       if (!err){
+               err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
+       }
+
+       return err;
+}
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 57bc7c0..2d6362a
@@ -61,8 +61,8 @@ typedef enum _dpm_status {
        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_ENABLE                      = 1,    /**< DPM Policy status enabled. */
+       DPM_DISABLE             = 0,    /**< DPM Policy status disabled. */
 
        DPM_FALSE                       = 0,    /**< DPM Policy status false. */
        DPM_TRUE                        = 1,    /**< DPM Policy status true. */
@@ -78,9 +78,15 @@ typedef enum _dpm_policy_cmd {
        DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST,
        DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST,
        DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL,
+       DPM_POLICY_BLUETOOTH_PAIRING_STATE,
+       DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE,
+       DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE,
+       DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE,
+       DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE,
        DPM_POLICY_END,
 } dpm_policy_cmd_t;
 
+
 struct dpm_policy {
        union {
                int value;
@@ -89,6 +95,26 @@ struct dpm_policy {
 };
 typedef struct dpm_policy dpm_policy_t;
 
+
+typedef enum dpm_profile {
+       DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE,
+       DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE,
+       DPM_PROFILE_NONE,
+} dpm_profile_t;
+
+struct dpm_profile_val {
+               int value; //tells whether the profile is enabled or disabled
+};
+typedef struct dpm_profile_val dpm_profile_state_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);
@@ -111,6 +137,23 @@ 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);
+dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value);
+dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void);
+dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value);
+dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile);
+dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value);
+dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void);
+dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value);
+dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void);
+dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void);
+dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void);
+dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value);
+dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void);
+dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value);
+dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(GSList *device_addresses);
+dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(GSList *device_addresses);
+dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(GSList *uuids);
+dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(GSList *uuids);
 
 #ifdef __cplusplus
 }