[Bluetooth][OTP] Add base code for OTP server role
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-otp.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_otp_server_init(const char *directory)
26 {
27         int result = BLUETOOTH_ERROR_INTERNAL;
28         bt_user_info_t *user_info;
29         char dir_name[BLUETOOTH_MAX_OTP_SERVER_DIR_NAME];
30         BT_DBG("+");
31
32         BT_CHECK_ENABLED(return);
33
34         user_info = _bt_get_user_data(BT_COMMON);
35         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
36
37         BT_INIT_PARAMS();
38         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
39
40         if (directory)
41                 g_strlcpy(dir_name, directory, sizeof(dir_name));
42         else
43                 dir_name[0] = '\0';
44
45         g_array_append_vals(in_param1, dir_name, BLUETOOTH_MAX_OTP_SERVER_DIR_NAME);
46
47         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_SERVER_INIT,
48                 in_param1, in_param2, in_param3, in_param4,
49                 user_info->cb, user_info->user_data);
50
51         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
52
53         BT_DBG("-");
54         return result;
55 }
56
57 BT_EXPORT_API int bluetooth_otp_server_deinit()
58 {
59         int result = BLUETOOTH_ERROR_INTERNAL;
60         bt_user_info_t *user_info;
61         BT_DBG("+");
62
63         BT_CHECK_ENABLED(return);
64
65         user_info = _bt_get_user_data(BT_COMMON);
66         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
67
68         BT_INIT_PARAMS();
69         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
70         BT_DBG("");
71
72         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_SERVER_DEINIT,
73                 in_param1, in_param2, in_param3, in_param4,
74                 user_info->cb, user_info->user_data);
75
76         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
77
78         BT_DBG("-");
79         return result;
80 }