summaryrefslogtreecommitdiff
path: root/include/bluetooth_private.h
blob: d83cd30c6766ea647c294e72adc527799f5249de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef __TIZEN_NETWORK_BLUETOOTH_PRIVATE_H__
#define __TIZEN_NETWORK_BLUETOOTH_PRIVATE_H__

#include <dlog.h>
#include <stdbool.h>
#include <system_info.h>
#include <bluetooth-api.h>
#include <bluetooth-audio-api.h>
#include <bluetooth-telephony-api.h>
#include <bluetooth-media-control.h>
#include <bluetooth-hid-api.h>
#include <bluetooth-ipsp-api.h>

#include "bluetooth.h"
#include "bluetooth_internal.h"

#ifdef __cplusplus
extern "C" {
#endif

#undef LOG_TAG
#define LOG_TAG "CAPI_NETWORK_BLUETOOTH"

#define BT_INFO(fmt, args...) SLOGI(fmt, ##args)
#define BT_DBG(fmt, args...) SLOGD(fmt, ##args)
#define BT_ERR(fmt, args...) SLOGE(fmt, ##args)

#define OPP_UUID "00001105-0000-1000-8000-00805f9b34fb"


/**
 * @internal
 * @brief Bluetooth callback.
 */
typedef enum {
	BT_EVENT_STATE_CHANGED = 0x00, /**< Adapter state is changed */
	BT_EVENT_LE_STATE_CHANGED, /**< Adapter le state is changed */
	BT_EVENT_NAME_CHANGED, /**< Adapter name is changed */
	BT_EVENT_VISIBILITY_MODE_CHANGED, /**< Adapter visibility mode is changed */
	BT_EVENT_VISIBILITY_DURATION_CHANGED, /**< Adapter visibility duration is changed */
	BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, /**< Device discovery state is changed */
	BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, /**< LE Device discovery state is changed */
	BT_EVENT_LE_SCAN_RESULT_UPDATED, /**< LE Scan result is updated */
	BT_EVENT_BOND_CREATED, /**< A bond is created */
	BT_EVENT_BOND_DESTROYED, /**< A bond is destroyed */
	BT_EVENT_AUTHORIZATION_CHANGED, /**< Authorization is changed */
	BT_EVENT_AUTHENTICATION_REQUEST, /**< Authentication events during pairing process*/
	BT_EVENT_SERVICE_SEARCHED, /**< Service search finish */
	BT_EVENT_DATA_RECEIVED, /**< Data is received */
	BT_EVENT_CONNECTION_STATE_CHANGED, /**< Connection state is changed */
	BT_EVENT_RFCOMM_CONNECTION_REQUESTED, /**< RFCOMM connection is requested */
	BT_EVENT_OPP_CONNECTION_REQUESTED, /**< OPP connection is requested */
	BT_EVENT_OPP_PUSH_REQUESTED, /**< OPP push is requested */
	BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS, /**< OPP transfer progress */
	BT_EVENT_OPP_SERVER_TRANSFER_FINISHED, /**< OPP transfer is completed */
	BT_EVENT_OPP_CLIENT_PUSH_RESPONSED, /**< OPP client connection is responsed */
	BT_EVENT_OPP_CLIENT_PUSH_PROGRESS, /**< OPP client push progress */
	BT_EVENT_OPP_CLIENT_PUSH_FINISHED, /**< OPP client push is finished */
	BT_EVENT_PAN_CONNECTION_STATE_CHANGED, /**< PAN connection change */
	BT_EVENT_NAP_CONNECTION_STATE_CHANGED, /**< NAP connection change */
	BT_EVENT_HDP_CONNECTED, /**< HDP connection change */
	BT_EVENT_HDP_DISCONNECTED, /**< HDP disconnection change */
	BT_EVENT_HDP_DATA_RECEIVED, /**< HDP Data receive Callabck */
	BT_EVENT_AUDIO_CONNECTION_STATUS, /**< Audio Connection change callback */
	BT_EVENT_AG_SCO_CONNECTION_STATUS, /**< Audio - AG SCO Connection state change callback */
	BT_EVENT_AG_CALL_HANDLING_EVENT, /**< Audio - AG call event callback */
	BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT, /**< Audio - AG 3-way call event callback */
	BT_EVENT_AG_DTMF_TRANSMITTED, /**< Audio - DTMF tone sending request */
	BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, /**< Audio Microphone change callback */
	BT_EVENT_AG_SPEAKER_GAIN_CHANGE, /**< Audio Speaker gain change callback */
	BT_EVENT_AG_VENDOR_CMD, /**< Audio - XSAT Vendor cmd */
	BT_EVENT_AVRCP_CONNECTION_STATUS, /**< AVRCP connection change callback */
	BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, /**< AVRCP equalizer state change callback */
	BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, /**< AVRCP repeat mode change callback */
	BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, /**< AVRCP equalizer mode change callback */
	BT_EVENT_AVRCP_SCAN_MODE_CHANGED, /**< AVRCP scan mode change callback */
	BT_EVENT_AVRCP_PLAY_STATUS_CHANGED, /**< AVRCP scan mode change callback */
	BT_EVENT_AVRCP_SONG_POSITION_CHANGED, /**< AVRCP scan mode change callback */
	BT_EVENT_AVRCP_TRACK_INFO_CHANGED, /**< AVRCP scan mode change callback */
	BT_EVENT_HID_CONNECTION_STATUS, /**< HID connection status callback */
	BT_EVENT_HID_DEVICE_CONNECTION_STATUS, /**< HID Device connection status callback */
	BT_EVENT_HID_DEVICE_DATA_RECEIVED, /**< HID Device Data received callback */
	BT_EVENT_DEVICE_CONNECTION_STATUS, /**< Device connection status callback */
	BT_EVENT_GATT_CONNECTION_STATUS, /** < GATT connection status callback */
	BT_EVENT_GATT_CLIENT_SERVICE_DISCOVERED, /** GATT services discovered callback */
	BT_EVENT_GATT_CLIENT_VALUE_CHANGED, /**< GATT characteristic value changed callback */
	BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC, /**< GATT characteristic value read callback */
	BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC, /**< GATT characteristic value write callback */
	BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR, /**< GATT descriptor value read callback */
	BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR, /**< GATT descriptor value write callback */
	BT_EVENT_GATT_SERVER_READ_REQUESTED, /**< GATT Characteristic/Descriptor Read Requested callback*/
#ifdef BT_ENABLE_LEGACY_GATT_CLIENT
	BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY, /**< GATT characteristic discovered callback */
	BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY, /**< GATT characteristic descriptor discovered callback */
	BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY, /**< GATT characteristic value changed callback */
	BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY, /**< GATT characteristic value read callback */
	BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY, /**< GATT characteristic value write callback */
#endif
	BT_EVENT_IPSP_INIT_STATE_CHANGED, /**< IPSP Init status changed callback */
	BT_EVENT_IPSP_CONNECTION_STATUS, /**< IPSP connection status callback */
	BT_EVENT_LE_DATA_LENGTH_CHANGED, /** LE data length changed callback */
	BT_EVENT_ADVERTISING_STATE_CHANGED, /**< Advertising state changed callback */
	BT_EVENT_MANUFACTURER_DATA_CHANGED, /**< Manufacturer data changed callback */
	BT_EVENT_CONNECTABLE_CHANGED_EVENT, /**< Adapter connectable changed callback */
	BT_EVENT_RSSI_ENABLED_EVENT, /**< RSSI Enabled callback */
	BT_EVENT_RSSI_ALERT_EVENT, /**< RSSI Alert callback */
	BT_EVENT_GET_RSSI_EVENT, /**< Get RSSI Strength callback */
#ifdef TIZEN_WEARABLE
	BT_EVENT_PBAP_CONNECTION_STATUS, /**< PBAP connection status callback */
	BT_EVENT_PBAP_PHONEBOOK_SIZE, /**< PBAP Phonebook Size status callback */
	BT_EVENT_PBAP_PHONEBOOK_PULL, /**< PBAP Phonebook Pull status callback */
	BT_EVENT_PBAP_VCARD_LIST, /**< PBAP vCard List status callback */
	BT_EVENT_PBAP_VCARD_PULL, /**< PBAP vCard Pull status callback */
	BT_EVENT_PBAP_PHONEBOOK_SEARCH, /**< PBAP Phonebook Search status callback */
	BT_EVENT_HF_SCO_CONNECTION_STATUS, /**< Audio - HF SCO Connection state change callback */
	BT_EVENT_HF_SPEAKER_GAIN_CHANGE, /**< Audio - HF Speaker gain change callback */
	BT_EVENT_HF_CALL_HANDLING_EVENT, /**< Audio - HF call event callback */
	BT_EVENT_HF_VENDOR_DEP_CMD_EVENT, /**< Audio - HF Vendor Command callback */
	BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT, /**< Audio - HF 3-way call event callback */
	BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT, /**< Audio - HF call status updated callback */
#endif
	BT_EVENT_MAX
} bt_event_e;

typedef enum {
	BT_GATT_ROLE_SERVER = 0x01,
	BT_GATT_ROLE_CLIENT = 0x02,
} bt_gatt_role_e;

#ifdef TIZEN_WEARABLE
/**
 * @internal
 */
typedef enum {
	BT_ADAPTER_LE_ADVERTISING_CONNECTABLE = 0x00, /**< Connectable undirected advertising (ADV_IND) */
	BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_HIGH = 0x01, /* @Deprecated since Tizen 2.4 */
	BT_ADAPTER_LE_ADVERTISING_SCANNABLE = 0x02, /**< Scannable undirected advertising (ADV_SCAN_IND) */
	BT_ADAPTER_LE_ADVERTISING_NON_CONNECTABLE = 0x03, /**< Non connectable undirected advertising (ADV_NONCOND_IND) */
	BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_LOW = 0x04, /* @Deprecated since Tizen 2.4 */
} bt_adapter_le_advertising_type_e;

/**
 * @internal
 */
typedef enum {
	BT_ADAPTER_LE_PACKET_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x02, /**<Incomplete list of 16 bit UUIDs */
	BT_ADAPTER_LE_PACKET_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x03, /**< Complete list of 16 bit UUIDs */
	BT_ADAPTER_LE_PACKET_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS = 0x06, /**< Incomplete list of 128 bit UUIDs */
	BT_ADAPTER_LE_PACKET_DATA_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS = 0x07, /**< Complete list of 128 bit UUID */
	BT_ADAPTER_LE_PACKET_DATA_LOCAL_NAME = 0x09, /**<local device name */
	BT_ADAPTER_LE_PACKET_DATA_TX_POWER_LEVEL = 0x0a, /**< TX-Power level*/
	BT_ADAPTER_LE_PACKET_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS = 0x14, /**< List of 16-bit Service Solicitation UUIDs*/
	BT_ADAPTER_LE_PACKET_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS = 0x15, /**< List of 128-bit Service Solicitation UUIDs*/
	BT_ADAPTER_LE_PACKET_DATA_SERVICE_DATA = 0x16, /**< Service data */
	BT_ADAPTER_LE_PACKET_DATA_APPEARANCE = 0x19, /**< Appearance*/
	BT_ADAPTER_LE_PACKET_DATA_MANUFACTURER_SPECIFIC_DATA = 0xff, /**< Manufacturer data */
} bt_adapter_le_packet_data_type_e;
#endif

/**
 * @internal
 */
typedef enum {
	BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x02, /**<Incomplete list of 16 bit UUIDs */
	BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x03, /**< Complete list of 16 bit UUIDs */
	BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS = 0x06, /**< Incomplete list of 128 bit UUIDs */
	BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS = 0x07, /**< Complete list of 128 bit UUID */
	BT_ADAPTER_LE_ADVERTISING_DATA_SHORT_LOCAL_NAME = 0x08, /**<Shortened local name */
	BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME = 0x09, /**<Complete local name */
	BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL = 0x0a, /**< TX-Power level*/
	BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS = 0x14, /**< List of 16-bit Service Solicitation UUIDs*/
	BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS = 0x15, /**< List of 128-bit Service Solicitation UUIDs*/
	BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA = 0x16, /**< Service data */
	BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE = 0x19, /**< Appearance*/
	BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA = 0xff, /**< Manufacturer data */
} bt_adapter_le_advertising_data_type_e;

/**
 * @internal
 */
typedef struct {
	bt_adapter_le_advertising_mode_e mode;
	bt_adapter_le_advertising_filter_policy_e filter_policy;
	bt_adapter_le_advertising_type_e type;
} bt_adapter_le_advertising_parameters_s;

typedef struct {
	int handle;

	bt_adapter_le_advertising_state_changed_cb cb;
	void *user_data;

	bt_adapter_le_advertising_parameters_s adv_params;

	unsigned int adv_data_len;
	char *adv_data;
	unsigned int adv_system_data_len;

	unsigned int scan_rsp_data_len;
	char *scan_rsp_data;
	unsigned int scan_rsp_system_data_len;
} bt_advertiser_s;

typedef struct {
	int slot_id;
	char *device_address;
	char *device_name;
	char *service_uuid;
	char *service_uuid_mask;
	char *service_solicitation_uuid;
	char *service_solicitation_uuid_mask;
	char *service_data_uuid;
	char *service_data;
	unsigned int service_data_len;
	char *service_data_mask;
	int manufacturer_id;
	char *manufacturer_data;
	unsigned int manufacturer_data_len;
	char *manufacturer_data_mask;
} bt_le_scan_filter_s;

/**
 * @internal
 */
typedef struct bt_event_sig_event_slot_s {
	const void *callback;
	void *user_data;
} bt_event_sig_event_slot_s;

typedef struct {
	GSList *services;
} bt_gatt_server_s;

typedef struct {
	GSList *services;
	char *remote_address;
	bool services_discovered;
} bt_gatt_client_s;

typedef struct {
	bt_gatt_type_e type;
	bt_gatt_role_e role;
	void *parent;
	char *path;
	char *uuid;
} bt_gatt_common_s;

typedef struct {
	bt_gatt_type_e type;
	bt_gatt_role_e role;
	void *parent;
	char *path;
	char *uuid;

	bool is_included_service;

	bt_gatt_service_type_e service_type;

	GSList *included_services;
	GSList *characteristics;
} bt_gatt_service_s;

typedef struct {
	bt_gatt_type_e type;
	bt_gatt_role_e role;
	void *parent;
	char *path;
	char *uuid;

	int permissions;
	int properties;
	bt_gatt_write_type_e write_type;

	GSList *descriptors;

	bt_gatt_client_characteristic_value_changed_cb value_changed_cb;
	void *value_changed_user_data;

	bt_gatt_server_write_value_requested_cb write_value_requested_cb;
	void *write_value_requested_user_data;

	bt_gatt_server_read_value_requested_cb read_requested_cb;
	void *read_requested_user_data;

	bt_gatt_server_notification_sent_cb notified_cb;
	void *notified_user_data;

	bt_gatt_server_characteristic_notification_state_changed_cb notification_changed_cb;
	void *notification_changed_user_data;

	int value_length;
	char *value;
} bt_gatt_characteristic_s;

typedef struct {
	bt_gatt_type_e type;
	bt_gatt_role_e role;
	void *parent;
	char *path;
	char *uuid;

	int permissions;

	bt_gatt_server_write_value_requested_cb write_value_requested_cb;
	void *write_value_requested_user_data;

	bt_gatt_server_read_value_requested_cb read_requested_cb;
	void *read_requested_user_data;

	int value_length;
	char *value;
} bt_gatt_descriptor_s;

typedef struct {
	bt_gatt_client_h client;
	bt_gatt_h gatt_handle;
	void *user_data;

	/*
	 * Temp callback. Once bluez's discover service issue is fixed,
	 * it will be removed
	 */
	bt_gatt_client_request_completed_cb cb;
} bt_gatt_client_cb_data_s;

typedef void (*_bt_gatt_client_value_changed_cb)(char *char_path,
		unsigned char *value, int value_length, void *user_data);

#define BT_CHECK_INPUT_PARAMETER(arg) \
	if (arg == NULL) { \
		LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, BT_ERROR_INVALID_PARAMETER); \
		return BT_ERROR_INVALID_PARAMETER; \
	}

