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_recover(void)
383 CHECK_OAL_INITIALIZED();
384 BT_INFO("Adapter Recover");
386 result = blued_api->recover();
387 if (result != BT_STATUS_SUCCESS) {
388 BT_ERR("Adapter Recover Failed: [%s]", status2string(result));
389 return convert_to_oal_status(result);
395 oal_status_t adapter_start_inquiry(unsigned short duration)
401 CHECK_OAL_INITIALIZED();
403 ret = blued_api->start_discovery();
404 if (ret != BT_STATUS_SUCCESS) {
405 BT_ERR("start_discovery failed: [%s]", status2string(ret));
406 return convert_to_oal_status(ret);
409 return OAL_STATUS_SUCCESS;
412 oal_status_t adapter_stop_inquiry(void)
418 CHECK_OAL_INITIALIZED();
420 ret = blued_api->cancel_discovery();
421 if (ret != BT_STATUS_SUCCESS) {
422 BT_ERR("cancel_discovery failed: [%s]", status2string(ret));
423 return convert_to_oal_status(ret);
426 return OAL_STATUS_SUCCESS;
429 /* Callbacks from Stack */
430 static void cb_adapter_state_change(bt_state_t status)
435 event = (BT_STATE_ON == status) ? OAL_EVENT_ADAPTER_ENABLED : OAL_EVENT_ADAPTER_DISABLED;
437 send_event(event, NULL, 0);
441 /* Callbacks from Stack */
442 static void cb_ble_state_change(bt_state_t status)
447 event = (BT_STATE_ON == status) ? OAL_EVENT_BLE_ENABLED : OAL_EVENT_BLE_DISABLED;
449 send_event(event, NULL, 0);
453 static gboolean retry_enable_adapter(gpointer data)
460 static gboolean retry_enable_le(gpointer data)
466 oal_status_t adapter_get_properties(void)
471 CHECK_OAL_INITIALIZED();
473 ret = blued_api->get_adapter_properties();
474 if (ret != BT_STATUS_SUCCESS) {
475 BT_ERR("get_adapter_properties failed: [%s]", status2string(ret));
476 return convert_to_oal_status(ret);
479 return OAL_STATUS_SUCCESS;
482 oal_status_t adapter_get_address(void)
487 CHECK_OAL_INITIALIZED();
489 ret = blued_api->get_adapter_property(BT_PROPERTY_BDADDR);
490 if (ret != BT_STATUS_SUCCESS) {
491 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
492 return convert_to_oal_status(ret);
495 return OAL_STATUS_SUCCESS;
498 oal_status_t adapter_get_version(void)
503 CHECK_OAL_INITIALIZED();
505 ret = blued_api->get_adapter_property(BT_PROPERTY_VERSION);
506 if (ret != BT_STATUS_SUCCESS) {
507 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
508 return convert_to_oal_status(ret);
511 return OAL_STATUS_SUCCESS;
514 oal_status_t adapter_get_name(void)
518 CHECK_OAL_INITIALIZED();
522 ret = blued_api->get_adapter_property(BT_PROPERTY_BDNAME);
523 if (ret != BT_STATUS_SUCCESS) {
524 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
525 return convert_to_oal_status(ret);
528 return OAL_STATUS_SUCCESS;
531 oal_status_t adapter_set_name(char * name)
536 CHECK_OAL_INITIALIZED();
538 OAL_CHECK_PARAMETER(name, return);
539 API_TRACE("Name: %s", name);
541 prop.type = BT_PROPERTY_BDNAME;
542 prop.len = strlen(name);
545 ret = blued_api->set_adapter_property(&prop);
546 if (ret != BT_STATUS_SUCCESS) {
547 BT_ERR("set_adapter_property: [%s]", status2string(ret));
548 ret = OAL_STATUS_INTERNAL_ERROR;
550 ret = OAL_STATUS_SUCCESS;
555 oal_status_t adapter_is_discoverable(int *p_discoverable)
557 OAL_CHECK_PARAMETER(p_discoverable, return);
559 *p_discoverable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
561 API_TRACE("%d", *p_discoverable);
563 return OAL_STATUS_SUCCESS;
566 oal_status_t adapter_is_connectable(int *p_connectable)
568 OAL_CHECK_PARAMETER(p_connectable, return);
570 *p_connectable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
571 || (scan_mode == BT_SCAN_MODE_CONNECTABLE);
573 API_TRACE("%d", *p_connectable);
575 return OAL_STATUS_SUCCESS;
578 oal_status_t adapter_get_discoverable_timeout(int *p_timeout)
580 API_TRACE("%d", discoverable_timeout);
582 *p_timeout = discoverable_timeout;
584 return OAL_STATUS_SUCCESS;
587 oal_status_t adapter_get_service_uuids(void)
591 CHECK_OAL_INITIALIZED();
594 ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
595 if (ret != BT_STATUS_SUCCESS) {
596 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
597 return convert_to_oal_status(ret);
599 return OAL_STATUS_SUCCESS;
602 oal_status_t adapter_get_bonded_devices(void)
606 CHECK_OAL_INITIALIZED();
610 ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
611 if (ret != BT_STATUS_SUCCESS) {
612 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
613 return convert_to_oal_status(ret);
616 return OAL_STATUS_SUCCESS;
619 static oal_status_t set_scan_mode(bt_scan_mode_t mode)
626 CHECK_OAL_INITIALIZED();
628 prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
629 prop.len = sizeof(bt_scan_mode_t);
631 res = blued_api->set_adapter_property(&prop);
632 if (res != BT_STATUS_SUCCESS) {
633 BT_ERR("set scan mode failed [%s]", status2string(res));
634 return convert_to_oal_status(res);
638 return OAL_STATUS_SUCCESS;
641 oal_status_t adapter_set_connectable(int connectable)
645 API_TRACE("%d", connectable);
647 CHECK_OAL_INITIALIZED();
649 mode = connectable ? BT_SCAN_MODE_CONNECTABLE : BT_SCAN_MODE_NONE;
651 return set_scan_mode(mode);
654 oal_status_t adapter_set_discoverable(void)
656 CHECK_OAL_INITIALIZED();
659 return set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
662 oal_status_t adapter_set_discoverable_timeout(int timeout)
666 uint32_t prop_val = timeout;
668 CHECK_OAL_INITIALIZED();
669 API_TRACE("%d", timeout);
671 prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
672 prop.len = sizeof(prop_val);
673 prop.val = &prop_val;
674 res = blued_api->set_adapter_property(&prop);
675 if (res != BT_STATUS_SUCCESS) {
676 BT_ERR("set_adapter_property failed [%s]", status2string(res));
677 return convert_to_oal_status(res);
679 return OAL_STATUS_SUCCESS;
682 oal_status_t adapter_ble_set_filter_policy(int filter_policy)
684 int ret = OAL_STATUS_SUCCESS;
686 CHECK_OAL_INITIALIZED();
689 BT_DBG("Filter policy applied is [%d]", filter_policy);
691 ret = gatts_set_filter_policy(filter_policy);
693 if (ret != OAL_STATUS_SUCCESS) {
694 BT_ERR("gatts_set_filter_policy: [%d]", ret);
698 return OAL_STATUS_SUCCESS;
701 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
702 int adv_type, int chnl_map, int tx_power, int timeout_s)
705 CHECK_OAL_INITIALIZED();
708 res = gatts_multi_adv_update(Ins_id, min_intv, max_intv,
709 adv_type, chnl_map, tx_power, timeout_s);
710 if (res != OAL_STATUS_SUCCESS) {
711 BT_ERR("gatts_multi_adv_update: [%d]", res);
714 return OAL_STATUS_SUCCESS;
717 oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id,
718 oal_ble_multi_adv_param_setup_t * adv_param_setup)
721 CHECK_OAL_INITIALIZED();
722 OAL_CHECK_PARAMETER(adv_param_setup, return);
726 res = gatts_multi_adv_set_inst_data(instance_id, adv_param_setup);
727 if (res != OAL_STATUS_SUCCESS) {
728 BT_ERR("failed: [%d]", res);
731 return OAL_STATUS_SUCCESS;
734 oal_status_t adapter_ble_multi_adv_enable(int instance_id)
737 CHECK_OAL_INITIALIZED();
740 res = gatts_multi_adv_enable(instance_id);
741 if (res != OAL_STATUS_SUCCESS) {
742 BT_ERR("failed: [%d]", res);
746 return OAL_STATUS_SUCCESS;
749 oal_status_t adapter_ble_multi_adv_disable(int instance_id)
752 CHECK_OAL_INITIALIZED();
755 res = gatts_multi_adv_disable(instance_id);
756 if (res != OAL_STATUS_SUCCESS) {
757 BT_ERR("failed: [%d]", res);
761 return OAL_STATUS_SUCCESS;
764 oal_status_t adapter_set_le_static_random_address(int enable)
768 CHECK_OAL_INITIALIZED();
769 API_TRACE("%d", enable);
772 ret = blued_api->set_le_static_random_address((enable ? 1 : 0));
773 if (ret != BT_STATUS_SUCCESS)
774 BT_ERR("Static address set failed: [%s]", status2string(ret));
775 ret = convert_to_oal_status(ret);
777 BT_INFO("Not Supported");
778 ret = OAL_STATUS_NOT_SUPPORT;
784 oal_status_t adapter_set_manufacturer_data(oal_manufacturer_data_t *m_data)
788 CHECK_OAL_INITIALIZED();
791 OAL_CHECK_PARAMETER(m_data, return);
792 ret = blued_api->adapter_le_set_manufacturer_data((bt_manufacturer_data_t*)m_data);
793 if (ret != BT_STATUS_SUCCESS)
794 BT_ERR("Setting manufacturer data Failed: [%s]",status2string(ret));
796 ret = convert_to_oal_status(ret);
800 oal_status_t adapter_set_white_list(bt_address_t *device_address, int address_type, bool is_add)
805 CHECK_OAL_INITIALIZED();
808 BT_INFO("BT remote device Address: %s", bdt_bd2str(device_address, &bdstr));
810 ret = blued_api->adapter_le_set_white_list((bt_bdaddr_t*)device_address, address_type, is_add);
811 if (ret != BT_STATUS_SUCCESS) {
813 BT_ERR("Add to White List Failed: [%s]",status2string(ret));
815 BT_ERR("Remove from White List Failed: [%s]",status2string(ret));
817 ret = convert_to_oal_status(ret);
821 oal_status_t adapter_ble_set_privacy(int set_privacy)
825 CHECK_OAL_INITIALIZED();
828 res = blued_api->adapter_le_set_privacy(set_privacy);
829 if (res != BT_STATUS_SUCCESS)
830 BT_ERR("Setting LE Privacy Failed: [%s]", status2string(res));
831 res = convert_to_oal_status(res);
836 static void cb_adapter_properties(bt_status_t status,
838 bt_property_t *properties)
842 BT_DBG("status: %d, count: %d", status, num_properties);
844 print_bt_properties(num_properties, properties);
846 if (status != BT_STATUS_SUCCESS) {
847 if (num_properties == 1) {
848 BT_ERR("Adapter Prop failed: status: [%s], count: %d, prop: %d",
849 status2string(status), num_properties, properties[num_properties-1].type);
851 BT_ERR("Adapter Prop failed: status: [%s], count: %d", status2string(status), num_properties);
856 for (i = 0; i < num_properties; i++) {
857 BT_DBG("prop type %d, len %d", properties[i].type, properties[i].len);
858 switch (properties[i].type) {
859 case BT_PROPERTY_VERSION: {
860 g_strlcpy(local_version, properties[i].val, BT_VERSION_STR_LEN_MAX);
861 local_version[properties[i].len] = '\0';
863 BT_DBG("Version: %s", local_version);
864 /* Send event to application */
865 if (num_properties == 1) {
866 char *adapter_ver = g_strdup(local_version);
868 /* Application has requested this property SET/GET hence send EVENT */
869 send_event(OAL_EVENT_ADAPTER_PROPERTY_VERSION, adapter_ver, strlen(adapter_ver));
873 case BT_PROPERTY_BDNAME: {
874 g_strlcpy(local_name, properties[i].val, BT_DEVICE_NAME_LENGTH_MAX);
875 local_name[properties[i].len] = '\0';
877 BT_DBG("Name: %s", local_name);
878 /* Send event to application */
879 if (num_properties == 1) {
880 char * adap_name = g_strdup(local_name);
882 /* Application has requested this property SET/GET hence send EVENT */
883 send_event(OAL_EVENT_ADAPTER_PROPERTY_NAME, adap_name, strlen(adap_name)+1);
887 case BT_PROPERTY_BDADDR: {
890 addr = properties[i].val;
891 memcpy(local_address.addr, addr->address, 6);
892 if (num_properties == 1) {
893 /* Application has requested this property SET/GET hence send EVENT */
894 send_event(OAL_EVENT_ADAPTER_PROPERTY_ADDRESS,
895 g_memdup(&local_address, sizeof(local_address)),
896 sizeof(local_address));
900 case BT_PROPERTY_UUIDS: {
903 num_uuid = properties[i].len/sizeof(bt_uuid_t);
905 BT_DBG("num_uuid: %d", num_uuid);
907 /* Send event to application */
908 if (num_properties == 1) {
909 event_adapter_services_t *uuids_event;
911 uuids_event = g_malloc(sizeof(event_adapter_services_t) + properties[i].len);
912 memcpy(uuids_event->service_list, properties[i].val, properties[i].len);
913 uuids_event->num = num_uuid;
915 /* Application has requested this property SET/GET hence send EVENT */
916 send_event(OAL_EVENT_ADAPTER_PROPERTY_SERVICES,
917 uuids_event, (sizeof(event_adapter_services_t) + num_uuid * sizeof(bt_uuid_t)));
921 case BT_PROPERTY_ADAPTER_SCAN_MODE: {
922 bt_scan_mode_t cur_mode = *((bt_scan_mode_t *)properties[i].val);
924 BT_INFO("Scan mode (%d)", cur_mode);
926 scan_mode = cur_mode;
928 /* Send event to application */
929 if (num_properties == 1) {
930 oal_event_t event = OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE;
932 if (BT_SCAN_MODE_CONNECTABLE == cur_mode)
933 event = OAL_EVENT_ADAPTER_MODE_CONNECTABLE;
934 else if (BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE == cur_mode)
935 event = OAL_EVENT_ADAPTER_MODE_DISCOVERABLE;
937 /* Application has requested this property SET/GET hence send EVENT */
938 send_event(event, NULL, 0);
942 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: {
945 timeout = *((uint32_t*)properties[i].val);
947 BT_INFO("Discoverability timeout: %d", timeout);
948 discoverable_timeout = timeout;
950 send_event(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT,
951 g_memdup(properties[i].val, sizeof(uint32_t)),
955 case BT_PROPERTY_ADAPTER_BONDED_DEVICES: {
958 bt_bdaddr_t *bonded_addr_list;
959 event_device_list_t *event_data;
961 num_bonded = properties[i].len/sizeof(bt_bdaddr_t);
962 BT_DBG("num_bonded %d", num_bonded);
964 if (num_properties > 1) /* No explicit req for this prop, ignore */
967 bonded_addr_list = properties[i].val;
968 event_data = g_malloc(sizeof(event_device_list_t) + num_bonded*sizeof(bt_address_t));
969 event_data->num = num_bonded;
971 for (j = 0; j < num_bonded; j++)
972 memcpy(event_data->devices[j].addr, bonded_addr_list[j].address, 6);
974 send_event(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST,
975 event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
978 case BT_PROPERTY_A2DP_ROLE: {
979 unsigned int a2dp_role;
981 a2dp_role = *((uint32_t*)properties[i].val);
983 BT_INFO("A2DP role: %u", a2dp_role);
985 send_event(OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE,
986 g_memdup(properties[i].val, sizeof(uint32_t)),
990 case BT_PROPERTY_LOCAL_LE_FEATURES: {
991 event_adapter_le_features_t *le_features;
993 le_features = g_malloc(sizeof(event_adapter_le_features_t));
995 le_features->max_adv_instance = ((bt_local_le_features_t *)(properties[i].val))->max_adv_instance;
996 le_features->rpa_offloading = ((bt_local_le_features_t *)(properties[i].val))->rpa_offload_supported;
997 le_features->max_adv_filter = ((bt_local_le_features_t *)(properties[i].val))->max_adv_filter_supported;
998 le_features->le_2m_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
999 le_features->le_coded_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
1001 BT_INFO("LE 2M PHY Support (%d)", le_features->le_2m_phy_support);
1002 BT_INFO("LE CODED PHY Support (%d)", le_features->le_coded_phy_support);
1004 send_event(OAL_EVENT_BLE_LOCAL_FEATURES,
1006 sizeof(event_adapter_le_features_t));
1009 case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STARTED: {
1010 BT_INFO("LE Discovery started");
1011 send_event(OAL_EVENT_BLE_DISCOVERY_STARTED, NULL, 0);
1014 case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STOPPED: {
1015 BT_INFO("LE Discovery stopped");
1016 send_event(OAL_EVENT_BLE_DISCOVERY_STOPPED, NULL, 0);
1020 BT_WARN("Unhandled property: %d", properties[i].type);
1026 static void cb_adapter_discovery_state_changed(bt_discovery_state_t state)
1030 event = (BT_DISCOVERY_STARTED == state) ? OAL_EVENT_ADAPTER_INQUIRY_STARTED : OAL_EVENT_ADAPTER_INQUIRY_FINISHED;
1032 BT_DBG("%d", state);
1033 send_event(event, NULL, 0);
1036 static void cb_adapter_device_found(int num_properties, bt_property_t *properties)
1038 remote_device_t dev_info;
1039 ble_adv_data_t adv_info;
1041 gpointer event_data;
1045 if (num_properties == 0) {
1046 BT_ERR("Unexpected, properties count is zero!!");
1050 memset(&dev_info, 0x00, sizeof(remote_device_t));
1051 memset(&adv_info, 0x00, sizeof(ble_adv_data_t));
1053 print_bt_properties(num_properties, properties);
1054 parse_device_properties(num_properties, properties, &dev_info, &adv_info);
1056 BT_INFO("number of properties= [%d] ", num_properties);
1058 if (dev_info.type != DEV_TYPE_BREDR) {
1059 /* BLE Single or DUAL mode found, so it should have Adv data */
1060 event_ble_dev_found_t * ble_dev_event = g_new0(event_ble_dev_found_t, 1);
1062 ble_dev_event->adv_len = adv_info.len;
1064 if (adv_info.len > 0 && adv_info.adv_data) {
1065 memcpy(ble_dev_event->adv_data, adv_info.adv_data, adv_info.len);
1066 ble_dev_event->adv_len = adv_info.len;
1068 ble_dev_event->adv_len = 0;
1070 ble_dev_event->device_info = dev_info;
1072 event_data = ble_dev_event;
1073 size = sizeof(event_ble_dev_found_t);
1074 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE;
1076 /* BREDR device, so No Adv data */
1077 event_dev_found_t * dev_event = g_new0(event_dev_found_t, 1);
1079 memcpy(dev_event, &dev_info, sizeof(remote_device_t));
1080 event_data = dev_event;
1081 size = sizeof(remote_device_t);
1082 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY;
1085 send_event(event, event_data, size);