Merge "DPM: Add basic code for device policy manager for BT." into tizen
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-network.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "bluetooth-api.h"
19 #include "bt-internal-types.h"
20
21 #include "bt-common.h"
22 #include "bt-request-sender.h"
23 #include "bt-event-handler.h"
24
25 BT_EXPORT_API int bluetooth_network_activate_server()
26 {
27         int result;
28
29         BT_CHECK_ENABLED(return);
30
31         BT_INIT_PARAMS();
32         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
33
34         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_ACTIVATE,
35                 in_param1, in_param2, in_param3, in_param4, &out_param);
36
37         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
38
39         return result;
40 }
41
42 BT_EXPORT_API int bluetooth_network_deactivate_server(void)
43 {
44         int result;
45
46         BT_CHECK_ENABLED(return);
47
48         BT_INIT_PARAMS();
49         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
50
51         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_DEACTIVATE,
52                 in_param1, in_param2, in_param3, in_param4, &out_param);
53
54         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
55
56         return result;
57 }
58
59 BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *device_address,
60                                                 bluetooth_network_role_t role,
61                                                 char *custom_uuid)
62 {
63         int result;
64         bt_user_info_t *user_info;
65
66         BT_CHECK_PARAMETER(device_address, return);
67         BT_CHECK_ENABLED(return);
68
69         if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_CONNECT)
70              == BLUETOOTH_ERROR_PERMISSION_DEINED) {
71                 BT_ERR("Don't have a privilege to use this API");
72                 return BLUETOOTH_ERROR_PERMISSION_DEINED;
73         }
74
75         user_info = _bt_get_user_data(BT_COMMON);
76         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
77
78         BT_INIT_PARAMS();
79         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
80
81         g_array_append_vals(in_param1, device_address,
82                                 sizeof(bluetooth_device_address_t));
83         g_array_append_vals(in_param2, &role, sizeof(int));
84
85         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_CONNECT,
86                 in_param1, in_param2, in_param3, in_param4,
87                 user_info->cb, user_info->user_data);
88
89         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
90
91         return result;
92 }
93
94 BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t *device_address)
95 {
96         int result;
97         bt_user_info_t *user_info;
98
99         BT_CHECK_PARAMETER(device_address, return);
100         BT_CHECK_ENABLED(return);
101
102         if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_DISCONNECT)
103              == BLUETOOTH_ERROR_PERMISSION_DEINED) {
104                 BT_ERR("Don't have a privilege to use this API");
105                 return BLUETOOTH_ERROR_PERMISSION_DEINED;
106         }
107
108         user_info = _bt_get_user_data(BT_COMMON);
109         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
110
111         BT_INIT_PARAMS();
112         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
113
114         g_array_append_vals(in_param1, device_address,
115                                         sizeof(bluetooth_device_address_t));
116
117         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_DISCONNECT,
118                 in_param1, in_param2, in_param3, in_param4,
119                 user_info->cb, user_info->user_data);
120
121         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
122
123         return result;
124 }
125
126 BT_EXPORT_API int bluetooth_network_server_disconnect(const bluetooth_device_address_t *device_address)
127 {
128         int result;
129         bt_user_info_t *user_info;
130
131         BT_CHECK_PARAMETER(device_address, return);
132         BT_CHECK_ENABLED(return);
133
134         if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_SERVER_DISCONNECT)
135              == BLUETOOTH_ERROR_PERMISSION_DEINED) {
136                 BT_ERR("Don't have a privilege to use this API");
137                 return BLUETOOTH_ERROR_PERMISSION_DEINED;
138         }
139
140         user_info = _bt_get_user_data(BT_COMMON);
141         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
142
143         BT_INIT_PARAMS();
144         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
145
146         g_array_append_vals(in_param1, device_address,
147                                         sizeof(bluetooth_device_address_t));
148
149         result = _bt_send_request_async(BT_BLUEZ_SERVICE,
150                                 BT_NETWORK_SERVER_DISCONNECT,
151                                 in_param1, in_param2, in_param3, in_param4,
152                                 user_info->cb, user_info->user_data);
153
154         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
155
156         return result;
157 }
158