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, uint8_t *name, uint8_t *path, uint32_t fd);
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 */
140 int oal_set_adapter_request_state(int enable)
142 return blued_api->set_hal_adapter_request_state(enable);
145 int oal_set_le_request_state(int enable)
147 return blued_api->set_hal_le_request_state(enable);
151 oal_status_t adapter_enable(void)
153 int ret = BT_STATUS_SUCCESS;
157 if (blued_api == NULL) {
158 BT_INFO("Stack is initializing, so pending enable");
159 g_timeout_add(200, retry_enable_adapter, NULL);
160 return OAL_STATUS_PENDING;
163 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
164 g_timeout_add(200, retry_enable_adapter, NULL);
165 return OAL_STATUS_PENDING;
168 ret = blued_api->enable();
170 if (ret != BT_STATUS_SUCCESS) {
171 BT_ERR("Enable failed: [%s]", status2string(ret));
172 return convert_to_oal_status(ret);
175 return OAL_STATUS_SUCCESS;
178 oal_status_t adapter_disable(void)
184 CHECK_OAL_INITIALIZED();
186 ret = blued_api->disable();
188 if (ret != BT_STATUS_SUCCESS) {
189 BT_ERR("Disable failed: [%s]", status2string(ret));
190 return convert_to_oal_status(ret);
192 return OAL_STATUS_SUCCESS;
195 oal_status_t le_enable(void)
197 int ret = BT_STATUS_SUCCESS;
200 CHECK_OAL_INITIALIZED();
203 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
204 g_timeout_add(200, retry_enable_le, NULL);
205 return OAL_STATUS_PENDING;
208 ret = blued_api->le_enable();
210 if (ret != BT_STATUS_SUCCESS) {
211 BT_ERR("Enable failed: [%s]", status2string(ret));
212 return convert_to_oal_status(ret);
215 BT_INFO("Not Supported");
216 ret = OAL_STATUS_NOT_SUPPORT;
222 oal_status_t le_disable(void)
228 CHECK_OAL_INITIALIZED();
231 ret = blued_api->le_disable();
233 if (ret != BT_STATUS_SUCCESS) {
234 BT_ERR("Disable failed: [%s]", status2string(ret));
235 return convert_to_oal_status(ret);
238 BT_INFO("Not Supported");
239 ret = OAL_STATUS_NOT_SUPPORT;
244 oal_status_t le_init(void)
246 int ret = BT_STATUS_SUCCESS;
248 CHECK_OAL_INITIALIZED();
250 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
251 g_timeout_add(200, retry_enable_le, NULL);
252 return OAL_STATUS_PENDING;
254 ret = blued_api->le_init();
255 if (ret != BT_STATUS_SUCCESS) {
256 BT_ERR("Enable failed: [%s]", status2string(ret));
257 return convert_to_oal_status(ret);
260 BT_INFO("Not Supported");
261 ret = OAL_STATUS_NOT_SUPPORT;
265 oal_status_t le_deinit(void)
267 int ret = BT_STATUS_SUCCESS;
269 CHECK_OAL_INITIALIZED();
271 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
272 g_timeout_add(200, retry_enable_le, NULL);
273 return OAL_STATUS_PENDING;
275 blued_api->le_deinit();
277 BT_INFO("Not Supported");
278 ret = OAL_STATUS_NOT_SUPPORT;
282 oal_status_t is_advertising(void)
284 int ret = BT_STATUS_SUCCESS;
286 CHECK_OAL_INITIALIZED();
288 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
289 g_timeout_add(200, retry_enable_le, NULL);
290 return OAL_STATUS_PENDING;
292 int r = blued_api->is_advertising();
294 ret = BT_STATUS_SUCCESS;
296 ret = BT_STATUS_FAIL;
298 BT_INFO("Not Supported");
299 ret = OAL_STATUS_NOT_SUPPORT;
303 oal_status_t adapter_start_custom_inquiry(discovery_type_t disc_type)
309 CHECK_OAL_INITIALIZED();
310 BT_INFO("Custom Discovery Type [0x%x]", disc_type);
313 ret = blued_api->start_custom_discovery(disc_type);
314 if (ret != BT_STATUS_SUCCESS) {
315 BT_ERR("start_custom_discovery failed: [%s]", status2string(ret));
316 return convert_to_oal_status(ret);
319 BT_INFO("Not Supported");
320 ret = OAL_STATUS_NOT_SUPPORT;
325 oal_status_t adapter_get_powered_status(gboolean *status)
328 unsigned char powered = 0;
332 CHECK_OAL_INITIALIZED();
334 OAL_CHECK_PARAMETER(status, return);
335 BT_INFO("Get Adapter Powered status");
338 ret = blued_api->get_adapter_powered_status(&powered);
339 if (ret != BT_STATUS_SUCCESS) {
340 BT_ERR("adapter_get_powered_status failed: [%s]", status2string(ret));
342 return convert_to_oal_status(ret);
349 BT_INFO("Not Supported");
350 ret = OAL_STATUS_NOT_SUPPORT;
355 oal_status_t adapter_reset(void)
361 CHECK_OAL_INITIALIZED();
362 BT_INFO("Adapter Reset");
365 ret = blued_api->reset();
366 if (ret != BT_STATUS_SUCCESS) {
367 BT_ERR("Adapter Reset failed: [%s]", status2string(ret));
368 return convert_to_oal_status(ret);
371 BT_INFO("Not Supported");
372 ret = OAL_STATUS_NOT_SUPPORT;
377 oal_status_t adapter_start_inquiry(unsigned short duration)
383 CHECK_OAL_INITIALIZED();
385 ret = blued_api->start_discovery();
386 if (ret != BT_STATUS_SUCCESS) {
387 BT_ERR("start_discovery failed: [%s]", status2string(ret));
388 return convert_to_oal_status(ret);
391 return OAL_STATUS_SUCCESS;
394 oal_status_t adapter_stop_inquiry(void)
400 CHECK_OAL_INITIALIZED();
402 ret = blued_api->cancel_discovery();
403 if (ret != BT_STATUS_SUCCESS) {
404 BT_ERR("cancel_discovery failed: [%s]", status2string(ret));
405 return convert_to_oal_status(ret);
408 return OAL_STATUS_SUCCESS;
411 /* Callbacks from Stack */
412 static void cb_adapter_state_change(bt_state_t status)
417 event = (BT_STATE_ON == status) ? OAL_EVENT_ADAPTER_ENABLED : OAL_EVENT_ADAPTER_DISABLED;
419 send_event(event, NULL, 0);
423 /* Callbacks from Stack */
424 static void cb_ble_state_change(bt_state_t status)
429 event = (BT_STATE_ON == status) ? OAL_EVENT_BLE_ENABLED : OAL_EVENT_BLE_DISABLED;
431 send_event(event, NULL, 0);
435 static gboolean retry_enable_adapter(gpointer data)
442 static gboolean retry_enable_le(gpointer data)
448 oal_status_t adapter_get_properties(void)
453 CHECK_OAL_INITIALIZED();
455 ret = blued_api->get_adapter_properties();
456 if (ret != BT_STATUS_SUCCESS) {
457 BT_ERR("get_adapter_properties failed: [%s]", status2string(ret));
458 return convert_to_oal_status(ret);
461 return OAL_STATUS_SUCCESS;
464 oal_status_t adapter_get_address(void)
469 CHECK_OAL_INITIALIZED();
471 ret = blued_api->get_adapter_property(BT_PROPERTY_BDADDR);
472 if (ret != BT_STATUS_SUCCESS) {
473 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
474 return convert_to_oal_status(ret);
477 return OAL_STATUS_SUCCESS;
480 oal_status_t adapter_get_version(void)
485 CHECK_OAL_INITIALIZED();
487 ret = blued_api->get_adapter_property(BT_PROPERTY_VERSION);
488 if (ret != BT_STATUS_SUCCESS) {
489 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
490 return convert_to_oal_status(ret);
493 return OAL_STATUS_SUCCESS;
496 oal_status_t adapter_get_name(void)
500 CHECK_OAL_INITIALIZED();
504 ret = blued_api->get_adapter_property(BT_PROPERTY_BDNAME);
505 if (ret != BT_STATUS_SUCCESS) {
506 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
507 return convert_to_oal_status(ret);
510 return OAL_STATUS_SUCCESS;
513 oal_status_t adapter_set_name(char * name)
518 CHECK_OAL_INITIALIZED();
520 OAL_CHECK_PARAMETER(name, return);
521 API_TRACE("Name: %s", name);
523 prop.type = BT_PROPERTY_BDNAME;
524 prop.len = strlen(name);
527 ret = blued_api->set_adapter_property(&prop);
528 if (ret != BT_STATUS_SUCCESS) {
529 BT_ERR("set_adapter_property: [%s]", status2string(ret));
530 ret = OAL_STATUS_INTERNAL_ERROR;
532 ret = OAL_STATUS_SUCCESS;
537 oal_status_t adapter_is_discoverable(int *p_discoverable)
539 OAL_CHECK_PARAMETER(p_discoverable, return);
541 *p_discoverable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
543 API_TRACE("%d", *p_discoverable);
545 return OAL_STATUS_SUCCESS;
548 oal_status_t adapter_is_connectable(int *p_connectable)
550 OAL_CHECK_PARAMETER(p_connectable, return);
552 *p_connectable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
553 || (scan_mode == BT_SCAN_MODE_CONNECTABLE);
555 API_TRACE("%d", *p_connectable);
557 return OAL_STATUS_SUCCESS;
560 oal_status_t adapter_get_discoverable_timeout(int *p_timeout)
562 API_TRACE("%d", discoverable_timeout);
564 *p_timeout = discoverable_timeout;
566 return OAL_STATUS_SUCCESS;
569 oal_status_t adapter_get_service_uuids(void)
573 CHECK_OAL_INITIALIZED();
576 ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
577 if (ret != BT_STATUS_SUCCESS) {
578 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
579 return convert_to_oal_status(ret);
581 return OAL_STATUS_SUCCESS;
584 oal_status_t adapter_get_bonded_devices(void)
588 CHECK_OAL_INITIALIZED();
592 ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
593 if (ret != BT_STATUS_SUCCESS) {
594 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
595 return convert_to_oal_status(ret);
598 return OAL_STATUS_SUCCESS;
601 static oal_status_t set_scan_mode(bt_scan_mode_t mode)
608 CHECK_OAL_INITIALIZED();
610 prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
611 prop.len = sizeof(bt_scan_mode_t);
613 res = blued_api->set_adapter_property(&prop);
614 if (res != BT_STATUS_SUCCESS) {
615 BT_ERR("set scan mode failed [%s]", status2string(res));
616 return convert_to_oal_status(res);
620 return OAL_STATUS_SUCCESS;
623 oal_status_t adapter_set_connectable(int connectable)
627 API_TRACE("%d", connectable);
629 CHECK_OAL_INITIALIZED();
631 mode = connectable ? BT_SCAN_MODE_CONNECTABLE : BT_SCAN_MODE_NONE;
633 return set_scan_mode(mode);
636 oal_status_t adapter_set_discoverable(void)
638 CHECK_OAL_INITIALIZED();
641 return set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
644 oal_status_t adapter_set_discoverable_timeout(int timeout)
648 uint32_t prop_val = timeout;
650 CHECK_OAL_INITIALIZED();
651 API_TRACE("%d", timeout);
653 prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
654 prop.len = sizeof(prop_val);
655 prop.val = &prop_val;
656 res = blued_api->set_adapter_property(&prop);
657 if (res != BT_STATUS_SUCCESS) {
658 BT_ERR("set_adapter_property failed [%s]", status2string(res));
659 return convert_to_oal_status(res);
661 return OAL_STATUS_SUCCESS;
664 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
665 int adv_type, int chnl_map, int tx_power, int timeout_s)
668 CHECK_OAL_INITIALIZED();
671 res = gatts_multi_adv_update(Ins_id, min_intv, max_intv,
672 adv_type, chnl_map, tx_power, timeout_s);
673 if (res != OAL_STATUS_SUCCESS) {
674 BT_ERR("gatts_multi_adv_update: [%d]", res);
677 return OAL_STATUS_SUCCESS;
680 oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id,
681 oal_ble_multi_adv_param_setup_t * adv_param_setup)
684 CHECK_OAL_INITIALIZED();
685 OAL_CHECK_PARAMETER(adv_param_setup, return);
689 res = gatts_multi_adv_set_inst_data(instance_id, adv_param_setup);
690 if (res != OAL_STATUS_SUCCESS) {
691 BT_ERR("failed: [%d]", res);
694 return OAL_STATUS_SUCCESS;
697 oal_status_t adapter_ble_multi_adv_enable(int instance_id)
700 CHECK_OAL_INITIALIZED();
703 res = gatts_multi_adv_enable(instance_id);
704 if (res != OAL_STATUS_SUCCESS) {
705 BT_ERR("failed: [%d]", res);
709 return OAL_STATUS_SUCCESS;
712 oal_status_t adapter_ble_multi_adv_disable(int instance_id)
715 CHECK_OAL_INITIALIZED();
718 res = gatts_multi_adv_disable(instance_id);
719 if (res != OAL_STATUS_SUCCESS) {
720 BT_ERR("failed: [%d]", res);
724 return OAL_STATUS_SUCCESS;
727 oal_status_t adapter_set_le_static_random_address(int enable)
731 CHECK_OAL_INITIALIZED();
732 API_TRACE("%d", enable);
735 ret = blued_api->set_le_static_random_address((enable ? 1 : 0));
736 if (ret != BT_STATUS_SUCCESS)
737 BT_ERR("Static address set failed: [%s]", status2string(ret));
738 ret = convert_to_oal_status(ret);
740 BT_INFO("Not Supported");
741 ret = OAL_STATUS_NOT_SUPPORT;
747 oal_status_t adapter_set_manufacturer_data(oal_manufacturer_data_t *m_data)
751 CHECK_OAL_INITIALIZED();
754 OAL_CHECK_PARAMETER(m_data, return);
755 ret = blued_api->adapter_le_set_manufacturer_data((bt_manufacturer_data_t*)m_data);
756 if (ret != BT_STATUS_SUCCESS)
757 BT_ERR("Setting manufacturer data Failed: [%s]",status2string(ret));
759 ret = convert_to_oal_status(ret);
763 oal_status_t adapter_set_white_list(bt_address_t *device_address, int address_type, bool is_add)
768 CHECK_OAL_INITIALIZED();
771 BT_INFO("BT remote device Address: %s", bdt_bd2str(device_address, &bdstr));
773 ret = blued_api->adapter_le_set_white_list((bt_bdaddr_t*)device_address, address_type, is_add);
774 if (ret != BT_STATUS_SUCCESS) {
776 BT_ERR("Add to White List Failed: [%s]",status2string(ret));
778 BT_ERR("Remove from White List Failed: [%s]",status2string(ret));
780 ret = convert_to_oal_status(ret);
784 oal_status_t adapter_ble_set_privacy(int set_privacy)
788 CHECK_OAL_INITIALIZED();
791 res = blued_api->adapter_le_set_privacy(set_privacy);
792 if (res != BT_STATUS_SUCCESS)
793 BT_ERR("Setting LE Privacy Failed: [%s]", status2string(res));
794 res = convert_to_oal_status(res);
799 static void cb_adapter_properties(bt_status_t status,
801 bt_property_t *properties)
805 BT_DBG("status: %d, count: %d", status, num_properties);
807 print_bt_properties(num_properties, properties);
809 if (status != BT_STATUS_SUCCESS) {
810 if (num_properties == 1) {
811 BT_ERR("Adapter Prop failed: status: [%s], count: %d, prop: %d",
812 status2string(status), num_properties, properties[num_properties-1].type);
814 BT_ERR("Adapter Prop failed: status: [%s], count: %d", status2string(status), num_properties);
819 for (i = 0; i < num_properties; i++) {
820 BT_DBG("prop type %d, len %d", properties[i].type, properties[i].len);
821 switch (properties[i].type) {
822 case BT_PROPERTY_VERSION: {
823 g_strlcpy(local_version, properties[i].val, BT_VERSION_STR_LEN_MAX);
824 local_version[properties[i].len] = '\0';
826 BT_DBG("Version: %s", local_version);
827 /* Send event to application */
828 if (num_properties == 1) {
829 char *adapter_ver = g_strdup(local_version);
831 /* Application has requested this property SET/GET hence send EVENT */
832 send_event(OAL_EVENT_ADAPTER_PROPERTY_VERSION, adapter_ver, strlen(adapter_ver));
836 case BT_PROPERTY_BDNAME: {
837 g_strlcpy(local_name, properties[i].val, BT_DEVICE_NAME_LENGTH_MAX);
838 local_name[properties[i].len] = '\0';
840 BT_DBG("Name: %s", local_name);
841 /* Send event to application */
842 if (num_properties == 1) {
843 char * adap_name = g_strdup(local_name);
845 /* Application has requested this property SET/GET hence send EVENT */
846 send_event(OAL_EVENT_ADAPTER_PROPERTY_NAME, adap_name, strlen(adap_name)+1);
850 case BT_PROPERTY_BDADDR: {
853 addr = properties[i].val;
854 memcpy(local_address.addr, addr->address, 6);
855 if (num_properties == 1) {
856 /* Application has requested this property SET/GET hence send EVENT */
857 send_event(OAL_EVENT_ADAPTER_PROPERTY_ADDRESS,
858 g_memdup(&local_address, sizeof(local_address)),
859 sizeof(local_address));
863 case BT_PROPERTY_UUIDS: {
866 num_uuid = properties[i].len/sizeof(bt_uuid_t);
868 BT_DBG("num_uuid: %d", num_uuid);
870 /* Send event to application */
871 if (num_properties == 1) {
872 event_adapter_services_t *uuids_event;
874 uuids_event = g_malloc(sizeof(event_adapter_services_t) + properties[i].len);
875 memcpy(uuids_event->service_list, properties[i].val, properties[i].len);
876 uuids_event->num = num_uuid;
878 /* Application has requested this property SET/GET hence send EVENT */
879 send_event(OAL_EVENT_ADAPTER_PROPERTY_SERVICES,
880 uuids_event, (sizeof(event_adapter_services_t) + num_uuid * sizeof(bt_uuid_t)));
884 case BT_PROPERTY_ADAPTER_SCAN_MODE: {
885 bt_scan_mode_t cur_mode = *((bt_scan_mode_t *)properties[i].val);
887 BT_INFO("Scan mode (%d)", cur_mode);
889 scan_mode = cur_mode;
891 /* Send event to application */
892 if (num_properties == 1) {
893 oal_event_t event = OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE;
895 if (BT_SCAN_MODE_CONNECTABLE == cur_mode)
896 event = OAL_EVENT_ADAPTER_MODE_CONNECTABLE;
897 else if (BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE == cur_mode)
898 event = OAL_EVENT_ADAPTER_MODE_DISCOVERABLE;
900 /* Application has requested this property SET/GET hence send EVENT */
901 send_event(event, NULL, 0);
905 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: {
908 timeout = *((uint32_t*)properties[i].val);
910 BT_INFO("Discoverability timeout: %d", timeout);
911 discoverable_timeout = timeout;
913 send_event(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT,
914 g_memdup(properties[i].val, sizeof(uint32_t)),
918 case BT_PROPERTY_ADAPTER_BONDED_DEVICES: {
921 bt_bdaddr_t *bonded_addr_list;
922 event_device_list_t *event_data;
924 num_bonded = properties[i].len/sizeof(bt_bdaddr_t);
925 BT_DBG("num_bonded %d", num_bonded);
927 if (num_properties > 1) /* No explicit req for this prop, ignore */
930 bonded_addr_list = properties[i].val;
931 event_data = g_malloc(sizeof(event_device_list_t) + num_bonded*sizeof(bt_address_t));
932 event_data->num = num_bonded;
934 for (j = 0; j < num_bonded; j++)
935 memcpy(event_data->devices[j].addr, bonded_addr_list[j].address, 6);
937 send_event(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST,
938 event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
941 case BT_PROPERTY_A2DP_ROLE: {
942 unsigned int a2dp_role;
944 a2dp_role = *((uint32_t*)properties[i].val);
946 BT_INFO("A2DP role: %u", a2dp_role);
948 send_event(OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE,
949 g_memdup(properties[i].val, sizeof(uint32_t)),
953 case BT_PROPERTY_LOCAL_LE_FEATURES: {
954 event_adapter_le_features_t *le_features;
956 le_features = g_malloc(sizeof(event_adapter_le_features_t));
958 le_features->max_adv_instance = ((bt_local_le_features_t *)(properties[i].val))->max_adv_instance;
959 le_features->rpa_offloading = ((bt_local_le_features_t *)(properties[i].val))->rpa_offload_supported;
960 le_features->max_adv_filter = ((bt_local_le_features_t *)(properties[i].val))->max_adv_filter_supported;
961 le_features->le_2m_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
962 le_features->le_coded_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
964 BT_INFO("LE 2M PHY Support (%d)", le_features->le_2m_phy_support);
965 BT_INFO("LE CODED PHY Support (%d)", le_features->le_coded_phy_support);
967 send_event(OAL_EVENT_BLE_LOCAL_FEATURES,
969 sizeof(event_adapter_le_features_t));
972 case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STARTED: {
973 BT_INFO("LE Discovery started");
974 send_event(OAL_EVENT_BLE_DISCOVERY_STARTED, NULL, 0);
977 case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STOPPED: {
978 BT_INFO("LE Discovery stopped");
979 send_event(OAL_EVENT_BLE_DISCOVERY_STOPPED, NULL, 0);
983 BT_WARN("Unhandled property: %d", properties[i].type);
989 static void cb_adapter_discovery_state_changed(bt_discovery_state_t state)
993 event = (BT_DISCOVERY_STARTED == state) ? OAL_EVENT_ADAPTER_INQUIRY_STARTED : OAL_EVENT_ADAPTER_INQUIRY_FINISHED;
996 send_event(event, NULL, 0);
999 static void cb_adapter_device_found(int num_properties, bt_property_t *properties)
1001 remote_device_t dev_info;
1002 ble_adv_data_t adv_info;
1004 gpointer event_data;
1008 if (num_properties == 0) {
1009 BT_ERR("Unexpected, properties count is zero!!");
1013 memset(&dev_info, 0x00, sizeof(remote_device_t));
1014 memset(&adv_info, 0x00, sizeof(ble_adv_data_t));
1016 print_bt_properties(num_properties, properties);
1017 parse_device_properties(num_properties, properties, &dev_info, &adv_info);
1019 BT_INFO("number of properties= [%d] ", num_properties);
1021 if (dev_info.type != DEV_TYPE_BREDR) {
1022 /* BLE Single or DUAL mode found, so it should have Adv data */
1023 event_ble_dev_found_t * ble_dev_event = g_new0(event_ble_dev_found_t, 1);
1025 ble_dev_event->adv_len = adv_info.len;
1027 if (adv_info.len > 0 && adv_info.adv_data) {
1028 memcpy(ble_dev_event->adv_data, adv_info.adv_data, adv_info.len);
1029 ble_dev_event->adv_len = adv_info.len;
1031 ble_dev_event->adv_len = 0;
1033 ble_dev_event->device_info = dev_info;
1035 event_data = ble_dev_event;
1036 size = sizeof(event_ble_dev_found_t);
1037 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE;
1039 /* BREDR device, so No Adv data */
1040 event_dev_found_t * dev_event = g_new0(event_dev_found_t, 1);
1042 memcpy(dev_event, &dev_info, sizeof(remote_device_t));
1043 event_data = dev_event;
1044 size = sizeof(remote_device_t);
1045 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY;
1048 send_event(event, event_data, size);