4 * Copyright (c) 2015 -2016 Samsung Electronics Co., Ltd All Rights Reserved.
6 * Contact: Anupam Roy <anupam.r@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "bt-hal-log.h"
30 #include "bt-hal-msg.h"
31 #include "bt-hal-utils.h"
33 #include <bt-hal-adapter-dbus-handler.h>
34 #include <bt-hal-device-dbus-handler.h>
35 #include <bt-hal-hidhost.h>
36 #include <bt-hal-hiddevice.h>
37 #include <bt-hal-socket.h>
38 #include <bt-hal-av.h>
39 #include <bt-hal-hf.h>
40 #include <bt-hal-hdp.h>
41 #include <bt-hal-a2dp-sink.h>
42 #include <bt-hal-avrcp-tg.h>
43 #include <bt-hal-avrcp-ctrl.h>
44 #include <bt-hal-gatt.h>
46 #include <bt-hal-adapter-le.h>
47 #include <bt-hal-agent.h>
49 #include <bt-hal-hf-client.h>
51 #define enum_prop_to_hal(prop, hal_prop, type) do { \
54 prop.len = sizeof(e); \
55 e = *((uint8_t *) (hal_prop->val)); \
58 static const bt_callbacks_t *bt_hal_cbacks = NULL;
61 /* Forward declarations */
62 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop, uint8_t num_props, uint16_t len);
63 static void __bt_device_props_to_hal(bt_property_t *send_props,
64 struct hal_property *prop, uint8_t num_props,
66 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len);
67 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len);
68 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len);
69 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len);
70 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len);
71 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len);
72 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len);
73 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len);
74 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len);
76 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len);
78 static bool interface_ready(void)
80 return bt_hal_cbacks != NULL;
83 static int init(bt_callbacks_t *callbacks)
86 DBG("HAL library Initialization..");
88 if (interface_ready())
89 return BT_STATUS_DONE;
91 bt_hal_cbacks = callbacks;
92 DBG("Store HAL stack msg handler callback");
93 _bt_hal_dbus_store_stack_msg_cb(__bt_hal_handle_stack_messages);
94 ret = _bt_hal_initialize_event_receiver(__bt_hal_handle_stack_messages);
96 if (ret == BT_STATUS_SUCCESS)
97 return BT_STATUS_SUCCESS;
99 return BT_STATUS_FAIL;
102 return BT_STATUS_SUCCESS;
106 static int enable(void)
108 return _bt_hal_dbus_enable_adapter();
111 /* Disable Adapter */
112 static int disable(void)
114 return _bt_hal_dbus_disable_adapter();
118 /* Tizen Specific Reset Adapter */
119 static int reset(void)
121 return _bt_hal_dbus_reset_adapter();
125 static void cleanup(void)
131 /* Tizen Specific Get Powered state */
132 static int get_adapter_powered_status(uint8_t *state)
135 ERR("Invalid param");
136 return BT_STATUS_PARM_INVALID;
139 return _bt_hal_get_adapter_powered_state(state);
143 static int get_adapter_properties(void)
145 return _bt_hal_dbus_get_adapter_properties();
148 static int get_adapter_property(bt_property_type_t type)
150 return _bt_hal_dbus_get_adapter_property(type);
153 static int set_adapter_property(const bt_property_t *property)
156 ERR("Invalid param");
157 return BT_STATUS_PARM_INVALID;
160 return _bt_hal_dbus_set_adapter_property(property);
163 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
166 ERR("Invalid param");
167 return BT_STATUS_PARM_INVALID;
170 return _bt_hal_dbus_get_remote_device_properties(remote_addr);
173 static int get_remote_device_property(bt_bdaddr_t *remote_addr,
174 bt_property_type_t type)
176 return BT_STATUS_UNSUPPORTED;
179 static int set_remote_device_property(bt_bdaddr_t *remote_addr,
180 const bt_property_t *property)
182 return _bt_hal_dbus_set_remote_device_property(remote_addr, property);
185 static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
187 return BT_STATUS_UNSUPPORTED;
190 static int get_remote_services(bt_bdaddr_t *remote_addr)
193 ERR("Invalid param");
194 return BT_STATUS_PARM_INVALID;
196 return _bt_hal_dbus_get_remote_device_services(remote_addr);
199 static int start_discovery(void)
201 return _bt_hal_dbus_start_discovery(false, 0x00);
205 static int start_custom_discovery(bt_disc_role_type_t disc_type)
207 return _bt_hal_dbus_start_discovery(true, disc_type);
211 static int cancel_discovery(void)
213 return _bt_hal_dbus_stop_discovery();
216 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
219 return _bt_hal_device_create_bond(bd_addr, transport);
222 static int cancel_bond(const bt_bdaddr_t *bd_addr)
224 return _bt_hal_device_cancel_bond(bd_addr);
227 static int remove_bond(const bt_bdaddr_t *bd_addr)
230 return _bt_hal_device_remove_bond(bd_addr);
233 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
234 uint8_t pin_len, bt_pin_code_t *pin_code)
236 return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code);
239 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
240 uint8_t accept, uint32_t passkey)
242 return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey);
245 static const void *get_profile_interface(const char *profile_id)
247 /*TODO: Profile interfaces to be included later*/
248 DBG("%s", profile_id);
250 if (!interface_ready())
253 if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
254 return bt_get_hidhost_interface();
256 if (!strcmp(profile_id, BT_PROFILE_HIDDEVICE_ID))
257 return bt_get_hiddevice_interface();
259 if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
260 return bt_get_socket_interface();
262 if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
265 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
266 return bt_get_av_interface();
268 if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
269 return bt_get_avrcp_tg_interface();
271 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
272 return bt_get_hf_interface();
274 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
275 return bt_get_hf_client_interface();
277 if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
278 return bt_get_gatt_interface();
280 if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
281 return bt_get_hl_interface();
283 if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
284 return bt_get_avrcp_ctrl_interface();
286 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
289 if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
292 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
293 return bt_get_a2dp_sink_interface();
298 static int dut_mode_configure(uint8_t enable)
300 return BT_STATUS_UNSUPPORTED;
303 static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
305 return BT_STATUS_UNSUPPORTED;
308 static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
310 return BT_STATUS_UNSUPPORTED;
313 static int config_hci_snoop_log(uint8_t enable)
315 return BT_STATUS_UNSUPPORTED;
318 static int get_connection_state(const bt_bdaddr_t *bd_addr)
321 return _bt_hal_device_get_connection_state(bd_addr);
324 static int set_os_callouts(bt_os_callouts_t *callouts)
326 DBG("callouts: %p", callouts);
328 /* TODO: implement */
330 return BT_STATUS_UNSUPPORTED;
333 static int read_energy_info(void)
335 return BT_STATUS_UNSUPPORTED;
338 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
339 uint8_t authorize, uint8_t save_settings)
342 return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
345 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
348 return _bt_hal_device_set_trust(bd_addr, auth);
352 static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id)
355 return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
358 static int register_agent_osp_server(uint32_t type, char *uuid, char *path, int fd)
361 return _bt_hal_device_register_osp_server(type, uuid, path, fd);
364 static int unregister_agent_osp_server(uint32_t type, char *uuid)
367 return _bt_hal_device_unregister_osp_server(type, uuid);
370 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
373 return _bt_hal_device_set_trusted_profile(bd_addr, profile, trust);
376 static int get_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted)
379 return _bt_hal_device_get_trusted_profile(bd_addr, profile, trusted);
382 static int get_connected_link_rssi_strength(bt_bdaddr_t *bd_addr, uint32_t conn_link_type)
385 return _bt_hal_device_get_connected_link_rssi_strength(bd_addr, conn_link_type);
388 static int enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
389 int low_threshold, int in_range_threshold, int high_threshold)
392 return _bt_hal_device_enable_rssi_monitoring(bd_addr, conn_link_type,
393 low_threshold, in_range_threshold, high_threshold);
396 static int enable_gap_auth_notifications(uint32_t type, uint8_t enable)
399 _bt_hal_enable_gap_auth_notifications(type, ((enable == 0) ? FALSE : TRUE));
400 return BT_STATUS_SUCCESS;
403 static int set_hal_adapter_request_state(int enable)
406 _bt_hal_set_adapter_request_state(enable);
407 return BT_STATUS_SUCCESS;
410 static int set_hal_le_request_state(int enable)
413 _bt_hal_set_le_request_state(enable);
414 return BT_STATUS_SUCCESS;
417 static int dev_disconnect(const bt_bdaddr_t *bd_addr)
420 return _bt_hal_device_disconnect(bd_addr);
424 static const bt_interface_t bluetooth_if = {
425 .size = sizeof(bt_interface_t),
434 .le_enable = _bt_hal_le_enable,
435 .le_disable = _bt_hal_le_disable,
436 .le_init = _bt_hal_le_init,
437 .le_deinit = _bt_hal_le_deinit,
438 .is_advertising = _bt_hal_is_advertising,
442 .get_adapter_powered_status = get_adapter_powered_status,
444 .get_adapter_properties = get_adapter_properties,
445 .get_adapter_property = get_adapter_property,
446 .set_adapter_property = set_adapter_property,
447 .get_remote_device_properties = get_remote_device_properties,
448 .get_remote_device_property = get_remote_device_property,
449 .set_remote_device_property = set_remote_device_property,
450 .get_remote_service_record = get_remote_service_record,
451 .get_remote_services = get_remote_services,
452 .start_discovery = start_discovery,
454 .start_custom_discovery = start_custom_discovery,
456 .cancel_discovery = cancel_discovery,
457 .create_bond = create_bond,
458 .remove_bond = remove_bond,
459 .cancel_bond = cancel_bond,
460 .pin_reply = pin_reply,
461 .ssp_reply = ssp_reply,
462 .get_profile_interface = get_profile_interface,
463 .dut_mode_configure = dut_mode_configure,
464 .dut_mode_send = dut_mode_send,
465 .le_test_mode = le_test_mode,
466 .config_hci_snoop_log = config_hci_snoop_log,
467 .get_connection_state = get_connection_state,
468 .set_os_callouts = set_os_callouts,
469 .read_energy_info = read_energy_info,
470 /* Tizen Specific API's*/
471 .authorize_response = authorize_response,
472 .set_authorization = set_authorization,
474 .get_service_connection_state = get_service_connection_state,
475 .register_agent_osp_server = register_agent_osp_server,
476 .unregister_agent_osp_server = unregister_agent_osp_server,
477 .set_trusted_profile = set_trusted_profile,
478 .get_trusted_profile = get_trusted_profile,
479 .enable_rssi_monitoring = enable_rssi_monitoring,
480 .get_connected_link_rssi_strength = get_connected_link_rssi_strength,
481 .enable_gap_auth_notifications = enable_gap_auth_notifications,
482 .set_le_static_random_address = _bt_hal_set_le_static_random_address,
483 .set_hal_adapter_request_state = set_hal_adapter_request_state,
484 .set_hal_le_request_state = set_hal_le_request_state,
485 .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data,
486 .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
487 .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
488 .device_disconnect = dev_disconnect,
492 static const bt_interface_t *get_bluetooth_interface(void)
495 return &bluetooth_if;
498 static int close_bluetooth(struct hw_device_t *device)
506 static int open_bluetooth(const struct hw_module_t *module, char const *name,
507 struct hw_device_t **device)
509 bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t));
513 memset(dev, 0, sizeof(bluetooth_device_t));
514 dev->common.tag = HARDWARE_DEVICE_TAG;
515 dev->common.version = 0;
516 dev->common.module = (struct hw_module_t *) module;
517 dev->common.close = close_bluetooth;
518 dev->get_bluetooth_interface = get_bluetooth_interface;
520 *device = (struct hw_device_t *) dev;
525 static struct hw_module_methods_t bluetooth_module_methods = {
526 .open = open_bluetooth,
529 struct hw_module_t HAL_MODULE_INFO_SYM = {
530 .tag = HARDWARE_MODULE_TAG,
533 .id = BT_HARDWARE_MODULE_ID,
534 .name = "Bluetooth stack",
535 .author = "Intel Corporation",
536 .methods = &bluetooth_module_methods
539 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
541 struct hal_ev_adapter_state_changed *ev = buf;
543 DBG("Adapter State: %d", ev->state);
545 if (bt_hal_cbacks->adapter_state_changed_cb)
546 bt_hal_cbacks->adapter_state_changed_cb(ev->state);
550 static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
552 struct hal_ev_le_state_changed *ev = buf;
554 DBG("Adapter State: %d", ev->state);
556 if (bt_hal_cbacks->le_state_changed_cb)
557 bt_hal_cbacks->le_state_changed_cb(ev->state);
561 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
562 uint8_t num_props, uint16_t len)
567 for (i = 0; i < num_props; i++) {
568 if (sizeof(*prop) + prop->len > len) {
569 ERR("invalid adapter properties(%zu > %u), cant process further properties!!!",
570 sizeof(*prop) + prop->len, len);
574 send_props[i].type = prop->type;
576 switch (prop->type) {
577 /* TODO: Add Adapter Properties */
579 send_props[i].len = prop->len;
580 send_props[i].val = prop->val;
584 DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
586 len -= sizeof(*prop) + prop->len;
587 buf += sizeof(*prop) + prop->len;
595 static void __bt_device_props_to_hal(bt_property_t *send_props,
596 struct hal_property *prop, uint8_t num_props,
604 for (i = 0; i < num_props; i++) {
606 if (sizeof(*prop) + prop->len > len) {
607 ERR("invalid device properties (%zu > %u), cant process further properties!!!",
608 sizeof(*prop) + prop->len, len);
612 send_props[i].type = prop->type;
614 DBG("HAL prop Type [%d]", prop->type);
616 switch (prop->type) {
617 case HAL_PROP_DEVICE_TYPE:
619 DBG("Device property:HAL_PROP_DEVICE_TYPE:");
620 enum_prop_to_hal(send_props[i], prop,
624 case HAL_PROP_DEVICE_VERSION_INFO:
626 DBG("Device property: HAL_PROP_DEVICE_VERSION_INFO");
627 static bt_remote_version_t e;
628 const struct hal_prop_device_info *p;
629 send_props[i].val = &e;
630 send_props[i].len = sizeof(e);
631 p = (struct hal_prop_device_info *) prop->val;
632 e.manufacturer = p->manufacturer;
633 e.sub_ver = p->sub_version;
634 e.version = p->version;
637 case HAL_PROP_DEVICE_SERVICE_REC:
639 DBG("Device property: HAL_PROP_DEVICE_SERVICE_REC");
640 static bt_service_record_t e;
641 const struct hal_prop_device_service_rec *p;
642 send_props[i].val = &e;
643 send_props[i].len = sizeof(e);
644 p = (struct hal_prop_device_service_rec *) prop->val;
645 memset(&e, 0, sizeof(e));
646 memcpy(&e.channel, &p->channel, sizeof(e.channel));
647 memcpy(e.uuid.uu, p->uuid, sizeof(e.uuid.uu));
648 memcpy(e.name, p->name, p->name_len);
652 send_props[i].len = prop->len;
653 send_props[i].val = prop->val;
657 DBG("prop[%d]: %s, len: %d", i, btproperty2str(&send_props[i]), prop->len);
658 len -= sizeof(*prop) + prop->len;
659 buf += sizeof(*prop) + prop->len;
669 ERR("invalid device properties (%u bytes left), ", len);
672 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
674 struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
675 bt_property_t props[ev->num_props];
678 if (!bt_hal_cbacks->adapter_properties_cb)
682 __bt_adapter_props_to_hal(props, ev->props, ev->num_props, len);
684 if (bt_hal_cbacks->adapter_properties_cb)
685 bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
688 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
690 struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
694 if (bt_hal_cbacks->discovery_state_changed_cb)
695 bt_hal_cbacks->discovery_state_changed_cb(ev->state);
698 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len)
700 struct hal_ev_device_found *ev = (struct hal_ev_device_found *) buf;
701 bt_property_t props[ev->num_props];
704 if (!bt_hal_cbacks->device_found_cb)
708 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
710 bt_hal_cbacks->device_found_cb(ev->num_props, props);
713 static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t len)
715 struct hal_ev_remote_device_props *ev = (struct hal_ev_remote_device_props *) buf;
717 bt_property_t props[ev->num_props];
721 if (!bt_hal_cbacks->remote_device_properties_cb)
725 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
726 memcpy(bd_addr.address, ev->bdaddr, 6);
727 bt_hal_cbacks->remote_device_properties_cb(
728 ev->status, &bd_addr, ev->num_props, props);
732 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
735 struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
739 memcpy(bd_addr.address, ev->bdaddr, 6);
741 DBG("[0x%x]", bd_addr.address[0]);
742 DBG("[0x%x]", bd_addr.address[1]);
743 DBG("[0x%x]", bd_addr.address[2]);
744 DBG("[0x%x]", bd_addr.address[3]);
745 DBG("[0x%x]", bd_addr.address[4]);
746 DBG("[0x%x]", bd_addr.address[5]);
748 DBG("Bonding State changed Status [0x%x]", ev->status);
749 DBG("Bonding State [0x%x]", ev->state);
751 if (!bt_hal_cbacks->bond_state_changed_cb) {
752 ERR("HAL User bond_state_changed_callback is not set!!");
756 bt_hal_cbacks->bond_state_changed_cb(ev->status, &bd_addr, ev->state);
760 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
762 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
766 memcpy(bd_addr.address, ev->bdaddr, 6);
768 DBG("[0x%x]", bd_addr.address[0]);
769 DBG("[0x%x]", bd_addr.address[1]);
770 DBG("[0x%x]", bd_addr.address[2]);
771 DBG("[0x%x]", bd_addr.address[3]);
772 DBG("[0x%x]", bd_addr.address[4]);
773 DBG("[0x%x]", bd_addr.address[5]);
775 DBG("ACL Status [0x%x]", ev->status);
776 DBG("ACL State [0x%x]", ev->state);
778 if (!bt_hal_cbacks->acl_state_changed_cb) {
779 ERR("HAL User acl_state_changed_cb is not set!!");
783 bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
787 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
789 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
793 memcpy(bd_addr.address, ev->bdaddr, 6);
795 DBG("Address: [%02X:%02X:%02X:%02X:%02X:%02X]", bd_addr.address[0],
796 bd_addr.address[1], bd_addr.address[2], bd_addr.address[3],
797 bd_addr.address[4], bd_addr.address[5]);
798 DBG("LE conn Status [0x%x]", ev->status);
799 DBG("LE conn State [0x%x]", ev->state);
802 if (!bt_hal_cbacks->le_conn_state_changed_cb) {
803 ERR("HAL User le_conn_state_changed_cb is not set!!");
807 bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
812 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
814 struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
819 memcpy(bd_addr.address, ev->bdaddr, 6);
822 DBG("[0x%x]", bd_addr.address[0]);
823 DBG("[0x%x]", bd_addr.address[1]);
824 DBG("[0x%x]", bd_addr.address[2]);
825 DBG("[0x%x]", bd_addr.address[3]);
826 DBG("[0x%x]", bd_addr.address[4]);
827 DBG("[0x%x]", bd_addr.address[5]);
829 DBG("Service Id: [%u]", ev->service_id);
831 if (!bt_hal_cbacks->authorize_request_cb) {
832 ERR("HAL User authorize_request_cb is not set!!");
836 bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
841 static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
843 struct hal_ev_sock_conn_auth *ev = buf;
846 uint8_t name[249] = {0, };
847 uint8_t path[249] = {0, };
852 memcpy(bd_addr.address, ev->bdaddr, 6);
853 memcpy(uuid.uu, ev->uuid, 16);
854 memcpy(name, ev->name, sizeof(name) - 1);
855 memcpy(path, ev->path, sizeof(name) - 1);
858 if (!bt_hal_cbacks->socket_authorize_request_cb) {
859 ERR("HAL User socket_authorize_request_cb is not set!!");
863 bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid, name, path, fd);
868 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
870 struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
875 memcpy(bd_addr.address, ev->bdaddr, 6);
876 memcpy(bd_name.name, ev->name, 248);
879 DBG("[0x%x]", bd_addr.address[0]);
880 DBG("[0x%x]", bd_addr.address[1]);
881 DBG("[0x%x]", bd_addr.address[2]);
882 DBG("[0x%x]", bd_addr.address[3]);
883 DBG("[0x%x]", bd_addr.address[4]);
884 DBG("[0x%x]", bd_addr.address[5]);
886 DBG("COD [%d]", ev->class_of_dev);
887 DBG("pairing variant [%d]", ev->pairing_variant);
888 DBG("passkey [%d]", ev->passkey);
890 if (!bt_hal_cbacks->ssp_request_cb) {
891 ERR("HAL User ssp_request_cb is not set!!");
895 bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
897 ev->pairing_variant, ev->passkey);
901 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
903 struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
908 memcpy(bd_addr.address, ev->bdaddr, 6);
909 memcpy(bd_name.name, ev->name, 248);
912 DBG("[0x%x]", bd_addr.address[0]);
913 DBG("[0x%x]", bd_addr.address[1]);
914 DBG("[0x%x]", bd_addr.address[2]);
915 DBG("[0x%x]", bd_addr.address[3]);
916 DBG("[0x%x]", bd_addr.address[4]);
917 DBG("[0x%x]", bd_addr.address[5]);
919 DBG("COD [%u]", ev->class_of_dev);
921 if (!bt_hal_cbacks->pin_request_cb) {
922 ERR("HAL User pin_request_cb is not set!!");
926 bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
931 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
933 struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
937 memcpy(bd_addr.address, ev->bdaddr, 6);
939 DBG("[0x%x]", bd_addr.address[0]);
940 DBG("[0x%x]", bd_addr.address[1]);
941 DBG("[0x%x]", bd_addr.address[2]);
942 DBG("[0x%x]", bd_addr.address[3]);
943 DBG("[0x%x]", bd_addr.address[4]);
944 DBG("[0x%x]", bd_addr.address[5]);
946 DBG("Device Trusted? [0x%x]", ev->trust);
948 if (!bt_hal_cbacks->device_trust_state_changed_cb) {
949 ERR("HAL User device_trust_state_changed_cb is not set!!");
953 bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
957 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
959 struct hal_ev_device_trusted_profiles_changed *ev = buf;
964 memcpy(bd_addr.address, ev->bdaddr, 6);
965 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
966 bd_addr.address[0], bd_addr.address[1],
967 bd_addr.address[2], bd_addr.address[3],
968 bd_addr.address[4], bd_addr.address[5]);
970 if (!bt_hal_cbacks->device_trusted_profiles_changed_cb) {
971 ERR("device_trusted_profiles_changed_cb is NULL");
975 bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
980 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
982 struct hal_ev_rssi_monitor_state_changed *ev = buf;
987 memcpy(bd_addr.address, ev->bdaddr, 6);
988 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
989 bd_addr.address[0], bd_addr.address[1],
990 bd_addr.address[2], bd_addr.address[3],
991 bd_addr.address[4], bd_addr.address[5]);
993 if (bt_hal_cbacks->rssi_monitor_state_changed_cb)
994 bt_hal_cbacks->rssi_monitor_state_changed_cb(
995 &bd_addr, ev->link_type, ev->state);
1000 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
1002 struct hal_ev_rssi_alert_recieved *ev = buf;
1003 bt_bdaddr_t bd_addr;
1007 memcpy(bd_addr.address, ev->bdaddr, 6);
1008 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
1009 bd_addr.address[0], bd_addr.address[1],
1010 bd_addr.address[2], bd_addr.address[3],
1011 bd_addr.address[4], bd_addr.address[5]);
1013 if (bt_hal_cbacks->rssi_alert_cb)
1014 bt_hal_cbacks->rssi_alert_cb(
1015 &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
1020 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
1022 struct hal_ev_raw_rssi_recieved *ev = buf;
1023 bt_bdaddr_t bd_addr;
1027 memcpy(bd_addr.address, ev->bdaddr, 6);
1028 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
1029 bd_addr.address[0], bd_addr.address[1],
1030 bd_addr.address[2], bd_addr.address[3],
1031 bd_addr.address[4], bd_addr.address[5]);
1033 if (bt_hal_cbacks->raw_rssi_received_cb)
1034 bt_hal_cbacks->raw_rssi_received_cb(
1035 &bd_addr, ev->link_type, ev->rssi);
1040 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
1044 case HAL_EV_ADAPTER_STATE_CHANGED:
1045 DBG("Event: HAL_EV_ADAPTER_STATE_CHANGED");
1046 __bt_hal_handle_adapter_state_changed(buf, len);
1048 case HAL_EV_ADAPTER_PROPS_CHANGED:
1049 DBG("Event: HAL_EV_ADAPTER_PROPS_CHANGED");
1050 __bt_hal_handle_adapter_property_changed(buf, len);
1052 case HAL_EV_DISCOVERY_STATE_CHANGED:
1053 DBG("Event: HAL_EV_DISCOVERY_STATE_CHANGED");
1054 __bt_hal_handle_adapter_discovery_state_changed(buf, len);
1056 case HAL_EV_DEVICE_FOUND:
1057 DBG("Event: HAL_EV_DEVICE_FOUND");
1058 __bt_hal_handle_device_found_event(buf, len);
1060 case HAL_EV_REMOTE_DEVICE_PROPS:
1061 DBG("Event: HAL_EV_REMOTE_DEVICE_PROPS");
1062 __bt_hal_handle_remote_device_properties_event(buf, len);
1064 case HAL_EV_BOND_STATE_CHANGED:
1065 DBG("Event: HAL_EV_BOND_STATE_CHANGED:");
1066 __bt_hal_handle_bond_state_changed_event(buf, len);
1068 case HAL_EV_ACL_STATE_CHANGED:
1069 DBG("Event: HAL_ACL_STATE_CONNECTED or Disconnected");
1070 __bt_hal_handle_device_acl_state_changed_event(buf, len);
1072 case HAL_EV_LE_CONN_STATE_CHANGED:
1073 DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
1074 __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
1076 case HAL_EV_SSP_REQUEST:
1077 DBG("Event: HAL_EV_SSP_REQUEST");
1078 __bt_hal_handle_ssp_request_event(buf, len);
1080 case HAL_EV_PIN_REQUEST:
1081 DBG("Event: HAL_EV_PIN_REQUEST");
1082 __bt_hal_handle_pin_request_event(buf, len);
1084 case HAL_EV_AUTHORIZE_REQUEST:
1085 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1086 __bt_hal_handle_authorize_request_event(buf, len);
1088 case HAL_EV_DEVICE_TRUST_CHANGED:
1089 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1090 __bt_hal_handle_device_trust_state_changed_event(buf, len);
1093 case HAL_EV_SOCK_AUTHORIZE_REQUEST:
1094 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1095 __bt_hal_handle_socket_authorize_request_event(buf, len);
1097 case HAL_EV_LE_STATE_CHANGED:
1098 DBG("Event: HAL_EV_LE_STATE_CHANGED");
1099 __bt_hal_handle_le_state_changed(buf, len);
1102 case HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED:
1103 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1104 __bt_hal_handle_device_trusted_profiles_changed_event(buf, len);
1106 case HAL_EV_RSSI_MONITOR_STATE_CHANGED:
1107 DBG("Event: HAL_EV_RSSI_MONITOR_STATE_CHANGED");
1108 __bt_handle_rssi_monitor_state_changed(buf, len);
1110 case HAL_EV_RSSI_ALERT_RECIEVED:
1111 DBG("Event: HAL_EV_RSSI_ALERT_RECIEVED");
1112 __bt_handle_rssi_alert_recieved(buf, len);
1114 case HAL_EV_RAW_RSSI_RECIEVED:
1115 DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
1116 __bt_handle_raw_rssi_recieved(buf, len);
1119 DBG("Event Currently not handled!!");