#define BT_FEATURE_COMMON "tizen.org/feature/network.bluetooth"
#define BT_FEATURE_LE "tizen.org/feature/network.bluetooth.le"
#define BT_FEATURE_AUDIO_CALL "tizen.org/feature/network.bluetooth.audio.call"
#define BT_FEATURE_AUDIO_MEDIA "tizen.org/feature/network.bluetooth.audio.media"
#define BT_FEATURE_AUDIO_CONTROLLER "tizen.org/feature/network.bluetooth.audio.controller"
#define BT_FEATURE_HEALTH "tizen.org/feature/network.bluetooth.health"
#define BT_FEATURE_HID_HOST "tizen.org/feature/network.bluetooth.hid"
#define BT_FEATURE_HID_DEVICE "tizen.org/feature/network.bluetooth.hid_device"
#define BT_FEATURE_OPP "tizen.org/feature/network.bluetooth.opp"
#define BT_FEATURE_TETHERING "tizen.org/feature/network.tethering.bluetooth"
#define BT_FEATURE_PBAP_CLIENT "tizen.org/feature/network.bluetooth.phonebook.client"

#define BT_CHECK_SUPPORTED_FEATURE(feature_name) \
do	{ \
	bool is_supported = false; \
	if (!system_info_get_platform_bool(feature_name, &is_supported)) { \
		if (is_supported == false) { \
			LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \
			return BT_ERROR_NOT_SUPPORTED; \
		} \
	} else { \
		LOGE("[%s] Fail to get the system feature: [%s]", __FUNCTION__, feature_name); \
	} \
} while (0)

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
 * @brief Enumerations of the authentication event types.
 *
 */
