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);
150 static int get_adapter_energy_info(uint32_t *tx_time, uint32_t *rx_time,
151 uint32_t *idle_time, uint32_t *energy_used)
153 return _bt_hal_dbus_get_energy_info(tx_time, rx_time, idle_time, energy_used);
157 static int get_adapter_properties(void)
159 return _bt_hal_dbus_get_adapter_properties();
162 static int get_adapter_property(bt_property_type_t type)
164 return _bt_hal_dbus_get_adapter_property(type);
167 static int set_adapter_property(const bt_property_t *property)
170 ERR("Invalid param");
171 return BT_STATUS_PARM_INVALID;
174 return _bt_hal_dbus_set_adapter_property(property);
177 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
180 ERR("Invalid param");
181 return BT_STATUS_PARM_INVALID;
184 return _bt_hal_dbus_get_remote_device_properties(remote_addr);
187 static int get_remote_device_property(bt_bdaddr_t *remote_addr,
188 bt_property_type_t type)
190 return BT_STATUS_UNSUPPORTED;
193 static int set_remote_device_property(bt_bdaddr_t *remote_addr,
194 const bt_property_t *property)
196 return _bt_hal_dbus_set_remote_device_property(remote_addr, property);
199 static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
201 return BT_STATUS_UNSUPPORTED;
204 static int get_remote_services(bt_bdaddr_t *remote_addr)
207 ERR("Invalid param");
208 return BT_STATUS_PARM_INVALID;
210 return _bt_hal_dbus_get_remote_device_services(remote_addr);
213 static int start_discovery(void)
215 return _bt_hal_dbus_start_discovery(false, 0x00);
219 static int start_custom_discovery(bt_disc_role_type_t disc_type)
221 return _bt_hal_dbus_start_discovery(true, disc_type);
225 static int cancel_discovery(void)
227 return _bt_hal_dbus_stop_discovery();
230 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
232 return _bt_hal_device_create_bond(bd_addr, transport);
235 static int cancel_bond(const bt_bdaddr_t *bd_addr)
237 return _bt_hal_device_cancel_bond(bd_addr);
240 static int remove_bond(const bt_bdaddr_t *bd_addr)
242 return _bt_hal_device_remove_bond(bd_addr);
245 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
246 uint8_t pin_len, bt_pin_code_t *pin_code)
248 return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code);
251 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
252 uint8_t accept, uint32_t passkey)
254 return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey);
257 static const void *get_profile_interface(const char *profile_id)
259 /*TODO: Profile interfaces to be included later*/
260 DBG("%s", profile_id);
262 if (!interface_ready())
265 if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
266 return bt_get_hidhost_interface();
268 if (!strcmp(profile_id, BT_PROFILE_HIDDEVICE_ID))
269 return bt_get_hiddevice_interface();
271 if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
272 return bt_get_socket_interface();
274 if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
277 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
278 return bt_get_av_interface();
280 if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
281 return bt_get_avrcp_tg_interface();
283 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
284 return bt_get_hf_interface();
286 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
287 return bt_get_hf_client_interface();
289 if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
290 return bt_get_gatt_interface();
292 if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
293 return bt_get_hl_interface();
295 if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
296 return bt_get_avrcp_ctrl_interface();
298 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
301 if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
304 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
305 return bt_get_a2dp_sink_interface();
310 static int dut_mode_configure(uint8_t enable)
312 return BT_STATUS_UNSUPPORTED;
315 static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
317 return BT_STATUS_UNSUPPORTED;
320 static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
322 return BT_STATUS_UNSUPPORTED;
325 static int config_hci_snoop_log(uint8_t enable)
327 return BT_STATUS_UNSUPPORTED;
330 static int get_connection_state(const bt_bdaddr_t *bd_addr)
333 return _bt_hal_device_get_connection_state(bd_addr);
336 static int set_os_callouts(bt_os_callouts_t *callouts)
338 DBG("callouts: %p", callouts);
340 /* TODO: implement */
342 return BT_STATUS_UNSUPPORTED;
345 static int read_energy_info(void)
347 return BT_STATUS_UNSUPPORTED;
350 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
351 uint8_t authorize, uint8_t save_settings)
353 return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
356 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
358 return _bt_hal_device_set_trust(bd_addr, auth);
362 static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id)
365 return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
368 static int register_agent_osp_server(uint32_t type, char *uuid, char *path, int fd)
371 return _bt_hal_device_register_osp_server(type, uuid, path, fd);
374 static int unregister_agent_osp_server(uint32_t type, char *uuid)
377 return _bt_hal_device_unregister_osp_server(type, uuid);
380 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
383 return _bt_hal_device_set_trusted_profile(bd_addr, profile, trust);
386 static int get_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted)
389 return _bt_hal_device_get_trusted_profile(bd_addr, profile, trusted);
392 static int get_device_ida(bt_bdaddr_t *bd_addr, bt_bdaddr_t *id_addr)
395 return _bt_hal_device_get_ida(bd_addr, id_addr);
398 static int get_connected_link_rssi_strength(bt_bdaddr_t *bd_addr, uint32_t conn_link_type)
401 return _bt_hal_device_get_connected_link_rssi_strength(bd_addr, conn_link_type);
404 static int enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
405 int low_threshold, int in_range_threshold, int high_threshold)
408 return _bt_hal_device_enable_rssi_monitoring(bd_addr, conn_link_type,
409 low_threshold, in_range_threshold, high_threshold);
412 static int enable_gap_auth_notifications(uint32_t type, uint8_t enable)
415 _bt_hal_enable_gap_auth_notifications(type, ((enable == 0) ? FALSE : TRUE));
416 return BT_STATUS_SUCCESS;
419 static int set_hal_adapter_request_state(int enable)
422 _bt_hal_set_adapter_request_state(enable);
423 return BT_STATUS_SUCCESS;
426 static int set_hal_le_request_state(int enable)
429 _bt_hal_set_le_request_state(enable);
430 return BT_STATUS_SUCCESS;
433 static int dev_disconnect(const bt_bdaddr_t *bd_addr)
435 return _bt_hal_device_disconnect(bd_addr);
439 static const bt_interface_t bluetooth_if = {
440 .size = sizeof(bt_interface_t),
451 .le_enable = _bt_hal_le_enable,
452 .le_disable = _bt_hal_le_disable,
453 .le_init = _bt_hal_le_init,
454 .le_deinit = _bt_hal_le_deinit,
455 .is_advertising = _bt_hal_is_advertising,
459 .get_adapter_powered_status = get_adapter_powered_status,
460 .get_adapter_energy_info = get_adapter_energy_info,
462 .get_adapter_properties = get_adapter_properties,
463 .get_adapter_property = get_adapter_property,
464 .set_adapter_property = set_adapter_property,
465 .get_remote_device_properties = get_remote_device_properties,
466 .get_remote_device_property = get_remote_device_property,
467 .set_remote_device_property = set_remote_device_property,
468 .get_remote_service_record = get_remote_service_record,
469 .get_remote_services = get_remote_services,
470 .start_discovery = start_discovery,
472 .start_custom_discovery = start_custom_discovery,
474 .cancel_discovery = cancel_discovery,
475 .create_bond = create_bond,
476 .remove_bond = remove_bond,
477 .cancel_bond = cancel_bond,
478 .pin_reply = pin_reply,
479 .ssp_reply = ssp_reply,
480 .get_profile_interface = get_profile_interface,
481 .dut_mode_configure = dut_mode_configure,
482 .dut_mode_send = dut_mode_send,
483 .le_test_mode = le_test_mode,
484 .config_hci_snoop_log = config_hci_snoop_log,
485 .get_connection_state = get_connection_state,
486 .set_os_callouts = set_os_callouts,
487 .read_energy_info = read_energy_info,
488 /* Tizen Specific API's*/
489 .authorize_response = authorize_response,
490 .set_authorization = set_authorization,
492 .get_service_connection_state = get_service_connection_state,
493 .register_agent_osp_server = register_agent_osp_server,
494 .unregister_agent_osp_server = unregister_agent_osp_server,
495 .set_trusted_profile = set_trusted_profile,
496 .get_trusted_profile = get_trusted_profile,
497 .get_device_ida = get_device_ida,
498 .enable_rssi_monitoring = enable_rssi_monitoring,
499 .get_connected_link_rssi_strength = get_connected_link_rssi_strength,
500 .enable_gap_auth_notifications = enable_gap_auth_notifications,
501 .set_le_static_random_address = _bt_hal_set_le_static_random_address,
502 .set_hal_adapter_request_state = set_hal_adapter_request_state,
503 .set_hal_le_request_state = set_hal_le_request_state,
504 .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data,
505 .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
506 .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
507 .device_disconnect = dev_disconnect,
511 static const bt_interface_t *get_bluetooth_interface(void)
514 return &bluetooth_if;
517 static int close_bluetooth(struct hw_device_t *device)
525 static int open_bluetooth(const struct hw_module_t *module, char const *name,
526 struct hw_device_t **device)
528 bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t));
532 memset(dev, 0, sizeof(bluetooth_device_t));
533 dev->common.tag = HARDWARE_DEVICE_TAG;
534 dev->common.version = 0;
535 dev->common.module = (struct hw_module_t *) module;
536 dev->common.close = close_bluetooth;
537 dev->get_bluetooth_interface = get_bluetooth_interface;
539 *device = (struct hw_device_t *) dev;
544 static struct hw_module_methods_t bluetooth_module_methods = {
545 .open = open_bluetooth,
548 struct hw_module_t HAL_MODULE_INFO_SYM = {
549 .tag = HARDWARE_MODULE_TAG,
552 .id = BT_HARDWARE_MODULE_ID,
554 .author = "Intel Corporation",
555 .methods = &bluetooth_module_methods
558 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
560 struct hal_ev_adapter_state_changed *ev = buf;
562 DBG("Adapter State: %d", ev->state);
564 if (bt_hal_cbacks->adapter_state_changed_cb)
565 bt_hal_cbacks->adapter_state_changed_cb(ev->state);
569 static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
571 struct hal_ev_le_state_changed *ev = buf;
573 DBG("Adapter State: %d", ev->state);
575 if (bt_hal_cbacks->le_state_changed_cb)
576 bt_hal_cbacks->le_state_changed_cb(ev->state);
580 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
581 uint8_t num_props, uint16_t len)
586 for (i = 0; i < num_props; i++) {
587 if (sizeof(*prop) + prop->len > len) {
588 ERR("invalid adapter properties(%zu > %u), cant process further properties!!!",
589 sizeof(*prop) + prop->len, len);
593 send_props[i].type = prop->type;
595 switch (prop->type) {
596 /* TODO: Add Adapter Properties */
598 send_props[i].len = prop->len;
599 send_props[i].val = prop->val;
603 DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
605 len -= sizeof(*prop) + prop->len;
606 buf += sizeof(*prop) + prop->len;
614 static void __bt_device_props_to_hal(bt_property_t *send_props,
615 struct hal_property *prop, uint8_t num_props,
621 for (i = 0; i < num_props; i++) {
622 if (sizeof(*prop) + prop->len > len) {
623 ERR("invalid device properties (%zu > %u), cant process further properties!!!",
624 sizeof(*prop) + prop->len, len);
628 send_props[i].type = prop->type;
630 switch (prop->type) {
631 case HAL_PROP_DEVICE_TYPE:
633 DBG("Device property:HAL_PROP_DEVICE_TYPE:");
634 enum_prop_to_hal(send_props[i], prop,
638 case HAL_PROP_DEVICE_VERSION_INFO:
640 DBG("Device property: HAL_PROP_DEVICE_VERSION_INFO");
641 static bt_remote_version_t e;
642 const struct hal_prop_device_info *p;
643 send_props[i].val = &e;
644 send_props[i].len = sizeof(e);
645 p = (struct hal_prop_device_info *) prop->val;
646 e.manufacturer = p->manufacturer;
647 e.sub_ver = p->sub_version;
648 e.version = p->version;
651 case HAL_PROP_DEVICE_SERVICE_REC:
653 DBG("Device property: HAL_PROP_DEVICE_SERVICE_REC");
654 static bt_service_record_t e;
655 const struct hal_prop_device_service_rec *p;
656 send_props[i].val = &e;
657 send_props[i].len = sizeof(e);
658 p = (struct hal_prop_device_service_rec *) prop->val;
659 memset(&e, 0, sizeof(e));
660 memcpy(&e.channel, &p->channel, sizeof(e.channel));
661 memcpy(e.uuid.uu, p->uuid, sizeof(e.uuid.uu));
662 memcpy(e.name, p->name, p->name_len);
666 send_props[i].len = prop->len;
667 send_props[i].val = prop->val;
671 DBG("prop[%d]: %s, len: %d", i, btproperty2str(&send_props[i]), prop->len);
672 len -= sizeof(*prop) + prop->len;
673 buf += sizeof(*prop) + prop->len;
682 ERR("invalid device properties (%u bytes left), ", len);
685 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
687 struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
688 bt_property_t props[ev->num_props];
690 if (!bt_hal_cbacks->adapter_properties_cb)
694 __bt_adapter_props_to_hal(props, ev->props, ev->num_props, len);
696 if (bt_hal_cbacks->adapter_properties_cb)
697 bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
700 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
702 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];
713 if (!bt_hal_cbacks->device_found_cb)
717 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
719 bt_hal_cbacks->device_found_cb(ev->num_props, props);
722 static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t len)
724 struct hal_ev_remote_device_props *ev = (struct hal_ev_remote_device_props *) buf;
726 bt_property_t props[ev->num_props];
728 if (!bt_hal_cbacks->remote_device_properties_cb)
732 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
733 memcpy(bd_addr.address, ev->bdaddr, 6);
734 bt_hal_cbacks->remote_device_properties_cb(
735 ev->status, &bd_addr, ev->num_props, props);
738 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
741 struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
744 memcpy(bd_addr.address, ev->bdaddr, 6);
746 DBG("Bonding State changed Status [0x%x]", ev->status);
747 DBG("Bonding State [0x%x]", ev->state);
749 if (!bt_hal_cbacks->bond_state_changed_cb) {
750 ERR("HAL User bond_state_changed_callback is not set!!");
754 bt_hal_cbacks->bond_state_changed_cb(ev->status, &bd_addr, ev->state);
757 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
759 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
762 memcpy(bd_addr.address, ev->bdaddr, 6);
763 DBG("ACL status[0x%x], Link state[0x%x] XX:XX:XX:XX:%02X:%02X",
764 ev->status, ev->state, bd_addr.address[4], bd_addr.address[5]);
766 if (!bt_hal_cbacks->acl_state_changed_cb) {
767 ERR("HAL User acl_state_changed_cb is not set!!");
771 bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
774 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
776 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
779 memcpy(bd_addr.address, ev->bdaddr, 6);
781 DBG("ACL status[0x%x], Link state[0x%x] XX:XX:XX:XX:%02X:%02X",
782 ev->status, ev->state, bd_addr.address[4], bd_addr.address[5]);
785 if (!bt_hal_cbacks->le_conn_state_changed_cb) {
786 ERR("HAL User le_conn_state_changed_cb is not set!!");
790 bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
794 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
796 struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
799 memcpy(bd_addr.address, ev->bdaddr, 6);
802 DBG("[0x%x]", bd_addr.address[0]);
803 DBG("[0x%x]", bd_addr.address[1]);
804 DBG("[0x%x]", bd_addr.address[2]);
805 DBG("[0x%x]", bd_addr.address[3]);
806 DBG("[0x%x]", bd_addr.address[4]);
807 DBG("[0x%x]", bd_addr.address[5]);
809 DBG("Service Id: [%u]", ev->service_id);
811 if (!bt_hal_cbacks->authorize_request_cb) {
812 ERR("HAL User authorize_request_cb is not set!!");
816 bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
820 static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
822 struct hal_ev_sock_conn_auth *ev = buf;
825 uint8_t name[249] = {0, };
826 uint8_t path[249] = {0, };
829 memcpy(bd_addr.address, ev->bdaddr, 6);
830 memcpy(uuid.uu, ev->uuid, 16);
831 memcpy(name, ev->name, sizeof(name) - 1);
832 memcpy(path, ev->path, sizeof(name) - 1);
835 if (!bt_hal_cbacks->socket_authorize_request_cb) {
836 ERR("HAL User socket_authorize_request_cb is not set!!");
840 bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid, name, path, fd);
844 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
846 struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
850 memcpy(bd_addr.address, ev->bdaddr, 6);
851 memcpy(bd_name.name, ev->name, 248);
854 DBG("[0x%x]", bd_addr.address[0]);
855 DBG("[0x%x]", bd_addr.address[1]);
856 DBG("[0x%x]", bd_addr.address[2]);
857 DBG("[0x%x]", bd_addr.address[3]);
858 DBG("[0x%x]", bd_addr.address[4]);
859 DBG("[0x%x]", bd_addr.address[5]);
861 DBG("COD [%d]", ev->class_of_dev);
862 DBG("pairing variant [%d]", ev->pairing_variant);
863 DBG("passkey [%d]", ev->passkey);
865 if (!bt_hal_cbacks->ssp_request_cb) {
866 ERR("HAL User ssp_request_cb is not set!!");
870 bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
872 ev->pairing_variant, ev->passkey);
875 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
877 struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
881 memcpy(bd_addr.address, ev->bdaddr, 6);
882 memcpy(bd_name.name, ev->name, 248);
885 DBG("[0x%x]", bd_addr.address[0]);
886 DBG("[0x%x]", bd_addr.address[1]);
887 DBG("[0x%x]", bd_addr.address[2]);
888 DBG("[0x%x]", bd_addr.address[3]);
889 DBG("[0x%x]", bd_addr.address[4]);
890 DBG("[0x%x]", bd_addr.address[5]);
892 DBG("COD [%u]", ev->class_of_dev);
894 if (!bt_hal_cbacks->pin_request_cb) {
895 ERR("HAL User pin_request_cb is not set!!");
899 bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
903 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
905 struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
908 memcpy(bd_addr.address, ev->bdaddr, 6);
910 DBG("[0x%x]", bd_addr.address[0]);
911 DBG("[0x%x]", bd_addr.address[1]);
912 DBG("[0x%x]", bd_addr.address[2]);
913 DBG("[0x%x]", bd_addr.address[3]);
914 DBG("[0x%x]", bd_addr.address[4]);
915 DBG("[0x%x]", bd_addr.address[5]);
917 DBG("Device Trusted? [0x%x]", ev->trust);
919 if (!bt_hal_cbacks->device_trust_state_changed_cb) {
920 ERR("HAL User device_trust_state_changed_cb is not set!!");
924 bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
927 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
929 struct hal_ev_device_trusted_profiles_changed *ev = buf;
933 memcpy(bd_addr.address, ev->bdaddr, 6);
934 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
935 bd_addr.address[0], bd_addr.address[1],
936 bd_addr.address[2], bd_addr.address[3],
937 bd_addr.address[4], bd_addr.address[5]);
939 if (!bt_hal_cbacks->device_trusted_profiles_changed_cb) {
940 ERR("device_trusted_profiles_changed_cb is NULL");
944 bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
948 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
950 struct hal_ev_rssi_monitor_state_changed *ev = buf;
954 memcpy(bd_addr.address, ev->bdaddr, 6);
955 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
956 bd_addr.address[0], bd_addr.address[1],
957 bd_addr.address[2], bd_addr.address[3],
958 bd_addr.address[4], bd_addr.address[5]);
960 if (bt_hal_cbacks->rssi_monitor_state_changed_cb)
961 bt_hal_cbacks->rssi_monitor_state_changed_cb(
962 &bd_addr, ev->link_type, ev->state);
966 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
968 struct hal_ev_rssi_alert_recieved *ev = buf;
972 memcpy(bd_addr.address, ev->bdaddr, 6);
973 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
974 bd_addr.address[0], bd_addr.address[1],
975 bd_addr.address[2], bd_addr.address[3],
976 bd_addr.address[4], bd_addr.address[5]);
978 if (bt_hal_cbacks->rssi_alert_cb)
979 bt_hal_cbacks->rssi_alert_cb(
980 &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
984 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
986 struct hal_ev_raw_rssi_recieved *ev = buf;
990 memcpy(bd_addr.address, ev->bdaddr, 6);
991 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
992 bd_addr.address[0], bd_addr.address[1],
993 bd_addr.address[2], bd_addr.address[3],
994 bd_addr.address[4], bd_addr.address[5]);
996 if (bt_hal_cbacks->raw_rssi_received_cb)
997 bt_hal_cbacks->raw_rssi_received_cb(
998 &bd_addr, ev->link_type, ev->rssi);
1002 static void __bt_handle_dbfw_plus_info_recieved(void *buf, uint16_t len)
1004 struct hal_ev_dbfw_plus_info_recieved *info = buf;
1007 if (bt_hal_cbacks->dbfw_plus_info_received_cb)
1008 bt_hal_cbacks->dbfw_plus_info_received_cb(
1009 info->data, info->data_len, info->event_code);
1013 static void __bt_handle_controller_error_recieved(void *buf, uint16_t len)
1015 struct hal_ev_controller_error_recieved *info = buf;
1016 uint8_t error_code = info->code;
1019 if (bt_hal_cbacks->controller_error_received_cb)
1020 bt_hal_cbacks->controller_error_received_cb(error_code);
1024 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
1027 case HAL_EV_ADAPTER_STATE_CHANGED:
1028 DBG("Event: HAL_EV_ADAPTER_STATE_CHANGED");
1029 __bt_hal_handle_adapter_state_changed(buf, len);
1031 case HAL_EV_ADAPTER_PROPS_CHANGED:
1032 DBG("Event: HAL_EV_ADAPTER_PROPS_CHANGED");
1033 __bt_hal_handle_adapter_property_changed(buf, len);
1035 case HAL_EV_DISCOVERY_STATE_CHANGED:
1036 DBG("Event: HAL_EV_DISCOVERY_STATE_CHANGED");
1037 __bt_hal_handle_adapter_discovery_state_changed(buf, len);
1039 case HAL_EV_DEVICE_FOUND:
1040 DBG("Event: HAL_EV_DEVICE_FOUND");
1041 __bt_hal_handle_device_found_event(buf, len);
1043 case HAL_EV_REMOTE_DEVICE_PROPS:
1044 DBG("Event: HAL_EV_REMOTE_DEVICE_PROPS");
1045 __bt_hal_handle_remote_device_properties_event(buf, len);
1047 case HAL_EV_BOND_STATE_CHANGED:
1048 DBG("Event: HAL_EV_BOND_STATE_CHANGED:");
1049 __bt_hal_handle_bond_state_changed_event(buf, len);
1051 case HAL_EV_ACL_STATE_CHANGED:
1052 __bt_hal_handle_device_acl_state_changed_event(buf, len);
1054 case HAL_EV_LE_CONN_STATE_CHANGED:
1055 DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
1056 __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
1058 case HAL_EV_SSP_REQUEST:
1059 DBG("Event: HAL_EV_SSP_REQUEST");
1060 __bt_hal_handle_ssp_request_event(buf, len);
1062 case HAL_EV_PIN_REQUEST:
1063 DBG("Event: HAL_EV_PIN_REQUEST");
1064 __bt_hal_handle_pin_request_event(buf, len);
1066 case HAL_EV_AUTHORIZE_REQUEST:
1067 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1068 __bt_hal_handle_authorize_request_event(buf, len);
1070 case HAL_EV_DEVICE_TRUST_CHANGED:
1071 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1072 __bt_hal_handle_device_trust_state_changed_event(buf, len);
1075 case HAL_EV_SOCK_AUTHORIZE_REQUEST:
1076 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1077 __bt_hal_handle_socket_authorize_request_event(buf, len);
1079 case HAL_EV_LE_STATE_CHANGED:
1080 DBG("Event: HAL_EV_LE_STATE_CHANGED");
1081 __bt_hal_handle_le_state_changed(buf, len);
1084 case HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED:
1085 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1086 __bt_hal_handle_device_trusted_profiles_changed_event(buf, len);
1088 case HAL_EV_RSSI_MONITOR_STATE_CHANGED:
1089 DBG("Event: HAL_EV_RSSI_MONITOR_STATE_CHANGED");
1090 __bt_handle_rssi_monitor_state_changed(buf, len);
1092 case HAL_EV_RSSI_ALERT_RECIEVED:
1093 DBG("Event: HAL_EV_RSSI_ALERT_RECIEVED");
1094 __bt_handle_rssi_alert_recieved(buf, len);
1096 case HAL_EV_RAW_RSSI_RECIEVED:
1097 DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
1098 __bt_handle_raw_rssi_recieved(buf, len);
1100 case HAL_EV_DBFW_PLUS_INFO_RECIEVED:
1101 DBG("Event: HAL_EV_DBFW_PLUS_INFO_RECIEVED");
1102 __bt_handle_dbfw_plus_info_recieved(buf, len);
1104 case HAL_EV_CONTROLLER_ERROR_RECIEVED:
1105 DBG("Event: HAL_EV_CONTROLLER_ERROR_RECIEVED");
1106 __bt_handle_controller_error_recieved(buf, len);
1109 DBG("Event Currently not handled!!");