2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/types.h>
28 #include "bluetooth-api.h"
32 #endif /* __cplusplus */
35 #define LOG_TAG "BLUETOOTH_FRWK_API"
38 #define BT_EXPORT_API __attribute__((visibility("default")))
41 #define LOG_COLOR_RESET "\033[0m"
42 #define LOG_COLOR_RED "\033[31m"
43 #define LOG_COLOR_YELLOW "\033[33m"
44 #define LOG_COLOR_GREEN "\033[32m"
45 #define LOG_COLOR_BLUE "\033[36m"
46 #define LOG_COLOR_PURPLE "\033[35m"
48 #define BT_DBG(fmt, args...) \
50 #define BT_INFO(fmt, args...) \
52 #define BT_ERR(fmt, args...) \
55 #define BT_DBG_UUID(uuids, len, i) \
56 BT_DBG("***UUIDs***"); \
57 for (i = 0; i < len; i++) { \
58 BT_DBG("%s", uuids[i]); \
61 #define BT_INFO_C(fmt, arg...) \
62 SLOGI_IF(TRUE, LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg)
63 #define BT_ERR_C(fmt, arg...) \
64 SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
66 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
67 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
69 //#define FUNCTION_TRACE
71 #define FN_START BT_DBG("[ENTER FUNC]")
72 #define FN_END BT_DBG("[EXIT FUNC]")
78 #define ret_if(expr) \
81 BT_ERR("(%s) return", #expr); \
86 #define retv_if(expr, val) \
89 BT_ERR("(%s) return", #expr); \
94 #define BT_INIT_PARAMS() \
95 GArray *in_param1 = NULL; \
96 GArray *in_param2 = NULL; \
97 GArray *in_param3 = NULL; \
98 GArray *in_param4 = NULL; \
99 GArray *out_param = NULL;
101 #define BT_FREE_PARAMS(IP1, IP2, IP3, IP4, OP) \
104 g_array_free(IP1, TRUE); \
106 g_array_free(IP2, TRUE); \
108 g_array_free(IP3, TRUE); \
110 g_array_free(IP4, TRUE); \
112 g_array_free(OP, TRUE); \
115 #define BT_ALLOC_PARAMS(IP1, IP2, IP3, IP4, OP) \
117 IP1 = g_array_new(TRUE, TRUE, sizeof(gchar)); \
118 IP2 = g_array_new(TRUE, TRUE, sizeof(gchar)); \
119 IP3 = g_array_new(TRUE, TRUE, sizeof(gchar)); \
120 IP4 = g_array_new(TRUE, TRUE, sizeof(gchar)); \
123 #define BT_INIT_AGENT_PARAMS() \
124 GArray *in_param = NULL; \
125 GArray *out_param = NULL;
127 #define BT_FREE_AGENT_PARAMS(IP, OP) \
130 g_array_free(IP, TRUE); \
132 g_array_free(OP, TRUE); \
135 #define BT_ALLOC_AGENT_PARAMS(IP, OP) \
137 IP = g_array_new(FALSE, FALSE, sizeof(gchar)); \
140 #define BT_CHECK_PARAMETER(arg, func) \
143 BT_ERR("%s is NULL", #arg); \
144 func BLUETOOTH_ERROR_INVALID_PARAM; \
148 #define BT_CHECK_ENABLED(func) \
150 if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) { \
151 BT_ERR("BT BREDR is not enabled"); \
152 func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
156 #define BT_CHECK_ENABLED_LE(func) \
158 if (bluetooth_check_adapter_le() == BLUETOOTH_ADAPTER_LE_DISABLED) { \
159 BT_ERR("BT LE is not enabled"); \
160 func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
164 #define BT_CHECK_ENABLED_ANY(func) \
166 if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED && \
167 bluetooth_check_adapter_le() == BLUETOOTH_ADAPTER_LE_DISABLED) { \
168 BT_ERR("BT is not enabled"); \
169 func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
173 #define BT_CHECK_ENABLED_INTERNAL(func) \
175 if (_bt_check_enabled_internal() == FALSE) { \
176 BT_ERR("BT BREDR is not enabled"); \
177 func BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; \
181 #define BT_ADDRESS_LENGTH_MAX 6
182 #define BT_ADDRESS_STRING_SIZE 18
183 #define BT_ADAPTER_OBJECT_PATH_MAX 50
184 #define BT_RFCOMM_BUFFER_LEN 1024
186 #define BT_ACCESS_DENIED_MSG "Rejected send message"
188 #define BT_EVENT_FREEDESKTOP "org.freedesktop.DBus"
189 #define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
191 #define BT_EVENT_MANAGER "org.bluez.Manager"
192 #define BT_MANAGER_PATH "/"
195 #define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
196 #define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
197 #define BT_DEVICE_INTERFACE "org.bluez.Device1"
198 #define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
201 #define BT_SERIAL_INTERFACE "org.bluez.Serial"
203 #define BT_BLUEZ_NAME "org.bluez"
204 #define BT_DBUS_NAME "org.projectx.bt"
205 #define BT_SERVICE_PATH "/org/projectx/bt_service"
207 #define BT_AGENT_NAME "org.bluez.frwk_agent"
208 #define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
210 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
213 #define BT_MAX_USER_INFO 5
214 #define RFKILL_EVENT_SIZE 8
215 #define RFKILL_NODE "/dev/rfkill"
220 RFKILL_TYPE_BLUETOOTH,
243 } bt_user_info_type_t;
250 void _bt_set_user_data(int type, void *callback, void *user_data);
252 void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
254 bt_user_info_t* _bt_get_user_data(int type);
256 void _bt_common_event_cb(int event, int result, void *param,
257 void *callback, void *user_data);
259 void _bt_input_event_cb(int event, int result, void *param,
260 void *callback, void *user_data);
262 void _bt_headset_event_cb(int event, int result, void *param,
263 void *callback, void *user_data);
265 void _bt_a2dp_source_event_cb(int event, int result, void *param,
266 void *callback, void *user_data);
268 void _bt_hf_event_cb(int event, int result, void *param,
269 void *callback, void *user_data);
271 void _bt_avrcp_event_cb(int event, int result, void *param,
272 void *callback, void *user_data);
274 void _bt_opp_client_event_cb(int event, int result, void *param,
275 void *callback, void *user_data);
277 void _bt_map_client_event_cb(int event, int result, void *param,
278 void *callback, void *user_data);
280 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
283 void _bt_convert_addr_string_to_type(unsigned char *addr,
284 const char *address);
286 void _bt_convert_addr_string_to_secure_string(char *addr,
287 const char *address);
289 void _bt_convert_addr_type_to_string(char *address,
290 unsigned char *addr);
292 const char *_bt_convert_error_to_string(int error);
294 const char *_bt_convert_service_function_to_string(int function);
296 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
298 gboolean _bt_utf8_validate(char *name);
303 gboolean authentication;
304 gboolean authorization;
309 } bt_register_profile_info_t;
311 int _bt_get_adapter_path(GDBusConnection *conn, char *path);
312 char *_bt_get_device_object_path(char *address);
313 int _bt_connect_profile(char *address, char *uuid, void *cb,
315 int _bt_disconnect_profile(char *address, char *uuid, void *cb,
318 int _bt_cancel_discovers(char *address);
319 int _bt_discover_services(char *address, char *uuid, void *cb,
321 int _bt_discover_service_uuids(char *address, char *remote_uuid);
322 int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class);
324 void _bt_set_le_scan_status(gboolean mode);
326 int _bt_register_profile(bt_register_profile_info_t *info, gboolean use_default_rfcomm);
327 int _bt_register_profile_platform(bt_register_profile_info_t *info, gboolean use_default_rfcomm);
328 int _bt_register_profile_ex(bt_register_profile_info_t *info, gboolean use_default_rfcomm, const char *name, const char *path);
330 void _bt_unregister_profile(char *path);
331 GDBusNodeInfo * _bt_get_gdbus_node(const gchar *xml_data);
332 GDBusNodeInfo * _bt_get_gdbus_node_ex(const gchar *xml_data, const char *bus_name);
333 int __rfcomm_assign_id(void);
334 void __rfcomm_delete_id(int id);
335 void _bt_unregister_gdbus(int object_id);
336 typedef int (*bt_new_connection_cb) (const char *path, int fd,
337 bluetooth_device_address_t *address);
338 int _bt_register_new_conn(const char *path, bt_new_connection_cb cb);
339 int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_connection_cb cb);
340 void _bt_swap_addr(unsigned char *dst, const unsigned char *src);
342 GDBusConnection *_bt_init_system_gdbus_conn(void);
344 GDBusConnection *g_bus_get_private_conn(void);
346 //GDBusConnection *_bt_get_system_gconn(void);
348 //GDBusConnection *_bt_get_system_conn(void);
350 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd);
351 int _bt_unregister_osp_server_in_agent(int type, char *uuid);
354 int _bt_check_privilege(int service_type, int service_function);
356 GDBusConnection *_bt_gdbus_init_system_gconn(void);
358 GDBusConnection *_bt_gdbus_get_system_gconn(void);
360 GVariant *_bt_get_managed_objects(void);
362 gboolean _bt_check_enabled_internal(void);
364 void _bt_set_adapter_internal_status(gboolean enabled);
366 int _bt_get_uuid_specification_name(const char *uuid, char **name);
368 void _bt_convert_device_path_to_address(const char *device_path,
369 char *device_address);
371 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
372 void _bt_rfcomm_server_free_all(void);
374 void _bt_rfcomm_server_disconnect_all(void);
376 void _bt_rfcomm_client_disconnect_all(void);
378 gboolean _check_uuid_path(char *path, char *uuid);
381 void _bluetooth_hid_free_hid_info(void);
386 #endif /* __cplusplus */
387 #endif /*_BT_COMMON_H_*/