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 oal_status_t adapter_enable(void)
141 int ret = BT_STATUS_SUCCESS;
144 CHECK_OAL_INITIALIZED();
145 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
146 g_timeout_add(200, retry_enable_adapter, NULL);
147 return OAL_STATUS_PENDING;
150 ret = blued_api->enable();
152 if (ret != BT_STATUS_SUCCESS) {
153 BT_ERR("Enable failed: [%s]", status2string(ret));
154 return convert_to_oal_status(ret);
157 return OAL_STATUS_SUCCESS;
160 oal_status_t adapter_disable(void)
166 CHECK_OAL_INITIALIZED();
168 ret = blued_api->disable();
170 if (ret != BT_STATUS_SUCCESS) {
171 BT_ERR("Disable failed: [%s]", status2string(ret));
172 return convert_to_oal_status(ret);
174 return OAL_STATUS_SUCCESS;
177 oal_status_t le_enable(void)
179 int ret = BT_STATUS_SUCCESS;
182 CHECK_OAL_INITIALIZED();
185 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
186 g_timeout_add(200, retry_enable_le, NULL);
187 return OAL_STATUS_PENDING;
190 ret = blued_api->le_enable();
192 if (ret != BT_STATUS_SUCCESS) {
193 BT_ERR("Enable failed: [%s]", status2string(ret));
194 return convert_to_oal_status(ret);
197 BT_INFO("Not Supported");
198 ret = OAL_STATUS_NOT_SUPPORT;
204 oal_status_t le_disable(void)
210 CHECK_OAL_INITIALIZED();
213 ret = blued_api->le_disable();
215 if (ret != BT_STATUS_SUCCESS) {
216 BT_ERR("Disable failed: [%s]", status2string(ret));
217 return convert_to_oal_status(ret);
220 BT_INFO("Not Supported");
221 ret = OAL_STATUS_NOT_SUPPORT;
226 oal_status_t le_init(void)
228 int ret = BT_STATUS_SUCCESS;
230 CHECK_OAL_INITIALIZED();
232 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
233 g_timeout_add(200, retry_enable_le, NULL);
234 return OAL_STATUS_PENDING;
236 ret = blued_api->le_init();
237 if (ret != BT_STATUS_SUCCESS) {
238 BT_ERR("Enable failed: [%s]", status2string(ret));
239 return convert_to_oal_status(ret);
242 BT_INFO("Not Supported");
243 ret = OAL_STATUS_NOT_SUPPORT;
247 oal_status_t le_deinit(void)
249 int ret = BT_STATUS_SUCCESS;
251 CHECK_OAL_INITIALIZED();
253 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
254 g_timeout_add(200, retry_enable_le, NULL);
255 return OAL_STATUS_PENDING;
257 blued_api->le_deinit();
259 BT_INFO("Not Supported");
260 ret = OAL_STATUS_NOT_SUPPORT;
264 oal_status_t is_advertising(void)
266 int ret = BT_STATUS_SUCCESS;
268 CHECK_OAL_INITIALIZED();
270 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
271 g_timeout_add(200, retry_enable_le, NULL);
272 return OAL_STATUS_PENDING;
274 int r = blued_api->is_advertising();
276 ret = BT_STATUS_SUCCESS;
278 ret = BT_STATUS_FAIL;
280 BT_INFO("Not Supported");
281 ret = OAL_STATUS_NOT_SUPPORT;
285 oal_status_t adapter_start_custom_inquiry(discovery_type_t disc_type)
291 CHECK_OAL_INITIALIZED();
292 BT_INFO("Custom Discovery Type [0x%x]", disc_type);
295 ret = blued_api->start_custom_discovery(disc_type);
296 if (ret != BT_STATUS_SUCCESS) {
297 BT_ERR("start_custom_discovery failed: [%s]", status2string(ret));
298 return convert_to_oal_status(ret);
301 BT_INFO("Not Supported");
302 ret = OAL_STATUS_NOT_SUPPORT;
307 oal_status_t adapter_get_powered_status(gboolean *status)
310 unsigned char powered = 0;
314 CHECK_OAL_INITIALIZED();
316 OAL_CHECK_PARAMETER(status, return);
317 BT_INFO("Get Adapter Powered status");
320 ret = blued_api->get_adapter_powered_status(&powered);
321 if (ret != BT_STATUS_SUCCESS) {
322 BT_ERR("adapter_get_powered_status failed: [%s]", status2string(ret));
324 return convert_to_oal_status(ret);
331 BT_INFO("Not Supported");
332 ret = OAL_STATUS_NOT_SUPPORT;
337 oal_status_t adapter_reset(void)
343 CHECK_OAL_INITIALIZED();
344 BT_INFO("Adapter Reset");
347 ret = blued_api->reset();
348 if (ret != BT_STATUS_SUCCESS) {
349 BT_ERR("Adapter Reset failed: [%s]", status2string(ret));
350 return convert_to_oal_status(ret);
353 BT_INFO("Not Supported");
354 ret = OAL_STATUS_NOT_SUPPORT;
359 oal_status_t adapter_start_inquiry(unsigned short duration)
365 CHECK_OAL_INITIALIZED();
367 ret = blued_api->start_discovery();
368 if (ret != BT_STATUS_SUCCESS) {
369 BT_ERR("start_discovery failed: [%s]", status2string(ret));
370 return convert_to_oal_status(ret);
373 return OAL_STATUS_SUCCESS;
376 oal_status_t adapter_stop_inquiry(void)
382 CHECK_OAL_INITIALIZED();
384 ret = blued_api->cancel_discovery();
385 if (ret != BT_STATUS_SUCCESS) {
386 BT_ERR("cancel_discovery failed: [%s]", status2string(ret));
387 return convert_to_oal_status(ret);
390 return OAL_STATUS_SUCCESS;
393 /* Callbacks from Stack */
394 static void cb_adapter_state_change(bt_state_t status)
399 event = (BT_STATE_ON == status) ? OAL_EVENT_ADAPTER_ENABLED : OAL_EVENT_ADAPTER_DISABLED;
401 send_event(event, NULL, 0);
405 /* Callbacks from Stack */
406 static void cb_ble_state_change(bt_state_t status)
411 event = (BT_STATE_ON == status) ? OAL_EVENT_BLE_ENABLED : OAL_EVENT_BLE_DISABLED;
413 send_event(event, NULL, 0);
417 static gboolean retry_enable_adapter(gpointer data)
424 static gboolean retry_enable_le(gpointer data)
430 oal_status_t adapter_get_properties(void)
435 CHECK_OAL_INITIALIZED();
437 ret = blued_api->get_adapter_properties();
438 if (ret != BT_STATUS_SUCCESS) {
439 BT_ERR("get_adapter_properties failed: [%s]", status2string(ret));
440 return convert_to_oal_status(ret);
443 return OAL_STATUS_SUCCESS;
446 oal_status_t adapter_get_address(void)
451 CHECK_OAL_INITIALIZED();
453 ret = blued_api->get_adapter_property(BT_PROPERTY_BDADDR);
454 if (ret != BT_STATUS_SUCCESS) {
455 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
456 return convert_to_oal_status(ret);
459 return OAL_STATUS_SUCCESS;
462 oal_status_t adapter_get_version(void)
467 CHECK_OAL_INITIALIZED();
469 ret = blued_api->get_adapter_property(BT_PROPERTY_VERSION);
470 if (ret != BT_STATUS_SUCCESS) {
471 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
472 return convert_to_oal_status(ret);
475 return OAL_STATUS_SUCCESS;
478 oal_status_t adapter_get_name(void)
482 CHECK_OAL_INITIALIZED();
486 ret = blued_api->get_adapter_property(BT_PROPERTY_BDNAME);
487 if (ret != BT_STATUS_SUCCESS) {
488 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
489 return convert_to_oal_status(ret);
492 return OAL_STATUS_SUCCESS;
495 oal_status_t adapter_set_name(char * name)
500 CHECK_OAL_INITIALIZED();
502 OAL_CHECK_PARAMETER(name, return);
503 API_TRACE("Name: %s", name);
505 prop.type = BT_PROPERTY_BDNAME;
506 prop.len = strlen(name);
509 ret = blued_api->set_adapter_property(&prop);
510 if (ret != BT_STATUS_SUCCESS) {
511 BT_ERR("set_adapter_property: [%s]", status2string(ret));
512 ret = OAL_STATUS_INTERNAL_ERROR;
514 ret = OAL_STATUS_SUCCESS;
519 oal_status_t adapter_is_discoverable(int *p_discoverable)
521 OAL_CHECK_PARAMETER(p_discoverable, return);
523 *p_discoverable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
525 API_TRACE("%d", *p_discoverable);
527 return OAL_STATUS_SUCCESS;
530 oal_status_t adapter_is_connectable(int *p_connectable)
532 OAL_CHECK_PARAMETER(p_connectable, return);
534 *p_connectable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
535 || (scan_mode == BT_SCAN_MODE_CONNECTABLE);
537 API_TRACE("%d", *p_connectable);
539 return OAL_STATUS_SUCCESS;
542 oal_status_t adapter_get_discoverable_timeout(int *p_timeout)
544 API_TRACE("%d", discoverable_timeout);
546 *p_timeout = discoverable_timeout;
548 return OAL_STATUS_SUCCESS;
551 oal_status_t adapter_get_service_uuids(void)
555 CHECK_OAL_INITIALIZED();
558 ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
559 if (ret != BT_STATUS_SUCCESS) {
560 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
561 return convert_to_oal_status(ret);
563 return OAL_STATUS_SUCCESS;
566 oal_status_t adapter_get_bonded_devices(void)
570 CHECK_OAL_INITIALIZED();
574 ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
575 if (ret != BT_STATUS_SUCCESS) {
576 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
577 return convert_to_oal_status(ret);
580 return OAL_STATUS_SUCCESS;
583 static oal_status_t set_scan_mode(bt_scan_mode_t mode)
590 CHECK_OAL_INITIALIZED();
592 prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
593 prop.len = sizeof(bt_scan_mode_t);
595 res = blued_api->set_adapter_property(&prop);
596 if (res != BT_STATUS_SUCCESS) {
597 BT_ERR("set scan mode failed [%s]", status2string(res));
598 return convert_to_oal_status(res);
602 return OAL_STATUS_SUCCESS;
605 oal_status_t adapter_set_connectable(int connectable)
609 API_TRACE("%d", connectable);
611 CHECK_OAL_INITIALIZED();
613 mode = connectable ? BT_SCAN_MODE_CONNECTABLE : BT_SCAN_MODE_NONE;
615 return set_scan_mode(mode);
618 oal_status_t adapter_set_discoverable(void)
620 CHECK_OAL_INITIALIZED();
623 return set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
626 oal_status_t adapter_set_discoverable_timeout(int timeout)
630 uint32_t prop_val = timeout;
632 CHECK_OAL_INITIALIZED();
633 API_TRACE("%d", timeout);
635 prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
636 prop.len = sizeof(prop_val);
637 prop.val = &prop_val;
638 res = blued_api->set_adapter_property(&prop);
639 if (res != BT_STATUS_SUCCESS) {
640 BT_ERR("set_adapter_property failed [%s]", status2string(res));
641 return convert_to_oal_status(res);
643 return OAL_STATUS_SUCCESS;
646 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
647 int adv_type, int chnl_map, int tx_power, int timeout_s)
650 CHECK_OAL_INITIALIZED();
653 res = gatts_multi_adv_update(Ins_id, min_intv, max_intv,
654 adv_type, chnl_map, tx_power, timeout_s);
655 if (res != OAL_STATUS_SUCCESS) {
656 BT_ERR("gatts_multi_adv_update: [%d]", res);
659 return OAL_STATUS_SUCCESS;
662 oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id,
663 oal_ble_multi_adv_param_setup_t * adv_param_setup)
666 CHECK_OAL_INITIALIZED();
667 OAL_CHECK_PARAMETER(adv_param_setup, return);
671 res = gatts_multi_adv_set_inst_data(instance_id, adv_param_setup);
672 if (res != OAL_STATUS_SUCCESS) {
673 BT_ERR("failed: [%d]", res);
676 return OAL_STATUS_SUCCESS;
679 oal_status_t adapter_ble_multi_adv_enable(int instance_id)
682 CHECK_OAL_INITIALIZED();
685 res = gatts_multi_adv_enable(instance_id);
686 if (res != OAL_STATUS_SUCCESS) {
687 BT_ERR("failed: [%d]", res);
691 return OAL_STATUS_SUCCESS;
694 oal_status_t adapter_ble_multi_adv_disable(int instance_id)
697 CHECK_OAL_INITIALIZED();
700 res = gatts_multi_adv_disable(instance_id);
701 if (res != OAL_STATUS_SUCCESS) {
702 BT_ERR("failed: [%d]", res);
706 return OAL_STATUS_SUCCESS;
709 static void cb_adapter_properties(bt_status_t status,
711 bt_property_t *properties)
715 BT_DBG("status: %d, count: %d", status, num_properties);
717 print_bt_properties(num_properties, properties);
719 if (status != BT_STATUS_SUCCESS) {
720 if (num_properties == 1) {
721 BT_ERR("Adapter Prop failed: status: [%s], count: %d, prop: %d",
722 status2string(status), num_properties, properties[num_properties-1].type);
724 BT_ERR("Adapter Prop failed: status: [%s], count: %d", status2string(status), num_properties);
729 for (i = 0; i < num_properties; i++) {
730 BT_DBG("prop type %d, len %d", properties[i].type, properties[i].len);
731 switch (properties[i].type) {
732 case BT_PROPERTY_VERSION: {
733 g_strlcpy(local_version, properties[i].val, BT_VERSION_STR_LEN_MAX);
734 local_version[properties[i].len] = '\0';
736 BT_DBG("Version: %s", local_version);
737 /* Send event to application */
738 if (num_properties == 1) {
739 char *adapter_ver = g_strdup(local_version);
741 /* Application has requested this property SET/GET hence send EVENT */
742 send_event(OAL_EVENT_ADAPTER_PROPERTY_VERSION, adapter_ver, strlen(adapter_ver));
746 case BT_PROPERTY_BDNAME: {
747 g_strlcpy(local_name, properties[i].val, BT_DEVICE_NAME_LENGTH_MAX);
748 local_name[properties[i].len] = '\0';
750 BT_DBG("Name: %s", local_name);
751 /* Send event to application */
752 if (num_properties == 1) {
753 char * adap_name = g_strdup(local_name);
755 /* Application has requested this property SET/GET hence send EVENT */
756 send_event(OAL_EVENT_ADAPTER_PROPERTY_NAME, adap_name, strlen(adap_name)+1);
760 case BT_PROPERTY_BDADDR: {
763 addr = properties[i].val;
764 memcpy(local_address.addr, addr->address, 6);
765 if (num_properties == 1) {
766 /* Application has requested this property SET/GET hence send EVENT */
767 send_event(OAL_EVENT_ADAPTER_PROPERTY_ADDRESS,
768 g_memdup(&local_address, sizeof(local_address)),
769 sizeof(local_address));
773 case BT_PROPERTY_UUIDS: {
776 num_uuid = properties[i].len/sizeof(bt_uuid_t);
778 BT_DBG("num_uuid: %d", num_uuid);
780 /* Send event to application */
781 if (num_properties == 1) {
782 event_adapter_services_t *uuids_event;
784 uuids_event = g_malloc(sizeof(event_adapter_services_t) + properties[i].len);
785 memcpy(uuids_event->service_list, properties[i].val, properties[i].len);
786 uuids_event->num = num_uuid;
788 /* Application has requested this property SET/GET hence send EVENT */
789 send_event(OAL_EVENT_ADAPTER_PROPERTY_SERVICES,
790 uuids_event, (sizeof(event_adapter_services_t) + num_uuid * sizeof(bt_uuid_t)));
794 case BT_PROPERTY_ADAPTER_SCAN_MODE: {
795 bt_scan_mode_t cur_mode = *((bt_scan_mode_t *)properties[i].val);
797 BT_INFO("Scan mode (%d)", cur_mode);
799 scan_mode = cur_mode;
801 /* Send event to application */
802 if (num_properties == 1) {
803 oal_event_t event = OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE;
805 if (BT_SCAN_MODE_CONNECTABLE == cur_mode)
806 event = OAL_EVENT_ADAPTER_MODE_CONNECTABLE;
807 else if (BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE == cur_mode)
808 event = OAL_EVENT_ADAPTER_MODE_DISCOVERABLE;
810 /* Application has requested this property SET/GET hence send EVENT */
811 send_event(event, NULL, 0);
815 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: {
818 timeout = *((uint32_t*)properties[i].val);
820 BT_INFO("Discoverability timeout: %d", timeout);
821 discoverable_timeout = timeout;
823 send_event(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT,
824 g_memdup(properties[i].val, sizeof(uint32_t)),
828 case BT_PROPERTY_ADAPTER_BONDED_DEVICES: {
831 bt_bdaddr_t *bonded_addr_list;
832 event_device_list_t *event_data;
834 num_bonded = properties[i].len/sizeof(bt_bdaddr_t);
835 BT_DBG("num_bonded %d", num_bonded);
837 if (num_properties > 1) /* No explicit req for this prop, ignore */
840 bonded_addr_list = properties[i].val;
841 event_data = g_malloc(sizeof(event_device_list_t) + num_bonded*sizeof(bt_address_t));
842 event_data->num = num_bonded;
844 for (j = 0; j < num_bonded; j++)
845 memcpy(event_data->devices[j].addr, bonded_addr_list[j].address, 6);
847 send_event(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST,
848 event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
851 case BT_PROPERTY_LOCAL_LE_FEATURES: {
852 event_adapter_le_features_t *le_features;
854 le_features = g_malloc(sizeof(event_adapter_le_features_t));
856 le_features->max_adv_instance = ((bt_local_le_features_t *)(properties[i].val))->max_adv_instance;
857 le_features->rpa_offloading = ((bt_local_le_features_t *)(properties[i].val))->rpa_offload_supported;
858 le_features->max_adv_filter = ((bt_local_le_features_t *)(properties[i].val))->max_adv_filter_supported;
859 le_features->le_2m_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
860 le_features->le_coded_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
862 BT_INFO("LE 2M PHY Support (%d)", le_features->le_2m_phy_support);
863 BT_INFO("LE CODED PHY Support (%d)", le_features->le_coded_phy_support);
865 send_event(OAL_EVENT_BLE_LOCAL_FEATURES,
867 sizeof(event_adapter_le_features_t));
871 BT_WARN("Unhandled property: %d", properties[i].type);
877 static void cb_adapter_discovery_state_changed(bt_discovery_state_t state)
881 event = (BT_DISCOVERY_STARTED == state) ? OAL_EVENT_ADAPTER_INQUIRY_STARTED : OAL_EVENT_ADAPTER_INQUIRY_FINISHED;
884 send_event(event, NULL, 0);
887 static void cb_adapter_device_found(int num_properties, bt_property_t *properties)
889 remote_device_t dev_info;
890 ble_adv_data_t adv_info;
896 if (num_properties == 0) {
897 BT_ERR("Unexpected, properties count is zero!!");
901 memset(&dev_info, 0x00, sizeof(remote_device_t));
902 memset(&adv_info, 0x00, sizeof(ble_adv_data_t));
904 print_bt_properties(num_properties, properties);
905 parse_device_properties(num_properties, properties, &dev_info, &adv_info);
907 BT_INFO("number of properties= [%d] ", num_properties, size);
909 if (dev_info.type != DEV_TYPE_BREDR) {
910 /* BLE Single or DUAL mode found, so it should have Adv data */
911 event_ble_dev_found_t * ble_dev_event = g_new0(event_ble_dev_found_t, 1);
913 ble_dev_event->adv_len = adv_info.len;
915 if (adv_info.len > 0 && adv_info.adv_data) {
916 memcpy(ble_dev_event->adv_data, adv_info.adv_data, adv_info.len);
917 ble_dev_event->adv_len = adv_info.len;
919 ble_dev_event->adv_len = 0;
921 ble_dev_event->device_info = dev_info;
923 event_data = ble_dev_event;
924 size = sizeof(event_ble_dev_found_t);
925 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE;
927 /* BREDR device, so No Adv data */
928 event_dev_found_t * dev_event = g_new0(event_dev_found_t, 1);
930 memcpy(dev_event, &dev_info, sizeof(remote_device_t));
931 event_data = dev_event;
932 size = sizeof(remote_device_t);
933 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY;
936 send_event(event, event_data, size);