67daab3021b43207ba4386dafd1feb5715790478
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-gap-agent.h
1 /*
2  * BLUETOOTH HAL
3  *
4  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Anupam Roy <anupam.r@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __BT_HAL_GAP_AGENT_H__
23 #define _BT_HAL_GAP_AGENT_H__
24
25 #include <stdint.h>
26 #include <glib.h>
27 #include <gio/gio.h>
28
29 #ifdef TIZEN_BT_HAL
30 typedef struct {
31         unsigned int type;
32         char *uuid;
33         char *path;
34         int fd;
35 } bt_hal_agent_osp_server_t;
36 #endif
37
38 typedef enum {
39         GAP_AGENT_EXEC_NO_OPERATION,
40         GAP_AGENT_EXEC_PAIRING,
41         GAP_AGENT_EXEC_AUTHORZATION,
42         GAP_AGENT_EXEC_CONFIRM_MODE,
43 } GapAgentExecType;
44
45 typedef struct _GapAgentPrivate GapAgentPrivate;
46
47 typedef gboolean(*GapAgentPasskeyFunc) (GapAgentPrivate *agent,
48                 GDBusProxy *device);
49 typedef gboolean(*GapAgentDisplayFunc) (GapAgentPrivate *agent, GDBusProxy *device,
50                 guint passkey);
51 typedef gboolean(*GapAgentConfirmFunc) (GapAgentPrivate *agent, GDBusProxy *device,
52                 guint passkey);
53 typedef gboolean(*GapAgentAuthorizeFunc) (GapAgentPrivate *agent,
54                 GDBusProxy *device, const char *uuid);
55 typedef gboolean(*GapAgentConfirmModeFunc) (GapAgentPrivate *agent,
56                 const char *mode, const char *sender,
57                 gboolean need_popup, void *data);
58 typedef gboolean(*GapAgentCancelFunc) (GapAgentPrivate *agent,
59                 const char *address);
60
61 typedef uint8_t bool_t;
62
63 typedef struct {
64         GapAgentPasskeyFunc pincode_func;
65         GapAgentDisplayFunc display_func;
66         GapAgentPasskeyFunc passkey_func;
67         GapAgentConfirmFunc confirm_func;
68         GapAgentAuthorizeFunc authorize_func;
69         GapAgentCancelFunc pairing_cancel_func;
70         GapAgentCancelFunc authorization_cancel_func;
71 } GAP_AGENT_FUNC_CB;
72
73 typedef enum {
74         GAP_AGENT_ACCEPT,
75         GAP_AGENT_REJECT,
76         GAP_AGENT_CANCEL,
77         GAP_AGENT_TIMEOUT,
78         GAP_AGENT_ACCEPT_ALWAYS,
79 } GAP_AGENT_ACCEPT_TYPE_T;
80
81 struct _GapAgentPrivate {
82         gchar *busname;
83         gchar *path;
84         GDBusProxy *adapter;
85         GDBusProxy *agent_manager;
86         GDBusProxy *dbus_proxy;
87         GapAgentExecType exec_type;
88         GDBusMethodInvocation *reply_context;
89
90         char pairing_addr[18];
91         char authorize_addr[18];
92
93         GSList *osp_servers;
94         GAP_AGENT_FUNC_CB cb;
95         gboolean canceled;
96 };
97
98 void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb,
99                 const char *path, GDBusProxy *adapter);
100
101 gboolean _gap_agent_register(GapAgentPrivate *agent);
102
103 void _gap_agent_reset_dbus(GapAgentPrivate *agent);
104
105 gchar* _gap_agent_get_path(GapAgentPrivate *agent);
106
107 gboolean _gap_agent_is_canceled(GapAgentPrivate *agent);
108
109 void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value);
110
111 gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
112                 const char *pin_code,
113                 GDBusMethodInvocation *context);
114 gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
115                 const char *passkey,
116                 GDBusMethodInvocation *context);
117 gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
118                 GDBusMethodInvocation *context);
119
120 gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
121                 GDBusMethodInvocation *context);
122
123 #ifdef TIZEN_BT_HAL
124 bt_hal_agent_osp_server_t *_bt_hal_gap_agent_find_osp_server_by_type(GSList *servers, unsigned int type, const char *uuid);
125
126 gboolean _bt_hal_gap_agent_register_osp_server(GapAgentPrivate *agent, unsigned int type, char *uuid, char *path, int fd);
127
128 gboolean _bt_hal_gap_agent_unregister_osp_server(GapAgentPrivate *agent, unsigned int type, char *uuid);
129 #endif
130 #endif //_BT_HAL_GAP_AGENT_H__