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)
226 return _bt_hal_device_create_bond(bd_addr, transport);
229 static int cancel_bond(const bt_bdaddr_t *bd_addr)
231 return _bt_hal_device_cancel_bond(bd_addr);
234 static int remove_bond(const bt_bdaddr_t *bd_addr)
236 return _bt_hal_device_remove_bond(bd_addr);
239 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
240 uint8_t pin_len, bt_pin_code_t *pin_code)
242 return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code);
245 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
246 uint8_t accept, uint32_t passkey)
248 return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey);
251 static const void *get_profile_interface(const char *profile_id)
253 /*TODO: Profile interfaces to be included later*/
254 DBG("%s", profile_id);
256 if (!interface_ready())
259 if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
260 return bt_get_hidhost_interface();
262 if (!strcmp(profile_id, BT_PROFILE_HIDDEVICE_ID))
263 return bt_get_hiddevice_interface();
265 if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
266 return bt_get_socket_interface();
268 if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
271 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
272 return bt_get_av_interface();
274 if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
275 return bt_get_avrcp_tg_interface();
277 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
278 return bt_get_hf_interface();
280 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
281 return bt_get_hf_client_interface();
283 if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
284 return bt_get_gatt_interface();
286 if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
287 return bt_get_hl_interface();
289 if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
290 return bt_get_avrcp_ctrl_interface();
292 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
295 if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
298 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
299 return bt_get_a2dp_sink_interface();
304 static int dut_mode_configure(uint8_t enable)
306 return BT_STATUS_UNSUPPORTED;
309 static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
311 return BT_STATUS_UNSUPPORTED;
314 static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
316 return BT_STATUS_UNSUPPORTED;
319 static int config_hci_snoop_log(uint8_t enable)
321 return BT_STATUS_UNSUPPORTED;
324 static int get_connection_state(const bt_bdaddr_t *bd_addr)
327 return _bt_hal_device_get_connection_state(bd_addr);
330 static int set_os_callouts(bt_os_callouts_t *callouts)
332 DBG("callouts: %p", callouts);
334 /* TODO: implement */
336 return BT_STATUS_UNSUPPORTED;
339 static int read_energy_info(void)
341 return BT_STATUS_UNSUPPORTED;
344 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
345 uint8_t authorize, uint8_t save_settings)
347 return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
350 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
352 return _bt_hal_device_set_trust(bd_addr, auth);
356 static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id)
359 return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
362 static int register_agent_osp_server(uint32_t type, char *uuid, char *path, int fd)
365 return _bt_hal_device_register_osp_server(type, uuid, path, fd);
368 static int unregister_agent_osp_server(uint32_t type, char *uuid)
371 return _bt_hal_device_unregister_osp_server(type, uuid);
374 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
377 return _bt_hal_device_set_trusted_profile(bd_addr, profile, trust);
380 static int get_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted)
383 return _bt_hal_device_get_trusted_profile(bd_addr, profile, trusted);
386 static int get_connected_link_rssi_strength(bt_bdaddr_t *bd_addr, uint32_t conn_link_type)
389 return _bt_hal_device_get_connected_link_rssi_strength(bd_addr, conn_link_type);
392 static int enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
393 int low_threshold, int in_range_threshold, int high_threshold)
396 return _bt_hal_device_enable_rssi_monitoring(bd_addr, conn_link_type,
397 low_threshold, in_range_threshold, high_threshold);
400 static int enable_gap_auth_notifications(uint32_t type, uint8_t enable)
403 _bt_hal_enable_gap_auth_notifications(type, ((enable == 0) ? FALSE : TRUE));
404 return BT_STATUS_SUCCESS;
407 static int set_hal_adapter_request_state(int enable)
410 _bt_hal_set_adapter_request_state(enable);
411 return BT_STATUS_SUCCESS;
414 static int set_hal_le_request_state(int enable)
417 _bt_hal_set_le_request_state(enable);
418 return BT_STATUS_SUCCESS;
421 static int dev_disconnect(const bt_bdaddr_t *bd_addr)
423 return _bt_hal_device_disconnect(bd_addr);
427 static const bt_interface_t bluetooth_if = {
428 .size = sizeof(bt_interface_t),
439 .le_enable = _bt_hal_le_enable,
440 .le_disable = _bt_hal_le_disable,
441 .le_init = _bt_hal_le_init,
442 .le_deinit = _bt_hal_le_deinit,
443 .is_advertising = _bt_hal_is_advertising,
447 .get_adapter_powered_status = get_adapter_powered_status,
449 .get_adapter_properties = get_adapter_properties,
450 .get_adapter_property = get_adapter_property,
451 .set_adapter_property = set_adapter_property,
452 .get_remote_device_properties = get_remote_device_properties,
453 .get_remote_device_property = get_remote_device_property,
454 .set_remote_device_property = set_remote_device_property,
455 .get_remote_service_record = get_remote_service_record,
456 .get_remote_services = get_remote_services,
457 .start_discovery = start_discovery,
459 .start_custom_discovery = start_custom_discovery,
461 .cancel_discovery = cancel_discovery,
462 .create_bond = create_bond,
463 .remove_bond = remove_bond,
464 .cancel_bond = cancel_bond,
465 .pin_reply = pin_reply,
466 .ssp_reply = ssp_reply,
467 .get_profile_interface = get_profile_interface,
468 .dut_mode_configure = dut_mode_configure,
469 .dut_mode_send = dut_mode_send,
470 .le_test_mode = le_test_mode,
471 .config_hci_snoop_log = config_hci_snoop_log,
472 .get_connection_state = get_connection_state,
473 .set_os_callouts = set_os_callouts,
474 .read_energy_info = read_energy_info,
475 /* Tizen Specific API's*/
476 .authorize_response = authorize_response,
477 .set_authorization = set_authorization,
479 .get_service_connection_state = get_service_connection_state,
480 .register_agent_osp_server = register_agent_osp_server,
481 .unregister_agent_osp_server = unregister_agent_osp_server,
482 .set_trusted_profile = set_trusted_profile,
483 .get_trusted_profile = get_trusted_profile,
484 .enable_rssi_monitoring = enable_rssi_monitoring,
485 .get_connected_link_rssi_strength = get_connected_link_rssi_strength,
486 .enable_gap_auth_notifications = enable_gap_auth_notifications,
487 .set_le_static_random_address = _bt_hal_set_le_static_random_address,
488 .set_hal_adapter_request_state = set_hal_adapter_request_state,
489 .set_hal_le_request_state = set_hal_le_request_state,
490 .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data,
491 .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
492 .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
493 .device_disconnect = dev_disconnect,
497 static const bt_interface_t *get_bluetooth_interface(void)
500 return &bluetooth_if;
503 static int close_bluetooth(struct hw_device_t *device)
511 static int open_bluetooth(const struct hw_module_t *module, char const *name,
512 struct hw_device_t **device)
514 bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t));
518 memset(dev, 0, sizeof(bluetooth_device_t));
519 dev->common.tag = HARDWARE_DEVICE_TAG;
520 dev->common.version = 0;
521 dev->common.module = (struct hw_module_t *) module;
522 dev->common.close = close_bluetooth;
523 dev->get_bluetooth_interface = get_bluetooth_interface;
525 *device = (struct hw_device_t *) dev;
530 static struct hw_module_methods_t bluetooth_module_methods = {
531 .open = open_bluetooth,
534 struct hw_module_t HAL_MODULE_INFO_SYM = {
535 .tag = HARDWARE_MODULE_TAG,
538 .id = BT_HARDWARE_MODULE_ID,
540 .author = "Intel Corporation",
541 .methods = &bluetooth_module_methods
544 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
546 struct hal_ev_adapter_state_changed *ev = buf;
548 DBG("Adapter State: %d", ev->state);
550 if (bt_hal_cbacks->adapter_state_changed_cb)
551 bt_hal_cbacks->adapter_state_changed_cb(ev->state);
555 static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
557 struct hal_ev_le_state_changed *ev = buf;
559 DBG("Adapter State: %d", ev->state);
561 if (bt_hal_cbacks->le_state_changed_cb)
562 bt_hal_cbacks->le_state_changed_cb(ev->state);
566 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
567 uint8_t num_props, uint16_t len)
572 for (i = 0; i < num_props; i++) {
573 if (sizeof(*prop) + prop->len > len) {
574 ERR("invalid adapter properties(%zu > %u), cant process further properties!!!",
575 sizeof(*prop) + prop->len, len);
579 send_props[i].type = prop->type;
581 switch (prop->type) {
582 /* TODO: Add Adapter Properties */
584 send_props[i].len = prop->len;
585 send_props[i].val = prop->val;
589 DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
591 len -= sizeof(*prop) + prop->len;
592 buf += sizeof(*prop) + prop->len;
600 static void __bt_device_props_to_hal(bt_property_t *send_props,
601 struct hal_property *prop, uint8_t num_props,
607 for (i = 0; i < num_props; i++) {
608 if (sizeof(*prop) + prop->len > len) {
609 ERR("invalid device properties (%zu > %u), cant process further properties!!!",
610 sizeof(*prop) + prop->len, len);
614 send_props[i].type = 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;
668 ERR("invalid device properties (%u bytes left), ", len);
671 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
673 struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
674 bt_property_t props[ev->num_props];
676 if (!bt_hal_cbacks->adapter_properties_cb)
680 __bt_adapter_props_to_hal(props, ev->props, ev->num_props, len);
682 if (bt_hal_cbacks->adapter_properties_cb)
683 bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
686 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
688 struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
690 if (bt_hal_cbacks->discovery_state_changed_cb)
691 bt_hal_cbacks->discovery_state_changed_cb(ev->state);
694 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len)
696 struct hal_ev_device_found *ev = (struct hal_ev_device_found *) buf;
697 bt_property_t props[ev->num_props];
699 if (!bt_hal_cbacks->device_found_cb)
703 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
705 bt_hal_cbacks->device_found_cb(ev->num_props, props);
708 static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t len)
710 struct hal_ev_remote_device_props *ev = (struct hal_ev_remote_device_props *) buf;
712 bt_property_t props[ev->num_props];
714 if (!bt_hal_cbacks->remote_device_properties_cb)
718 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
719 memcpy(bd_addr.address, ev->bdaddr, 6);
720 bt_hal_cbacks->remote_device_properties_cb(
721 ev->status, &bd_addr, ev->num_props, props);
724 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
727 struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
730 memcpy(bd_addr.address, ev->bdaddr, 6);
732 DBG("Bonding State changed Status [0x%x]", ev->status);
733 DBG("Bonding State [0x%x]", ev->state);
735 if (!bt_hal_cbacks->bond_state_changed_cb) {
736 ERR("HAL User bond_state_changed_callback is not set!!");
740 bt_hal_cbacks->bond_state_changed_cb(ev->status, &bd_addr, ev->state);
743 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
745 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
748 memcpy(bd_addr.address, ev->bdaddr, 6);
749 INFO("ACL status[0x%x], state[0x%x]: XX:XX:XX:XX:XX:%02X", ev->status, ev->state, bd_addr.address[5]);
751 if (!bt_hal_cbacks->acl_state_changed_cb) {
752 ERR("HAL User acl_state_changed_cb is not set!!");
756 bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
759 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
761 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
764 memcpy(bd_addr.address, ev->bdaddr, 6);
766 DBG("Address: [%02X:%02X:%02X:%02X:%02X:%02X]", bd_addr.address[0],
767 bd_addr.address[1], bd_addr.address[2], bd_addr.address[3],
768 bd_addr.address[4], bd_addr.address[5]);
769 DBG("LE conn Status [0x%x]", ev->status);
770 DBG("LE conn State [0x%x]", ev->state);
773 if (!bt_hal_cbacks->le_conn_state_changed_cb) {
774 ERR("HAL User le_conn_state_changed_cb is not set!!");
778 bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
782 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
784 struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
787 memcpy(bd_addr.address, ev->bdaddr, 6);
790 DBG("[0x%x]", bd_addr.address[0]);
791 DBG("[0x%x]", bd_addr.address[1]);
792 DBG("[0x%x]", bd_addr.address[2]);
793 DBG("[0x%x]", bd_addr.address[3]);
794 DBG("[0x%x]", bd_addr.address[4]);
795 DBG("[0x%x]", bd_addr.address[5]);
797 DBG("Service Id: [%u]", ev->service_id);
799 if (!bt_hal_cbacks->authorize_request_cb) {
800 ERR("HAL User authorize_request_cb is not set!!");
804 bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
808 static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
810 struct hal_ev_sock_conn_auth *ev = buf;
813 uint8_t name[249] = {0, };
814 uint8_t path[249] = {0, };
817 memcpy(bd_addr.address, ev->bdaddr, 6);
818 memcpy(uuid.uu, ev->uuid, 16);
819 memcpy(name, ev->name, sizeof(name) - 1);
820 memcpy(path, ev->path, sizeof(name) - 1);
823 if (!bt_hal_cbacks->socket_authorize_request_cb) {
824 ERR("HAL User socket_authorize_request_cb is not set!!");
828 bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid, name, path, fd);
832 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
834 struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
838 memcpy(bd_addr.address, ev->bdaddr, 6);
839 memcpy(bd_name.name, ev->name, 248);
842 DBG("[0x%x]", bd_addr.address[0]);
843 DBG("[0x%x]", bd_addr.address[1]);
844 DBG("[0x%x]", bd_addr.address[2]);
845 DBG("[0x%x]", bd_addr.address[3]);
846 DBG("[0x%x]", bd_addr.address[4]);
847 DBG("[0x%x]", bd_addr.address[5]);
849 DBG("COD [%d]", ev->class_of_dev);
850 DBG("pairing variant [%d]", ev->pairing_variant);
851 DBG("passkey [%d]", ev->passkey);
853 if (!bt_hal_cbacks->ssp_request_cb) {
854 ERR("HAL User ssp_request_cb is not set!!");
858 bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
860 ev->pairing_variant, ev->passkey);
863 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
865 struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
869 memcpy(bd_addr.address, ev->bdaddr, 6);
870 memcpy(bd_name.name, ev->name, 248);
873 DBG("[0x%x]", bd_addr.address[0]);
874 DBG("[0x%x]", bd_addr.address[1]);
875 DBG("[0x%x]", bd_addr.address[2]);
876 DBG("[0x%x]", bd_addr.address[3]);
877 DBG("[0x%x]", bd_addr.address[4]);
878 DBG("[0x%x]", bd_addr.address[5]);
880 DBG("COD [%u]", ev->class_of_dev);
882 if (!bt_hal_cbacks->pin_request_cb) {
883 ERR("HAL User pin_request_cb is not set!!");
887 bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
891 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
893 struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
896 memcpy(bd_addr.address, ev->bdaddr, 6);
898 DBG("[0x%x]", bd_addr.address[0]);
899 DBG("[0x%x]", bd_addr.address[1]);
900 DBG("[0x%x]", bd_addr.address[2]);
901 DBG("[0x%x]", bd_addr.address[3]);
902 DBG("[0x%x]", bd_addr.address[4]);
903 DBG("[0x%x]", bd_addr.address[5]);
905 DBG("Device Trusted? [0x%x]", ev->trust);
907 if (!bt_hal_cbacks->device_trust_state_changed_cb) {
908 ERR("HAL User device_trust_state_changed_cb is not set!!");
912 bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
915 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
917 struct hal_ev_device_trusted_profiles_changed *ev = buf;
921 memcpy(bd_addr.address, ev->bdaddr, 6);
922 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
923 bd_addr.address[0], bd_addr.address[1],
924 bd_addr.address[2], bd_addr.address[3],
925 bd_addr.address[4], bd_addr.address[5]);
927 if (!bt_hal_cbacks->device_trusted_profiles_changed_cb) {
928 ERR("device_trusted_profiles_changed_cb is NULL");
932 bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
936 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
938 struct hal_ev_rssi_monitor_state_changed *ev = buf;
942 memcpy(bd_addr.address, ev->bdaddr, 6);
943 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
944 bd_addr.address[0], bd_addr.address[1],
945 bd_addr.address[2], bd_addr.address[3],
946 bd_addr.address[4], bd_addr.address[5]);
948 if (bt_hal_cbacks->rssi_monitor_state_changed_cb)
949 bt_hal_cbacks->rssi_monitor_state_changed_cb(
950 &bd_addr, ev->link_type, ev->state);
954 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
956 struct hal_ev_rssi_alert_recieved *ev = buf;
960 memcpy(bd_addr.address, ev->bdaddr, 6);
961 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
962 bd_addr.address[0], bd_addr.address[1],
963 bd_addr.address[2], bd_addr.address[3],
964 bd_addr.address[4], bd_addr.address[5]);
966 if (bt_hal_cbacks->rssi_alert_cb)
967 bt_hal_cbacks->rssi_alert_cb(
968 &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
972 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
974 struct hal_ev_raw_rssi_recieved *ev = buf;
978 memcpy(bd_addr.address, ev->bdaddr, 6);
979 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
980 bd_addr.address[0], bd_addr.address[1],
981 bd_addr.address[2], bd_addr.address[3],
982 bd_addr.address[4], bd_addr.address[5]);
984 if (bt_hal_cbacks->raw_rssi_received_cb)
985 bt_hal_cbacks->raw_rssi_received_cb(
986 &bd_addr, ev->link_type, ev->rssi);
990 static void __bt_handle_dbfw_plus_info_recieved(void *buf, uint16_t len)
992 struct hal_ev_dbfw_plus_info_recieved *info = buf;
995 if (bt_hal_cbacks->dbfw_plus_info_received_cb)
996 bt_hal_cbacks->dbfw_plus_info_received_cb(
997 info->data, info->data_len, info->event_code);
1001 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
1004 case HAL_EV_ADAPTER_STATE_CHANGED:
1005 DBG("Event: HAL_EV_ADAPTER_STATE_CHANGED");
1006 __bt_hal_handle_adapter_state_changed(buf, len);
1008 case HAL_EV_ADAPTER_PROPS_CHANGED:
1009 DBG("Event: HAL_EV_ADAPTER_PROPS_CHANGED");
1010 __bt_hal_handle_adapter_property_changed(buf, len);
1012 case HAL_EV_DISCOVERY_STATE_CHANGED:
1013 DBG("Event: HAL_EV_DISCOVERY_STATE_CHANGED");
1014 __bt_hal_handle_adapter_discovery_state_changed(buf, len);
1016 case HAL_EV_DEVICE_FOUND:
1017 DBG("Event: HAL_EV_DEVICE_FOUND");
1018 __bt_hal_handle_device_found_event(buf, len);
1020 case HAL_EV_REMOTE_DEVICE_PROPS:
1021 DBG("Event: HAL_EV_REMOTE_DEVICE_PROPS");
1022 __bt_hal_handle_remote_device_properties_event(buf, len);
1024 case HAL_EV_BOND_STATE_CHANGED:
1025 DBG("Event: HAL_EV_BOND_STATE_CHANGED:");
1026 __bt_hal_handle_bond_state_changed_event(buf, len);
1028 case HAL_EV_ACL_STATE_CHANGED:
1029 DBG("Event: HAL_ACL_STATE_CONNECTED or Disconnected");
1030 __bt_hal_handle_device_acl_state_changed_event(buf, len);
1032 case HAL_EV_LE_CONN_STATE_CHANGED:
1033 DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
1034 __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
1036 case HAL_EV_SSP_REQUEST:
1037 DBG("Event: HAL_EV_SSP_REQUEST");
1038 __bt_hal_handle_ssp_request_event(buf, len);
1040 case HAL_EV_PIN_REQUEST:
1041 DBG("Event: HAL_EV_PIN_REQUEST");
1042 __bt_hal_handle_pin_request_event(buf, len);
1044 case HAL_EV_AUTHORIZE_REQUEST:
1045 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1046 __bt_hal_handle_authorize_request_event(buf, len);
1048 case HAL_EV_DEVICE_TRUST_CHANGED:
1049 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1050 __bt_hal_handle_device_trust_state_changed_event(buf, len);
1053 case HAL_EV_SOCK_AUTHORIZE_REQUEST:
1054 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1055 __bt_hal_handle_socket_authorize_request_event(buf, len);
1057 case HAL_EV_LE_STATE_CHANGED:
1058 DBG("Event: HAL_EV_LE_STATE_CHANGED");
1059 __bt_hal_handle_le_state_changed(buf, len);
1062 case HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED:
1063 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1064 __bt_hal_handle_device_trusted_profiles_changed_event(buf, len);
1066 case HAL_EV_RSSI_MONITOR_STATE_CHANGED:
1067 DBG("Event: HAL_EV_RSSI_MONITOR_STATE_CHANGED");
1068 __bt_handle_rssi_monitor_state_changed(buf, len);
1070 case HAL_EV_RSSI_ALERT_RECIEVED:
1071 DBG("Event: HAL_EV_RSSI_ALERT_RECIEVED");
1072 __bt_handle_rssi_alert_recieved(buf, len);
1074 case HAL_EV_RAW_RSSI_RECIEVED:
1075 DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
1076 __bt_handle_raw_rssi_recieved(buf, len);
1078 case HAL_EV_DBFW_PLUS_INFO_RECIEVED:
1079 DBG("Event: HAL_EV_DBFW_PLUS_INFO_RECIEVED");
1080 __bt_handle_dbfw_plus_info_recieved(buf, len);
1083 DBG("Event Currently not handled!!");