Merge branch 'master' into tizen_2.1
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-network.c
1 /*
2  * bluetooth-frwk
3  *
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *              http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "bluetooth-api.h"
21 #include "bt-internal-types.h"
22
23 #include "bt-common.h"
24 #include "bt-request-sender.h"
25 #include "bt-event-handler.h"
26
27 BT_EXPORT_API int bluetooth_network_activate_server()
28 {
29         int result;
30
31         BT_CHECK_ENABLED(return);
32
33         BT_INIT_PARAMS();
34         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
35
36         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_ACTIVATE,
37                 in_param1, in_param2, in_param3, in_param4, &out_param);
38
39         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
40
41         return result;
42 }
43
44 BT_EXPORT_API int bluetooth_network_deactivate_server(void)
45 {
46         int result;
47
48         BT_CHECK_ENABLED(return);
49
50         BT_INIT_PARAMS();
51         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
52
53         result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_DEACTIVATE,
54                 in_param1, in_param2, in_param3, in_param4, &out_param);
55
56         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
57
58         return result;
59 }
60
61 BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *device_address,
62                                                 bluetooth_network_role_t role,
63                                                 char *custom_uuid)
64 {
65         int result;
66         bt_user_info_t *user_info;
67
68         BT_CHECK_PARAMETER(device_address, return);
69         BT_CHECK_ENABLED(return);
70
71         BT_INIT_PARAMS();
72         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
73
74         user_info = _bt_get_user_data(BT_COMMON);
75         retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
76
77         g_array_append_vals(in_param1, device_address,
78                                 sizeof(bluetooth_device_address_t));
79         g_array_append_vals(in_param2, &role, sizeof(int));
80
81         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_CONNECT,
82                 in_param1, in_param2, in_param3, in_param4,
83                 user_info->cb, user_info->user_data);
84
85         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
86
87         return result;
88 }
89
90 BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t *device_address)
91 {
92         int result;
93         bt_user_info_t *user_info;
94
95         BT_CHECK_PARAMETER(device_address, return);
96         BT_CHECK_ENABLED(return);
97
98         BT_INIT_PARAMS();
99         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
100
101         user_info = _bt_get_user_data(BT_COMMON);
102         retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
103
104         g_array_append_vals(in_param1, device_address,
105                                         sizeof(bluetooth_device_address_t));
106
107         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_DISCONNECT,
108                 in_param1, in_param2, in_param3, in_param4,
109                 user_info->cb, user_info->user_data);
110
111         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
112
113         return result;
114 }
115