2 * Open Adaptation Layer (OAL)
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <bluetooth.h>
26 #include "oal-event.h"
27 #include "oal-internal.h"
28 #include "oal-common.h"
29 #include "oal-manager.h"
30 #include "oal-utils.h"
32 static const bt_interface_t * blued_api;
34 void device_mgr_init(const bt_interface_t * stack_if)
39 void device_mgr_cleanup(void)
45 oal_status_t device_query_attributes(bt_address_t *addr)
50 CHECK_OAL_INITIALIZED();
52 OAL_CHECK_PARAMETER(addr, return);
54 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
56 res = blued_api->get_remote_device_properties((bt_bdaddr_t *)addr);
57 if (res != BT_STATUS_SUCCESS) {
58 BT_ERR("get_remote_device_properties error: [%s]", status2string(res));
59 return convert_to_oal_status(res);
62 return OAL_STATUS_SUCCESS;
65 oal_status_t device_set_alias(bt_address_t * addr, char * alias)
71 CHECK_OAL_INITIALIZED();
72 OAL_CHECK_PARAMETER(addr, return);
73 OAL_CHECK_PARAMETER(alias, return);
75 API_TRACE("%s ->Alias: %s", bdt_bd2str(addr, &bdstr), alias);
77 prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME;
78 prop.len = strlen(alias);
80 res = blued_api->set_remote_device_property((bt_bdaddr_t*)addr, &prop);
81 if (res != BT_STATUS_SUCCESS) {
82 BT_ERR("set_remote_device_property error: [%s]", status2string(res));
83 BT_ERR("Alias: %s", alias);
84 return convert_to_oal_status(res);
87 return OAL_STATUS_SUCCESS;
90 void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
91 int num_properties, bt_property_t *properties)
94 gpointer event_data = NULL;
95 remote_device_t *dev_info;
96 ble_adv_data_t adv_info;
100 if(BT_STATUS_SUCCESS != status) {
101 BT_ERR("[%s]status: %d", bdt_bd2str((bt_address_t*)bd_addr, &bdstr), status);
105 BT_DBG("[%s]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
106 dev_info = g_new0(remote_device_t, 1);
107 memcpy(dev_info->address.addr, bd_addr->address, 6);
108 parse_device_properties(num_properties, properties, dev_info, &adv_info);
110 if(num_properties == 1) {
111 /* For one particular property a dedicated event to be sent */
112 switch(properties[0].type) {
113 case BT_PROPERTY_BDNAME:
114 event = OAL_EVENT_DEVICE_NAME;
115 event_data = dev_info;
116 send_event_trace(event, event_data, sizeof(remote_device_t),
117 (bt_address_t*)bd_addr, "Name: %s", dev_info->name);
119 case BT_PROPERTY_UUIDS: {
120 event_dev_services_t *services_info;
121 bt_uuid_t *uuids = (bt_uuid_t *) properties[0].val;
123 services_info = g_malloc(sizeof(event_dev_services_t) + properties[0].len);
124 services_info->address = dev_info->address;
125 memcpy(services_info->service_list, uuids, properties[0].len);
126 services_info->num = properties[0].len/sizeof(bt_uuid_t);
127 event = OAL_EVENT_DEVICE_SERVICES;
128 event_data = services_info;
129 size = sizeof(event_dev_services_t) + properties[0].len;
134 BT_ERR("Single Property [%d] not handled", properties[0].type);
139 event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
140 if (dev_info->type != DEV_TYPE_BREDR) {
143 BT_INFO("BLE Device");
144 /* BLE Single or DUAL mode found, so it should have Adv data */
145 dev_props_event->adv_len = adv_info.len;
146 if(dev_props_event->adv_len > 0)
147 memcpy(dev_props_event->adv_data,
148 adv_info.adv_data, adv_info.len);
150 for (i = 0; i < dev_props_event->adv_len; i++)
151 BT_INFO("Adv Data[%d] = [0x%x]",
152 i, dev_props_event->adv_data[i]);
153 memcpy(&dev_props_event->device_info,
154 dev_info, sizeof(remote_device_t));
156 BT_INFO("BREDR type Device");
157 memcpy(&dev_props_event->device_info,
158 dev_info, sizeof(remote_device_t));
161 event_data = dev_props_event;
162 event = OAL_EVENT_DEVICE_PROPERTIES;
163 size = sizeof(event_dev_properties_t);
166 send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);