typedef enum {
	BT_AUTH_KEYBOARD_PASSKEY_DISPLAY = 0, /**< PIN display event to user for entering PIN in keyboard */
	BT_AUTH_PIN_REQUEST,                  /**< Legacy PIN or PASSKEY request event */
	BT_AUTH_PASSKEY_CONFIRM_REQUEST,      /**< PASSKEY confirmation event to match PASSKEY in remote device */
} bt_authentication_type_info_e;

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_HID_DEVICE_MODULE
 * @brief The structure type containing the HID RC key event information.
 * @since_tizen 3.0
 *
 * @see bt_hid_device_send_rc_key_event()
 */
typedef struct {
        unsigned short key[3]; /**< The key value - currently pressed keys : Max 3 at once */
} bt_hid_rc_key_data_s;

/**
 * @internal
 * @brief Check the initialzating status
 */
int _bt_check_init_status(void);

#define BT_CHECK_INIT_STATUS() \
	if (_bt_check_init_status() == BT_ERROR_NOT_INITIALIZED) { \
		LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \
		return BT_ERROR_NOT_INITIALIZED; \
	}

#define BT_CHECK_ADAPTER_STATUS() \
	if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) { \
		LOGE("[%s] BT_ERROR_NOT_ENABLED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_ENABLED); \
		return BT_ERROR_NOT_ENABLED; \
	}

/**
 * @internal
 * @brief Initialize Bluetooth LE adapter
 */
int _bt_le_adapter_init(void);

/**
 * @internal
 * @brief Deinitialize Bluetooth LE adapter
 */
int _bt_le_adapter_deinit(void);

/**
 * @internal
 * @brief Set the event callback.
 */
void _bt_set_cb(int events, void *callback, void *user_data);

/**
 * @internal
 * @brief Unset the event callback.
 */
void _bt_unset_cb(int events);

/**
 * @internal
 * @brief Check if the event callback exist or not.
 */
bool _bt_check_cb(int events);

/**
 * @internal
 * @brief Convert Bluetooth F/W error codes to capi Bluetooth error codes.
 */
int _bt_get_error_code(int origin_error);


/**
 * @internal
 * @brief Convert Bluetooth F/W bluetooth_device_info_t to capi bt_device_info_s.
 */
int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_t *source_dev);


/**
 * @internal
 * @brief Free bt_device_info_s.
 */
void _bt_free_bt_device_info_s(bt_device_info_s *device_info);

/**
 * @internal
 * @brief Convert Bluetooth F/W bluetooth_device_address_t to string.
 */
int _bt_convert_address_to_string(char **addr_str, bluetooth_device_address_t *addr_hex);


/**
 * @internal
 * @brief Convert string to Bluetooth F/W bluetooth_device_address_t.
 */
void _bt_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str);


