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.
20 #include "bluetooth-api.h"
21 #include "bt-internal-types.h"
23 #include "bt-service-common.h"
24 #include "bt-service-event.h"
25 #include "bt-service-event-manager.h"
27 #define MAX_DEVICES 100
33 static struct uuid_def hid_uuids[] = {
34 { "00001124-0000-1000-8000-00805f9b34fb" },
35 { "00001200-0000-1000-8000-00805f9b34fb" },
38 static struct uuid_def tizen_mobile_uuids[] = {
39 { "00001800-0000-1000-8000-00805f9b34fb" },
40 { "00001801-0000-1000-8000-00805f9b34fb" },
41 { "0000110c-0000-1000-8000-00805f9b34fb" },
42 { "0000110a-0000-1000-8000-00805f9b34fb" },
43 { "00001132-0000-1000-8000-00805f9b34fb" },
44 { "00001133-0000-1000-8000-00805f9b34fb" },
45 { "0000112f-0000-1000-8000-00805f9b34fb" },
46 { "00001105-0000-1000-8000-00805f9b34fb" },
47 { "0000111f-0000-1000-8000-00805f9b34fb" },
48 { "00001112-0000-1000-8000-00805f9b34fb" },
51 static struct uuid_def mobile_uuids[] = {
52 { "00001105-0000-1000-8000-00805f9b34fb" },
53 { "0000110a-0000-1000-8000-00805f9b34fb" },
54 { "0000110c-0000-1000-8000-00805f9b34fb" },
55 { "00001112-0000-1000-8000-00805f9b34fb" },
56 { "00001115-0000-1000-8000-00805f9b34fb" },
57 { "00001116-0000-1000-8000-00805f9b34fb" },
58 { "0000111f-0000-1000-8000-00805f9b34fb" },
59 { "0000112d-0000-1000-8000-00805f9b34fb" },
60 { "0000112f-0000-1000-8000-00805f9b34fb" },
61 { "00001132-0000-1000-8000-00805f9b34fb" },
62 { "00001200-0000-1000-8000-00805f9b34fb" },
63 { "00001800-0000-1000-8000-00805f9b34fb" },
64 { "00001801-0000-1000-8000-00805f9b34fb" },
67 static struct uuid_def a2dp_only_uuids[] = {
68 { "0000110b-0000-1000-8000-00805f9b34fb" },
69 { "0000110c-0000-1000-8000-00805f9b34fb" },
70 { "0000110d-0000-1000-8000-00805f9b34fb" },
71 { "0000110e-0000-1000-8000-00805f9b34fb" },
74 static struct uuid_def headset_uuids[] = {
75 { "0000111e-0000-1000-8000-00805f9b34fb" },
76 { "00001108-0000-1000-8000-00805f9b34fb" },
77 { "0000110d-0000-1000-8000-00805f9b34fb" },
78 { "0000110b-0000-1000-8000-00805f9b34fb" },
79 { "0000110e-0000-1000-8000-00805f9b34fb" },
82 struct bt_sample_dev_info_t {
87 struct uuid_def *uuids;
88 unsigned int uuid_count;
90 bluetooth_connected_link_t connected;
92 char *manufacturer_data;
93 int manufacturer_data_len;
97 static struct bt_sample_dev_info_t sample_devices[] = {
98 { -69, 2360344, "00:1B:66:01:23:1C", "Sennheiser P", a2dp_only_uuids, sizeof(a2dp_only_uuids) / sizeof(a2dp_only_uuids[0]), FALSE, 0x00, FALSE, NULL, 0, BDADDR_BREDR},
99 { -70, 5898764, "A8:7C:01:EF:3C:73", "Galaxy S6 edge", mobile_uuids, sizeof(mobile_uuids) / sizeof(mobile_uuids[0]), FALSE, 0x00, FALSE, NULL, 0, BDADDR_BREDR},
100 { -58, 2360324, "50:C9:71:56:30:5A", "Jabra SUPREME a4.18.0", headset_uuids, sizeof(headset_uuids) / sizeof(headset_uuids[0]), FALSE, 0x00, FALSE, NULL, 0, BDADDR_BREDR},
101 { -75, 5767692, "AC:5A:14:24:B9:33", "Tizen 3.0 Mobile", tizen_mobile_uuids, sizeof(tizen_mobile_uuids) / sizeof(tizen_mobile_uuids[0]), FALSE, 0x00, FALSE, NULL, 0, BDADDR_BREDR},
102 { -60, 9600, "34:15:9E:D4:83:B3", "Apple Wireless Mouse", hid_uuids, sizeof(hid_uuids) / sizeof(hid_uuids[0]), FALSE, 0x00, FALSE, NULL, 0, BDADDR_BREDR},
110 static GSList *timer_list = NULL;
111 static int sample_device_num = sizeof(sample_devices) / sizeof(sample_devices[0]);
113 void _bt_create_event_timer(int event_id, int interval, void *event_cb, void *user_data)
115 bt_timer_info_t *event_info = NULL;
119 event_info = g_malloc0(sizeof(bt_timer_info_t));
121 _bt_delete_event_timer(event_id);
123 event_info->event_id = event_id;
125 /* Assign a timer id */
126 event_info->timer_id = g_timeout_add(interval, (GSourceFunc)event_cb, (gpointer)user_data);
128 BT_DBG("Create event timer. event id: %d, timer id: %d", event_id, event_info->timer_id);
130 timer_list = g_slist_append(timer_list, event_info);
135 void _bt_delete_event_timer(int event_id)
141 BT_DBG("Remove event timer. event id: %d", event_id);
143 for (l = timer_list; l != NULL; l = g_slist_next(l)) {
144 bt_timer_info_t *info = l->data;
148 if (info->event_id == event_id) {
149 BT_DBG("Found the event id");
150 /* Remove the previous timer */
151 g_source_remove(info->timer_id);
152 timer_list = g_slist_remove(timer_list, info);
161 void _bt_delete_all_event_timer(void)
167 for (l = timer_list; l != NULL; l = g_slist_next(l)) {
168 bt_timer_info_t *info = l->data;
172 g_source_remove(info->timer_id);
173 timer_list = g_slist_remove(timer_list, info);
177 g_slist_free(timer_list);
183 int _bt_get_sample_device_number(void)
185 return sample_device_num;
188 bt_remote_dev_info_t *_bt_get_sample_device(int index)
190 bt_remote_dev_info_t *dev_info;
192 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
194 dev_info->rssi = sample_devices[index].rssi;
195 dev_info->class = sample_devices[index].class;
196 dev_info->paired = sample_devices[index].paired;
197 dev_info->connected = sample_devices[index].connected;
198 dev_info->trust = sample_devices[index].trust;
199 dev_info->addr_type = sample_devices[index].addr_type;
201 dev_info->name = g_strdup(sample_devices[index].name);
202 dev_info->address = g_strdup(sample_devices[index].address);
204 dev_info->uuid_count = sample_devices[index].uuid_count;
206 if (dev_info->uuid_count > 0) {
208 dev_info->uuids = g_malloc0(sizeof(char *) * dev_info->uuid_count);
210 for (i = 0; i < dev_info->uuid_count; i++) {
211 BT_DBG("uuid[%d]: %s", i, sample_devices[index].uuids[i]);
212 dev_info->uuids[i] = g_strdup(sample_devices[index].uuids[i].uuid);
216 dev_info->manufacturer_data_len = sample_devices[index].manufacturer_data_len;
218 if (dev_info->manufacturer_data_len > 0) {
219 dev_info->manufacturer_data = g_malloc0(dev_info->manufacturer_data_len);
220 memcpy(dev_info->manufacturer_data, sample_devices[index].manufacturer_data,
221 dev_info->manufacturer_data_len);