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;
35 void device_mgr_init(const bt_interface_t * stack_if)
40 void device_mgr_cleanup(void)
46 oal_status_t device_query_attributes(bt_address_t *addr)
51 CHECK_OAL_INITIALIZED();
53 OAL_CHECK_PARAMETER(addr, return);
55 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
57 res = blued_api->get_remote_device_properties((bt_bdaddr_t *)addr);
58 if (res != BT_STATUS_SUCCESS) {
59 BT_ERR("get_remote_device_properties error: [%s]", status2string(res));
60 return convert_to_oal_status(res);
63 return OAL_STATUS_SUCCESS;
66 oal_status_t device_query_services(bt_address_t * addr)
71 CHECK_OAL_INITIALIZED();
73 OAL_CHECK_PARAMETER(addr, return);
75 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
77 res = blued_api->get_remote_services((bt_bdaddr_t *)addr);
78 if (res != BT_STATUS_SUCCESS) {
79 BT_ERR("get_remote_services error: [%s]", status2string(res));
80 return convert_to_oal_status(res);
83 return OAL_STATUS_SUCCESS;
86 oal_status_t device_stop_query_sevices(bt_address_t * addr)
88 CHECK_OAL_INITIALIZED();
90 OAL_CHECK_PARAMETER(addr, return);
92 API_TRACE("Stop SDP search");
93 /* Currently no HAL Interface for Stopping Service Search */
94 return BT_STATUS_UNSUPPORTED;
97 oal_status_t device_set_alias(bt_address_t * addr, char * alias)
103 CHECK_OAL_INITIALIZED();
104 OAL_CHECK_PARAMETER(addr, return);
105 OAL_CHECK_PARAMETER(alias, return);
107 API_TRACE("%s ->Alias: %s", bdt_bd2str(addr, &bdstr), alias);
109 prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME;
110 prop.len = strlen(alias);
112 res = blued_api->set_remote_device_property((bt_bdaddr_t*)addr, &prop);
113 if (res != BT_STATUS_SUCCESS) {
114 BT_ERR("set_remote_device_property error: [%s]", status2string(res));
115 BT_ERR("Alias: %s", alias);
116 return convert_to_oal_status(res);
119 return OAL_STATUS_SUCCESS;
122 oal_status_t device_create_bond(bt_address_t *addr, oal_conn_type_e transport)
127 CHECK_OAL_INITIALIZED();
129 OAL_CHECK_PARAMETER(addr, return);
131 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
133 res = blued_api->create_bond((bt_bdaddr_t *)addr, transport);
134 if (res != BT_STATUS_SUCCESS) {
135 BT_ERR("create_bond error: [%s]", status2string(res));
136 return convert_to_oal_status(res);
139 return OAL_STATUS_SUCCESS;
142 oal_status_t device_destroy_bond(bt_address_t * addr)
147 CHECK_OAL_INITIALIZED();
149 OAL_CHECK_PARAMETER(addr, return);
151 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
153 res = blued_api->remove_bond((bt_bdaddr_t *)addr);
154 if (res != BT_STATUS_SUCCESS) {
155 BT_ERR("remove_bond error: [%s]", status2string(res));
156 return convert_to_oal_status(res);
159 return OAL_STATUS_SUCCESS;
162 oal_status_t device_stop_bond(bt_address_t * addr)
167 CHECK_OAL_INITIALIZED();
169 OAL_CHECK_PARAMETER(addr, return);
171 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
173 res = blued_api->cancel_bond((bt_bdaddr_t *)addr);
174 if (res != BT_STATUS_SUCCESS) {
175 BT_ERR("cancel_bond error: [%s]", status2string(res));
176 return convert_to_oal_status(res);
179 return OAL_STATUS_SUCCESS;
182 oal_status_t device_accept_pin_request(bt_address_t * addr, const char * pin)
187 CHECK_OAL_INITIALIZED();
189 OAL_CHECK_PARAMETER(addr, return);
190 OAL_CHECK_PARAMETER(pin, return);
192 API_TRACE("[%s] PIN: %s", bdt_bd2str(addr, &bdstr), pin);
194 res = blued_api->pin_reply((bt_bdaddr_t *)addr, TRUE, strlen(pin), (bt_pin_code_t *)pin);
195 if (res != BT_STATUS_SUCCESS) {
196 BT_ERR("pin_reply error: [%s]", status2string(res));
197 BT_ERR("PIN: %s", pin);
198 return convert_to_oal_status(res);
201 return OAL_STATUS_SUCCESS;
204 oal_status_t device_reject_pin_request(bt_address_t * addr)
209 CHECK_OAL_INITIALIZED();
211 OAL_CHECK_PARAMETER(addr, return);
213 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
215 res = blued_api->pin_reply((bt_bdaddr_t *)addr, FALSE, 0, NULL);
216 if (res != BT_STATUS_SUCCESS) {
217 BT_ERR("pin_reply error: [%s]", status2string(res));
218 return convert_to_oal_status(res);
221 return OAL_STATUS_SUCCESS;
224 oal_status_t device_accept_passkey_entry(bt_address_t * addr, uint32_t passkey)
229 CHECK_OAL_INITIALIZED();
231 OAL_CHECK_PARAMETER(addr, return);
233 API_TRACE("[%s] Passkey: %d", bdt_bd2str(addr, &bdstr), passkey);
235 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_PASSKEY_ENTRY, TRUE, passkey);
236 if (res != BT_STATUS_SUCCESS) {
237 BT_ERR("ssp_reply error: [%s]", status2string(res));
238 BT_ERR("Passkey: %d", passkey);
239 return convert_to_oal_status(res);
243 return OAL_STATUS_SUCCESS;
246 oal_status_t device_reject_passkey_entry(bt_address_t * addr)
251 CHECK_OAL_INITIALIZED();
253 OAL_CHECK_PARAMETER(addr, return);
255 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
257 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_PASSKEY_ENTRY, FALSE, 0);
258 if (res != BT_STATUS_SUCCESS) {
259 BT_ERR("ssp_reply error: [%s]", status2string(res));
260 return convert_to_oal_status(res);
263 return OAL_STATUS_SUCCESS;
266 oal_status_t device_reply_passkey_confirmation(bt_address_t * addr, int accept)
271 CHECK_OAL_INITIALIZED();
273 OAL_CHECK_PARAMETER(addr, return);
275 API_TRACE("[%s] accept: %d", bdt_bd2str(addr, &bdstr), accept);
277 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_PASSKEY_CONFIRMATION, accept, 0);
278 if (res != BT_STATUS_SUCCESS) {
279 BT_ERR("ssp_reply error: [%s]", status2string(res));
280 BT_ERR("%d", accept);
281 return convert_to_oal_status(res);
284 return OAL_STATUS_SUCCESS;
288 oal_status_t device_reply_ssp_consent(bt_address_t * addr, int accept)
293 CHECK_OAL_INITIALIZED();
295 OAL_CHECK_PARAMETER(addr, return);
297 API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), accept);
299 res = blued_api->ssp_reply((bt_bdaddr_t *)addr, BT_SSP_VARIANT_CONSENT, accept, 0);
300 if (res != BT_STATUS_SUCCESS) {
301 BT_ERR("ssp_reply error: [%s]", status2string(res));
302 BT_ERR("%d", accept);
303 return convert_to_oal_status(res);
306 return OAL_STATUS_SUCCESS;
309 oal_status_t device_reply_auth_request(bt_address_t * addr, oal_service_t service_type, int accept, int always)
314 CHECK_OAL_INITIALIZED();
316 OAL_CHECK_PARAMETER(addr, return);
318 API_TRACE("[%s] Accept: %d, always: %d, service_type: %d", bdt_bd2str(addr, &bdstr), accept, always, service_type);
320 res = blued_api->authorize_response((bt_bdaddr_t *)addr, service_type, accept, always);
321 if (res != BT_STATUS_SUCCESS) {
322 BT_ERR("authorize_response error: [%s]", status2string(res));
323 BT_ERR("Accept: [%d], always: [%d], service_type: [%d]", accept, always, service_type);
324 return convert_to_oal_status(res);
327 return OAL_STATUS_SUCCESS;
330 oal_status_t device_set_authorized(bt_address_t * addr, int authorize)
335 CHECK_OAL_INITIALIZED();
337 OAL_CHECK_PARAMETER(addr, return);
339 API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), authorize);
341 res = blued_api->set_authorization((bt_bdaddr_t *)addr, authorize);
342 if (res != BT_STATUS_SUCCESS) {
343 BT_ERR("set_authorization error: [%s]", status2string(res));
344 BT_ERR("%d", authorize);
345 return convert_to_oal_status(res);
348 return OAL_STATUS_SUCCESS;
351 gboolean device_get_acl_conn_state(bt_address_t * addr)
356 CHECK_OAL_INITIALIZED();
357 OAL_CHECK_PARAMETER(addr, return);
359 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
361 res = blued_api->get_connection_state((bt_bdaddr_t *)addr);
362 BT_ERR("get_connection_state returned: [%s]", res ? "TRUE" : "FALSE");
367 gboolean device_get_svc_conn_state(bt_address_t * addr, oal_service_t svc_id)
372 CHECK_OAL_INITIALIZED();
373 OAL_CHECK_PARAMETER(addr, return);
375 API_TRACE("[%s] %d", bdt_bd2str(addr, &bdstr), svc_id);
378 res = blued_api->get_service_connection_state((bt_bdaddr_t *)addr, svc_id);
380 BT_ERR("Not supported");
383 BT_ERR("get_service_connection_state returned: [%s]", res ? "TRUE" : "FALSE");
388 oal_status_t device_register_osp_server(oal_osp_server_type_e type, char *uuid, char *path, int fd)
391 uint32_t server_type;
393 CHECK_OAL_INITIALIZED();
395 API_TRACE("type: %d", type);
399 case OAL_OSP_SERVER_OBEX:
400 server_type = BT_OSP_SERVER_OBEX;
402 case OAL_OSP_SERVER_RFCOMM:
403 server_type = BT_OSP_SERVER_RFCOMM;
406 BT_ERR("unknown type: %d", type);
407 return OAL_STATUS_INVALID_PARAM;
410 res = blued_api->register_agent_osp_server(server_type, uuid, path, fd);
411 if (res != BT_STATUS_SUCCESS) {
412 BT_ERR("register_agent_osp_server error: [%s]", status2string(res));
413 return convert_to_oal_status(res);
416 return OAL_STATUS_SUCCESS;
418 BT_ERR("Not supported");
419 res = OAL_STATUS_NOT_SUPPORT;
424 oal_status_t device_unregister_osp_server(oal_osp_server_type_e type, char *uuid)
427 uint32_t server_type;
429 CHECK_OAL_INITIALIZED();
431 API_TRACE("type: %d", type);
435 case OAL_OSP_SERVER_OBEX:
436 server_type = BT_OSP_SERVER_OBEX;
438 case OAL_OSP_SERVER_RFCOMM:
439 server_type = BT_OSP_SERVER_RFCOMM;
442 BT_ERR("unknown type: %d", type);
443 return OAL_STATUS_INVALID_PARAM;
446 res = blued_api->unregister_agent_osp_server(server_type, uuid);
447 if (res != BT_STATUS_SUCCESS) {
448 BT_ERR("unregister_agent_osp_server error: [%s]", status2string(res));
449 return convert_to_oal_status(res);
452 return OAL_STATUS_SUCCESS;
454 BT_ERR("Not supported");
455 res = OAL_STATUS_NOT_SUPPORT;
460 oal_status_t device_set_trust_profile(bt_address_t *addr, oal_trusted_profile_e profile, gboolean trust)
465 CHECK_OAL_INITIALIZED();
467 OAL_CHECK_PARAMETER(addr, return);
469 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
472 res = blued_api->set_trusted_profile((bt_bdaddr_t *)addr, profile, (trust ? 1 : 0));
473 if (res != BT_STATUS_SUCCESS) {
474 BT_ERR("set_trusted_profile error: [%s]", status2string(res));
475 return convert_to_oal_status(res);
478 return OAL_STATUS_SUCCESS;
480 BT_ERR("Not supported");
481 res = OAL_STATUS_NOT_SUPPORT;
486 oal_status_t device_get_trust_profile(bt_address_t *addr, oal_trusted_profile_e profile, unsigned int *trusted)
491 CHECK_OAL_INITIALIZED();
493 OAL_CHECK_PARAMETER(addr, return);
495 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
498 res = blued_api->get_trusted_profile((bt_bdaddr_t *)addr, profile, trusted);
499 if (res != BT_STATUS_SUCCESS) {
500 BT_ERR("get_trusted_profile error: [%s]", status2string(res));
501 return convert_to_oal_status(res);
504 return OAL_STATUS_SUCCESS;
506 BT_ERR("Not supported");
507 res = OAL_STATUS_NOT_SUPPORT;
512 oal_status_t device_enable_rssi_monitoring(bt_address_t *addr, unsigned int link_type,
513 int low_threshold, int in_range_threshold, int high_threshold)
518 CHECK_OAL_INITIALIZED();
520 OAL_CHECK_PARAMETER(addr, return);
522 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
525 res = blued_api->enable_rssi_monitoring((bt_bdaddr_t *)addr, link_type,
526 low_threshold, in_range_threshold, high_threshold);
527 if (res != BT_STATUS_SUCCESS) {
528 BT_ERR("enable_rssi_monitoring error: [%s]", status2string(res));
529 return convert_to_oal_status(res);
532 return OAL_STATUS_SUCCESS;
534 BT_ERR("Not supported");
535 res = OAL_STATUS_NOT_SUPPORT;
540 oal_status_t device_get_connected_link_rssi_strength(bt_address_t *addr, unsigned int link_type)
545 CHECK_OAL_INITIALIZED();
547 OAL_CHECK_PARAMETER(addr, return);
549 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
552 res = blued_api->get_connected_link_rssi_strength((bt_bdaddr_t *)addr, link_type);
553 if (res != BT_STATUS_SUCCESS) {
554 BT_ERR("get_connected_link_rssi_strength error: [%s]", status2string(res));
555 return convert_to_oal_status(res);
558 return OAL_STATUS_SUCCESS;
560 BT_ERR("Not supported");
561 res = OAL_STATUS_NOT_SUPPORT;
566 oal_status_t device_enable_gap_auth_notifications(oal_gap_auth_type_e type, gboolean enable)
570 CHECK_OAL_INITIALIZED();
572 API_TRACE("type: [%d], enable: %d", type, enable);
575 res = blued_api->enable_gap_auth_notifications(type, (enable ? 1 : 0));
576 if (res != BT_STATUS_SUCCESS) {
577 BT_ERR("enable_gap_auth_notifications error: [%s]", status2string(res));
578 return convert_to_oal_status(res);
581 return OAL_STATUS_SUCCESS;
583 BT_ERR("Not supported");
584 res = OAL_STATUS_NOT_SUPPORT;
589 oal_status_t device_disconnect(bt_address_t * addr)
594 CHECK_OAL_INITIALIZED();
596 OAL_CHECK_PARAMETER(addr, return);
598 API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
600 res = blued_api->device_disconnect((bt_bdaddr_t *)addr);
601 if (res != BT_STATUS_SUCCESS) {
602 BT_ERR("device_disconnect error: [%s]", status2string(res));
603 return convert_to_oal_status(res);
606 return OAL_STATUS_SUCCESS;
609 void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
610 int num_properties, bt_property_t *properties)
613 gpointer event_data = NULL;
614 remote_device_t *dev_info;
615 ble_adv_data_t adv_info;
619 BT_DBG("[%s]status: [%d] num properties [%d]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr),
620 status, num_properties);
622 dev_info = g_new0(remote_device_t, 1);
623 memcpy(dev_info->address.addr, bd_addr->address, 6);
624 parse_device_properties(num_properties, properties, dev_info, &adv_info);
626 if (num_properties == 0) {
627 BT_ERR("!!Unexpected!! num properties is 0 status [%d]", status);
628 /* It is possible that app called get bonded device info for a device
629 which is not yet bonded or udner bonding, in such case, stack will return no properties.
630 It is also possible that after bonding is done, BT MW attempted to fetch
631 bonded device info, but due to internal stack error, 0 properties with status FAIL
632 are received from stack. In such cases, simply send the event to BT MW
633 and let it handle this event */
634 event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
635 memcpy(&dev_props_event->device_info,
636 dev_info, sizeof(remote_device_t));
637 event_data = dev_props_event;
638 event = OAL_EVENT_DEVICE_PROPERTIES;
639 size = sizeof(event_dev_properties_t);
641 } else if (num_properties == 1) {
642 /* For one particular property a dedicated event to be sent */
643 switch (properties[0].type) {
644 case BT_PROPERTY_BDNAME:
645 event = OAL_EVENT_DEVICE_NAME;
646 event_data = dev_info;
647 send_event_trace(event, event_data, sizeof(remote_device_t),
648 (bt_address_t*)bd_addr, "Name: %s", dev_info->name);
650 case BT_PROPERTY_UUIDS: {
651 event_dev_services_t *services_info;
652 bt_uuid_t *uuids = (bt_uuid_t *) properties[0].val;
653 BT_INFO("Properties len [%d] event structure size [%zu]", properties[0].len, sizeof(event_dev_services_t));
655 services_info = g_malloc(sizeof(event_dev_services_t) + properties[0].len);
656 services_info->address = dev_info->address;
657 memcpy(services_info->service_list, uuids, properties[0].len);
658 services_info->num = properties[0].len/sizeof(bt_uuid_t);
659 BT_INFO("Number of UUID [%d]", services_info->num);
660 event = OAL_EVENT_DEVICE_SERVICES;
661 event_data = services_info;
662 size = sizeof(event_dev_services_t) + properties[0].len;
667 BT_ERR("Single Property [%d] not handled", properties[0].type);
672 event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
673 if (dev_info->type != DEV_TYPE_BREDR) {
676 BT_INFO("BLE Device");
677 /* BLE Single or DUAL mode found, so it should have Adv data */
678 dev_props_event->adv_len = adv_info.len;
679 if (dev_props_event->adv_len > 0)
680 memcpy(dev_props_event->adv_data,
681 adv_info.adv_data, adv_info.len);
683 for (i = 0; i < dev_props_event->adv_len; i++)
684 BT_INFO("Adv Data[%d] = [0x%x]",
685 i, dev_props_event->adv_data[i]);
686 memcpy(&dev_props_event->device_info,
687 dev_info, sizeof(remote_device_t));
689 BT_INFO("BREDR type Device");
690 memcpy(&dev_props_event->device_info,
691 dev_info, sizeof(remote_device_t));
694 event_data = dev_props_event;
695 event = OAL_EVENT_DEVICE_PROPERTIES;
696 size = sizeof(event_dev_properties_t);
700 send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
703 void cb_device_bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
704 bt_bond_state_t state)
706 bt_address_t * address = g_new0(bt_address_t, 1);
710 BT_DBG("status: %d, state: %d", status, state);
712 memcpy(address->addr, bd_addr->address, 6);
715 case BT_BOND_STATE_BONDED:
716 event = OAL_EVENT_DEVICE_BONDING_SUCCESS;
718 case BT_BOND_STATE_NONE:
719 /* Reaches both when bonding removed or bonding cancelled */
720 if (BT_STATUS_SUCCESS != status) {
721 event_dev_bond_failed_t * bond_fail_info = g_new0(event_dev_bond_failed_t, 1);
722 bond_fail_info->status = convert_to_oal_status(status);
723 bond_fail_info->address = *address;
724 size = sizeof(event_dev_bond_failed_t);
725 send_event_bda_trace(OAL_EVENT_DEVICE_BONDING_FAILED, bond_fail_info, size, (bt_address_t*)bd_addr);
729 event = OAL_EVENT_DEVICE_BONDING_REMOVED;
731 case BT_BOND_STATE_BONDING:
735 BT_ERR("Unexpected Bond state %d", state);
739 send_event_bda_trace(event, address, sizeof(bt_address_t), (bt_address_t*)bd_addr);
742 void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
743 bt_acl_state_t state)
745 event_dev_conn_status_t * conn_status = g_new0(event_dev_conn_status_t, 1);
746 //bt_address_t * address = g_new0(bt_address_t, 1);
750 BT_DBG("ACL State:%d, state: %d", status, state);
752 memcpy(conn_status->address.addr, bd_addr->address, 6);
755 conn_status->status = convert_to_oal_status(status);
757 if (BT_STATUS_SUCCESS != status) {
758 /* At present only timeout will cause non-success status, later we can add more */
759 conn_status->status = OAL_STATUS_CONN_TIMEOUT;
760 BT_ERR("ACL State Error:%d, state: %d", status, state);
762 conn_status->status = OAL_STATUS_SUCCESS;
764 memcpy(conn_status->address.addr, bd_addr->address, 6);
767 BT_INFO("ACL STATE :%d, conn_status->status :%d, BT_ACL_STATE: %d", status, conn_status->status, state);
770 case BT_ACL_STATE_CONNECTED:
771 event = OAL_EVENT_DEVICE_ACL_CONNECTED;
772 conn_status->status = OAL_STATUS_SUCCESS;
774 case BT_ACL_STATE_DISCONNECTED:
775 event = OAL_EVENT_DEVICE_ACL_DISCONNECTED;
778 BT_ERR("Unexpected ACL state %d", state);
783 size = sizeof(event_dev_conn_status_t);
784 send_event_bda_trace(event, conn_status, size, (bt_address_t*)bd_addr);
788 void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
789 bt_le_conn_state_t state)
791 event_dev_conn_status_t * conn_status = g_new0(event_dev_conn_status_t, 1);
792 //bt_address_t * address = g_new0(bt_address_t, 1);
796 BT_DBG("LE conn status:%d, state: %d", status, state);
797 memcpy(conn_status->address.addr, bd_addr->address, 6);
798 conn_status->status = convert_to_oal_status(status);
801 case BT_LE_CONN_STATE_CONNECTED:
802 event = OAL_EVENT_DEVICE_LE_CONNECTED;
804 case BT_LE_CONN_STATE_DISCONNECTED:
805 event = OAL_EVENT_DEVICE_LE_DISCONNECTED;
808 BT_ERR("Unexpected ACL state %d", state);
813 size = sizeof(event_dev_conn_status_t);
814 send_event_bda_trace(event, conn_status, size, (bt_address_t*)bd_addr);
818 void cb_device_pin_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class)
820 remote_device_t * dev_info = g_new0(remote_device_t, 1);
824 memcpy(dev_info->address.addr, bd_addr->address, 6);
825 g_strlcpy(dev_info->name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
826 dev_info->cod = device_class;
827 size = sizeof(remote_device_t);
829 send_event_bda_trace(OAL_EVENT_DEVICE_PIN_REQUEST, dev_info, size, (bt_address_t*)bd_addr);
832 void cb_device_ssp_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class,
833 bt_ssp_variant_t pairing_variant, uint32_t pass_key)
836 gpointer event_data = NULL;
840 switch (pairing_variant) {
841 case BT_SSP_VARIANT_PASSKEY_ENTRY:
843 remote_device_t * dev_info = g_new0(remote_device_t, 1);
844 memcpy(dev_info->address.addr, bd_addr->address, 6);
845 g_strlcpy(dev_info->name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
846 dev_info->cod = device_class;
847 event = OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST;
848 event_data = dev_info;
849 size = sizeof(remote_device_t);
852 case BT_SSP_VARIANT_PASSKEY_NOTIFICATION:
854 event_dev_passkey_t * passkey_data = g_new0(event_dev_passkey_t, 1);
856 memcpy(passkey_data->device_info.address.addr, bd_addr->address, 6);
857 g_strlcpy(passkey_data->device_info.name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
858 passkey_data->device_info.cod = device_class;
859 passkey_data->pass_key = pass_key;
860 event = OAL_EVENT_DEVICE_PASSKEY_DISPLAY;
861 event_data = passkey_data;
862 size = sizeof(event_dev_passkey_t);
865 case BT_SSP_VARIANT_PASSKEY_CONFIRMATION:
867 event_dev_passkey_t * passkey_data = g_new0(event_dev_passkey_t, 1);
869 memcpy(passkey_data->device_info.address.addr, bd_addr->address, 6);
870 g_strlcpy(passkey_data->device_info.name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
871 passkey_data->device_info.cod = device_class;
872 passkey_data->pass_key = pass_key;
873 event = OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST;
874 event_data = passkey_data;
875 size = sizeof(event_dev_passkey_t);
878 case BT_SSP_VARIANT_CONSENT:
880 remote_device_t * dev_info = g_new0(remote_device_t, 1);
882 memcpy(dev_info->address.addr, bd_addr->address, 6);
883 g_strlcpy(dev_info->name, (const gchar *)bdname->name, BT_DEVICE_NAME_LENGTH_MAX);
884 dev_info->cod = device_class;
885 event = OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST;
886 event_data = dev_info;
887 size = sizeof(remote_device_t);
892 BT_ERR("Unhandled SSP request [%d]", pairing_variant);
896 send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
899 void cb_device_authorize_request(bt_bdaddr_t *bd_addr, bt_service_id_t service_d)
901 event_dev_authorize_req_t * auth_req = g_new0(event_dev_authorize_req_t, 1);
903 BT_INFO("service_d: %d", service_d);
904 memcpy(auth_req->address.addr, bd_addr->address, 6);
905 auth_req->service_id = service_d;
907 send_event_bda_trace(OAL_EVENT_DEVICE_AUTHORIZE_REQUEST, auth_req, sizeof(event_dev_authorize_req_t), (bt_address_t*)bd_addr);
910 void cb_device_trust_state_changed(bt_bdaddr_t *bd_addr, bt_device_trust_state_t trusted)
913 event_dev_trust_t * trust_val = g_new0(event_dev_trust_t, 1);
915 if (trusted == BT_DEVICE_TRUSTED) {
916 BT_INFO("Device is Trusted");
917 event = OAL_EVENT_DEVICE_TRUSTED;
919 BT_INFO("Device is Un Trusted");
920 event = OAL_EVENT_DEVICE_UNTRUSTED;
922 memcpy(trust_val->address.addr, bd_addr->address, 6);
923 trust_val->status = OAL_STATUS_SUCCESS;
924 send_event_bda_trace(event, trust_val, sizeof(event_dev_trust_t), (bt_address_t*)bd_addr);
928 void cb_socket_conn_authorize_request(bt_bdaddr_t *bd_addr, bt_uuid_t *uuid, uint8_t *name, uint8_t *path, uint32_t fd)
930 event_socket_authorize_req_t *auth_req = g_new0(event_socket_authorize_req_t, 1);
932 memcpy(auth_req->address.addr, bd_addr->address, 6);
933 memcpy(auth_req->uuid.uuid, uuid->uu, 16);
934 memcpy(auth_req->name, name, sizeof(auth_req->name) - 1);
935 memcpy(auth_req->path, path, sizeof(auth_req->path) - 1);
938 send_event_bda_trace(OAL_EVENT_SOCKET_AUTHORIZE_REQUEST, auth_req, sizeof(event_socket_authorize_req_t), (bt_address_t*)bd_addr);
941 void cb_device_trusted_profiles_changed(bt_bdaddr_t *bd_addr, uint32_t trust_val)
943 event_device_trusted_profiles_t *ev = g_new0(event_device_trusted_profiles_t, 1);
947 memcpy(ev->address.addr, bd_addr->address, 6);
948 ev->trust_val = trust_val;
949 send_event_bda_trace(OAL_EVENT_DEVICE_TRUSTED_PROFILES_CHANGED,
950 ev, sizeof(event_device_trusted_profiles_t), (bt_address_t*)bd_addr);
954 void cb_rssi_monitor_state_changed(bt_bdaddr_t *bd_addr, int32_t link_type, uint8_t state)
956 event_dev_rssi_info_t *ev = g_new0(event_dev_rssi_info_t, 1);
957 oal_event_t event = OAL_EVENT_RSSI_MONITORING_ENABLED;
961 memcpy(ev->address.addr, bd_addr->address, 6);
962 ev->link_type = link_type;
964 event = OAL_EVENT_RSSI_MONITORING_DISABLED;
966 send_event_bda_trace(event, ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
971 void cb_rssi_alert(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t alert_type, int32_t rssi)
973 event_dev_rssi_info_t *ev = g_new0(event_dev_rssi_info_t, 1);
977 memcpy(ev->address.addr, bd_addr->address, 6);
978 ev->link_type = link_type;
979 ev->alert_type = alert_type;
982 send_event_bda_trace(OAL_EVENT_RSSI_ALERT_RECEIVED,
983 ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
987 void cb_raw_rssi_received(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t rssi)
989 event_dev_rssi_info_t *ev = g_new0(event_dev_rssi_info_t, 1);
993 memcpy(ev->address.addr, bd_addr->address, 6);
994 ev->link_type = link_type;
997 send_event_bda_trace(OAL_EVENT_RAW_RSSI_RECEIVED,
998 ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);