/**
 * @internal
 * @brief Convert error code to string.
 */
char *_bt_convert_error_to_string(int error);

/**
 * @internal
 * @brief Convert the visibility mode
 */
bt_adapter_visibility_mode_e _bt_get_bt_visibility_mode_e(bluetooth_discoverable_mode_t mode);

/**
 * @internal
 * @brief Since the Audio call back and event proxy call backs have different prototype it is wrapper function.
 */
void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_data);

#ifdef TIZEN_WEARABLE
/**
 * @internal
 * @brief Since the HF call back and event proxy call backs have different prototype it is wrapper function.
 */
void _bt_hf_event_proxy(int event, bt_hf_event_param_t *param, void *user_data);
#endif

/**
 * @internal
 * @brief Since the Telephony call back and event proxy call backs have different prototype it is wrapper function.
 */
void _bt_telephony_event_proxy(int event, telephony_event_param_t *param, void *user_data);

/**
 * @internal
 * @brief Since the AVRCP call back and event proxy call backs have different prototype it is wrapper function.
 */
void _bt_avrcp_event_proxy(int event, media_event_param_t *param, void *user_data);

/**
 * @internal
 * @brief Since the HID call back and event proxy call backs have different prototype it is wrapper function.
 */
void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data);

void _bt_adapter_le_invoke_advertising_state_cb(int handle, int result, bt_adapter_le_advertising_state_e adv_state);

