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);
82 extern void cb_dbfw_plus_info_received(unsigned char *data, uint32_t length, uint8_t event_code);
85 static bt_callbacks_t callbacks = {
86 .size = sizeof(callbacks),
87 .adapter_state_changed_cb = cb_adapter_state_change,
88 .adapter_properties_cb = cb_adapter_properties,
89 .remote_device_properties_cb = cb_device_properties,
90 .device_found_cb = cb_adapter_device_found,
91 .discovery_state_changed_cb = cb_adapter_discovery_state_changed,
92 .pin_request_cb = cb_device_pin_request,
93 .ssp_request_cb = cb_device_ssp_request,
94 .bond_state_changed_cb = cb_device_bond_state_changed,
95 .acl_state_changed_cb = cb_device_acl_state_changed,
96 .thread_evt_cb = NULL,
97 .dut_mode_recv_cb = NULL,
98 .le_test_mode_cb = NULL,
99 .energy_info_cb = NULL,
100 .authorize_request_cb = cb_device_authorize_request,
101 .device_trust_state_changed_cb = cb_device_trust_state_changed,
103 .socket_authorize_request_cb = cb_socket_conn_authorize_request,
104 .le_state_changed_cb = cb_ble_state_change,
105 .le_conn_state_changed_cb = cb_device_le_conn_state_changed,
106 .device_trusted_profiles_changed_cb = cb_device_trusted_profiles_changed,
107 .rssi_monitor_state_changed_cb = cb_rssi_monitor_state_changed,
108 .rssi_alert_cb = cb_rssi_alert,
109 .raw_rssi_received_cb = cb_raw_rssi_received,
110 .dbfw_plus_info_received_cb = cb_dbfw_plus_info_received,
114 oal_status_t adapter_mgr_init(const bt_interface_t * stack_if)
117 blued_api = stack_if;
119 ret = blued_api->init(&callbacks);
121 if (ret != BT_STATUS_SUCCESS) {
122 BT_ERR("Adapter callback registration failed: [%s]", status2string(ret));
123 blued_api->cleanup();
124 return convert_to_oal_status(ret);
127 return OAL_STATUS_SUCCESS;
130 const bt_interface_t* adapter_get_stack_interface(void)
135 void adapter_mgr_cleanup(void)
137 /* Nothing to clean yet , do not set blued_api NULL as it will be used to clean Bluedroid states */
142 int oal_set_adapter_request_state(int enable)
144 return blued_api->set_hal_adapter_request_state(enable);
147 int oal_set_le_request_state(int enable)
149 return blued_api->set_hal_le_request_state(enable);
153 oal_status_t adapter_enable(void)
155 int ret = BT_STATUS_SUCCESS;
159 if (blued_api == NULL) {
160 BT_INFO("Stack is initializing, so pending enable");
161 g_timeout_add(200, retry_enable_adapter, NULL);
162 return OAL_STATUS_PENDING;
165 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
166 g_timeout_add(200, retry_enable_adapter, NULL);
167 return OAL_STATUS_PENDING;
170 ret = blued_api->enable();
172 if (ret != BT_STATUS_SUCCESS) {
173 BT_ERR("Enable failed: [%s]", status2string(ret));
174 return convert_to_oal_status(ret);
177 return OAL_STATUS_SUCCESS;
180 oal_status_t adapter_disable(void)
186 CHECK_OAL_INITIALIZED();
188 ret = blued_api->disable();
190 if (ret != BT_STATUS_SUCCESS) {
191 BT_ERR("Disable failed: [%s]", status2string(ret));
192 return convert_to_oal_status(ret);
194 return OAL_STATUS_SUCCESS;
197 oal_status_t le_enable(void)
199 int ret = BT_STATUS_SUCCESS;
202 CHECK_OAL_INITIALIZED();
205 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
206 g_timeout_add(200, retry_enable_le, NULL);
207 return OAL_STATUS_PENDING;
210 ret = blued_api->le_enable();
212 if (ret != BT_STATUS_SUCCESS) {
213 BT_ERR("Enable failed: [%s]", status2string(ret));
214 return convert_to_oal_status(ret);
217 BT_INFO("Not Supported");
218 ret = OAL_STATUS_NOT_SUPPORT;
224 oal_status_t le_disable(void)
230 CHECK_OAL_INITIALIZED();
233 ret = blued_api->le_disable();
235 if (ret != BT_STATUS_SUCCESS) {
236 BT_ERR("Disable failed: [%s]", status2string(ret));
237 return convert_to_oal_status(ret);
240 BT_INFO("Not Supported");
241 ret = OAL_STATUS_NOT_SUPPORT;
246 oal_status_t le_init(void)
248 int ret = BT_STATUS_SUCCESS;
250 CHECK_OAL_INITIALIZED();
252 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
253 g_timeout_add(200, retry_enable_le, NULL);
254 return OAL_STATUS_PENDING;
256 ret = blued_api->le_init();
257 if (ret != BT_STATUS_SUCCESS) {
258 BT_ERR("Enable failed: [%s]", status2string(ret));
259 return convert_to_oal_status(ret);
262 BT_INFO("Not Supported");
263 ret = OAL_STATUS_NOT_SUPPORT;
267 oal_status_t le_deinit(void)
269 int ret = BT_STATUS_SUCCESS;
271 CHECK_OAL_INITIALIZED();
273 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
274 g_timeout_add(200, retry_enable_le, NULL);
275 return OAL_STATUS_PENDING;
277 blued_api->le_deinit();
279 BT_INFO("Not Supported");
280 ret = OAL_STATUS_NOT_SUPPORT;
284 oal_status_t is_advertising(void)
286 int ret = BT_STATUS_SUCCESS;
288 CHECK_OAL_INITIALIZED();
290 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
291 g_timeout_add(200, retry_enable_le, NULL);
292 return OAL_STATUS_PENDING;
294 int r = blued_api->is_advertising();
296 ret = BT_STATUS_SUCCESS;
298 ret = BT_STATUS_FAIL;
300 BT_INFO("Not Supported");
301 ret = OAL_STATUS_NOT_SUPPORT;
305 oal_status_t adapter_start_custom_inquiry(discovery_type_t disc_type)
311 CHECK_OAL_INITIALIZED();
312 BT_INFO("Custom Discovery Type [0x%x]", disc_type);
315 ret = blued_api->start_custom_discovery(disc_type);
316 if (ret != BT_STATUS_SUCCESS) {
317 BT_ERR("start_custom_discovery failed: [%s]", status2string(ret));
318 return convert_to_oal_status(ret);
321 BT_INFO("Not Supported");
322 ret = OAL_STATUS_NOT_SUPPORT;
327 oal_status_t adapter_get_powered_status(gboolean *status)
330 unsigned char powered = 0;
334 CHECK_OAL_INITIALIZED();
336 OAL_CHECK_PARAMETER(status, return);
337 BT_INFO("Get Adapter Powered status");
340 ret = blued_api->get_adapter_powered_status(&powered);
341 if (ret != BT_STATUS_SUCCESS) {
342 BT_ERR("adapter_get_powered_status failed: [%s]", status2string(ret));
344 return convert_to_oal_status(ret);
351 BT_INFO("Not Supported");
352 ret = OAL_STATUS_NOT_SUPPORT;
357 oal_status_t adapter_reset(void)
363 CHECK_OAL_INITIALIZED();
364 BT_INFO("Adapter Reset");
367 ret = blued_api->reset();
368 if (ret != BT_STATUS_SUCCESS) {
369 BT_ERR("Adapter Reset failed: [%s]", status2string(ret));
370 return convert_to_oal_status(ret);
373 BT_INFO("Not Supported");
374 ret = OAL_STATUS_NOT_SUPPORT;
379 oal_status_t adapter_recover(void)
385 CHECK_OAL_INITIALIZED();
386 BT_INFO("Adapter Recover");
388 result = blued_api->recover();
389 if (result != BT_STATUS_SUCCESS) {
390 BT_ERR("Adapter Recover Failed: [%s]", status2string(result));
391 return convert_to_oal_status(result);
397 oal_status_t adapter_start_inquiry(unsigned short duration)
403 CHECK_OAL_INITIALIZED();
405 ret = blued_api->start_discovery();
406 if (ret != BT_STATUS_SUCCESS) {
407 BT_ERR("start_discovery failed: [%s]", status2string(ret));
408 return convert_to_oal_status(ret);
411 return OAL_STATUS_SUCCESS;
414 oal_status_t adapter_stop_inquiry(void)
420 CHECK_OAL_INITIALIZED();
422 ret = blued_api->cancel_discovery();
423 if (ret != BT_STATUS_SUCCESS) {
424 BT_ERR("cancel_discovery failed: [%s]", status2string(ret));
425 return convert_to_oal_status(ret);
428 return OAL_STATUS_SUCCESS;
431 /* Callbacks from Stack */
432 static void cb_adapter_state_change(bt_state_t status)
437 event = (BT_STATE_ON == status) ? OAL_EVENT_ADAPTER_ENABLED : OAL_EVENT_ADAPTER_DISABLED;
439 send_event(event, NULL, 0);
443 /* Callbacks from Stack */
444 static void cb_ble_state_change(bt_state_t status)
449 event = (BT_STATE_ON == status) ? OAL_EVENT_BLE_ENABLED : OAL_EVENT_BLE_DISABLED;
451 send_event(event, NULL, 0);
455 static gboolean retry_enable_adapter(gpointer data)
462 static gboolean retry_enable_le(gpointer data)
468 oal_status_t adapter_get_properties(void)
473 CHECK_OAL_INITIALIZED();
475 ret = blued_api->get_adapter_properties();
476 if (ret != BT_STATUS_SUCCESS) {
477 BT_ERR("get_adapter_properties failed: [%s]", status2string(ret));
478 return convert_to_oal_status(ret);
481 return OAL_STATUS_SUCCESS;
484 oal_status_t adapter_get_address(void)
489 CHECK_OAL_INITIALIZED();
491 ret = blued_api->get_adapter_property(BT_PROPERTY_BDADDR);
492 if (ret != BT_STATUS_SUCCESS) {
493 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
494 return convert_to_oal_status(ret);
497 return OAL_STATUS_SUCCESS;
500 oal_status_t adapter_get_version(void)
505 CHECK_OAL_INITIALIZED();
507 ret = blued_api->get_adapter_property(BT_PROPERTY_VERSION);
508 if (ret != BT_STATUS_SUCCESS) {
509 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
510 return convert_to_oal_status(ret);
513 return OAL_STATUS_SUCCESS;
516 oal_status_t adapter_get_name(void)
520 CHECK_OAL_INITIALIZED();
524 ret = blued_api->get_adapter_property(BT_PROPERTY_BDNAME);
525 if (ret != BT_STATUS_SUCCESS) {
526 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
527 return convert_to_oal_status(ret);
530 return OAL_STATUS_SUCCESS;
533 oal_status_t adapter_get_connectable(void)
537 CHECK_OAL_INITIALIZED();
541 ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_SCAN_MODE);
542 if (ret != BT_STATUS_SUCCESS) {
543 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
544 return convert_to_oal_status(ret);
547 return OAL_STATUS_SUCCESS;
550 oal_status_t adapter_set_name(char * name)
555 CHECK_OAL_INITIALIZED();
557 OAL_CHECK_PARAMETER(name, return);
558 API_TRACE("Name: %s", name);
560 prop.type = BT_PROPERTY_BDNAME;
561 prop.len = strlen(name);
564 ret = blued_api->set_adapter_property(&prop);
565 if (ret != BT_STATUS_SUCCESS) {
566 BT_ERR("set_adapter_property: [%s]", status2string(ret));
567 ret = OAL_STATUS_INTERNAL_ERROR;
569 ret = OAL_STATUS_SUCCESS;
574 oal_status_t adapter_is_discoverable(int *p_discoverable)
576 OAL_CHECK_PARAMETER(p_discoverable, return);
578 *p_discoverable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
580 API_TRACE("%d", *p_discoverable);
582 return OAL_STATUS_SUCCESS;
585 oal_status_t adapter_is_connectable(int *p_connectable)
587 OAL_CHECK_PARAMETER(p_connectable, return);
589 *p_connectable = (scan_mode == BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
590 || (scan_mode == BT_SCAN_MODE_CONNECTABLE);
592 API_TRACE("%d", *p_connectable);
594 return OAL_STATUS_SUCCESS;
597 oal_status_t adapter_get_discoverable_timeout(int *p_timeout)
599 API_TRACE("%d", discoverable_timeout);
601 *p_timeout = discoverable_timeout;
603 return OAL_STATUS_SUCCESS;
606 oal_status_t adapter_get_service_uuids(void)
610 CHECK_OAL_INITIALIZED();
613 ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
614 if (ret != BT_STATUS_SUCCESS) {
615 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
616 return convert_to_oal_status(ret);
618 return OAL_STATUS_SUCCESS;
621 oal_status_t adapter_get_bonded_devices(void)
625 CHECK_OAL_INITIALIZED();
629 ret = blued_api->get_adapter_property(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
630 if (ret != BT_STATUS_SUCCESS) {
631 BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
632 return convert_to_oal_status(ret);
635 return OAL_STATUS_SUCCESS;
638 static oal_status_t set_scan_mode(bt_scan_mode_t mode)
645 CHECK_OAL_INITIALIZED();
647 prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE;
648 prop.len = sizeof(bt_scan_mode_t);
650 res = blued_api->set_adapter_property(&prop);
651 if (res != BT_STATUS_SUCCESS) {
652 BT_ERR("set scan mode failed [%s]", status2string(res));
653 return convert_to_oal_status(res);
657 return OAL_STATUS_SUCCESS;
660 oal_status_t adapter_set_connectable(int connectable)
664 API_TRACE("%d", connectable);
666 CHECK_OAL_INITIALIZED();
668 mode = connectable ? BT_SCAN_MODE_CONNECTABLE : BT_SCAN_MODE_NONE;
670 return set_scan_mode(mode);
673 oal_status_t adapter_set_discoverable(void)
675 CHECK_OAL_INITIALIZED();
678 return set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
681 oal_status_t adapter_set_discoverable_timeout(int timeout)
685 uint32_t prop_val = timeout;
687 CHECK_OAL_INITIALIZED();
688 API_TRACE("%d", timeout);
690 prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT;
691 prop.len = sizeof(prop_val);
692 prop.val = &prop_val;
693 res = blued_api->set_adapter_property(&prop);
694 if (res != BT_STATUS_SUCCESS) {
695 BT_ERR("set_adapter_property failed [%s]", status2string(res));
696 return convert_to_oal_status(res);
698 return OAL_STATUS_SUCCESS;
701 oal_status_t adapter_ble_set_filter_policy(int filter_policy)
703 int ret = OAL_STATUS_SUCCESS;
705 CHECK_OAL_INITIALIZED();
708 BT_DBG("Filter policy applied is [%d]", filter_policy);
710 ret = gatts_set_filter_policy(filter_policy);
712 if (ret != OAL_STATUS_SUCCESS) {
713 BT_ERR("gatts_set_filter_policy: [%d]", ret);
717 return OAL_STATUS_SUCCESS;
720 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
721 int adv_type, int chnl_map, int tx_power, int timeout_s)
724 CHECK_OAL_INITIALIZED();
727 res = gatts_multi_adv_update(Ins_id, min_intv, max_intv,
728 adv_type, chnl_map, tx_power, timeout_s);
729 if (res != OAL_STATUS_SUCCESS) {
730 BT_ERR("gatts_multi_adv_update: [%d]", res);
733 return OAL_STATUS_SUCCESS;
736 oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id,
737 oal_ble_multi_adv_param_setup_t * adv_param_setup)
740 CHECK_OAL_INITIALIZED();
741 OAL_CHECK_PARAMETER(adv_param_setup, return);
745 res = gatts_multi_adv_set_inst_data(instance_id, adv_param_setup);
746 if (res != OAL_STATUS_SUCCESS) {
747 BT_ERR("failed: [%d]", res);
750 return OAL_STATUS_SUCCESS;
753 oal_status_t adapter_ble_multi_adv_enable(int instance_id)
756 CHECK_OAL_INITIALIZED();
759 res = gatts_multi_adv_enable(instance_id);
760 if (res != OAL_STATUS_SUCCESS) {
761 BT_ERR("failed: [%d]", res);
765 return OAL_STATUS_SUCCESS;
768 oal_status_t adapter_ble_multi_adv_disable(int instance_id)
771 CHECK_OAL_INITIALIZED();
774 res = gatts_multi_adv_disable(instance_id);
775 if (res != OAL_STATUS_SUCCESS) {
776 BT_ERR("failed: [%d]", res);
780 return OAL_STATUS_SUCCESS;
783 oal_status_t adapter_set_le_static_random_address(int enable)
787 CHECK_OAL_INITIALIZED();
788 API_TRACE("%d", enable);
791 ret = blued_api->set_le_static_random_address((enable ? 1 : 0));
792 if (ret != BT_STATUS_SUCCESS)
793 BT_ERR("Static address set failed: [%s]", status2string(ret));
794 ret = convert_to_oal_status(ret);
796 BT_INFO("Not Supported");
797 ret = OAL_STATUS_NOT_SUPPORT;
803 oal_status_t adapter_set_manufacturer_data(oal_manufacturer_data_t *m_data)
807 CHECK_OAL_INITIALIZED();
810 OAL_CHECK_PARAMETER(m_data, return);
811 ret = blued_api->adapter_le_set_manufacturer_data((bt_manufacturer_data_t*)m_data);
812 if (ret != BT_STATUS_SUCCESS)
813 BT_ERR("Setting manufacturer data Failed: [%s]",status2string(ret));
815 ret = convert_to_oal_status(ret);
819 oal_status_t adapter_set_white_list(bt_address_t *device_address, int address_type, bool is_add)
824 CHECK_OAL_INITIALIZED();
827 BT_INFO("BT remote device Address: %s", bdt_bd2str(device_address, &bdstr));
829 ret = blued_api->adapter_le_set_white_list((bt_bdaddr_t*)device_address, address_type, is_add);
830 if (ret != BT_STATUS_SUCCESS) {
832 BT_ERR("Add to White List Failed: [%s]",status2string(ret));
834 BT_ERR("Remove from White List Failed: [%s]",status2string(ret));
836 ret = convert_to_oal_status(ret);
840 oal_status_t adapter_ble_set_privacy(int set_privacy)
844 CHECK_OAL_INITIALIZED();
847 res = blued_api->adapter_le_set_privacy(set_privacy);
848 if (res != BT_STATUS_SUCCESS)
849 BT_ERR("Setting LE Privacy Failed: [%s]", status2string(res));
850 res = convert_to_oal_status(res);
855 static void cb_adapter_properties(bt_status_t status,
857 bt_property_t *properties)
861 BT_DBG("status: %d, count: %d", status, num_properties);
863 print_bt_properties(num_properties, properties);
865 if (status != BT_STATUS_SUCCESS) {
866 if (num_properties == 1) {
867 BT_ERR("Adapter Prop failed: status: [%s], count: %d, prop: %d",
868 status2string(status), num_properties, properties[num_properties-1].type);
870 BT_ERR("Adapter Prop failed: status: [%s], count: %d", status2string(status), num_properties);
875 for (i = 0; i < num_properties; i++) {
876 BT_DBG("prop type %d, len %d", properties[i].type, properties[i].len);
877 switch (properties[i].type) {
878 case BT_PROPERTY_VERSION: {
879 g_strlcpy(local_version, properties[i].val, BT_VERSION_STR_LEN_MAX);
880 local_version[properties[i].len] = '\0';
882 BT_DBG("Version: %s", local_version);
883 /* Send event to application */
884 if (num_properties == 1) {
885 char *adapter_ver = g_strdup(local_version);
887 /* Application has requested this property SET/GET hence send EVENT */
888 send_event(OAL_EVENT_ADAPTER_PROPERTY_VERSION, adapter_ver, strlen(adapter_ver));
892 case BT_PROPERTY_BDNAME: {
893 g_strlcpy(local_name, properties[i].val, BT_DEVICE_NAME_LENGTH_MAX);
894 local_name[properties[i].len] = '\0';
896 BT_DBG("Name: %s", local_name);
897 /* Send event to application */
898 if (num_properties == 1) {
899 char * adap_name = g_strdup(local_name);
901 /* Application has requested this property SET/GET hence send EVENT */
902 send_event(OAL_EVENT_ADAPTER_PROPERTY_NAME, adap_name, strlen(adap_name)+1);
906 case BT_PROPERTY_BDADDR: {
909 addr = properties[i].val;
910 memcpy(local_address.addr, addr->address, 6);
911 if (num_properties == 1) {
912 /* Application has requested this property SET/GET hence send EVENT */
913 send_event(OAL_EVENT_ADAPTER_PROPERTY_ADDRESS,
914 g_memdup(&local_address, sizeof(local_address)),
915 sizeof(local_address));
919 case BT_PROPERTY_UUIDS: {
922 num_uuid = properties[i].len/sizeof(bt_uuid_t);
924 BT_DBG("num_uuid: %d", num_uuid);
926 /* Send event to application */
927 if (num_properties == 1) {
928 event_adapter_services_t *uuids_event;
930 uuids_event = g_malloc(sizeof(event_adapter_services_t) + properties[i].len);
931 memcpy(uuids_event->service_list, properties[i].val, properties[i].len);
932 uuids_event->num = num_uuid;
934 /* Application has requested this property SET/GET hence send EVENT */
935 send_event(OAL_EVENT_ADAPTER_PROPERTY_SERVICES,
936 uuids_event, (sizeof(event_adapter_services_t) + num_uuid * sizeof(bt_uuid_t)));
940 case BT_PROPERTY_ADAPTER_SCAN_MODE: {
941 bt_scan_mode_t cur_mode = *((bt_scan_mode_t *)properties[i].val);
943 BT_INFO("Scan mode (%d)", cur_mode);
945 scan_mode = cur_mode;
947 /* Send event to application */
948 if (num_properties == 1) {
949 oal_event_t event = OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE;
951 if (BT_SCAN_MODE_CONNECTABLE == cur_mode)
952 event = OAL_EVENT_ADAPTER_MODE_CONNECTABLE;
953 else if (BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE == cur_mode)
954 event = OAL_EVENT_ADAPTER_MODE_DISCOVERABLE;
956 /* Application has requested this property SET/GET hence send EVENT */
957 send_event(event, NULL, 0);
961 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: {
964 timeout = *((uint32_t*)properties[i].val);
966 BT_INFO("Discoverability timeout: %d", timeout);
967 discoverable_timeout = timeout;
969 send_event(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT,
970 g_memdup(properties[i].val, sizeof(uint32_t)),
974 case BT_PROPERTY_ADAPTER_BONDED_DEVICES: {
977 bt_bdaddr_t *bonded_addr_list;
978 event_device_list_t *event_data;
980 num_bonded = properties[i].len/sizeof(bt_bdaddr_t);
981 BT_DBG("num_bonded %d", num_bonded);
983 if (num_properties > 1) /* No explicit req for this prop, ignore */
986 bonded_addr_list = properties[i].val;
987 event_data = g_malloc(sizeof(event_device_list_t) + num_bonded*sizeof(bt_address_t));
988 event_data->num = num_bonded;
990 for (j = 0; j < num_bonded; j++)
991 memcpy(event_data->devices[j].addr, bonded_addr_list[j].address, 6);
993 send_event(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST,
994 event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
997 case BT_PROPERTY_A2DP_ROLE: {
998 unsigned int a2dp_role;
1000 a2dp_role = *((uint32_t*)properties[i].val);
1002 BT_INFO("A2DP role: %u", a2dp_role);
1004 send_event(OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE,
1005 g_memdup(properties[i].val, sizeof(uint32_t)),
1009 case BT_PROPERTY_LOCAL_LE_FEATURES: {
1010 event_adapter_le_features_t *le_features;
1012 le_features = g_malloc(sizeof(event_adapter_le_features_t));
1014 le_features->max_adv_instance = ((bt_local_le_features_t *)(properties[i].val))->max_adv_instance;
1015 le_features->rpa_offloading = ((bt_local_le_features_t *)(properties[i].val))->rpa_offload_supported;
1016 le_features->max_adv_filter = ((bt_local_le_features_t *)(properties[i].val))->max_adv_filter_supported;
1017 le_features->le_2m_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
1018 le_features->le_coded_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
1020 BT_INFO("LE 2M PHY Support (%d)", le_features->le_2m_phy_support);
1021 BT_INFO("LE CODED PHY Support (%d)", le_features->le_coded_phy_support);
1023 send_event(OAL_EVENT_BLE_LOCAL_FEATURES,
1025 sizeof(event_adapter_le_features_t));
1028 case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STARTED: {
1029 BT_INFO("LE Discovery started");
1030 send_event(OAL_EVENT_BLE_DISCOVERY_STARTED, NULL, 0);
1033 case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STOPPED: {
1034 BT_INFO("LE Discovery stopped");
1035 send_event(OAL_EVENT_BLE_DISCOVERY_STOPPED, NULL, 0);
1039 BT_WARN("Unhandled property: %d", properties[i].type);
1045 static void cb_adapter_discovery_state_changed(bt_discovery_state_t state)
1049 event = (BT_DISCOVERY_STARTED == state) ? OAL_EVENT_ADAPTER_INQUIRY_STARTED : OAL_EVENT_ADAPTER_INQUIRY_FINISHED;
1051 BT_DBG("%d", state);
1052 send_event(event, NULL, 0);
1055 static void cb_adapter_device_found(int num_properties, bt_property_t *properties)
1057 remote_device_t dev_info;
1058 ble_adv_data_t adv_info;
1060 gpointer event_data;
1064 if (num_properties == 0) {
1065 BT_ERR("Unexpected, properties count is zero!!");
1069 memset(&dev_info, 0x00, sizeof(remote_device_t));
1070 memset(&adv_info, 0x00, sizeof(ble_adv_data_t));
1072 print_bt_properties(num_properties, properties);
1073 parse_device_properties(num_properties, properties, &dev_info, &adv_info);
1075 BT_INFO("number of properties= [%d] ", num_properties);
1077 if (dev_info.type != DEV_TYPE_BREDR) {
1078 /* BLE Single or DUAL mode found, so it should have Adv data */
1079 event_ble_dev_found_t * ble_dev_event = g_new0(event_ble_dev_found_t, 1);
1081 ble_dev_event->adv_len = adv_info.len;
1083 if (adv_info.len > 0 && adv_info.adv_data) {
1084 memcpy(ble_dev_event->adv_data, adv_info.adv_data, adv_info.len);
1085 ble_dev_event->adv_len = adv_info.len;
1087 ble_dev_event->adv_len = 0;
1089 ble_dev_event->device_info = dev_info;
1091 event_data = ble_dev_event;
1092 size = sizeof(event_ble_dev_found_t);
1093 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE;
1095 /* BREDR device, so No Adv data */
1096 event_dev_found_t * dev_event = g_new0(event_dev_found_t, 1);
1098 memcpy(dev_event, &dev_info, sizeof(remote_device_t));
1099 event_data = dev_event;
1100 size = sizeof(remote_device_t);
1101 event = OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY;
1104 send_event(event, event_data, size);