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.
27 #include <bluetooth.h>
29 #include "oal-event.h"
30 #include "oal-internal.h"
31 #include "oal-manager.h"
32 #include "oal-hardware.h"
33 #include "oal-common.h"
34 #include "oal-utils.h"
37 #define CHECK_MAX(max, x) (((max) > (x)) ? (x) : (max))
39 static const bt_interface_t * blued_api;
41 static bt_address_t local_address;
42 static char local_name[BT_DEVICE_NAME_LENGTH_MAX + 1] = {'O', 'A', 'L', 0};
43 static char local_version[BT_VERSION_STR_LEN_MAX + 1];
44 static bt_scan_mode_t scan_mode = BT_SCAN_MODE_NONE;
45 static int discoverable_timeout = 0;
47 /* Forward declarations */
48 oal_status_t convert_to_oal_status(bt_status_t status);
49 static gboolean retry_enable_adapter(gpointer data);
51 static gboolean retry_enable_le(gpointer data);
53 oal_status_t oal_mgr_init_internal(void);
56 /* Callback registered with Stack */
57 static void cb_adapter_state_change(bt_state_t status);
58 static void cb_adapter_discovery_state_changed(bt_discovery_state_t state);
59 static void cb_adapter_device_found(int num_properties, bt_property_t *properties);
60 static void cb_adapter_properties(bt_status_t status,
61 int num_properties, bt_property_t *properties);
62 extern void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
63 int num_properties, bt_property_t *properties);
64 extern void cb_device_bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
65 bt_bond_state_t state);
66 extern void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
67 bt_acl_state_t state);
68 extern void cb_device_pin_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class);
69 extern void cb_device_ssp_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class,
70 bt_ssp_variant_t pairing_variant, uint32_t pass_key);
71 extern void cb_device_authorize_request(bt_bdaddr_t *remote_bd_addr, bt_service_id_t service_d);
72 extern void cb_device_trust_state_changed(bt_bdaddr_t *remote_bd_addr, bt_device_trust_state_t trusted);
74 extern void cb_socket_conn_authorize_request(bt_bdaddr_t *remote_bd_addr, bt_uuid_t *uuid);
75 static void cb_ble_state_change(bt_state_t status);
76 extern void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
77 bt_le_conn_state_t state);
78 extern void cb_device_trusted_profiles_changed(bt_bdaddr_t *bd_addr, uint32_t trust_val);
79 extern void cb_rssi_monitor_state_changed(bt_bdaddr_t *bd_addr, int32_t link_type, uint8_t state);
80 extern void cb_rssi_alert(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t alert_type, int32_t rssi);
81 extern void cb_raw_rssi_received(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t rssi);
84 static bt_callbacks_t callbacks = {
85 .size = sizeof(callbacks),
86 .adapter_state_changed_cb = cb_adapter_state_change,
87 .adapter_properties_cb = cb_adapter_properties,
88 .remote_device_properties_cb = cb_device_properties,
89 .device_found_cb = cb_adapter_device_found,
90 .discovery_state_changed_cb = cb_adapter_discovery_state_changed,
91 .pin_request_cb = cb_device_pin_request,
92 .ssp_request_cb = cb_device_ssp_request,
93 .bond_state_changed_cb = cb_device_bond_state_changed,
94 .acl_state_changed_cb = cb_device_acl_state_changed,
95 .thread_evt_cb = NULL,
96 .dut_mode_recv_cb = NULL,
97 .le_test_mode_cb = NULL,
98 .energy_info_cb = NULL,
99 .authorize_request_cb = cb_device_authorize_request,
100 .device_trust_state_changed_cb = cb_device_trust_state_changed,
102 .socket_authorize_request_cb = cb_socket_conn_authorize_request,
103 .le_state_changed_cb = cb_ble_state_change,
104 .le_conn_state_changed_cb = cb_device_le_conn_state_changed,
105 .device_trusted_profiles_changed_cb = cb_device_trusted_profiles_changed,
106 .rssi_monitor_state_changed_cb = cb_rssi_monitor_state_changed,
107 .rssi_alert_cb = cb_rssi_alert,
108 .raw_rssi_received_cb = cb_raw_rssi_received,
112 oal_status_t adapter_mgr_init(const bt_interface_t * stack_if)
115 blued_api = stack_if;
117 ret = blued_api->init(&callbacks);
119 if (ret != BT_STATUS_SUCCESS) {
120 BT_ERR("Adapter callback registration failed: [%s]", status2string(ret));
121 blued_api->cleanup();
122 return convert_to_oal_status(ret);
125 return OAL_STATUS_SUCCESS;
128 const bt_interface_t* adapter_get_stack_interface(void)
133 void adapter_mgr_cleanup(void)
135 /* Nothing to clean yet , do not set blued_api NULL as it will be used to clean Bluedroid states */
139 int oal_set_adapter_request_state(int enable)
141 return blued_api->set_hal_adapter_request_state(enable);
144 int oal_set_le_request_state(int enable)
146 return blued_api->set_hal_le_request_state(enable);
149 oal_status_t adapter_enable(void)
151 int ret = BT_STATUS_SUCCESS;
154 CHECK_OAL_INITIALIZED();
155 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
156 g_timeout_add(200, retry_enable_adapter, NULL);
157 return OAL_STATUS_PENDING;
160 ret = blued_api->enable();
162 if (ret != BT_STATUS_SUCCESS) {
163 BT_ERR("Enable failed: [%s]", status2string(ret));
164 return convert_to_oal_status(ret);
167 return OAL_STATUS_SUCCESS;
170 oal_status_t adapter_disable(void)
176 CHECK_OAL_INITIALIZED();
178 ret = blued_api->disable();
180 if (ret != BT_STATUS_SUCCESS) {
181 BT_ERR("Disable failed: [%s]", status2string(ret));
182 return convert_to_oal_status(ret);
184 return OAL_STATUS_SUCCESS;
187 oal_status_t le_enable(void)
189 int ret = BT_STATUS_SUCCESS;
192 CHECK_OAL_INITIALIZED();
195 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
196 g_timeout_add(200, retry_enable_le, NULL);
197 return OAL_STATUS_PENDING;
200 ret = blued_api->le_enable();
202 if (ret != BT_STATUS_SUCCESS) {
203 BT_ERR("Enable failed: [%s]", status2string(ret));
204 return convert_to_oal_status(ret);
207 BT_INFO("Not Supported");
208 ret = OAL_STATUS_NOT_SUPPORT;
214 oal_status_t le_disable(void)
220 CHECK_OAL_INITIALIZED();
223 ret = blued_api->le_disable();
225 if (ret != BT_STATUS_SUCCESS) {
226 BT_ERR("Disable failed: [%s]", status2string(ret));
227 return convert_to_oal_status(ret);
230 BT_INFO("Not Supported");
231 ret = OAL_STATUS_NOT_SUPPORT;
236 oal_status_t le_init(void)
238 int ret = BT_STATUS_SUCCESS;
240 CHECK_OAL_INITIALIZED();
242 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
243 g_timeout_add(200, retry_enable_le, NULL);
244 return OAL_STATUS_PENDING;
246 ret = blued_api->le_init();
247 if (ret != BT_STATUS_SUCCESS) {
248 BT_ERR("Enable failed: [%s]", status2string(ret));
249 return convert_to_oal_status(ret);
252 BT_INFO("Not Supported");
253 ret = OAL_STATUS_NOT_SUPPORT;
257 oal_status_t le_deinit(void)
259 int ret = BT_STATUS_SUCCESS;
261 CHECK_OAL_INITIALIZED();
263 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
264 g_timeout_add(200, retry_enable_le, NULL);
265 return OAL_STATUS_PENDING;
267 blued_api->le_deinit();
269 BT_INFO("Not Supported");
270 ret = OAL_STATUS_NOT_SUPPORT;
274 oal_status_t is_advertising(void)
276 int ret = BT_STATUS_SUCCESS;
278 CHECK_OAL_INITIALIZED();
280 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
281 g_timeout_add(200, retry_enable_le, NULL);
282 return OAL_STATUS_PENDING;
284 int r = blued_api->is_advertising();
286 ret = BT_STATUS_SUCCESS;
288 ret = BT_STATUS_FAIL;
290 BT_INFO("Not Supported");
291 ret = OAL_STATUS_NOT_SUPPORT;
295 oal_status_t adapter_start_custom_inquiry(discovery_type_t disc_type)
301 CHECK_OAL_INITIALIZED();
302 BT_INFO("Custom Discovery Type [0x%x]", disc_type);
305 ret = blued_api->start_custom_discovery(disc_type);
306 if (ret != BT_STATUS_SUCCESS) {
307 BT_ERR("start_custom_discovery failed: [%s]", status2string(ret));
308 return convert_to_oal_status(ret);
311 BT_INFO("Not Supported");
312 ret = OAL_STATUS_NOT_SUPPORT;
317 oal_status_t adapter_get_powered_status(gboolean *status)
320 unsigned char powered = 0;
324 CHECK_OAL_INITIALIZED();
326 OAL_CHECK_PARAMETER(status, return);
327 BT_INFO("Get Adapter Powered status");
330 ret = blued_api->get_adapter_powered_status(&powered);
331 if (ret != BT_STATUS_SUCCESS) {
332 BT_ERR("adapter_get_powered_status failed: [%s]", status2string(ret));
334 return convert_to_oal_status(ret);
341 BT_INFO("Not Supported");
342 ret = OAL_STATUS_NOT_SUPPORT;
347 oal_status_t adapter_reset(void)
353 CHECK_OAL_INITIALIZED();
354 BT_INFO("Adapter Reset");
357 ret = blued_api->reset();
358 if (ret != BT_STATUS_SUCCESS) {
359 BT_ERR("Adapter Reset failed: [%s]", status2string(ret));
360 return convert_to_oal_status(ret);
363 BT_INFO("Not Supported");
364 ret = OAL_STATUS_NOT_SUPPORT;
369 oal_status_t adapter_start_inquiry(unsigned short duration)
375 CHECK_OAL_INITIALIZED();
377 ret = blued_api->start_discovery();
378 if (ret != BT_STATUS_SUCCESS) {
379 BT_ERR("start_discovery failed: [%s]", status2string(ret));
380 return convert_to_oal_status(ret);
383 return OAL_STATUS_SUCCESS;
386 oal_status_t adapter_stop_inquiry(void)
392 CHECK_OAL_INITIALIZED();
394 ret = blued_api->cancel_discovery();
395 if (ret != BT_STATUS_SUCCESS) {
396 BT_ERR("cancel_discovery failed: [%s]", status2string(ret));
397 return convert_to_oal_status(ret);
400 return OAL_STATUS_SUCCESS;
403 /* Callbacks from Stack */
404 static void cb_adapter_state_change(bt_state_t status)
409 event = (BT_STATE_ON == status) ? OAL_EVENT_ADAPTER_ENABLED : OAL_EVENT_ADAPTER_DISABLED;
411 send_event(event, NULL, 0);
415 /* Callbacks from Stack */
416 static void cb_ble_state_change(bt_state_t status)
421 event = (BT_STATE_ON == status) ? OAL_EVENT_BLE_ENABLED : OAL_EVENT_BLE_DISABLED;
423 send_event(event, NULL, 0);
427 static gboolean retry_enable_adapter(gpointer data)
434 static gboolean retry_enable_le(gpointer data)
440 oal_status_t adapter_get_properties(void)
445 CHECK_OAL_INITIALIZED();
447 ret = blued_api->get_adapter_properties();
448 if (ret != BT_STATUS_SUCCESS) {
449 BT_ERR("get_adapter_properties failed: [%s]", status2string(ret));
450 return convert_to_oal_status(ret);
453 return OAL_STATUS_SUCCESS;
456 oal_status_t adapter_get_address(void)
461 CHECK_OAL_INITIALIZED();
463 ret = blued_api->get_adapter_property(BT_PROPERTY_BDADDR);
464 if (ret != BT_STATUS_SUCCESS) {
465 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
466 return convert_to_oal_status(ret);
469 return OAL_STATUS_SUCCESS;
472 oal_status_t adapter_get_version(void)
477 CHECK_OAL_INITIALIZED();
479 ret = blued_api->get_adapter_property(BT_PROPERTY_VERSION);
480 if (ret != BT_STATUS_SUCCESS) {
481 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
482 return convert_to_oal_status(ret);
485 return OAL_STATUS_SUCCESS;
488 oal_status_t adapter_get_name(void)
492 CHECK_OAL_INITIALIZED();
496 ret = blued_api->get_adapter_property(BT_PROPERTY_BDNAME);
497 if (ret != BT_STATUS_SUCCESS) {
498 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
499 return convert_to_oal_status(ret);
502 return OAL_STATUS_SUCCESS;
505 oal_status_t adapter_set_name(char * name)
510 CHECK_OAL_INITIALIZED();
512 OAL_CHECK_PARAMETER(name, return);
513 API_TRACE("Name: %s", name);
515 prop.type = BT_PROPERTY_BDNAME;
516 prop.len = strlen(name);
519 ret = blued_api->set_adapter_property(&prop);
520 if (ret != BT_STATUS_SUCCESS) {
521 BT_ERR("set_adapter_property: [%s]", status2string(ret));
522 ret = OAL_STATUS_INTERNAL_ERROR;
524 ret = OAL_STATUS_SUCCESS;
529 oal_status_t adapter_is_discoverable(int *p_discoverable)
531 OAL_CHECK_PARAMETER(p_discoverable, return);
533 *p_discoverable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
535 API_TRACE("%d", *p_discoverable);
537 return OAL_STATUS_SUCCESS;
540 oal_status_t adapter_is_connectable(int *p_connectable)
542 OAL_CHECK_PARAMETER(p_connectable, return);
544 *p_connectable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
545 || (scan_mode == BT_SCAN_MODE_CONNECTABLE);
547 API_TRACE("%d", *p_connectable);
549 return OAL_STATUS_SUCCESS;
552 oal_status_t adapter_get_discoverable_timeout(int *p_timeout)
554 API_TRACE("%d", discoverable_timeout);
556 *p_timeout = discoverable_timeout;
558 return OAL_STATUS_SUCCESS;
561 oal_status_t adapter_get_service_uuids(void)
565 CHECK_OAL_INITIALIZED();
568 ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
569 if (ret != BT_STATUS_SUCCESS) {
570 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
571 return convert_to_oal_status(ret);
573 return OAL_STATUS_SUCCESS;
576 oal_status_t adapter_get_bonded_devices(void)
580 CHECK_OAL_INITIALIZED();
584 ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
585 if (ret != BT_STATUS_SUCCESS) {
586 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
587 return convert_to_oal_status(ret);
590 return OAL_STATUS_SUCCESS;
593 static oal_status_t set_scan_mode(bt_scan_mode_t mode)
600 CHECK_OAL_INITIALIZED();
602 prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
603 prop.len = sizeof(bt_scan_mode_t);
605 res = blued_api->set_adapter_property(&prop);
606 if (res != BT_STATUS_SUCCESS) {
607 BT_ERR("set scan mode failed [%s]", status2string(res));
608 return convert_to_oal_status(res);
612 return OAL_STATUS_SUCCESS;
615 oal_status_t adapter_set_connectable(int connectable)
619 API_TRACE("%d", connectable);
621 CHECK_OAL_INITIALIZED();
623 mode = connectable ? BT_SCAN_MODE_CONNECTABLE : BT_SCAN_MODE_NONE;
625 return set_scan_mode(mode);
628 oal_status_t adapter_set_discoverable(void)
630 CHECK_OAL_INITIALIZED();
633 return set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
636 oal_status_t adapter_set_discoverable_timeout(int timeout)
640 uint32_t prop_val = timeout;
642 CHECK_OAL_INITIALIZED();
643 API_TRACE("%d", timeout);
645 prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
646 prop.len = sizeof(prop_val);
647 prop.val = &prop_val;
648 res = blued_api->set_adapter_property(&prop);
649 if (res != BT_STATUS_SUCCESS) {
650 BT_ERR("set_adapter_property failed [%s]", status2string(res));
651 return convert_to_oal_status(res);
653 return OAL_STATUS_SUCCESS;
656 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
657 int adv_type, int chnl_map, int tx_power, int timeout_s)
660 CHECK_OAL_INITIALIZED();
663 res = gatts_multi_adv_update(Ins_id, min_intv, max_intv,
664 adv_type, chnl_map, tx_power, timeout_s);
665 if (res != OAL_STATUS_SUCCESS) {
666 BT_ERR("gatts_multi_adv_update: [%d]", res);
669 return OAL_STATUS_SUCCESS;
672 oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id,
673 oal_ble_multi_adv_param_setup_t * adv_param_setup)
676 CHECK_OAL_INITIALIZED();
677 OAL_CHECK_PARAMETER(adv_param_setup, return);
681 res = gatts_multi_adv_set_inst_data(instance_id, adv_param_setup);
682 if (res != OAL_STATUS_SUCCESS) {
683 BT_ERR("failed: [%d]", res);
686 return OAL_STATUS_SUCCESS;
689 oal_status_t adapter_ble_multi_adv_enable(int instance_id)
692 CHECK_OAL_INITIALIZED();
695 res = gatts_multi_adv_enable(instance_id);
696 if (res != OAL_STATUS_SUCCESS) {
697 BT_ERR("failed: [%d]", res);
701 return OAL_STATUS_SUCCESS;
704 oal_status_t adapter_ble_multi_adv_disable(int instance_id)
707 CHECK_OAL_INITIALIZED();
710 res = gatts_multi_adv_disable(instance_id);
711 if (res != OAL_STATUS_SUCCESS) {
712 BT_ERR("failed: [%d]", res);
716 return OAL_STATUS_SUCCESS;
719 oal_status_t adapter_set_le_static_random_address(int enable)
723 CHECK_OAL_INITIALIZED();
724 API_TRACE("%d", enable);
727 ret = blued_api->set_le_static_random_address((enable ? 1 : 0));
728 if (ret != BT_STATUS_SUCCESS)
729 BT_ERR("Static address set failed: [%s]", status2string(ret));
730 ret = convert_to_oal_status(ret);
732 BT_INFO("Not Supported");
733 ret = OAL_STATUS_NOT_SUPPORT;
739 static void cb_adapter_properties(bt_status_t status,
741 bt_property_t *properties)
745 BT_DBG("status: %d, count: %d", status, num_properties);
747 print_bt_properties(num_properties, properties);
749 if (status != BT_STATUS_SUCCESS) {
750 if (num_properties == 1) {
751 BT_ERR("Adapter Prop failed: status: [%s], count: %d, prop: %d",
752 status2string(status), num_properties, properties[num_properties-1].type);
754 BT_ERR("Adapter Prop failed: status: [%s], count: %d", status2string(status), num_properties);
759 for (i = 0; i < num_properties; i++) {
760 BT_DBG("prop type %d, len %d", properties[i].type, properties[i].len);
761 switch (properties[i].type) {
762 case BT_PROPERTY_VERSION: {
763 g_strlcpy(local_version, properties[i].val, BT_VERSION_STR_LEN_MAX);
764 local_version[properties[i].len] = '\0';
766 BT_DBG("Version: %s", local_version);
767 /* Send event to application */
768 if (num_properties == 1) {
769 char *adapter_ver = g_strdup(local_version);
771 /* Application has requested this property SET/GET hence send EVENT */
772 send_event(OAL_EVENT_ADAPTER_PROPERTY_VERSION, adapter_ver, strlen(adapter_ver));
776 case BT_PROPERTY_BDNAME: {
777 g_strlcpy(local_name, properties[i].val, BT_DEVICE_NAME_LENGTH_MAX);
778 local_name[properties[i].len] = '\0';
780 BT_DBG("Name: %s", local_name);
781 /* Send event to application */
782 if (num_properties == 1) {
783 char * adap_name = g_strdup(local_name);
785 /* Application has requested this property SET/GET hence send EVENT */
786 send_event(OAL_EVENT_ADAPTER_PROPERTY_NAME, adap_name, strlen(adap_name)+1);
790 case BT_PROPERTY_BDADDR: {
793 addr = properties[i].val;
794 memcpy(local_address.addr, addr->address, 6);
795 if (num_properties == 1) {
796 /* Application has requested this property SET/GET hence send EVENT */
797 send_event(OAL_EVENT_ADAPTER_PROPERTY_ADDRESS,
798 g_memdup(&local_address, sizeof(local_address)),
799 sizeof(local_address));
803 case BT_PROPERTY_UUIDS: {
806 num_uuid = properties[i].len/sizeof(bt_uuid_t);
808 BT_DBG("num_uuid: %d", num_uuid);
810 /* Send event to application */
811 if (num_properties == 1) {
812 event_adapter_services_t *uuids_event;
814 uuids_event = g_malloc(sizeof(event_adapter_services_t) + properties[i].len);
815 memcpy(uuids_event->service_list, properties[i].val, properties[i].len);
816 uuids_event->num = num_uuid;
818 /* Application has requested this property SET/GET hence send EVENT */
819 send_event(OAL_EVENT_ADAPTER_PROPERTY_SERVICES,
820 uuids_event, (sizeof(event_adapter_services_t) + num_uuid * sizeof(bt_uuid_t)));
824 case BT_PROPERTY_ADAPTER_SCAN_MODE: {
825 bt_scan_mode_t cur_mode = *((bt_scan_mode_t *)properties[i].val);
827 BT_INFO("Scan mode (%d)", cur_mode);
829 scan_mode = cur_mode;
831 /* Send event to application */
832 if (num_properties == 1) {
833 oal_event_t event = OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE;
835 if (BT_SCAN_MODE_CONNECTABLE == cur_mode)
836 event = OAL_EVENT_ADAPTER_MODE_CONNECTABLE;
837 else if (BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE == cur_mode)
838 event = OAL_EVENT_ADAPTER_MODE_DISCOVERABLE;
840 /* Application has requested this property SET/GET hence send EVENT */
841 send_event(event, NULL, 0);
845 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: {
848 timeout = *((uint32_t*)properties[i].val);
850 BT_INFO("Discoverability timeout: %d", timeout);
851 discoverable_timeout = timeout;
853 send_event(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT,
854 g_memdup(properties[i].val, sizeof(uint32_t)),
858 case BT_PROPERTY_ADAPTER_BONDED_DEVICES: {
861 bt_bdaddr_t *bonded_addr_list;
862 event_device_list_t *event_data;
864 num_bonded = properties[i].len/sizeof(bt_bdaddr_t);
865 BT_DBG("num_bonded %d", num_bonded);
867 if (num_properties > 1) /* No explicit req for this prop, ignore */
870 bonded_addr_list = properties[i].val;
871 event_data = g_malloc(sizeof(event_device_list_t) + num_bonded*sizeof(bt_address_t));
872 event_data->num = num_bonded;
874 for (j = 0; j < num_bonded; j++)
875 memcpy(event_data->devices[j].addr, bonded_addr_list[j].address, 6);
877 send_event(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST,
878 event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
881 case BT_PROPERTY_LOCAL_LE_FEATURES: {
882 event_adapter_le_features_t *le_features;
884 le_features = g_malloc(sizeof(event_adapter_le_features_t));
886 le_features->max_adv_instance = ((bt_local_le_features_t *)(properties[i].val))->max_adv_instance;
887 le_features->rpa_offloading = ((bt_local_le_features_t *)(properties[i].val))->rpa_offload_supported;
888 le_features->max_adv_filter = ((bt_local_le_features_t *)(properties[i].val))->max_adv_filter_supported;
889 le_features->le_2m_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
890 le_features->le_coded_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
892 BT_INFO("LE 2M PHY Support (%d)", le_features->le_2m_phy_support);
893 BT_INFO("LE CODED PHY Support (%d)", le_features->le_coded_phy_support);
895 send_event(OAL_EVENT_BLE_LOCAL_FEATURES,
897 sizeof(event_adapter_le_features_t));
901 BT_WARN("Unhandled property: %d", properties[i].type);
907 static void cb_adapter_discovery_state_changed(bt_discovery_state_t state)
911 event = (BT_DISCOVERY_STARTED == state) ? OAL_EVENT_ADAPTER_INQUIRY_STARTED : OAL_EVENT_ADAPTER_INQUIRY_FINISHED;
914 send_event(event, NULL, 0);
917 static void cb_adapter_device_found(int num_properties, bt_property_t *properties)
919 remote_device_t dev_info;
920 ble_adv_data_t adv_info;
926 if (num_properties == 0) {
927 BT_ERR("Unexpected, properties count is zero!!");
931 memset(&dev_info, 0x00, sizeof(remote_device_t));
932 memset(&adv_info, 0x00, sizeof(ble_adv_data_t));
934 print_bt_properties(num_properties, properties);
935 parse_device_properties(num_properties, properties, &dev_info, &adv_info);
937 BT_INFO("number of properties= [%d] ", num_properties);
939 if (dev_info.type != DEV_TYPE_BREDR) {
940 /* BLE Single or DUAL mode found, so it should have Adv data */
941 event_ble_dev_found_t * ble_dev_event = g_new0(event_ble_dev_found_t, 1);
943 ble_dev_event->adv_len = adv_info.len;
945 if (adv_info.len > 0 && adv_info.adv_data) {
946 memcpy(ble_dev_event->adv_data, adv_info.adv_data, adv_info.len);
947 ble_dev_event->adv_len = adv_info.len;
949 ble_dev_event->adv_len = 0;
951 ble_dev_event->device_info = dev_info;
953 event_data = ble_dev_event;
954 size = sizeof(event_ble_dev_found_t);
955 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE;
957 /* BREDR device, so No Adv data */
958 event_dev_found_t * dev_event = g_new0(event_dev_found_t, 1);
960 memcpy(dev_event, &dev_info, sizeof(remote_device_t));
961 event_data = dev_event;
962 size = sizeof(remote_device_t);
963 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY;
966 send_event(event, event_data, size);