#ifdef BT_ENABLE_LEGACY_GATT_CLIENT
bool _bt_gatt_is_legacy_client_mode(void);
#endif

const GSList *_bt_gatt_get_client_list(void);

const GSList *_bt_gatt_get_server_list(void);

int _bt_gatt_client_update_all(bt_gatt_client_h client);

/**
 * @internal
 * @brief IPSP Init state changed callback
 */
typedef void (*bt_le_ipsp_init_state_changed_cb)
		(int result, bool ipsp_initialized, void *user_data);

/**
 * @internal
 * @brief Initialize Bluetooth LE IPSP service and set the callback
 */
int _bt_le_ipsp_initialize(bt_le_ipsp_init_state_changed_cb callback, void *user_data);

/**
 * @internal
 * @brief De-Initialize Bluetooth LE IPSP service and unset the callback
 */
int _bt_le_ipsp_deinitialize(void);

/**
 * @internal
 * @brief Connect to a IPSP service over LE to remote device.
 */
int _bt_le_ipsp_connect(const char *address);

/**
 * @internal
 * @brief Disconnect to a IPSP service over LE to remote device.
 */
int _bt_le_ipsp_disconnect(const char *address);

/**
* @internal
* @brief Check whether IPSP service is initialized
*/
int _bt_le_ipsp_is_initialized(void);

