8552031ac88858b655ea6ee51139981ba70fdfce
[platform/core/connectivity/bluetooth-agent.git] / hid-agent / bluetooth-hid-agent.h
1 /*
2  * Bluetooth-hid-agent
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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 #ifndef __DEF_BT_HID_AGENT_H_
21 #define __DEF_BT_HID_AGENT_H_
22 #define FUNCTION_TRACE
23
24 #include <stdio.h>
25 #include <dlog.h>
26 #include <glib.h>
27 #include <sys/socket.h>
28 #include <gio/gio.h>
29 #include <gio/gunixfdlist.h>
30 #include <inttypes.h>
31
32 #undef LOG_TAG
33 #define LOG_TAG "BLUETOOTH_HID_AGENT"
34
35 #define LOG_COLOR_RESET    "\033[0m"
36 #define LOG_COLOR_RED      "\033[31m"
37 #define LOG_COLOR_YELLOW   "\033[33m"
38 #define LOG_COLOR_GREEN         "\033[32m"
39 #define LOG_COLOR_BLUE          "\033[36m"
40 #define LOG_COLOR_PURPLE   "\033[35m"
41
42 #define DBG(fmt, args...) SLOGD(fmt, ##args)
43 #define INFO(fmt, args...) SLOGI(fmt, ##args)
44 #define ERR(fmt, args...) SLOGE(fmt, ##args)
45 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
46 #define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
47 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
48 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
49 #define INFO_C(fmt, arg...) \
50         SLOGI_IF(TRUE,  LOG_COLOR_BLUE" "fmt" "LOG_COLOR_RESET, ##arg)
51 #define ERR_C(fmt, arg...) \
52         SLOGI_IF(TRUE,  LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
53
54 #ifdef FUNCTION_TRACE
55 #define FN_START DBG("[ENTER FUNC]")
56 #define FN_END DBG("[EXIT FUNC]")
57 #else
58 #define FN_START
59 #define FN_END
60 #endif
61
62 #define BT_HID_SERVICE_NAME "org.bluez.hid_agent"
63 #define BT_HID_AGENT_OBJECT_PATH "/org/bluez/hid_agent"
64 #define BT_HID_SERVICE_INTERFACE "org.tizen.HidApp"
65 #define BT_HID_AGENT_ERROR (__bt_hid_agent_error_quark())
66
67 #define BT_HID_BLUEZ_OBJECT_PATH "/org/tizen/hid"
68 #define BT_HID_BLUEZ_INTERFACE  "org.bluez.HidAgent"
69
70 #define BLUEZ_SERVICE_NAME "org.bluez"
71 #define BLUEZ_HID_INTERFACE_NAME "org.bluez.hid_device"
72
73 #define BLUEZ_PROFILE_MGMT_INTERFACE "org.bluez.ProfileManager1"
74 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
75 #define BT_ADAPTER_INTERFACE    "org.bluez.Adapter1"
76
77 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
78 #define BT_INTERFACES_ADDED "InterfacesAdded"
79 #define BT_INTERFACES_REMOVED "InterfacesRemoved"
80 #define BT_PROPERTY_CHANGED "PropertiesChanged"
81
82 #define BLUEZ_MEDIA_TRANSPORT_INTERFACE "org.bluez.MediaTransport1"
83 #define BLUEZ_MEDIA_ENDPOINT_INTERFACE "org.bluez.MediaEndpoint1"
84 #define BLUEZ_DEVICE_INTERFACE  "org.bluez.Device1"
85 #define A2DP_SOURCE_ENDPOINT "/MediaEndpoint/A2DPSource"
86
87 #define BT_ADDRESS_STRING_SIZE 18
88 #define BT_ADAPTER_OBJECT_PATH_MAX 50
89 #define BT_HID_DATA_BUF_SIZE 1024
90
91 #define BT_ERROR_INTERNAL "InternalError"
92 #define BT_ERROR_NOT_AVAILABLE "NotAvailable"
93 #define BT_ERROR_NOT_CONNECTED "NotConnected"
94 #define BT_ERROR_NOT_CONNECTION_FAILED "ConnectionFailed"
95 #define BT_ERROR_BUSY "InProgress"
96 #define BT_ERROR_INVALID_PARAM "InvalidArguments"
97 #define BT_ERROR_ALREADY_EXIST "AlreadyExists"
98 #define BT_ERROR_ALREADY_CONNECTED "Already Connected"
99 #define BT_ERROR_NO_MEMORY "No memory"
100 #define BT_ERROR_NO_DATA "No data"
101 #define BT_ERROR_I_O_ERROR "I/O error"
102 #define BT_ERROR_OPERATION_NOT_AVAILABLE "Operation currently not available"
103 #define BT_ERROR_OPERATION_NOT_ALLOWED "Operation not allowed"
104 #define BT_ERROR_OPERATION_NOT_SUPPORTED "Operation not supported"
105 #define BT_ERROR_INVALID_FILE_DESCRIPTOR "Invalid File Descriptor"
106
107 #define ret_if(expr) \
108         do { \
109                 if (expr) { \
110                         ERR("(%s) return", #expr); \
111                         return; \
112                 } \
113         } while (0)
114
115 typedef enum {
116         BT_HID_AGENT_ERROR_NONE,
117         BT_HID_AGENT_ERROR_INTERNAL,
118         BT_HID_AGENT_ERROR_NOT_AVAILABLE,
119         BT_HID_AGENT_ERROR_NOT_CONNECTED,
120         BT_HID_AGENT_ERROR_CONNECTION_FAILED,
121         BT_HID_AGENT_ERROR_BUSY,
122         BT_HID_AGENT_ERROR_INVALID_PARAM,
123         BT_HID_AGENT_ERROR_ALREADY_EXIST,
124         BT_HID_AGENT_ERROR_ALREADY_CONNECTED,
125         BT_HID_AGENT_ERROR_NO_MEMORY,
126         BT_HID_AGENT_ERROR_NO_DATA,
127         BT_HID_AGENT_ERROR_I_O_ERROR,
128         BT_HID_AGENT_ERROR_APPLICATION,
129         BT_HID_AGENT_ERROR_NOT_ALLOWED,
130         BT_HID_AGENT_ERROR_NOT_SUPPORTED,
131         BT_HID_AGENT_ERROR_INVALID_FILE_DESCRIPTOR,
132 } bt_hid_agent_error_t;
133
134 typedef enum {
135         BT_HID_STATE_UNAVAILABLE,
136         BT_HID_STATE_DISCONNECTED,
137         BT_HID_STATE_CONNECTING,
138         BT_HID_STATE_CONNECTED,
139         BT_HID_STATE_DISCONNECTING,
140 } bt_hid_state_t;
141
142 typedef struct {
143         guint32 fd;
144         char remote_addr[BT_ADDRESS_STRING_SIZE];
145         char *object_path;
146         GDBusMethodInvocation *context;
147         char *path;
148 } bt_hid_agent_info_t;
149
150 typedef struct {
151         unsigned char b[6];
152 } __attribute__((packed)) bdaddr_t;
153
154 /* Remote socket address */
155 struct sockaddr_remote {
156         sa_family_t     family;
157         bdaddr_t        remote_bdaddr;
158         uint8_t         channel;
159 };
160
161 bt_hid_agent_error_t _bt_hid_disconnect_profile(void);
162
163 #endif /* __DEF_BT_HID_AGENT_H_ */