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.
24 #include <bluetooth.h>
26 #include "oal-event.h"
27 #include "oal-internal.h"
28 #include "oal-common.h"
29 #include "oal-manager.h"
30 #include "oal-utils.h"
31 #include "oal-device-mgr.h"
33 static const bt_interface_t * blued_api;
38 void device_mgr_init(const bt_interface_t * stack_if)
43 void device_mgr_cleanup(void)
49 oal_status_t device_query_attributes(bt_address_t *addr)
54 CHECK_OAL_INITIALIZED();
56 OAL_CHECK_PARAMETER(addr, return);
58 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
60 res = blued_api->get_remote_device_properties((bt_bdaddr_t *)addr);
61 if (res != BT_STATUS_SUCCESS) {
62 BT_ERR("get_remote_device_properties error: [%s]", status2string(res));
63 return convert_to_oal_status(res);
66 return OAL_STATUS_SUCCESS;
69 oal_status_t device_query_services(bt_address_t * addr)
74 CHECK_OAL_INITIALIZED();
76 OAL_CHECK_PARAMETER(addr, return);
78 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
80 res = blued_api->get_remote_services((bt_bdaddr_t *)addr);
81 if (res != BT_STATUS_SUCCESS) {
82 BT_ERR("get_remote_services error: [%s]", status2string(res));
83 return convert_to_oal_status(res);
86 return OAL_STATUS_SUCCESS;
89 oal_status_t device_stop_query_sevices(bt_address_t * addr)
91 CHECK_OAL_INITIALIZED();
93 OAL_CHECK_PARAMETER(addr, return);
95 API_TRACE("Stop SDP search");
96 /* Currently no HAL Interface for Stopping Service Search */
97 return BT_STATUS_UNSUPPORTED;
100 oal_status_t device_set_alias(bt_address_t * addr, char * alias)
106 CHECK_OAL_INITIALIZED();
107 OAL_CHECK_PARAMETER(addr, return);
108 OAL_CHECK_PARAMETER(alias, return);
110 API_TRACE("%s ->Alias: %s", bdt_bd2str(addr, &bdstr), alias);
112 prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME;
113 prop.len = strlen(alias);
115 res = blued_api->set_remote_device_property((bt_bdaddr_t*)addr, &prop);
116 if (res != BT_STATUS_SUCCESS) {
117 BT_ERR("set_remote_device_property error: [%s]", status2string(res));
118 BT_ERR("Alias: %s", alias);
119 return convert_to_oal_status(res);
122 return OAL_STATUS_SUCCESS;
125 oal_status_t device_create_bond(bt_address_t *addr, oal_conn_type_e transport)
130 CHECK_OAL_INITIALIZED();
132 OAL_CHECK_PARAMETER(addr, return);
134 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
136 res = blued_api->create_bond((bt_bdaddr_t *)addr, transport);
137 if (res != BT_STATUS_SUCCESS) {
138 BT_ERR("create_bond error: [%s]", status2string(res));
139 return convert_to_oal_status(res);
142 return OAL_STATUS_SUCCESS;
145 oal_status_t device_destroy_bond(bt_address_t * addr)
150 CHECK_OAL_INITIALIZED();
152 OAL_CHECK_PARAMETER(addr, return);
154 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
156 res = blued_api->remove_bond((bt_bdaddr_t *)addr);
157 if (res != BT_STATUS_SUCCESS) {
158 BT_ERR("remove_bond error: [%s]", status2string(res));
159 return convert_to_oal_status(res);
162 return OAL_STATUS_SUCCESS;
165 oal_status_t device_stop_bond(bt_address_t * addr)
170 CHECK_OAL_INITIALIZED();
172 OAL_CHECK_PARAMETER(addr, return);
174 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
176 res = blued_api->cancel_bond((bt_bdaddr_t *)addr);
177 if (res != BT_STATUS_SUCCESS) {
178 BT_ERR("cancel_bond error: [%s]", status2string(res));
179 return convert_to_oal_status(res);
182 return OAL_STATUS_SUCCESS;
185 oal_status_t device_accept_pin_request(bt_address_t * addr, const char * pin)
190 CHECK_OAL_INITIALIZED();
192 OAL_CHECK_PARAMETER(addr, return);
193 OAL_CHECK_PARAMETER(pin, return);
195 API_TRACE("[%s] PIN: %s", bdt_bd2str(addr, &bdstr), pin);
197 res = blued_api->pin_reply((bt_bdaddr_t *)addr, TRUE, strlen(pin), (bt_pin_code_t *)pin);
198 if (res != BT_STATUS_SUCCESS) {
199 BT_ERR("pin_reply error: [%s]", status2string(res));
200 BT_ERR("PIN: %s", pin);
201 return convert_to_oal_status(res);
204 return OAL_STATUS_SUCCESS;
207 oal_status_t device_reject_pin_request(bt_address_t * addr)
212 CHECK_OAL_INITIALIZED();
214 OAL_CHECK_PARAMETER(addr, return);
216 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
218 res = blued_api->pin_reply((bt_bdaddr_t *)addr, FALSE, 0, NULL);
219 if (res != BT_STATUS_SUCCESS) {
220 BT_ERR("pin_reply error: [%s]", status2string(res));
221 return convert_to_oal_status(res);
224 return OAL_STATUS_SUCCESS;
227 oal_status_t device_accept_passkey_entry(bt_address_t * addr, uint32_t passkey)
232 CHECK_OAL_INITIALIZED();
234 OAL_CHECK_PARAMETER(addr, return);
236 API_TRACE("[%s] Passkey: %d", bdt_bd2str(addr, &bdstr), passkey);
238 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_PASSKEY_ENTRY, TRUE, passkey);
239 if (res != BT_STATUS_SUCCESS) {
240 BT_ERR("ssp_reply error: [%s]", status2string(res));
241 BT_ERR("Passkey: %d", passkey);
242 return convert_to_oal_status(res);
246 return OAL_STATUS_SUCCESS;
249 oal_status_t device_reject_passkey_entry(bt_address_t * addr)
254 CHECK_OAL_INITIALIZED();
256 OAL_CHECK_PARAMETER(addr, return);
258 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
260 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_PASSKEY_ENTRY, FALSE, 0);
261 if (res != BT_STATUS_SUCCESS) {
262 BT_ERR("ssp_reply error: [%s]", status2string(res));
263 return convert_to_oal_status(res);
266 return OAL_STATUS_SUCCESS;
269 oal_status_t device_reply_passkey_confirmation(bt_address_t * addr, int accept)
274 CHECK_OAL_INITIALIZED();
276 OAL_CHECK_PARAMETER(addr, return);
278 API_TRACE("[%s] accept: %d", bdt_bd2str(addr, &bdstr), accept);
280 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_PASSKEY_CONFIRMATION, accept, 0);
281 if (res != BT_STATUS_SUCCESS) {
282 BT_ERR("ssp_reply error: [%s]", status2string(res));
283 BT_ERR("%d", accept);
284 return convert_to_oal_status(res);
287 return OAL_STATUS_SUCCESS;
291 oal_status_t device_reply_ssp_consent(bt_address_t * addr, int accept)
296 CHECK_OAL_INITIALIZED();
298 OAL_CHECK_PARAMETER(addr, return);
300 API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), accept);
302 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_CONSENT, accept, 0);
303 if (res != BT_STATUS_SUCCESS) {
304 BT_ERR("ssp_reply error: [%s]", status2string(res));
305 BT_ERR("%d", accept);
306 return convert_to_oal_status(res);
309 return OAL_STATUS_SUCCESS;
312 oal_status_t device_reply_auth_request(bt_address_t * addr, oal_service_t service_type, int accept, int always)
317 CHECK_OAL_INITIALIZED();
319 OAL_CHECK_PARAMETER(addr, return);
321 API_TRACE("[%s] Accept: %d, always: %d, service_type: %d", bdt_bd2str(addr, &bdstr), accept, always, service_type);
323 res = blued_api->authorize_response((bt_bdaddr_t *)addr, service_type, accept, always);
324 if (res != BT_STATUS_SUCCESS) {
325 BT_ERR("authorize_response error: [%s]", status2string(res));
326 BT_ERR("Accept: [%d], always: [%d], service_type: [%d]", accept, always, service_type);
327 return convert_to_oal_status(res);
330 return OAL_STATUS_SUCCESS;
333 oal_status_t device_set_authorized(bt_address_t * addr, int authorize)
338 CHECK_OAL_INITIALIZED();
340 OAL_CHECK_PARAMETER(addr, return);
342 API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), authorize);
344 res = blued_api->set_authorization((bt_bdaddr_t *)addr, authorize);
345 if (res != BT_STATUS_SUCCESS) {
346 BT_ERR("set_authorization error: [%s]", status2string(res));
347 BT_ERR("%d", authorize);
348 return convert_to_oal_status(res);
351 return OAL_STATUS_SUCCESS;
354 gboolean device_get_acl_conn_state(bt_address_t * addr)
359 CHECK_OAL_INITIALIZED();
360 OAL_CHECK_PARAMETER(addr, return);
362 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
364 res = blued_api->get_connection_state((bt_bdaddr_t *)addr);
365 BT_ERR("get_connection_state returned: [%s]", res ? "TRUE" : "FALSE");
370 gboolean device_get_svc_conn_state(bt_address_t * addr, oal_service_t svc_id)
375 CHECK_OAL_INITIALIZED();
376 OAL_CHECK_PARAMETER(addr, return);
378 API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), svc_id);
381 res = blued_api->get_service_connection_state((bt_bdaddr_t *)addr, svc_id);
383 BT_ERR("Not supported");
386 BT_ERR("get_service_connection_state returned: [%s]", res ? "TRUE" : "FALSE");
391 oal_status_t device_register_osp_server(oal_osp_server_type_e type, char *uuid, char *path, int fd)
394 uint32_t server_type;
396 CHECK_OAL_INITIALIZED();
398 API_TRACE("type: %d", type);
402 case OAL_OSP_SERVER_OBEX:
403 server_type = BT_OSP_SERVER_OBEX;
405 case OAL_OSP_SERVER_RFCOMM:
406 server_type = BT_OSP_SERVER_RFCOMM;
409 BT_ERR("unknown type: %d", type);
410 return OAL_STATUS_INVALID_PARAM;
413 res = blued_api->register_agent_osp_server(server_type, uuid, path, fd);
414 if (res != BT_STATUS_SUCCESS) {
415 BT_ERR("register_agent_osp_server error: [%s]", status2string(res));
416 return convert_to_oal_status(res);
419 return OAL_STATUS_SUCCESS;
421 BT_ERR("Not supported");
422 res = OAL_STATUS_NOT_SUPPORT;
427 oal_status_t device_unregister_osp_server(oal_osp_server_type_e type, char *uuid)
430 uint32_t server_type;
432 CHECK_OAL_INITIALIZED();
434 API_TRACE("type: %d", type);
438 case OAL_OSP_SERVER_OBEX:
439 server_type = BT_OSP_SERVER_OBEX;
441 case OAL_OSP_SERVER_RFCOMM:
442 server_type = BT_OSP_SERVER_RFCOMM;
445 BT_ERR("unknown type: %d", type);
446 return OAL_STATUS_INVALID_PARAM;
449 res = blued_api->unregister_agent_osp_server(server_type, uuid);
450 if (res != BT_STATUS_SUCCESS) {
451 BT_ERR("unregister_agent_osp_server error: [%s]", status2string(res));
452 return convert_to_oal_status(res);
455 return OAL_STATUS_SUCCESS;
457 BT_ERR("Not supported");
458 res = OAL_STATUS_NOT_SUPPORT;
463 oal_status_t device_set_trust_profile(bt_address_t *addr, oal_trusted_profile_e profile, gboolean trust)
468 CHECK_OAL_INITIALIZED();
470 OAL_CHECK_PARAMETER(addr, return);
472 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
475 res = blued_api->set_trusted_profile((bt_bdaddr_t *)addr, profile, (trust ? 1 : 0));
476 if (res != BT_STATUS_SUCCESS) {
477 BT_ERR("set_trusted_profile error: [%s]", status2string(res));
478 return convert_to_oal_status(res);
481 return OAL_STATUS_SUCCESS;
483 BT_ERR("Not supported");
484 res = OAL_STATUS_NOT_SUPPORT;
489 oal_status_t device_get_trust_profile(bt_address_t *addr, oal_trusted_profile_e profile, unsigned int *trusted)
494 CHECK_OAL_INITIALIZED();
496 OAL_CHECK_PARAMETER(addr, return);
498 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
501 res = blued_api->get_trusted_profile((bt_bdaddr_t *)addr, profile, trusted);
502 if (res != BT_STATUS_SUCCESS) {
503 BT_ERR("get_trusted_profile error: [%s]", status2string(res));
504 return convert_to_oal_status(res);
507 return OAL_STATUS_SUCCESS;
509 BT_ERR("Not supported");
510 res = OAL_STATUS_NOT_SUPPORT;
515 oal_status_t device_enable_rssi_monitoring(bt_address_t *addr, unsigned int link_type,
516 int low_threshold, int in_range_threshold, int high_threshold)
521 CHECK_OAL_INITIALIZED();
523 OAL_CHECK_PARAMETER(addr, return);
525 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
528 res = blued_api->enable_rssi_monitoring((bt_bdaddr_t *)addr, link_type,
529 low_threshold, in_range_threshold, high_threshold);
530 if (res != BT_STATUS_SUCCESS) {
531 BT_ERR("enable_rssi_monitoring error: [%s]", status2string(res));
532 return convert_to_oal_status(res);
535 return OAL_STATUS_SUCCESS;
537 BT_ERR("Not supported");
538 res = OAL_STATUS_NOT_SUPPORT;
543 oal_status_t device_get_connected_link_rssi_strength(bt_address_t *addr, unsigned int link_type)
548 CHECK_OAL_INITIALIZED();
550 OAL_CHECK_PARAMETER(addr, return);
552 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
555 res = blued_api->get_connected_link_rssi_strength((bt_bdaddr_t *)addr, link_type);
556 if (res != BT_STATUS_SUCCESS) {
557 BT_ERR("get_connected_link_rssi_strength error: [%s]", status2string(res));
558 return convert_to_oal_status(res);
561 return OAL_STATUS_SUCCESS;
563 BT_ERR("Not supported");
564 res = OAL_STATUS_NOT_SUPPORT;
569 oal_status_t device_enable_gap_auth_notifications(oal_gap_auth_type_e type, gboolean enable)
573 CHECK_OAL_INITIALIZED();
575 API_TRACE("type: [%d], enable: %d", type, enable);
578 res = blued_api->enable_gap_auth_notifications(type, (enable ? 1 : 0));
579 if (res != BT_STATUS_SUCCESS) {
580 BT_ERR("enable_gap_auth_notifications error: [%s]", status2string(res));
581 return convert_to_oal_status(res);
584 return OAL_STATUS_SUCCESS;
586 BT_ERR("Not supported");
587 res = OAL_STATUS_NOT_SUPPORT;
592 oal_status_t device_disconnect(bt_address_t * addr)
597 CHECK_OAL_INITIALIZED();
599 OAL_CHECK_PARAMETER(addr, return);
601 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
603 res = blued_api->device_disconnect((bt_bdaddr_t *)addr);
604 if (res != BT_STATUS_SUCCESS) {
605 BT_ERR("device_disconnect error: [%s]", status2string(res));
606 return convert_to_oal_status(res);
609 return OAL_STATUS_SUCCESS;
612 void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
613 int num_properties, bt_property_t *properties)
616 gpointer event_data = NULL;
617 remote_device_t *dev_info;
618 ble_adv_data_t adv_info;
622 BT_DBG("[%s]status: [%d] num properties [%d]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr),
623 status, num_properties);
625 dev_info = g_new0(remote_device_t, 1);
626 memcpy(dev_info->address.addr, bd_addr->address, 6);
627 parse_device_properties(num_properties, properties, dev_info, &adv_info);
629 if (num_properties == 0) {
630 BT_ERR("!!Unexpected!! num properties is 0 status [%d]", status);
631 /* It is possible that app called get bonded device info for a device
632 which is not yet bonded or udner bonding, in such case, stack will return no properties.
633 It is also possible that after bonding is done, BT MW attempted to fetch
634 bonded device info, but due to internal stack error, 0 properties with status FAIL
635 are received from stack. In such cases, simply send the event to BT MW
636 and let it handle this event */
637 event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
638 memcpy(&dev_props_event->device_info,
639 dev_info, sizeof(remote_device_t));
640 event_data = dev_props_event;
641 event = OAL_EVENT_DEVICE_PROPERTIES;
642 size = sizeof(event_dev_properties_t);
644 } else if (num_properties == 1) {
645 /* For one particular property a dedicated event to be sent */
646 switch (properties[0].type) {
647 case BT_PROPERTY_BDNAME:
648 event = OAL_EVENT_DEVICE_NAME;
649 event_data = dev_info;
650 send_event_trace(event, event_data, sizeof(remote_device_t),
651 (bt_address_t*)bd_addr, "Name: %s", dev_info->name);
653 case BT_PROPERTY_UUIDS: {
654 event_dev_services_t *services_info;
655 bt_uuid_t *uuids = (bt_uuid_t *) properties[0].val;
656 BT_INFO("Properties len [%d] event structure size [%zu]", properties[0].len, sizeof(event_dev_services_t));
658 services_info = g_malloc(sizeof(event_dev_services_t) + properties[0].len);
659 services_info->address = dev_info->address;
660 memcpy(services_info->service_list, uuids, properties[0].len);
661 services_info->num = properties[0].len/sizeof(bt_uuid_t);
662 BT_INFO("Number of UUID [%d]", services_info->num);
663 event = OAL_EVENT_DEVICE_SERVICES;
664 event_data = services_info;
665 size = sizeof(event_dev_services_t) + properties[0].len;
670 BT_ERR("Single Property [%d] not handled", properties[0].type);
675 event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
676 if (dev_info->type != DEV_TYPE_BREDR) {
679 BT_INFO("BLE Device");
680 /* BLE Single or DUAL mode found, so it should have Adv data */
681 dev_props_event->adv_len = adv_info.len;
682 if (dev_props_event->adv_len > 0)
683 memcpy(dev_props_event->adv_data,
684 adv_info.adv_data, adv_info.len);
686 for (i = 0; i < dev_props_event->adv_len; i++)
687 BT_INFO("Adv Data[%d] = [0x%x]",
688 i, dev_props_event->adv_data[i]);
689 memcpy(&dev_props_event->device_info,
690 dev_info, sizeof(remote_device_t));
692 BT_INFO("BREDR type Device");
693 memcpy(&dev_props_event->device_info,
694 dev_info, sizeof(remote_device_t));
697 event_data = dev_props_event;
698 event = OAL_EVENT_DEVICE_PROPERTIES;
699 size = sizeof(event_dev_properties_t);
703 send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
706 void cb_device_bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
707 bt_bond_state_t state)
709 bt_address_t * address = g_new0(bt_address_t, 1);
713 BT_DBG("status: %d, state: %d", status, state);
715 memcpy(address->addr, bd_addr->address, 6);
718 case BT_BOND_STATE_BONDED:
719 event = OAL_EVENT_DEVICE_BONDING_SUCCESS;
721 case BT_BOND_STATE_NONE:
722 /* Reaches both when bonding removed or bonding cancelled */
723 if (BT_STATUS_SUCCESS != status) {
724 event_dev_bond_failed_t * bond_fail_info = g_new0(event_dev_bond_failed_t, 1);
725 bond_fail_info->status = convert_to_oal_status(status);
726 bond_fail_info->address = *address;
727 size = sizeof(event_dev_bond_failed_t);
728 send_event_bda_trace(OAL_EVENT_DEVICE_BONDING_FAILED, bond_fail_info, size, (bt_address_t*)bd_addr);
732 event = OAL_EVENT_DEVICE_BONDING_REMOVED;
734 case BT_BOND_STATE_BONDING:
738 BT_ERR("Unexpected Bond state %d", state);
742 send_event_bda_trace(event, address, sizeof(bt_address_t), (bt_address_t*)bd_addr);
745 void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
746 bt_acl_state_t state)
748 event_dev_conn_status_t * conn_status = g_new0(event_dev_conn_status_t, 1);
749 //bt_address_t * address = g_new0(bt_address_t, 1);
753 BT_DBG("ACL State:%d, state: %d", status, state);
755 memcpy(conn_status->address.addr, bd_addr->address, 6);
758 conn_status->status = convert_to_oal_status(status);
759 conn_status->rssi = dbfw_rssi;
761 if (BT_STATUS_SUCCESS != status) {
762 /* At present only timeout will cause non-success status, later we can add more */
763 conn_status->status = OAL_STATUS_CONN_TIMEOUT;
764 BT_ERR("ACL State Error:%d, state: %d", status, state);
766 conn_status->status = OAL_STATUS_SUCCESS;
768 memcpy(conn_status->address.addr, bd_addr->address, 6);
771 BT_INFO("ACL STATE :%d, conn_status->status :%d, BT_ACL_STATE: %d", status, conn_status->status, state);
774 case BT_ACL_STATE_CONNECTED:
775 event = OAL_EVENT_DEVICE_ACL_CONNECTED;
776 conn_status->status = OAL_STATUS_SUCCESS;
778 case BT_ACL_STATE_DISCONNECTED:
779 event = OAL_EVENT_DEVICE_ACL_DISCONNECTED;
782 BT_ERR("Unexpected ACL state %d", state);
787 size = sizeof(event_dev_conn_status_t);
788 send_event_bda_trace(event, conn_status, size, (bt_address_t*)bd_addr);
792 void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
793 bt_le_conn_state_t state)
795 event_dev_conn_status_t * conn_status = g_new0(event_dev_conn_status_t, 1);
796 //bt_address_t * address = g_new0(bt_address_t, 1);
800 BT_DBG("LE conn status:%d, state: %d", status, state);
801 memcpy(conn_status->address.addr, bd_addr->address, 6);
802 conn_status->status = convert_to_oal_status(status);
803 conn_status->rssi = dbfw_rssi;
806 case BT_LE_CONN_STATE_CONNECTED:
807 event = OAL_EVENT_DEVICE_LE_CONNECTED;
809 case BT_LE_CONN_STATE_DISCONNECTED:
810 event = OAL_EVENT_DEVICE_LE_DISCONNECTED;
813 BT_ERR("Unexpected ACL state %d", state);
818 size = sizeof(event_dev_conn_status_t);
819 send_event_bda_trace(event, conn_status, size, (bt_address_t*)bd_addr);
823 void cb_device_pin_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class)
825 remote_device_t * dev_info = g_new0(remote_device_t, 1);
829 memcpy(dev_info->address.addr, bd_addr->address, 6);
830 g_strlcpy(dev_info->name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
831 dev_info->cod = device_class;
832 size = sizeof(remote_device_t);
834 send_event_bda_trace(OAL_EVENT_DEVICE_PIN_REQUEST, dev_info, size, (bt_address_t*)bd_addr);
837 void cb_device_ssp_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class,
838 bt_ssp_variant_t pairing_variant, uint32_t pass_key)
841 gpointer event_data = NULL;
845 switch (pairing_variant) {
846 case BT_SSP_VARIANT_PASSKEY_ENTRY:
848 remote_device_t * dev_info = g_new0(remote_device_t, 1);
849 memcpy(dev_info->address.addr, bd_addr->address, 6);
850 g_strlcpy(dev_info->name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
851 dev_info->cod = device_class;
852 event = OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST;
853 event_data = dev_info;
854 size = sizeof(remote_device_t);
857 case BT_SSP_VARIANT_PASSKEY_NOTIFICATION:
859 event_dev_passkey_t * passkey_data = g_new0(event_dev_passkey_t, 1);
861 memcpy(passkey_data->device_info.address.addr, bd_addr->address, 6);
862 g_strlcpy(passkey_data->device_info.name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
863 passkey_data->device_info.cod = device_class;
864 passkey_data->pass_key = pass_key;
865 event = OAL_EVENT_DEVICE_PASSKEY_DISPLAY;
866 event_data = passkey_data;
867 size = sizeof(event_dev_passkey_t);
870 case BT_SSP_VARIANT_PASSKEY_CONFIRMATION:
872 event_dev_passkey_t * passkey_data = g_new0(event_dev_passkey_t, 1);
874 memcpy(passkey_data->device_info.address.addr, bd_addr->address, 6);
875 g_strlcpy(passkey_data->device_info.name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
876 passkey_data->device_info.cod = device_class;
877 passkey_data->pass_key = pass_key;
878 event = OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST;
879 event_data = passkey_data;
880 size = sizeof(event_dev_passkey_t);
883 case BT_SSP_VARIANT_CONSENT:
885 remote_device_t * dev_info = g_new0(remote_device_t, 1);
887 memcpy(dev_info->address.addr, bd_addr->address, 6);
888 g_strlcpy(dev_info->name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
889 dev_info->cod = device_class;
890 event = OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST;
891 event_data = dev_info;
892 size = sizeof(remote_device_t);
897 BT_ERR("Unhandled SSP request [%d]", pairing_variant);
901 send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
904 void cb_device_authorize_request(bt_bdaddr_t *bd_addr, bt_service_id_t service_d)
906 event_dev_authorize_req_t * auth_req = g_new0(event_dev_authorize_req_t, 1);
908 BT_INFO("service_d: %d", service_d);
909 memcpy(auth_req->address.addr, bd_addr->address, 6);
910 auth_req->service_id = service_d;
912 send_event_bda_trace(OAL_EVENT_DEVICE_AUTHORIZE_REQUEST, auth_req, sizeof(event_dev_authorize_req_t), (bt_address_t*)bd_addr);
915 void cb_device_trust_state_changed(bt_bdaddr_t *bd_addr, bt_device_trust_state_t trusted)
918 event_dev_trust_t * trust_val = g_new0(event_dev_trust_t, 1);
920 if (trusted == BT_DEVICE_TRUSTED) {
921 BT_INFO("Device is Trusted");
922 event = OAL_EVENT_DEVICE_TRUSTED;
924 BT_INFO("Device is Un Trusted");
925 event = OAL_EVENT_DEVICE_UNTRUSTED;
927 memcpy(trust_val->address.addr, bd_addr->address, 6);
928 trust_val->status = OAL_STATUS_SUCCESS;
929 send_event_bda_trace(event, trust_val, sizeof(event_dev_trust_t), (bt_address_t*)bd_addr);
933 void cb_socket_conn_authorize_request(bt_bdaddr_t *bd_addr, bt_uuid_t *uuid, uint8_t *name, uint8_t *path, uint32_t fd)
935 event_socket_authorize_req_t *auth_req = g_new0(event_socket_authorize_req_t, 1);
937 memcpy(auth_req->address.addr, bd_addr->address, 6);
938 memcpy(auth_req->uuid.uuid, uuid->uu, 16);
939 memcpy(auth_req->name, name, sizeof(auth_req->name) - 1);
940 memcpy(auth_req->path, path, sizeof(auth_req->path) - 1);
943 send_event_bda_trace(OAL_EVENT_SOCKET_AUTHORIZE_REQUEST, auth_req, sizeof(event_socket_authorize_req_t), (bt_address_t*)bd_addr);
946 void cb_device_trusted_profiles_changed(bt_bdaddr_t *bd_addr, uint32_t trust_val)
948 event_device_trusted_profiles_t *ev = g_new0(event_device_trusted_profiles_t, 1);
952 memcpy(ev->address.addr, bd_addr->address, 6);
953 ev->trust_val = trust_val;
954 send_event_bda_trace(OAL_EVENT_DEVICE_TRUSTED_PROFILES_CHANGED,
955 ev, sizeof(event_device_trusted_profiles_t), (bt_address_t*)bd_addr);
959 void cb_rssi_monitor_state_changed(bt_bdaddr_t *bd_addr, int32_t link_type, uint8_t state)
961 event_dev_rssi_info_t *ev = g_new0(event_dev_rssi_info_t, 1);
962 oal_event_t event = OAL_EVENT_RSSI_MONITORING_ENABLED;
966 memcpy(ev->address.addr, bd_addr->address, 6);
967 ev->link_type = link_type;
969 event = OAL_EVENT_RSSI_MONITORING_DISABLED;
971 send_event_bda_trace(event, ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
976 void cb_rssi_alert(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t alert_type, int32_t rssi)
978 event_dev_rssi_info_t *ev = g_new0(event_dev_rssi_info_t, 1);
982 memcpy(ev->address.addr, bd_addr->address, 6);
983 ev->link_type = link_type;
984 ev->alert_type = alert_type;
987 send_event_bda_trace(OAL_EVENT_RSSI_ALERT_RECEIVED,
988 ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
992 void cb_raw_rssi_received(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t rssi)
994 event_dev_rssi_info_t *ev = g_new0(event_dev_rssi_info_t, 1);
998 memcpy(ev->address.addr, bd_addr->address, 6);
999 ev->link_type = link_type;
1002 send_event_bda_trace(OAL_EVENT_RAW_RSSI_RECEIVED,
1003 ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
1007 static gboolean __device_init_dbfw_rssi_cb(gpointer user_data)
1013 static void __device_parse_dbfw_set_rssi(unsigned char *data, uint32_t length)
1016 dbfw_rssi = 0xFFFFFF00 | data[4];
1017 BT_INFO("dbfw_rssi = %d", dbfw_rssi);
1018 g_timeout_add(1000, __device_init_dbfw_rssi_cb, NULL);
1021 void cb_dbfw_plus_info_received(unsigned char *data, uint32_t length, uint8_t event_code)
1024 char *data_str = NULL;
1027 ret_if(data == NULL);
1029 data_str = g_malloc0(length * 2 + 1);
1030 for (i = 0; i < length; i++)
1031 snprintf(&data_str[i * 2], 3, "%02X", data[i]);
1032 data_str[i * 2] = '\0';
1034 switch(event_code) {
1035 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_INFO:
1036 BT_DBG("## Event Code: Linkloss Debug Info");
1037 snprintf(evt_str, 18, "[DBFW]Linkloss(D)");
1038 __device_parse_dbfw_set_rssi(data, length);
1040 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_CLOCK_INFO:
1041 BT_DBG("## Event Code: Linkloss Clock Info");
1042 snprintf(evt_str, 18, "[DBFW]Linkloss(C)");
1044 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_PAGE_SLOTS:
1045 BT_DBG("## Event Code: Linkloss Page slots");
1046 snprintf(evt_str, 18, "[DBFW]Linkloss(P)");
1048 case BT_DBFW_PLUS_EVENT_CODE_LINK_LOSS_LMP_TRACE:
1049 BT_DBG("## Event Code: Linkloss LMP trace");
1050 snprintf(evt_str, 18, "[DBFW]Linkloss(L)");
1052 case BT_DBFW_PLUS_EVENT_CODE_A2DP_INFO:
1053 BT_DBG("## Event Code: A2DP Info");
1054 snprintf(evt_str, 18, "[DBFW]A2DP");
1056 case BT_DBFW_PLUS_EVENT_CODE_HFP_INFO:
1057 BT_DBG("## Event Code: HFP Info");
1058 snprintf(evt_str, 18, "[DBFW]HFP");
1060 case BT_DBFW_PLUS_EVENT_CODE_HFP_SCO_PACKET_TYPE_INFO:
1061 BT_DBG("## Event Code: HFP SCO Packet Type");
1062 snprintf(evt_str, 18, "[DBFW]SCO");
1065 BT_DBG("## Unknown event code (0x%02x)", event_code);
1066 snprintf(evt_str, 18, "[DBFW]0x%02X", event_code);