85cf9743776b3a97ba5b1766c4896444c2f88e04
[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,
46                         BLUETOOTH_MAX_OTP_SERVER_DIR_NAME);
47
48         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_SERVER_INIT,
49                 in_param1, in_param2, in_param3, in_param4,
50                 user_info->cb, user_info->user_data);
51
52         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
53
54         BT_DBG("-");
55         return result;
56 }
57
58 BT_EXPORT_API int bluetooth_otp_server_deinit()
59 {
60         int result = BLUETOOTH_ERROR_INTERNAL;
61         bt_user_info_t *user_info;
62         BT_DBG("+");
63
64         BT_CHECK_ENABLED(return);
65
66         user_info = _bt_get_user_data(BT_COMMON);
67         retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
68
69         BT_INIT_PARAMS();
70         BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
71         BT_DBG("");
72
73         result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_SERVER_DEINIT,
74                 in_param1, in_param2, in_param3, in_param4,
75                 user_info->cb, user_info->user_data);
76
77         BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
78
79         BT_DBG("-");
80         return result;
81 }