/**
 * @internal
 * @brief IPSP Connection state changed callback
 */
typedef void (*_bt_le_ipsp_connection_state_changed_cb)
		(int result, bool connected, const char *remote_address, void *user_data);
/**
 * @internal
 * @brief Set IPSP connection state event change callback.
 */
int _bt_le_ipsp_set_connection_state_changed_cb(_bt_le_ipsp_connection_state_changed_cb callback,
						void *user_data);

/**
 * @internal
 * @brief Unset IPSP connection state event change callback.
 */
int _bt_le_ipsp_unset_connection_state_changed_cb(void);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_LE_MODULE
 * @brief Reads the maximum data length of LE packets supported by the controller.
 * @since_tizen 3.0
 *
 * @retval #BT_ERROR_NONE  Successful
 * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
 * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
 *
 * @see bt_initialize
 */
int bt_adapter_le_read_maximum_data_length(
		int *max_tx_octets, int *max_tx_time,
		int *max_rx_octets, int *max_rx_time);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_LE_MODULE
 * @brief Writes the Host suggested default data length of LE packets to the controller.
 * @since_tizen 3.0
 *
 * @retval #BT_ERROR_NONE  Successful
 * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
 * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
 *
 * @see bt_initialize
 */
int bt_adapter_le_write_host_suggested_default_data_length(
	const unsigned int def_tx_Octets,  const unsigned int def_tx_Time);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_LE_MODULE
 * @brief Reads the Host suggested data length values of LE packets from the controller.
 * @since_tizen 3.0
 *
 * @retval #BT_ERROR_NONE  Successful
 * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
 * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
 *
 * @see bt_initialize
 */
