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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
|
/*
* 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.
*/
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <dlog.h>
#include <stdio.h>
#include <stdbool.h>
#include <bluetooth-api.h>
#include "bluetooth.h"
#include "bluetooth_private.h"
#include "bluetooth-media-control.h"
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_BLUETOOTH"
static bool is_initialized = false;
static bt_event_sig_event_slot_s bt_event_slot_container[] = {
{BT_EVENT_STATE_CHANGED, NULL, NULL},
{BT_EVENT_NAME_CHANGED, NULL, NULL},
{BT_EVENT_VISIBILITY_MODE_CHANGED, NULL, NULL},
{BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, NULL, NULL},
{BT_EVENT_BOND_CREATED, NULL, NULL},
{BT_EVENT_BOND_DESTROYED, NULL, NULL},
{BT_EVENT_AUTHORIZATION_CHANGED, NULL, NULL},
{BT_EVENT_SERVICE_SEARCHED, NULL, NULL},
{BT_EVENT_DATA_RECEIVED, NULL, NULL},
{BT_EVENT_CONNECTION_STATE_CHANGED, NULL, NULL},
{BT_EVENT_RFCOMM_CONNECTION_REQUESTED, NULL, NULL},
{BT_EVENT_OPP_CONNECTION_REQUESTED, NULL, NULL},
{BT_EVENT_OPP_PUSH_REQUESTED, NULL, NULL},
{BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS, NULL, NULL},
{BT_EVENT_OPP_SERVER_TRANSFER_FINISHED, NULL, NULL},
{BT_EVENT_OPP_CLIENT_PUSH_RESPONSED, NULL, NULL},
{BT_EVENT_OPP_CLIENT_PUSH_PROGRESS, NULL, NULL},
{BT_EVENT_OPP_CLIENT_PUSH_FINISHED, NULL, NULL},
{BT_EVENT_PAN_CONNECTION_STATE_CHANGED, NULL, NULL},
{BT_EVENT_NAP_CONNECTION_STATE_CHANGED, NULL, NULL},
{BT_EVENT_HDP_CONNECTED, NULL, NULL},
{BT_EVENT_HDP_DISCONNECTED, NULL, NULL},
{BT_EVENT_HDP_DATA_RECIEVED, NULL, NULL},
{BT_EVENT_AUDIO_CONNECTION_STATUS, NULL, NULL},
{BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, NULL, NULL},
{BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, NULL, NULL},
{BT_EVENT_AVRCP_CONNECTION_STATUS, NULL, NULL},
{BT_EVENT_HID_CONNECTION_STATUS, NULL, NULL}
};
/*
* Internal Functions
*/
static void __bt_event_proxy(int event, bluetooth_event_param_t * param, void *user_data);
static int __bt_get_cb_index(int event);
static void __bt_convert_lower_to_upper(char *origin);
static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_info_t *source);
static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info);
static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info);
static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info);
/*
* Public Functions
*/
int bt_initialize(void)
{
if (is_initialized != true) {
if (bluetooth_register_callback(&__bt_event_proxy, NULL) != BLUETOOTH_ERROR_NONE) {
LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, BT_ERROR_OPERATION_FAILED);
return BT_ERROR_OPERATION_FAILED;
}
is_initialized = true;
}
return BT_ERROR_NONE;
}
int bt_deinitialize(void)
{
BT_CHECK_INIT_STATUS();
if (bluetooth_unregister_callback() != BLUETOOTH_ERROR_NONE) {
LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, BT_ERROR_OPERATION_FAILED);
return BT_ERROR_OPERATION_FAILED;
}
is_initialized = false;
return BT_ERROR_NONE;
}
/*
* Common Functions
*/
int _bt_check_init_status(void)
{
if (is_initialized != true)
{
LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED);
return BT_ERROR_NOT_INITIALIZED;
}
return BT_ERROR_NONE;
}
void _bt_set_cb(int events, void *callback, void *user_data)
{
bt_event_slot_container[events].callback = callback;
bt_event_slot_container[events].user_data = user_data;
}
void _bt_unset_cb(int events)
{
if (bt_event_slot_container[events].callback != NULL) {
bt_event_slot_container[events].callback = NULL;
bt_event_slot_container[events].user_data = NULL;
}
}
bool _bt_check_cb(int events)
{
return (bt_event_slot_container[events].callback != NULL) ? true : false;
}
int _bt_get_error_code(int origin_error)
{
switch (origin_error) {
case BLUETOOTH_ERROR_NONE:
return BT_ERROR_NONE;
case BLUETOOTH_ERROR_INVALID_DATA:
case BLUETOOTH_ERROR_INVALID_PARAM:
case BLUETOOTH_ERROR_NOT_CONNECTED:
case BLUETOOTH_ERROR_NOT_SUPPORT:
return BT_ERROR_INVALID_PARAMETER;
case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
case BLUETOOTH_ERROR_OUT_OF_MEMORY:
return BT_ERROR_OUT_OF_MEMORY;
case BLUETOOTH_ERROR_TIMEOUT:
return BT_ERROR_TIMED_OUT;
case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
return BT_ERROR_NOT_ENABLED;
case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
return BT_ERROR_ALREADY_DONE;
case BLUETOOTH_ERROR_NOT_PAIRED:
return BT_ERROR_REMOTE_DEVICE_NOT_BONDED;
case BLUETOOTH_ERROR_NOT_IN_OPERATION:
return BT_ERROR_NOT_IN_PROGRESS;
case BLUETOOTH_ERROR_IN_PROGRESS:
return BT_ERROR_NOW_IN_PROGRESS;
case BLUETOOTH_ERROR_DEVICE_BUSY:
return BT_ERROR_RESOURCE_BUSY;
case BLUETOOTH_ERROR_CANCEL:
case BLUETOOTH_ERROR_CANCEL_BY_USER:
return BT_ERROR_CANCELLED;
case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
return BT_ERROR_AUTH_FAILED;
case BLUETOOTH_ERROR_HOST_DOWN:
return BT_ERROR_REMOTE_DEVICE_NOT_FOUND;
case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
return BT_ERROR_SERVICE_SEARCH_FAILED;
case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
case BLUETOOTH_ERROR_PARING_FAILED:
case BLUETOOTH_ERROR_MAX_CONNECTION:
case BLUETOOTH_ERROR_ALREADY_CONNECT:
case BLUETOOTH_ERROR_NO_RESOURCES:
case BLUETOOTH_ERROR_REGISTRATION_FAILED:
case BLUETOOTH_ERROR_CONNECTION_BUSY:
case BLUETOOTH_ERROR_MAX_CLIENT:
case BLUETOOTH_ERROR_INVALID_CALLBACK:
case BLUETOOTH_ERROR_NOT_FOUND:
case BLUETOOTH_ERROR_INTERNAL:
case BLUETOOTH_ERROR_CONNECTION_ERROR:
case BLUETOOTH_ERROR_ACCESS_DENIED:
default:
return BT_ERROR_OPERATION_FAILED;
}
}
int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_t *source_dev)
{
int i = 0;
BT_CHECK_INPUT_PARAMETER(source_dev);
*dest_dev = (bt_device_info_s *)malloc(sizeof(bt_device_info_s));
if (*dest_dev == NULL) {
return BT_ERROR_OUT_OF_MEMORY;
}
if (strlen(source_dev->device_name.name) > 0) {
(*dest_dev)->remote_name = strdup(source_dev->device_name.name);
} else {
(*dest_dev)->remote_name = NULL;
}
_bt_convert_address_to_string(&((*dest_dev)->remote_address), &(source_dev->device_address));
(*dest_dev)->bt_class.major_device_class = source_dev->device_class.major_class;
(*dest_dev)->bt_class.minor_device_class = source_dev->device_class.minor_class;
(*dest_dev)->bt_class.major_service_class_mask = source_dev->device_class.service_class;
if (source_dev->service_index > 0) {
(*dest_dev)->service_uuid = (char **)malloc(sizeof(char *) * source_dev->service_index);
if ((*dest_dev)->service_uuid != NULL) {
for (i = 0; i < source_dev->service_index; i++) {
(*dest_dev)->service_uuid[i] = strdup(source_dev->uuids[i]);
if ((*dest_dev)->service_uuid[i] != NULL) {
__bt_convert_lower_to_upper((*dest_dev)->service_uuid[i]);
}
}
}
} else {
(*dest_dev)->service_uuid = NULL;
}
(*dest_dev)->service_count = source_dev->service_index;
(*dest_dev)->is_bonded = (bool)source_dev->paired;
(*dest_dev)->is_connected = (bool)source_dev->connected;
(*dest_dev)->is_authorized = (bool)source_dev->trust;
return BT_ERROR_NONE;
}
void _bt_free_bt_device_info_s(bt_device_info_s *device_info)
{
int i = 0;
if (device_info == NULL)
return;
if (device_info->remote_name != NULL)
free(device_info->remote_name);
if (device_info->remote_address != NULL)
free(device_info->remote_address);
if (device_info->service_uuid != NULL) {
for (i = 0; i < device_info->service_count; i++) {
if (device_info->service_uuid[i] != NULL)
free(device_info->service_uuid[i]);
}
free(device_info->service_uuid);
}
free(device_info);
device_info = NULL;
}
int _bt_convert_address_to_string(char **addr_str, bluetooth_device_address_t *addr_hex)
{
char address[18] = { 0, };
snprintf(address, 18, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", addr_hex->addr[0], addr_hex->addr[1], addr_hex->addr[2], addr_hex->addr[3], addr_hex->addr[4], addr_hex->addr[5]);
*addr_str = strdup(address);
if (*addr_str != NULL) {
return BT_ERROR_NONE;
} else {
return BT_ERROR_OUT_OF_MEMORY;
}
}
void _bt_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str)
{
int i = 0;
unsigned int addr[BLUETOOTH_ADDRESS_LENGTH] = { 0, };
i = sscanf(addr_str, "%X:%X:%X:%X:%X:%X", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]);
if (i != BLUETOOTH_ADDRESS_LENGTH) {
LOGI("[%s] Invalid format string - %s", __FUNCTION__, addr_str);
}
for (i = 0; i < BLUETOOTH_ADDRESS_LENGTH; i++) {
addr_hex->addr[i] = (unsigned char)addr[i];
}
}
char *_bt_convert_error_to_string(int error)
{
switch (error) {
case BT_ERROR_CANCELLED:
return "CANCELLED";
case BT_ERROR_INVALID_PARAMETER:
return "INVALID_PARAMETER";
case BT_ERROR_OUT_OF_MEMORY:
return "OUT_OF_MEMORY";
case BT_ERROR_RESOURCE_BUSY:
return "RESOURCE_BUSY";
case BT_ERROR_TIMED_OUT:
return "TIMED_OUT";
case BT_ERROR_NOW_IN_PROGRESS:
return "NOW_IN_PROGRESS";
case BT_ERROR_NOT_INITIALIZED:
return "NOT_INITIALIZED";
case BT_ERROR_NOT_ENABLED:
return "DEVICE_NOT_ENABLED";
case BT_ERROR_ALREADY_DONE:
return "ALREADY_DONE";
case BT_ERROR_OPERATION_FAILED:
return "OPERATION_FAILED";
case BT_ERROR_NOT_IN_PROGRESS:
return "NOT_IN_PROGRESS";
case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
return "REMOTE_DEVICE_NOT_BONDED";
case BT_ERROR_AUTH_REJECTED:
return "AUTH_REJECTED";
case BT_ERROR_AUTH_FAILED:
return "AUTH_FAILED";
case BT_ERROR_REMOTE_DEVICE_NOT_FOUND:
return "REMOTE_DEVICE_NOT_FOUND";
case BT_ERROR_SERVICE_SEARCH_FAILED:
return "SERVICE_SEARCH_FAILED";
default:
return "UNKNOWN";
}
}
bt_adapter_visibility_mode_e _bt_get_bt_visibility_mode_e(bluetooth_discoverable_mode_t mode)
{
switch (mode) {
case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE:
return BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE;
case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE:
return BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE;
default:
return BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
}
}
/*
* Internal Functions
*/
static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_info_t *source)
{
int i = 0;
*dest = (bt_device_sdp_info_s *)malloc(sizeof(bt_device_sdp_info_s));
if (*dest == NULL) {
return BT_ERROR_OUT_OF_MEMORY;
}
if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) {
__bt_free_bt_device_sdp_info_s(*dest);
return BT_ERROR_OUT_OF_MEMORY;
}
if (source->service_index > 0) {
(*dest)->service_uuid = (char **)malloc(sizeof(char *) * source->service_index);
if ((*dest)->service_uuid == NULL) {
__bt_free_bt_device_sdp_info_s(*dest);
return BT_ERROR_OUT_OF_MEMORY;
}
for (i = 0; i < source->service_index; i++) {
(*dest)->service_uuid[i] = strdup(source->uuids[i]);
if ((*dest)->service_uuid[i] == NULL) {
__bt_free_bt_device_sdp_info_s(*dest);
return BT_ERROR_OUT_OF_MEMORY;
}
__bt_convert_lower_to_upper((*dest)->service_uuid[i]);
}
} else {
(*dest)->service_uuid = NULL;
}
(*dest)->service_count = source->service_index;
return BT_ERROR_NONE;
}
static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info)
{
int i = 0;
if (sdp_info == NULL)
return;
if (sdp_info->remote_address != NULL)
free(sdp_info->remote_address);
if (sdp_info->service_uuid != NULL) {
for (i = 0; i < sdp_info->service_count; i++) {
if (sdp_info->service_uuid[i] != NULL)
free(sdp_info->service_uuid[i]);
}
free(sdp_info->service_uuid);
}
free(sdp_info);
sdp_info = NULL;
}
void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_data)
{
bluetooth_event_param_t new_param;
new_param.event = param->event;
new_param.param_data = param->param_data;
new_param.result = param->result;
new_param.user_data = NULL;
__bt_event_proxy(event, &new_param, user_data);
}
void _bt_avrcp_event_proxy(int event, media_event_param_t *param, void *user_data)
{
bluetooth_event_param_t new_param;
new_param.event = param->event;
new_param.param_data = param->param_data;
new_param.result = param->result;
new_param.user_data = param->user_data;
__bt_event_proxy(event, &new_param, user_data);
}
void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data)
{
bluetooth_event_param_t new_param;
new_param.event = param->event;
new_param.param_data = param->param_data;
new_param.result = param->result;
new_param.user_data = param->user_data;
__bt_event_proxy(event, &new_param, user_data);
}
static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *user_data)
{
bluetooth_rfcomm_connection_t *connection_ind = NULL;
bluetooth_rfcomm_disconnection_t *disconnection_ind = NULL;
bt_socket_connection_s rfcomm_connection;
bt_device_sdp_info_s *sdp_info = NULL;
bt_adapter_device_discovery_info_s *discovery_info = NULL;
bt_device_info_s *bonded_device = NULL;
bluetooth_rfcomm_connection_request_t *reqeust_ind = NULL;
bt_obex_server_authorize_into_t *auth_info = NULL;
bt_obex_server_transfer_info_t *transfer_info = NULL;
bt_opc_transfer_info_t *client_info = NULL;
bluetooth_device_address_t *bd_addr = NULL;
char *device_addr = NULL;
int error_code = BT_ERROR_NONE;
int event_index = -1;
bluetooth_network_device_info_t *dev_info = NULL;
bt_hdp_connected_t *hdp_conn_info = NULL;
bt_hdp_disconnected_t *hdp_disconn_info = NULL;
bt_hdp_data_ind_t *hdp_data_ind = NULL;
event_index = __bt_get_cb_index(event);
if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) {
return;
}
memset(&rfcomm_connection, 0x00, sizeof(bt_socket_connection_s));
switch (event) {
case BLUETOOTH_EVENT_ENABLED:
LOGI("[%s] bt_adapter_state_changed_cb() will be called with BT_ADAPTER_ENABLED", __FUNCTION__);
((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_ADAPTER_ENABLED, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_DISABLED:
LOGI("[%s] bt_adapter_state_changed_cb() will be called with BT_ADAPTER_DISABLED", __FUNCTION__);
((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_ADAPTER_DISABLED, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
LOGI("[%s] bt_adapter_name_changed_cb() will be called", __FUNCTION__);
((bt_adapter_name_changed_cb)bt_event_slot_container[event_index].callback)
((char *)(param->param_data), bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
LOGI("[%s] bt_adapter_visibility_mode_changed_cb() will be called", __FUNCTION__);
((bt_adapter_visibility_mode_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), _bt_get_bt_visibility_mode_e(*(bt_adapter_visibility_mode_e *)(param->param_data)), bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_DISCOVERY_STARTED:
LOGI("[%s] bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_STARTED", __FUNCTION__);
((bt_adapter_device_discovery_state_changed_cb) bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_STARTED, NULL, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
LOGI("[%s] bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FINISHED", __FUNCTION__);
((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, NULL, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
LOGI("[%s] bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FOUND", __FUNCTION__);
if (__bt_get_bt_adapter_device_discovery_info_s(&discovery_info, (bluetooth_device_info_t *)(param->param_data)) == BT_ERROR_NONE) {
((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FOUND, discovery_info, bt_event_slot_container[event_index].user_data);
__bt_free_bt_adapter_device_discovery_info_s(discovery_info);
} else {
((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FOUND, NULL, bt_event_slot_container[event_index].user_data);
}
break;
case BLUETOOTH_EVENT_BONDING_FINISHED:
LOGI("[%s] bt_device_bond_created_cb() will be called", __FUNCTION__);
_bt_get_bt_device_info_s(&bonded_device, (bluetooth_device_info_t *)(param->param_data));
((bt_device_bond_created_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), bonded_device, bt_event_slot_container[event_index].user_data);
_bt_free_bt_device_info_s(bonded_device);
bonded_device = NULL;
break;
case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED:
LOGI("[%s] bt_device_bond_destroyed_cb() will be called", __FUNCTION__);
_bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data));
((bt_device_bond_destroyed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data);
if (device_addr != NULL)
free(device_addr);
device_addr = NULL;
break;
case BLUETOOTH_EVENT_DEVICE_AUTHORIZED:
LOGI("[%s] bt_device_authorization_changed_cb() will be called with BT_DEVICE_AUTHORIZED", __FUNCTION__);
_bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data));
((bt_device_authorization_changed_cb)bt_event_slot_container[event_index].callback)
(BT_DEVICE_AUTHORIZED, device_addr, bt_event_slot_container[event_index].user_data);
if (device_addr != NULL)
free(device_addr);
device_addr = NULL;
break;
case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED:
LOGI("[%s] bt_device_authorization_changed_cb() will be called with BT_DEVICE_UNAUTHORIZED", __FUNCTION__);
_bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data));
((bt_device_authorization_changed_cb)bt_event_slot_container[event_index].callback)
(BT_DEVICE_UNAUTHORIZED, device_addr, bt_event_slot_container[event_index].user_data);
if (device_addr != NULL)
free(device_addr);
device_addr = NULL;
break;
case BLUETOOTH_EVENT_SERVICE_SEARCHED:
LOGI("[%s] bt_device_service_searched_cb() will be called", __FUNCTION__);
__bt_get_bt_device_sdp_info_s(&sdp_info, (bt_sdp_info_t *)(param->param_data));
error_code = _bt_get_error_code(param->result);
// In service search, BT_ERROR_SERVICE_SEARCH_FAILED is returned instead of BT_ERROR_OPERATION_FAILED.
if (error_code == BT_ERROR_OPERATION_FAILED)
error_code = BT_ERROR_SERVICE_SEARCH_FAILED;
((bt_device_service_searched_cb)bt_event_slot_container[event_index].callback)
(error_code, sdp_info, bt_event_slot_container[event_index].user_data);
__bt_free_bt_device_sdp_info_s(sdp_info);
break;
case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
LOGI("[%s] bt_socket_data_received_cb() will be called", __FUNCTION__);
((bt_socket_data_received_cb)bt_event_slot_container[event_index].callback)
((bt_socket_received_data_s *)(param->param_data), bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
LOGI("[%s] bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_CONNECTED", __FUNCTION__);
if (param->result == BLUETOOTH_ERROR_INVALID_PARAM)
error_code = BT_ERROR_OPERATION_FAILED;
else
error_code = _bt_get_error_code(param->result);
connection_ind = (bluetooth_rfcomm_connection_t *)(param->param_data);
rfcomm_connection.socket_fd = connection_ind->socket_fd;
rfcomm_connection.local_role = connection_ind->device_role;
if (connection_ind->uuid) {
rfcomm_connection.service_uuid = strdup(connection_ind->uuid);
LOGI("uuid: [%s]", rfcomm_connection.service_uuid);
}
_bt_convert_address_to_string(&(rfcomm_connection.remote_address), &(connection_ind->device_addr));
((bt_socket_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(error_code, BT_SOCKET_CONNECTED, &rfcomm_connection, bt_event_slot_container[event_index].user_data);
if (rfcomm_connection.remote_address != NULL) {
free(rfcomm_connection.remote_address);
rfcomm_connection.remote_address = NULL;
}
if (rfcomm_connection.service_uuid != NULL) {
free(rfcomm_connection.service_uuid);
rfcomm_connection.service_uuid = NULL;
}
break;
case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
LOGI("[%s] bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_DISCONNECTED", __FUNCTION__);
disconnection_ind = (bluetooth_rfcomm_disconnection_t *)(param->param_data);
rfcomm_connection.socket_fd = disconnection_ind->socket_fd;
rfcomm_connection.local_role = disconnection_ind->device_role;
if (disconnection_ind->uuid) {
rfcomm_connection.service_uuid = strdup(disconnection_ind->uuid);
LOGI("uuid: [%s]", rfcomm_connection.service_uuid);
}
_bt_convert_address_to_string(&(rfcomm_connection.remote_address), &(disconnection_ind->device_addr));
((bt_socket_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), BT_SOCKET_DISCONNECTED, &rfcomm_connection, bt_event_slot_container[event_index].user_data);
if (rfcomm_connection.remote_address != NULL) {
free(rfcomm_connection.remote_address);
rfcomm_connection.remote_address = NULL;
}
if (rfcomm_connection.service_uuid != NULL) {
free(rfcomm_connection.service_uuid);
rfcomm_connection.service_uuid = NULL;
}
break;
case BLUETOOTH_EVENT_RFCOMM_AUTHORIZE:
LOGI("[%s] bt_socket_connection_requested_cb() will be called", __FUNCTION__);
reqeust_ind = (bluetooth_rfcomm_connection_request_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, &(reqeust_ind->device_addr));
((bt_socket_connection_requested_cb)bt_event_slot_container[event_index].callback)
(reqeust_ind->socket_fd, device_addr, bt_event_slot_container[event_index].user_data);
if (device_addr != NULL)
free(device_addr);
break;
case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
LOGI("[%s] bt_opp_server_connection_requested_cb() will be called", __FUNCTION__);
bd_addr = (bluetooth_device_address_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, bd_addr);
((bt_opp_server_connection_requested_cb)bt_event_slot_container[event_index].callback)
(device_addr, bt_event_slot_container[event_index].user_data);
if (device_addr != NULL)
free(device_addr);
break;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
LOGI("[%s] bt_opp_server_push_requested_cb() will be called", __FUNCTION__);
auth_info = (bt_obex_server_authorize_into_t *)(param->param_data);
((bt_opp_server_push_requested_cb)bt_event_slot_container[event_index].callback)
(auth_info->filename, auth_info->length, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
LOGI("[%s] bt_opp_server_transfer_started_cb() will be called", __FUNCTION__);
transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data);
((bt_opp_server_transfer_progress_cb)bt_event_slot_container[event_index].callback)
(transfer_info->filename, transfer_info->file_size, 0, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
LOGI("[%s] bt_opp_server_transfer_in_progress_cb() will be called", __FUNCTION__);
transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data);
((bt_opp_server_transfer_progress_cb)bt_event_slot_container[event_index].callback)
(transfer_info->filename, transfer_info->file_size, transfer_info->percentage, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
LOGI("[%s] bt_opp_server_transfer_completed_cb() will be called", __FUNCTION__);
transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data);
((bt_opp_server_transfer_finished_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), transfer_info->filename, transfer_info->file_size, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OPC_CONNECTED:
LOGI("[%s] bt_opp_client_push_responded_cb() will be called", __FUNCTION__);
bd_addr = (bluetooth_device_address_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, bd_addr);
LOGI("address: %s", device_addr);
((bt_opp_client_push_responded_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OPC_DISCONNECTED:
LOGI("[%s] bt_opp_client_push_finished_cb() will be called", __FUNCTION__);
bd_addr = (bluetooth_device_address_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, bd_addr);
LOGI("address: %s", device_addr);
((bt_opp_client_push_finished_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
LOGI("[%s] bt_opp_client_transfer_started_cb() will be called", __FUNCTION__);
client_info = (bt_opc_transfer_info_t *)(param->param_data);
((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback)
(client_info->filename, client_info->size, 0, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
LOGI("[%s] bt_opp_client_transfer_in_progress_cb() will be called", __FUNCTION__);
client_info = (bt_opc_transfer_info_t *)(param->param_data);
((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback)
(client_info->filename, client_info->size, client_info->percentage, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
LOGI("[%s] bt_opp_client_push_progress_cb() will be called", __FUNCTION__);
client_info = (bt_opc_transfer_info_t *)(param->param_data);
if (param->result != BLUETOOTH_ERROR_NONE) {
LOGI("[%s] bt_opp_client_push_finished_cb() will be called", __FUNCTION__);
break;
}
((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback)
(client_info->filename, client_info->size, 100, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED", __FUNCTION__);
dev_info = (bluetooth_network_device_info_t *)(param->param_data);
if (param->result != BLUETOOTH_ERROR_NONE) {
LOGI("[%s]BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED", __FUNCTION__);
}
_bt_convert_address_to_string(&device_addr, &dev_info->device_address);
((bt_nap_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(TRUE, device_addr, dev_info->interface_name, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED", __FUNCTION__);
dev_info = (bluetooth_network_device_info_t *)(param->param_data);
if (param->result != BLUETOOTH_ERROR_NONE) {
LOGI("[%s]BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED", __FUNCTION__);
}
_bt_convert_address_to_string(&device_addr, &dev_info->device_address);
((bt_nap_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(FALSE, device_addr, dev_info->interface_name, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_NETWORK_DISCONNECTED:
LOGI("[%s] Network callback will be", __FUNCTION__);
((bt_panu_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), FALSE, NULL, BLUETOOTH_NETWORK_NAP_ROLE,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_NETWORK_CONNECTED:
LOGI("[%s] Network callback will be ", __FUNCTION__);
((bt_panu_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), TRUE, NULL, BLUETOOTH_NETWORK_NAP_ROLE,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_HDP_CONNECTED:
LOGI("[%s] HDP Connected ", __FUNCTION__);
hdp_conn_info = (bt_hdp_connected_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, &hdp_conn_info->device_address);
((bt_hdp_connected_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), device_addr, hdp_conn_info->app_handle,
hdp_conn_info->type, hdp_conn_info->channel_id,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_HDP_DISCONNECTED:
LOGI("[%s] HDP disconnected callback will be ", __FUNCTION__);
hdp_disconn_info = (bt_hdp_disconnected_t *)(param->param_data);
_bt_convert_address_to_string(&device_addr, &hdp_disconn_info->device_address);
((bt_hdp_disconnected_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), device_addr,
hdp_disconn_info->channel_id, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
LOGI("[%s] HDP data recieved callback will be ", __FUNCTION__);
hdp_data_ind = (bt_hdp_data_ind_t *)(param->param_data);
if (param->result != BLUETOOTH_ERROR_NONE) {
LOGI("[%s] BLUETOOTH_EVENT_HDP_DATA_RECEIVED will be called", __FUNCTION__);
}
((bt_hdp_data_received_cb)bt_event_slot_container[event_index].callback)
(hdp_data_ind->channel_id, hdp_data_ind->buffer, hdp_data_ind->size,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AG_CONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_AG_CONNECTED ", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AG_DISCONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_AG_DISCONNECTED ", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AG_SPEAKER_GAIN:
LOGI("[%s] BLUETOOTH_EVENT_AG_SPEAKER_GAIN", __FUNCTION__);
int *spk_gain = (int *)(param->param_data);
if (param->result != BLUETOOTH_ERROR_NONE) {
LOGI("[%s] BLUETOOTH_EVENT_AG_SPEAKER_GAIN will be called", __FUNCTION__);
}
((bt_ag_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback)
(NULL, *spk_gain, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AG_MIC_GAIN:
LOGI("[%s] BLUETOOTH_EVENT_AG_MIC_GAIN", __FUNCTION__);
int *mik_gain = (int *)(param->param_data);
if (param->result != BLUETOOTH_ERROR_NONE) {
LOGI("[%s] BLUETOOTH_EVENT_AG_MIC_GAIN will be called", __FUNCTION__);
}
((bt_ag_microphone_gain_changed_cb)bt_event_slot_container[event_index].callback)
(NULL, *mik_gain , bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_AG_AUDIO_CONNECTED", __FUNCTION__);
((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), TRUE, NULL, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AV_CONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_AV_CONNECTED ", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_EVENT_AV_DISCONNECTED:
LOGI("[%s] BLUETOOTH_EVENT_Av_DISCONNECTED ", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP,
bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_HID_CONNECTED:
LOGI("[%s] BLUETOOTH_HID_CONNECTED", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_hid_host_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), TRUE, device_addr, bt_event_slot_container[event_index].user_data);
break;
case BLUETOOTH_HID_DISCONNECTED:
LOGI("[%s] BLUETOOTH_HID_DISCONNECTED", __FUNCTION__);
device_addr = (char *)(param->param_data);
((bt_hid_host_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
(_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data);
break;
default:
break;
}
}
static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info) {
int i;
BT_CHECK_INPUT_PARAMETER(source_info);
*discovery_info = (bt_adapter_device_discovery_info_s *)malloc(sizeof(bt_adapter_device_discovery_info_s));
if (*discovery_info == NULL) {
return BT_ERROR_OUT_OF_MEMORY;
}
if (strlen(source_info->device_name.name) > 0) {
(*discovery_info)->remote_name = strdup(source_info->device_name.name);
} else {
(*discovery_info)->remote_name = NULL;
}
_bt_convert_address_to_string(&((*discovery_info)->remote_address), &(source_info->device_address));
(*discovery_info)->bt_class.major_device_class = source_info->device_class.major_class;
(*discovery_info)->bt_class.minor_device_class = source_info->device_class.minor_class;
(*discovery_info)->bt_class.major_service_class_mask = source_info->device_class.service_class;
if (source_info->service_index > 0) {
(*discovery_info)->service_uuid = (char **)malloc(sizeof(char *) * source_info->service_index);
if ((*discovery_info)->service_uuid != NULL) {
for (i = 0; i < source_info->service_index; i++) {
(*discovery_info)->service_uuid[i] = strdup(source_info->uuids[i]);
if ((*discovery_info)->service_uuid[i] != NULL) {
__bt_convert_lower_to_upper((*discovery_info)->service_uuid[i]);
}
LOGI("[%s] UUID: %s", __FUNCTION__, (*discovery_info)->service_uuid[i]);
}
}
} else {
(*discovery_info)->service_uuid = NULL;
}
(*discovery_info)->service_count = source_info->service_index;
(*discovery_info)->rssi = (int)source_info->rssi;
(*discovery_info)->is_bonded = (bool)source_info->paired;
return BT_ERROR_NONE;
}
static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info)
{
int i;
if (discovery_info == NULL)
return;
if (discovery_info->remote_name != NULL)
free(discovery_info->remote_name);
if (discovery_info->remote_address != NULL)
free(discovery_info->remote_address);
if (discovery_info->service_uuid != NULL) {
for (i = 0; i < discovery_info->service_count; i++) {
if (discovery_info->service_uuid[i] != NULL)
free(discovery_info->service_uuid[i]);
}
free(discovery_info->service_uuid);
}
free(discovery_info);
discovery_info = NULL;
}
static int __bt_get_cb_index(int event)
{
switch (event) {
case BLUETOOTH_EVENT_ENABLED:
case BLUETOOTH_EVENT_DISABLED:
return BT_EVENT_STATE_CHANGED;
case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
return BT_EVENT_NAME_CHANGED;
case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
return BT_EVENT_VISIBILITY_MODE_CHANGED;
case BLUETOOTH_EVENT_DISCOVERY_STARTED:
case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
return BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED;
case BLUETOOTH_EVENT_BONDING_FINISHED:
return BT_EVENT_BOND_CREATED;
case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED:
return BT_EVENT_BOND_DESTROYED;
case BLUETOOTH_EVENT_DEVICE_AUTHORIZED:
case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED:
return BT_EVENT_AUTHORIZATION_CHANGED;
case BLUETOOTH_EVENT_SERVICE_SEARCHED:
return BT_EVENT_SERVICE_SEARCHED;
case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
return BT_EVENT_DATA_RECEIVED;
case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
return BT_EVENT_CONNECTION_STATE_CHANGED;
case BLUETOOTH_EVENT_RFCOMM_AUTHORIZE:
return BT_EVENT_RFCOMM_CONNECTION_REQUESTED;
case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
return BT_EVENT_OPP_CONNECTION_REQUESTED;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
return BT_EVENT_OPP_PUSH_REQUESTED;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
return BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
return BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS;
case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
return BT_EVENT_OPP_SERVER_TRANSFER_FINISHED;
case BLUETOOTH_EVENT_OPC_CONNECTED:
return BT_EVENT_OPP_CLIENT_PUSH_RESPONSED;
case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
return BT_EVENT_OPP_CLIENT_PUSH_PROGRESS;
case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
return BT_EVENT_OPP_CLIENT_PUSH_PROGRESS;
case BLUETOOTH_EVENT_OPC_DISCONNECTED:
return BT_EVENT_OPP_CLIENT_PUSH_FINISHED;
case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
return BT_EVENT_NAP_CONNECTION_STATE_CHANGED;
case BLUETOOTH_EVENT_NETWORK_CONNECTED:
case BLUETOOTH_EVENT_NETWORK_DISCONNECTED:
return BT_EVENT_PAN_CONNECTION_STATE_CHANGED;
case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
return BT_EVENT_HDP_DATA_RECIEVED;
case BLUETOOTH_EVENT_HDP_CONNECTED:
return BT_EVENT_HDP_CONNECTED;
case BLUETOOTH_EVENT_HDP_DISCONNECTED:
return BT_EVENT_HDP_DISCONNECTED;
case BLUETOOTH_EVENT_AG_CONNECTED:
return BT_EVENT_AUDIO_CONNECTION_STATUS;
case BLUETOOTH_EVENT_AG_DISCONNECTED:
return BT_EVENT_AUDIO_CONNECTION_STATUS;
case BLUETOOTH_EVENT_AG_SPEAKER_GAIN:
return BT_EVENT_AG_SPEAKER_GAIN_CHANGE;
case BLUETOOTH_EVENT_AG_MIC_GAIN:
return BT_EVENT_AG_MICROPHONE_GAIN_CHANGE;
case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED:
return BT_EVENT_AUDIO_CONNECTION_STATUS;
case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED:
return BT_EVENT_AUDIO_CONNECTION_STATUS;
case BLUETOOTH_EVENT_AV_CONNECTED:
return BT_EVENT_AUDIO_CONNECTION_STATUS;
case BLUETOOTH_EVENT_AV_DISCONNECTED:
return BT_EVENT_AUDIO_CONNECTION_STATUS;
case BLUETOOTH_HID_CONNECTED:
return BT_EVENT_HID_CONNECTION_STATUS;
case BLUETOOTH_HID_DISCONNECTED:
return BT_EVENT_HID_CONNECTION_STATUS;
default:
return -1;
}
}
static void __bt_convert_lower_to_upper(char *origin)
{
int length = strlen(origin);
int i = 0;
for (i = 0; i < length; i++) {
if (islower(origin[i])) {
origin[i] = toupper(origin[i]);
}
}
}
|