4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #ifdef TIZEN_MDM_ENABLE
25 #include <syspopup_caller.h>
26 #include "bt-internal-types.h"
27 #include "bt-common.h"
30 int _bt_launch_mdm_popup(char *mode)
36 retv_if(b == NULL, BLUETOOTH_ERROR_INTERNAL);
38 bundle_add(b, "mode", mode);
40 ret = syspopup_launch(BT_MDM_SYSPOPUP, b);
43 BT_ERR("Popup launch failed: %d\n", ret);
50 bt_mdm_status_e _bt_check_mdm_handsfree_only(void)
54 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
56 mode = mdm_get_allow_bluetooth_mode();
57 mdm_release_service();
59 return (mode == MDM_BT_HANDSFREE_ONLY ? BT_MDM_RESTRICTED : BT_MDM_ALLOWED);
63 bt_mdm_status_e _bt_check_mdm_pairing_restriction(void)
65 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
67 if (mdm_get_service() != MDM_RESULT_SUCCESS)
68 return BT_MDM_NO_SERVICE;
70 if (mdm_get_bluetooth_pairing_state() == MDM_RESTRICTED) {
71 /* Not allow to visible on */
72 BT_ERR("Pairing Restricted");
73 mdm_status = BT_MDM_RESTRICTED;
75 mdm_release_service();
80 bt_mdm_status_e _bt_check_mdm_transfer_restriction(void)
82 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
84 mdm_status = _bt_check_mdm_blacklist_uuid(BT_OPP_UUID);
86 if (mdm_status == BT_MDM_NO_SERVICE || mdm_status == BT_MDM_RESTRICTED) {
90 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
92 if (mdm_get_bluetooth_data_transfer_state() == MDM_RESTRICTED ||
93 mdm_get_allow_bluetooth_mode() == MDM_BT_HANDSFREE_ONLY) {
94 /* Not allow to visible on */
95 BT_ERR("Restricted to set visible mode");
96 mdm_status = BT_MDM_RESTRICTED;
98 mdm_release_service();
103 bt_mdm_status_e _bt_check_mdm_hsp_restriction(void)
105 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
107 mdm_status = _bt_check_mdm_blacklist_uuid(BT_HFP_AUDIO_GATEWAY_UUID);
109 if (mdm_status == BT_MDM_NO_SERVICE || mdm_status == BT_MDM_RESTRICTED) {
113 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
115 if (mdm_get_bluetooth_profile_state(BLUETOOTH_HSP_PROFILE) == MDM_RESTRICTED ||
116 mdm_get_bluetooth_profile_state(BLUETOOTH_HFP_PROFILE) == MDM_RESTRICTED) {
117 /* Not allow to visible on */
118 BT_ERR("Restrict hsp / hfp profile");
119 mdm_status = BT_MDM_RESTRICTED;
121 mdm_release_service();
126 bt_mdm_status_e _bt_check_mdm_a2dp_restriction(void)
128 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
130 mdm_status = _bt_check_mdm_blacklist_uuid(BT_A2DP_UUID);
132 if (mdm_status == BT_MDM_NO_SERVICE || mdm_status == BT_MDM_RESTRICTED) {
136 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
138 if (mdm_get_bluetooth_profile_state(BLUETOOTH_A2DP_PROFILE) == MDM_RESTRICTED) {
139 /* Not allow to visible on */
140 BT_ERR("Restrict a2dp profile");
141 mdm_status = BT_MDM_RESTRICTED;
143 mdm_release_service();
148 bt_mdm_status_e _bt_check_mdm_avrcp_restriction(void)
150 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
153 mdm_status = _bt_check_mdm_blacklist_uuid(BT_AVRCP_TARGET_UUID);
155 if (mdm_status == BT_MDM_NO_SERVICE || mdm_status == BT_MDM_RESTRICTED) {
159 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
161 if (mdm_get_bluetooth_profile_state(BLUETOOTH_AVRCP_PROFILE) == MDM_RESTRICTED) {
162 /* Not allow to visible on */
163 BT_ERR("Restrict avrcp profile");
164 mdm_status = BT_MDM_RESTRICTED;
166 mdm_release_service();
171 bt_mdm_status_e _bt_check_mdm_spp_restriction(void)
173 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
175 mdm_status = _bt_check_mdm_blacklist_uuid(BT_SPP_UUID);
177 if (mdm_status == BT_MDM_NO_SERVICE || mdm_status == BT_MDM_RESTRICTED) {
181 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
183 if (mdm_get_bluetooth_profile_state(BLUETOOTH_SPP_PROFILE) == MDM_RESTRICTED) {
184 /* Not allow to visible on */
185 BT_ERR("Restrict spp profile");
186 mdm_status = BT_MDM_RESTRICTED;
188 mdm_release_service();
193 bt_mdm_status_e _bt_check_mdm_whitelist_devices(const bluetooth_device_address_t *address)
195 mdm_data_t *lp_data = NULL;
196 GList *whitelist = NULL;
198 bluetooth_device_info_t dev_info;
199 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
201 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
203 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
205 if (bluetooth_get_bonded_device(address,
206 &dev_info) != BLUETOOTH_ERROR_NONE) {
207 BT_ERR("Not paired device");
211 lp_data = mdm_get_bluetooth_devices_from_whitelist();
212 if (lp_data == NULL) {
213 BT_ERR("No whitelist");
214 mdm_release_service();
218 for (whitelist = (GList *)lp_data->data; whitelist; whitelist = whitelist->next) {
219 device_name = whitelist->data;
221 DBG_SECURE("whitelist device name: %s", device_name);
223 if (g_strcmp0(dev_info.device_name.name,
225 mdm_status = BT_MDM_RESTRICTED;
230 mdm_free_data(lp_data);
231 mdm_release_service();
236 bt_mdm_status_e _bt_check_mdm_whitelist_uuid(char *uuid)
240 char *blacklist_uuid;
241 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
243 if (mdm_get_service() != MDM_RESULT_SUCCESS)
244 return BT_MDM_NO_SERVICE;
249 lp_data = mdm_get_bluetooth_uuids_from_blacklist();
250 if (lp_data == NULL) {
251 BT_ERR("No blacklist");
252 mdm_release_service();
256 for (blacklist = (GList *)lp_data->data; blacklist; blacklist = blacklist->next) {
257 blacklist_uuid = blacklist->data;
259 BT_DBG("blacklist_uuid: %s", blacklist_uuid);
261 if (g_strcmp0(blacklist_uuid, uuid) == 0) {
262 mdm_status = BT_MDM_RESTRICTED;
267 mdm_free_data(lp_data);
268 mdm_release_service();
273 bt_mdm_status_e _bt_check_mdm_blacklist_devices(const bluetooth_device_address_t *address)
278 bluetooth_device_info_t dev_info;
279 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
281 if (mdm_get_service() != MDM_RESULT_SUCCESS) return BT_MDM_NO_SERVICE;
283 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
285 if (bluetooth_get_bonded_device(address,
286 &dev_info) != BLUETOOTH_ERROR_NONE) {
287 BT_ERR("Not paired device");
291 lp_data = mdm_get_bluetooth_devices_from_blacklist();
292 if (lp_data == NULL) {
293 BT_ERR("No blacklist");
294 mdm_release_service();
298 for (blacklist = (GList *)lp_data->data; blacklist; blacklist = blacklist->next) {
299 device_name = blacklist->data;
301 DBG_SECURE("blacklist name: %s", device_name);
303 if (g_strcmp0(dev_info.device_name.name,
305 mdm_status = BT_MDM_RESTRICTED;
310 mdm_free_data(lp_data);
311 mdm_release_service();
316 bt_mdm_status_e _bt_check_mdm_blacklist_uuid(char *uuid)
320 char *blacklist_uuid;
321 bt_mdm_status_e mdm_status = BT_MDM_ALLOWED;
323 if (mdm_get_service() != MDM_RESULT_SUCCESS)
324 return BT_MDM_NO_SERVICE;
329 lp_data = mdm_get_bluetooth_uuids_from_blacklist();
330 if (lp_data == NULL) {
331 BT_ERR("No blacklist");
332 mdm_release_service();
336 for (blacklist = (GList *)lp_data->data; blacklist; blacklist = blacklist->next) {
337 blacklist_uuid = blacklist->data;
339 BT_DBG("blacklist_uuid: %s", blacklist_uuid);
341 if (g_strcmp0(blacklist_uuid, uuid) == 0) {
342 mdm_status = BT_MDM_RESTRICTED;
347 mdm_free_data(lp_data);
348 mdm_release_service();