int bt_adapter_le_read_suggested_default_data_length(
	unsigned int *def_tx_Octets,  unsigned int *def_tx_Time);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_LE_MODULE
 * @brief Allows the host to suggest to controller, the data length parameters to be used
 * for a given LE Connection.
 * @since_tizen 3.0
 *
 * @retval #BT_ERROR_NONE  Successful
 * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
 * @retval #BT_ERROR_NOT_SUPPORTED  Not supported
 *
 * @see bt_initialize
 */
int bt_device_le_set_data_length(const char *remote_address,
	unsigned int max_tx_Octets,  unsigned int max_tx_Time);

/**
 * @internal
 * @brief LE data length changed callback
 */
typedef void (*_bt_le_set_data_length_changed_cb)
		(int result, const char *remote_address, int max_tx_octets,
		int max_tx_time, int max_rx_octets, int max_rx_time, void *user_data);

int bt_device_le_set_data_length_change_cb(
	_bt_le_set_data_length_changed_cb callback, void *user_data);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
 * @brief Called when remote device requests authentication.
 * @param[in] result
 * @param[in] auth_type
 *             typedef enum {
 *              BT_AUTH_KEYBOARD_PASSKEY_DISPLAY = 0, : PIN display event to user for entering PIN in keyboard
 *              BT_AUTH_PIN_REQUEST,                  : Legacy PIN or PASSKEY request event
 *              BT_AUTH_PASSKEY_CONFIRM_REQUEST,      : PASSKEY confirmation event to match PASSKEY in remote device
 *             } bt_authentication_type_info_e;
 * @param[in] device_name  Name of the remote device
 * @param[in] remote_addr  Remote BD address
 * @param[in] pass_key     PASSKEY string
 *            PASSKEY string is valid only if authentication types are following
 *             a/ BT_AUTH_KEYBOARD_PASSKEY_DISPLAY
 *             b/ BT_AUTH_PASSKEY_CONFIRM_REQUEST
 *            pass_key string will be invalid if authentication event is of type BT_AUTH_PIN_REQUEST
 *            as this event indicates that user MUST enter PIN or PASSKEY and perform authentication.
 *
 *            Upon receiving BT_AUTH_KEYBOARD_PASSKEY_DISPLAY event, user should enter PASSKEY in keyboard
 *            Application can also call bt_device_cancel_bonding() Upon receiving BT_AUTH_KEYBOARD_PASSKEY_DISPLAY
 *            event which will fail the on-going pairing with remote device.
 * @param[in] user_data The user data passed from the callback registration function
 * @see bt_adapter_set_authentication_req_cb()
 */
