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 Recover Adapter */
119 static int recover(void)
121 return _bt_hal_dbus_recover_adapter();
126 /* Tizen Specific Reset Adapter */
127 static int reset(void)
129 return _bt_hal_dbus_reset_adapter();
133 static void cleanup(void)
139 /* Tizen Specific Get Powered state */
140 static int get_adapter_powered_status(uint8_t *state)
143 ERR("Invalid param");
144 return BT_STATUS_PARM_INVALID;
147 return _bt_hal_get_adapter_powered_state(state);
151 static int get_adapter_properties(void)
153 return _bt_hal_dbus_get_adapter_properties();
156 static int get_adapter_property(bt_property_type_t type)
158 return _bt_hal_dbus_get_adapter_property(type);
161 static int set_adapter_property(const bt_property_t *property)
164 ERR("Invalid param");
165 return BT_STATUS_PARM_INVALID;
168 return _bt_hal_dbus_set_adapter_property(property);
171 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
174 ERR("Invalid param");
175 return BT_STATUS_PARM_INVALID;
178 return _bt_hal_dbus_get_remote_device_properties(remote_addr);
181 static int get_remote_device_property(bt_bdaddr_t *remote_addr,
182 bt_property_type_t type)
184 return BT_STATUS_UNSUPPORTED;
187 static int set_remote_device_property(bt_bdaddr_t *remote_addr,
188 const bt_property_t *property)
190 return _bt_hal_dbus_set_remote_device_property(remote_addr, property);
193 static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
195 return BT_STATUS_UNSUPPORTED;
198 static int get_remote_services(bt_bdaddr_t *remote_addr)
201 ERR("Invalid param");
202 return BT_STATUS_PARM_INVALID;
204 return _bt_hal_dbus_get_remote_device_services(remote_addr);
207 static int start_discovery(void)
209 return _bt_hal_dbus_start_discovery(false, 0x00);
213 static int start_custom_discovery(bt_disc_role_type_t disc_type)
215 return _bt_hal_dbus_start_discovery(true, disc_type);
219 static int cancel_discovery(void)
221 return _bt_hal_dbus_stop_discovery();
224 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
227 return _bt_hal_device_create_bond(bd_addr, transport);
230 static int cancel_bond(const bt_bdaddr_t *bd_addr)
232 return _bt_hal_device_cancel_bond(bd_addr);
235 static int remove_bond(const bt_bdaddr_t *bd_addr)
238 return _bt_hal_device_remove_bond(bd_addr);
241 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
242 uint8_t pin_len, bt_pin_code_t *pin_code)
244 return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code);
247 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
248 uint8_t accept, uint32_t passkey)
250 return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey);
253 static const void *get_profile_interface(const char *profile_id)
255 /*TODO: Profile interfaces to be included later*/
256 DBG("%s", profile_id);
258 if (!interface_ready())
261 if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
262 return bt_get_hidhost_interface();
264 if (!strcmp(profile_id, BT_PROFILE_HIDDEVICE_ID))
265 return bt_get_hiddevice_interface();
267 if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
268 return bt_get_socket_interface();
270 if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
273 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
274 return bt_get_av_interface();
276 if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
277 return bt_get_avrcp_tg_interface();
279 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
280 return bt_get_hf_interface();
282 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
283 return bt_get_hf_client_interface();
285 if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
286 return bt_get_gatt_interface();
288 if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
289 return bt_get_hl_interface();
291 if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
292 return bt_get_avrcp_ctrl_interface();
294 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
297 if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
300 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
301 return bt_get_a2dp_sink_interface();
306 static int dut_mode_configure(uint8_t enable)
308 return BT_STATUS_UNSUPPORTED;
311 static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
313 return BT_STATUS_UNSUPPORTED;
316 static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
318 return BT_STATUS_UNSUPPORTED;
321 static int config_hci_snoop_log(uint8_t enable)
323 return BT_STATUS_UNSUPPORTED;
326 static int get_connection_state(const bt_bdaddr_t *bd_addr)
329 return _bt_hal_device_get_connection_state(bd_addr);
332 static int set_os_callouts(bt_os_callouts_t *callouts)
334 DBG("callouts: %p", callouts);
336 /* TODO: implement */
338 return BT_STATUS_UNSUPPORTED;
341 static int read_energy_info(void)
343 return BT_STATUS_UNSUPPORTED;
346 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
347 uint8_t authorize, uint8_t save_settings)
350 return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
353 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
356 return _bt_hal_device_set_trust(bd_addr, auth);
360 static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id)
363 return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
366 static int register_agent_osp_server(uint32_t type, char *uuid, char *path, int fd)
369 return _bt_hal_device_register_osp_server(type, uuid, path, fd);
372 static int unregister_agent_osp_server(uint32_t type, char *uuid)
375 return _bt_hal_device_unregister_osp_server(type, uuid);
378 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
381 return _bt_hal_device_set_trusted_profile(bd_addr, profile, trust);
384 static int get_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted)
387 return _bt_hal_device_get_trusted_profile(bd_addr, profile, trusted);
390 static int get_connected_link_rssi_strength(bt_bdaddr_t *bd_addr, uint32_t conn_link_type)
393 return _bt_hal_device_get_connected_link_rssi_strength(bd_addr, conn_link_type);
396 static int enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
397 int low_threshold, int in_range_threshold, int high_threshold)
400 return _bt_hal_device_enable_rssi_monitoring(bd_addr, conn_link_type,
401 low_threshold, in_range_threshold, high_threshold);
404 static int enable_gap_auth_notifications(uint32_t type, uint8_t enable)
407 _bt_hal_enable_gap_auth_notifications(type, ((enable == 0) ? FALSE : TRUE));
408 return BT_STATUS_SUCCESS;
411 static int set_hal_adapter_request_state(int enable)
414 _bt_hal_set_adapter_request_state(enable);
415 return BT_STATUS_SUCCESS;
418 static int set_hal_le_request_state(int enable)
421 _bt_hal_set_le_request_state(enable);
422 return BT_STATUS_SUCCESS;
425 static int dev_disconnect(const bt_bdaddr_t *bd_addr)
428 return _bt_hal_device_disconnect(bd_addr);
432 static const bt_interface_t bluetooth_if = {
433 .size = sizeof(bt_interface_t),
444 .le_enable = _bt_hal_le_enable,
445 .le_disable = _bt_hal_le_disable,
446 .le_init = _bt_hal_le_init,
447 .le_deinit = _bt_hal_le_deinit,
448 .is_advertising = _bt_hal_is_advertising,
452 .get_adapter_powered_status = get_adapter_powered_status,
454 .get_adapter_properties = get_adapter_properties,
455 .get_adapter_property = get_adapter_property,
456 .set_adapter_property = set_adapter_property,
457 .get_remote_device_properties = get_remote_device_properties,
458 .get_remote_device_property = get_remote_device_property,
459 .set_remote_device_property = set_remote_device_property,
460 .get_remote_service_record = get_remote_service_record,
461 .get_remote_services = get_remote_services,
462 .start_discovery = start_discovery,
464 .start_custom_discovery = start_custom_discovery,
466 .cancel_discovery = cancel_discovery,
467 .create_bond = create_bond,
468 .remove_bond = remove_bond,
469 .cancel_bond = cancel_bond,
470 .pin_reply = pin_reply,
471 .ssp_reply = ssp_reply,
472 .get_profile_interface = get_profile_interface,
473 .dut_mode_configure = dut_mode_configure,
474 .dut_mode_send = dut_mode_send,
475 .le_test_mode = le_test_mode,
476 .config_hci_snoop_log = config_hci_snoop_log,
477 .get_connection_state = get_connection_state,
478 .set_os_callouts = set_os_callouts,
479 .read_energy_info = read_energy_info,
480 /* Tizen Specific API's*/
481 .authorize_response = authorize_response,
482 .set_authorization = set_authorization,
484 .get_service_connection_state = get_service_connection_state,
485 .register_agent_osp_server = register_agent_osp_server,
486 .unregister_agent_osp_server = unregister_agent_osp_server,
487 .set_trusted_profile = set_trusted_profile,
488 .get_trusted_profile = get_trusted_profile,
489 .enable_rssi_monitoring = enable_rssi_monitoring,
490 .get_connected_link_rssi_strength = get_connected_link_rssi_strength,
491 .enable_gap_auth_notifications = enable_gap_auth_notifications,
492 .set_le_static_random_address = _bt_hal_set_le_static_random_address,
493 .set_hal_adapter_request_state = set_hal_adapter_request_state,
494 .set_hal_le_request_state = set_hal_le_request_state,
495 .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data,
496 .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
497 .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
498 .device_disconnect = dev_disconnect,
502 static const bt_interface_t *get_bluetooth_interface(void)
505 return &bluetooth_if;
508 static int close_bluetooth(struct hw_device_t *device)
516 static int open_bluetooth(const struct hw_module_t *module, char const *name,
517 struct hw_device_t **device)
519 bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t));
523 memset(dev, 0, sizeof(bluetooth_device_t));
524 dev->common.tag = HARDWARE_DEVICE_TAG;
525 dev->common.version = 0;
526 dev->common.module = (struct hw_module_t *) module;
527 dev->common.close = close_bluetooth;
528 dev->get_bluetooth_interface = get_bluetooth_interface;
530 *device = (struct hw_device_t *) dev;
535 static struct hw_module_methods_t bluetooth_module_methods = {
536 .open = open_bluetooth,
539 struct hw_module_t HAL_MODULE_INFO_SYM = {
540 .tag = HARDWARE_MODULE_TAG,
543 .id = BT_HARDWARE_MODULE_ID,
545 .author = "Intel Corporation",
546 .methods = &bluetooth_module_methods
549 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
551 struct hal_ev_adapter_state_changed *ev = buf;
553 DBG("Adapter State: %d", ev->state);
555 if (bt_hal_cbacks->adapter_state_changed_cb)
556 bt_hal_cbacks->adapter_state_changed_cb(ev->state);
560 static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
562 struct hal_ev_le_state_changed *ev = buf;
564 DBG("Adapter State: %d", ev->state);
566 if (bt_hal_cbacks->le_state_changed_cb)
567 bt_hal_cbacks->le_state_changed_cb(ev->state);
571 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
572 uint8_t num_props, uint16_t len)
577 for (i = 0; i < num_props; i++) {
578 if (sizeof(*prop) + prop->len > len) {
579 ERR("invalid adapter properties(%zu > %u), cant process further properties!!!",
580 sizeof(*prop) + prop->len, len);
584 send_props[i].type = prop->type;
586 switch (prop->type) {
587 /* TODO: Add Adapter Properties */
589 send_props[i].len = prop->len;
590 send_props[i].val = prop->val;
594 DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
596 len -= sizeof(*prop) + prop->len;
597 buf += sizeof(*prop) + prop->len;
605 static void __bt_device_props_to_hal(bt_property_t *send_props,
606 struct hal_property *prop, uint8_t num_props,
614 for (i = 0; i < num_props; i++) {
616 if (sizeof(*prop) + prop->len > len) {
617 ERR("invalid device properties (%zu > %u), cant process further properties!!!",
618 sizeof(*prop) + prop->len, len);
622 send_props[i].type = prop->type;
624 DBG("HAL prop Type [%d]", prop->type);
626 switch (prop->type) {
627 case HAL_PROP_DEVICE_TYPE:
629 DBG("Device property:HAL_PROP_DEVICE_TYPE:");
630 enum_prop_to_hal(send_props[i], prop,
634 case HAL_PROP_DEVICE_VERSION_INFO:
636 DBG("Device property: HAL_PROP_DEVICE_VERSION_INFO");
637 static bt_remote_version_t e;
638 const struct hal_prop_device_info *p;
639 send_props[i].val = &e;
640 send_props[i].len = sizeof(e);
641 p = (struct hal_prop_device_info *) prop->val;
642 e.manufacturer = p->manufacturer;
643 e.sub_ver = p->sub_version;
644 e.version = p->version;
647 case HAL_PROP_DEVICE_SERVICE_REC:
649 DBG("Device property: HAL_PROP_DEVICE_SERVICE_REC");
650 static bt_service_record_t e;
651 const struct hal_prop_device_service_rec *p;
652 send_props[i].val = &e;
653 send_props[i].len = sizeof(e);
654 p = (struct hal_prop_device_service_rec *) prop->val;
655 memset(&e, 0, sizeof(e));
656 memcpy(&e.channel, &p->channel, sizeof(e.channel));
657 memcpy(e.uuid.uu, p->uuid, sizeof(e.uuid.uu));
658 memcpy(e.name, p->name, p->name_len);
662 send_props[i].len = prop->len;
663 send_props[i].val = prop->val;
667 DBG("prop[%d]: %s, len: %d", i, btproperty2str(&send_props[i]), prop->len);
668 len -= sizeof(*prop) + prop->len;
669 buf += sizeof(*prop) + prop->len;
679 ERR("invalid device properties (%u bytes left), ", len);
682 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
684 struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
685 bt_property_t props[ev->num_props];
688 if (!bt_hal_cbacks->adapter_properties_cb)
692 __bt_adapter_props_to_hal(props, ev->props, ev->num_props, len);
694 if (bt_hal_cbacks->adapter_properties_cb)
695 bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
698 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
700 struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
704 if (bt_hal_cbacks->discovery_state_changed_cb)
705 bt_hal_cbacks->discovery_state_changed_cb(ev->state);
708 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len)
710 struct hal_ev_device_found *ev = (struct hal_ev_device_found *) buf;
711 bt_property_t props[ev->num_props];
714 if (!bt_hal_cbacks->device_found_cb)
718 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
720 bt_hal_cbacks->device_found_cb(ev->num_props, props);
723 static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t len)
725 struct hal_ev_remote_device_props *ev = (struct hal_ev_remote_device_props *) buf;
727 bt_property_t props[ev->num_props];
731 if (!bt_hal_cbacks->remote_device_properties_cb)
735 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
736 memcpy(bd_addr.address, ev->bdaddr, 6);
737 bt_hal_cbacks->remote_device_properties_cb(
738 ev->status, &bd_addr, ev->num_props, props);
742 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
745 struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
749 memcpy(bd_addr.address, ev->bdaddr, 6);
751 DBG("[0x%x]", bd_addr.address[0]);
752 DBG("[0x%x]", bd_addr.address[1]);
753 DBG("[0x%x]", bd_addr.address[2]);
754 DBG("[0x%x]", bd_addr.address[3]);
755 DBG("[0x%x]", bd_addr.address[4]);
756 DBG("[0x%x]", bd_addr.address[5]);
758 DBG("Bonding State changed Status [0x%x]", ev->status);
759 DBG("Bonding State [0x%x]", ev->state);
761 if (!bt_hal_cbacks->bond_state_changed_cb) {
762 ERR("HAL User bond_state_changed_callback is not set!!");
766 bt_hal_cbacks->bond_state_changed_cb(ev->status, &bd_addr, ev->state);
770 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
772 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
776 memcpy(bd_addr.address, ev->bdaddr, 6);
778 DBG("[0x%x]", bd_addr.address[0]);
779 DBG("[0x%x]", bd_addr.address[1]);
780 DBG("[0x%x]", bd_addr.address[2]);
781 DBG("[0x%x]", bd_addr.address[3]);
782 DBG("[0x%x]", bd_addr.address[4]);
783 DBG("[0x%x]", bd_addr.address[5]);
785 DBG("ACL Status [0x%x]", ev->status);
786 DBG("ACL State [0x%x]", ev->state);
788 if (!bt_hal_cbacks->acl_state_changed_cb) {
789 ERR("HAL User acl_state_changed_cb is not set!!");
793 bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
797 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
799 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
803 memcpy(bd_addr.address, ev->bdaddr, 6);
805 DBG("Address: [%02X:%02X:%02X:%02X:%02X:%02X]", bd_addr.address[0],
806 bd_addr.address[1], bd_addr.address[2], bd_addr.address[3],
807 bd_addr.address[4], bd_addr.address[5]);
808 DBG("LE conn Status [0x%x]", ev->status);
809 DBG("LE conn State [0x%x]", ev->state);
812 if (!bt_hal_cbacks->le_conn_state_changed_cb) {
813 ERR("HAL User le_conn_state_changed_cb is not set!!");
817 bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
822 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
824 struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
829 memcpy(bd_addr.address, ev->bdaddr, 6);
832 DBG("[0x%x]", bd_addr.address[0]);
833 DBG("[0x%x]", bd_addr.address[1]);
834 DBG("[0x%x]", bd_addr.address[2]);
835 DBG("[0x%x]", bd_addr.address[3]);
836 DBG("[0x%x]", bd_addr.address[4]);
837 DBG("[0x%x]", bd_addr.address[5]);
839 DBG("Service Id: [%u]", ev->service_id);
841 if (!bt_hal_cbacks->authorize_request_cb) {
842 ERR("HAL User authorize_request_cb is not set!!");
846 bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
851 static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
853 struct hal_ev_sock_conn_auth *ev = buf;
856 uint8_t name[249] = {0, };
857 uint8_t path[249] = {0, };
862 memcpy(bd_addr.address, ev->bdaddr, 6);
863 memcpy(uuid.uu, ev->uuid, 16);
864 memcpy(name, ev->name, sizeof(name) - 1);
865 memcpy(path, ev->path, sizeof(name) - 1);
868 if (!bt_hal_cbacks->socket_authorize_request_cb) {
869 ERR("HAL User socket_authorize_request_cb is not set!!");
873 bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid, name, path, fd);
878 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
880 struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
885 memcpy(bd_addr.address, ev->bdaddr, 6);
886 memcpy(bd_name.name, ev->name, 248);
889 DBG("[0x%x]", bd_addr.address[0]);
890 DBG("[0x%x]", bd_addr.address[1]);
891 DBG("[0x%x]", bd_addr.address[2]);
892 DBG("[0x%x]", bd_addr.address[3]);
893 DBG("[0x%x]", bd_addr.address[4]);
894 DBG("[0x%x]", bd_addr.address[5]);
896 DBG("COD [%d]", ev->class_of_dev);
897 DBG("pairing variant [%d]", ev->pairing_variant);
898 DBG("passkey [%d]", ev->passkey);
900 if (!bt_hal_cbacks->ssp_request_cb) {
901 ERR("HAL User ssp_request_cb is not set!!");
905 bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
907 ev->pairing_variant, ev->passkey);
911 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
913 struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
918 memcpy(bd_addr.address, ev->bdaddr, 6);
919 memcpy(bd_name.name, ev->name, 248);
922 DBG("[0x%x]", bd_addr.address[0]);
923 DBG("[0x%x]", bd_addr.address[1]);
924 DBG("[0x%x]", bd_addr.address[2]);
925 DBG("[0x%x]", bd_addr.address[3]);
926 DBG("[0x%x]", bd_addr.address[4]);
927 DBG("[0x%x]", bd_addr.address[5]);
929 DBG("COD [%u]", ev->class_of_dev);
931 if (!bt_hal_cbacks->pin_request_cb) {
932 ERR("HAL User pin_request_cb is not set!!");
936 bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
941 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
943 struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
947 memcpy(bd_addr.address, ev->bdaddr, 6);
949 DBG("[0x%x]", bd_addr.address[0]);
950 DBG("[0x%x]", bd_addr.address[1]);
951 DBG("[0x%x]", bd_addr.address[2]);
952 DBG("[0x%x]", bd_addr.address[3]);
953 DBG("[0x%x]", bd_addr.address[4]);
954 DBG("[0x%x]", bd_addr.address[5]);
956 DBG("Device Trusted? [0x%x]", ev->trust);
958 if (!bt_hal_cbacks->device_trust_state_changed_cb) {
959 ERR("HAL User device_trust_state_changed_cb is not set!!");
963 bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
967 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
969 struct hal_ev_device_trusted_profiles_changed *ev = buf;
974 memcpy(bd_addr.address, ev->bdaddr, 6);
975 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
976 bd_addr.address[0], bd_addr.address[1],
977 bd_addr.address[2], bd_addr.address[3],
978 bd_addr.address[4], bd_addr.address[5]);
980 if (!bt_hal_cbacks->device_trusted_profiles_changed_cb) {
981 ERR("device_trusted_profiles_changed_cb is NULL");
985 bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
990 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
992 struct hal_ev_rssi_monitor_state_changed *ev = buf;
997 memcpy(bd_addr.address, ev->bdaddr, 6);
998 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
999 bd_addr.address[0], bd_addr.address[1],
1000 bd_addr.address[2], bd_addr.address[3],
1001 bd_addr.address[4], bd_addr.address[5]);
1003 if (bt_hal_cbacks->rssi_monitor_state_changed_cb)
1004 bt_hal_cbacks->rssi_monitor_state_changed_cb(
1005 &bd_addr, ev->link_type, ev->state);
1010 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
1012 struct hal_ev_rssi_alert_recieved *ev = buf;
1013 bt_bdaddr_t bd_addr;
1017 memcpy(bd_addr.address, ev->bdaddr, 6);
1018 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
1019 bd_addr.address[0], bd_addr.address[1],
1020 bd_addr.address[2], bd_addr.address[3],
1021 bd_addr.address[4], bd_addr.address[5]);
1023 if (bt_hal_cbacks->rssi_alert_cb)
1024 bt_hal_cbacks->rssi_alert_cb(
1025 &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
1030 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
1032 struct hal_ev_raw_rssi_recieved *ev = buf;
1033 bt_bdaddr_t bd_addr;
1037 memcpy(bd_addr.address, ev->bdaddr, 6);
1038 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
1039 bd_addr.address[0], bd_addr.address[1],
1040 bd_addr.address[2], bd_addr.address[3],
1041 bd_addr.address[4], bd_addr.address[5]);
1043 if (bt_hal_cbacks->raw_rssi_received_cb)
1044 bt_hal_cbacks->raw_rssi_received_cb(
1045 &bd_addr, ev->link_type, ev->rssi);
1050 static void __bt_handle_dbfw_plus_info_recieved(void *buf, uint16_t len)
1052 struct hal_ev_dbfw_plus_info_recieved *info = buf;
1056 if (bt_hal_cbacks->dbfw_plus_info_received_cb)
1057 bt_hal_cbacks->dbfw_plus_info_received_cb(
1058 info->data, info->data_len, info->event_code);
1063 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
1067 case HAL_EV_ADAPTER_STATE_CHANGED:
1068 DBG("Event: HAL_EV_ADAPTER_STATE_CHANGED");
1069 __bt_hal_handle_adapter_state_changed(buf, len);
1071 case HAL_EV_ADAPTER_PROPS_CHANGED:
1072 DBG("Event: HAL_EV_ADAPTER_PROPS_CHANGED");
1073 __bt_hal_handle_adapter_property_changed(buf, len);
1075 case HAL_EV_DISCOVERY_STATE_CHANGED:
1076 DBG("Event: HAL_EV_DISCOVERY_STATE_CHANGED");
1077 __bt_hal_handle_adapter_discovery_state_changed(buf, len);
1079 case HAL_EV_DEVICE_FOUND:
1080 DBG("Event: HAL_EV_DEVICE_FOUND");
1081 __bt_hal_handle_device_found_event(buf, len);
1083 case HAL_EV_REMOTE_DEVICE_PROPS:
1084 DBG("Event: HAL_EV_REMOTE_DEVICE_PROPS");
1085 __bt_hal_handle_remote_device_properties_event(buf, len);
1087 case HAL_EV_BOND_STATE_CHANGED:
1088 DBG("Event: HAL_EV_BOND_STATE_CHANGED:");
1089 __bt_hal_handle_bond_state_changed_event(buf, len);
1091 case HAL_EV_ACL_STATE_CHANGED:
1092 DBG("Event: HAL_ACL_STATE_CONNECTED or Disconnected");
1093 __bt_hal_handle_device_acl_state_changed_event(buf, len);
1095 case HAL_EV_LE_CONN_STATE_CHANGED:
1096 DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
1097 __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
1099 case HAL_EV_SSP_REQUEST:
1100 DBG("Event: HAL_EV_SSP_REQUEST");
1101 __bt_hal_handle_ssp_request_event(buf, len);
1103 case HAL_EV_PIN_REQUEST:
1104 DBG("Event: HAL_EV_PIN_REQUEST");
1105 __bt_hal_handle_pin_request_event(buf, len);
1107 case HAL_EV_AUTHORIZE_REQUEST:
1108 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1109 __bt_hal_handle_authorize_request_event(buf, len);
1111 case HAL_EV_DEVICE_TRUST_CHANGED:
1112 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1113 __bt_hal_handle_device_trust_state_changed_event(buf, len);
1116 case HAL_EV_SOCK_AUTHORIZE_REQUEST:
1117 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1118 __bt_hal_handle_socket_authorize_request_event(buf, len);
1120 case HAL_EV_LE_STATE_CHANGED:
1121 DBG("Event: HAL_EV_LE_STATE_CHANGED");
1122 __bt_hal_handle_le_state_changed(buf, len);
1125 case HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED:
1126 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1127 __bt_hal_handle_device_trusted_profiles_changed_event(buf, len);
1129 case HAL_EV_RSSI_MONITOR_STATE_CHANGED:
1130 DBG("Event: HAL_EV_RSSI_MONITOR_STATE_CHANGED");
1131 __bt_handle_rssi_monitor_state_changed(buf, len);
1133 case HAL_EV_RSSI_ALERT_RECIEVED:
1134 DBG("Event: HAL_EV_RSSI_ALERT_RECIEVED");
1135 __bt_handle_rssi_alert_recieved(buf, len);
1137 case HAL_EV_RAW_RSSI_RECIEVED:
1138 DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
1139 __bt_handle_raw_rssi_recieved(buf, len);
1141 case HAL_EV_DBFW_PLUS_INFO_RECIEVED:
1142 DBG("Event: HAL_EV_DBFW_PLUS_INFO_RECIEVED");
1143 __bt_handle_dbfw_plus_info_recieved(buf, len);
1146 DBG("Event Currently not handled!!");