typedef void (*bt_adapter_authentication_req_cb)(int result, bt_authentication_type_info_e auth_type,
						char *device_name, char *remote_addr,
						char *pass_key, void *user_data);

int bt_adapter_set_authentication_req_cb(bt_adapter_authentication_req_cb callback, void *user_data);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
 * @brief Unregisters a callback function that will be invoked when remote device requests authentication.
 * @return 0 on success, otherwise a negative error value.
 * @retval #BT_ERROR_NONE Successful
 * @retval #BT_ERROR_NOT_INITIALIZED Not initialized
 * @pre The Bluetooth service must be initialized by bt_initialize().
 * @see bt_initialize()
 * @see bt_adapter_set_authentication_req_cb()
 */
int bt_adapter_unset_authentication_req_cb(void);

/**
 * @ingroup  CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
 * @brief  API to reply with PIN or PASSKEY with authentication type - TRUE or FALSE.
 * @remarks  This function can be called by application when remote device requests PIN or PASSKEY from
 *           local adapter.
 * @param[in]  passkey  The passkey to be provided by application when remote devices requests for it.
 * @param[in]  authentication_reply This indicates whether application wants to accept or cancel the on-going pairing
 * @pre  This function can only be called when application receieves authentication event (BT_AUTH_PIN_REQUEST)
 *       from remote device.
 * @see  bt_adapter_set_authentication_req_cb()
 */
int bt_passkey_reply(char *passkey, bool authentication_reply);

/**
 * @ingroup  CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE
 * @brief  API to reply to the PASSKEY confirmation for on-going pairing with remote device.
 * @remarks  This function can be called by application, when local adapter wants PASSKEY confirmation from user.
 * @param[in]  confirmation_reply This indicates whether application wants to accepts or cancels the on-going pairing
 *             confirmation_reply : TRUE will indicate that Application has confirmed the PASSKEY
 *             confirmation_reply : FALSE will indicate that Application has failed to confirm the PASSKEY. In this situation
 *             the pairing will be failed.
 * @pre  This function can only be called when application receives authentication event (BT_AUTH_PASSKEY_CONFIRM_REQUEST)
 *       from remote device.
 * @see  bt_adapter_set_authentication_req_cb()
 */
int bt_passkey_confirmation_reply(bool confirmation_reply);

/**
 * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE
 * @brief Sends the RC key event data.
 * @since_tizen 3.0
 * @privlevel platform
 * @privilege %http://tizen.org/privilege/bluetooth.admin
 *
 * @param[in] remote_address device address of remote device.
 * @param[in] key_data  key data the need to be passed to remote device
 * @return 0 on success, otherwise a negative error value.
 * @retval #BT_ERROR_NONE  Successful
 * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
 * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
 * @retval #BT_ERROR_OPERATION_FAILED  Operation failed
 * @retval #BT_ERROR_PERMISSION_DENIED  Permission denied
 *
 * @pre The HID connection must be established.
 * @see bt_hid_device_connection_state_changed_cb()
 */
int bt_hid_device_send_rc_key_event(const char *remote_address,
				const bt_hid_rc_key_data_s *key_data);

#ifdef __cplusplus
}
#endif

#endif /* __TIZEN_NETWORK_BLUETOOTH_PRIVATE_H__ */