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-socket.h>
37 #include <bt-hal-av.h>
38 #include <bt-hal-hf.h>
39 #include <bt-hal-hdp.h>
40 #include <bt-hal-a2dp-sink.h>
41 #include <bt-hal-avrcp-tg.h>
42 #include <bt-hal-avrcp-ctrl.h>
43 #include <bt-hal-gatt.h>
45 #include <bt-hal-adapter-le.h>
46 #include <bt-hal-agent.h>
49 #define enum_prop_to_hal(prop, hal_prop, type) do { \
52 prop.len = sizeof(e); \
53 e = *((uint8_t *) (hal_prop->val)); \
56 static const bt_callbacks_t *bt_hal_cbacks = NULL;
59 /* Forward declarations */
60 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop, uint8_t num_props, uint16_t len);
61 static void __bt_device_props_to_hal(bt_property_t *send_props,
62 struct hal_property *prop, uint8_t num_props,
64 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len);
65 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len);
66 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len);
67 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len);
68 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len);
69 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len);
70 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len);
71 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len);
72 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len);
74 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len);
76 static bool interface_ready(void)
78 return bt_hal_cbacks != NULL;
81 static int init(bt_callbacks_t *callbacks)
84 DBG("HAL library Initialization..");
86 if (interface_ready())
87 return BT_STATUS_DONE;
89 bt_hal_cbacks = callbacks;
90 DBG("Store HAL stack msg handler callback");
91 _bt_hal_dbus_store_stack_msg_cb(__bt_hal_handle_stack_messages);
92 ret = _bt_hal_initialize_event_receiver(__bt_hal_handle_stack_messages);
94 if (ret == BT_STATUS_SUCCESS)
95 return BT_STATUS_SUCCESS;
97 return BT_STATUS_FAIL;
100 return BT_STATUS_SUCCESS;
104 static int enable(void)
106 return _bt_hal_dbus_enable_adapter();
109 /* Disable Adapter */
110 static int disable(void)
112 return _bt_hal_dbus_disable_adapter();
116 /* Tizen Specific Reset Adapter */
117 static int reset(void)
119 return _bt_hal_dbus_reset_adapter();
123 static void cleanup(void)
129 /* Tizen Specific Get Powered state */
130 static int get_adapter_powered_status(uint8_t *state)
133 ERR("Invalid param");
134 return BT_STATUS_PARM_INVALID;
137 return _bt_hal_get_adapter_powered_state(state);
141 static int get_adapter_properties(void)
143 return _bt_hal_dbus_get_adapter_properties();
146 static int get_adapter_property(bt_property_type_t type)
148 return _bt_hal_dbus_get_adapter_property(type);
151 static int set_adapter_property(const bt_property_t *property)
154 ERR("Invalid param");
155 return BT_STATUS_PARM_INVALID;
158 return _bt_hal_dbus_set_adapter_property(property);
161 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
164 ERR("Invalid param");
165 return BT_STATUS_PARM_INVALID;
168 return _bt_hal_dbus_get_remote_device_properties(remote_addr);
171 static int get_remote_device_property(bt_bdaddr_t *remote_addr,
172 bt_property_type_t type)
174 return BT_STATUS_UNSUPPORTED;
177 static int set_remote_device_property(bt_bdaddr_t *remote_addr,
178 const bt_property_t *property)
180 return _bt_hal_dbus_set_remote_device_property(remote_addr, property);
183 static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
185 return BT_STATUS_UNSUPPORTED;
188 static int get_remote_services(bt_bdaddr_t *remote_addr)
191 ERR("Invalid param");
192 return BT_STATUS_PARM_INVALID;
194 return _bt_hal_dbus_get_remote_device_services(remote_addr);
197 static int start_discovery(void)
199 return _bt_hal_dbus_start_discovery(false, 0x00);
203 static int start_custom_discovery(bt_disc_role_type_t disc_type)
205 return _bt_hal_dbus_start_discovery(true, disc_type);
209 static int cancel_discovery(void)
211 return _bt_hal_dbus_stop_discovery();
214 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
217 return _bt_hal_device_create_bond(bd_addr, transport);
220 static int cancel_bond(const bt_bdaddr_t *bd_addr)
222 return _bt_hal_device_cancel_bond(bd_addr);
225 static int remove_bond(const bt_bdaddr_t *bd_addr)
228 return _bt_hal_device_remove_bond(bd_addr);
231 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
232 uint8_t pin_len, bt_pin_code_t *pin_code)
234 return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code);
237 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
238 uint8_t accept, uint32_t passkey)
240 return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey);
243 static const void *get_profile_interface(const char *profile_id)
245 /*TODO: Profile interfaces to be included later*/
246 DBG("%s", profile_id);
248 if (!interface_ready())
251 if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
252 return bt_get_hidhost_interface();
254 if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
255 return bt_get_socket_interface();
257 if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
260 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
261 return bt_get_av_interface();
263 if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
264 return bt_get_avrcp_tg_interface();
266 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
267 return bt_get_hf_interface();
269 if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
270 return bt_get_gatt_interface();
272 if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
273 return bt_get_hl_interface();
275 if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
276 return bt_get_avrcp_ctrl_interface();
278 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
281 if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
284 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
285 return bt_get_a2dp_sink_interface();
290 static int dut_mode_configure(uint8_t enable)
292 return BT_STATUS_UNSUPPORTED;
295 static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
297 return BT_STATUS_UNSUPPORTED;
300 static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
302 return BT_STATUS_UNSUPPORTED;
305 static int config_hci_snoop_log(uint8_t enable)
307 return BT_STATUS_UNSUPPORTED;
310 static int get_connection_state(const bt_bdaddr_t *bd_addr)
313 return _bt_hal_device_get_connection_state(bd_addr);
316 static int set_os_callouts(bt_os_callouts_t *callouts)
318 DBG("callouts: %p", callouts);
320 /* TODO: implement */
322 return BT_STATUS_UNSUPPORTED;
325 static int read_energy_info(void)
327 return BT_STATUS_UNSUPPORTED;
330 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
331 uint8_t authorize, uint8_t save_settings)
334 return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
337 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
340 return _bt_hal_device_set_trust(bd_addr, auth);
344 static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id)
347 return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
350 static int set_agent_osp_server(uint32_t type, uint8_t enable)
353 return _bt_hal_device_set_osp_server(type, enable);
356 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
359 return _bt_hal_device_set_trusted_profile(bd_addr, profile, trust);
362 static int get_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted)
365 return _bt_hal_device_get_trusted_profile(bd_addr, profile, trusted);
368 static int get_connected_link_rssi_strength(bt_bdaddr_t *bd_addr, uint32_t conn_link_type)
371 return _bt_hal_device_get_connected_link_rssi_strength(bd_addr, conn_link_type);
374 static int enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
375 int low_threshold, int in_range_threshold, int high_threshold)
378 return _bt_hal_device_enable_rssi_monitoring(bd_addr, conn_link_type,
379 low_threshold, in_range_threshold, high_threshold);
382 static int enable_gap_auth_notifications(uint32_t type, uint8_t enable)
385 _bt_hal_enable_gap_auth_notifications(type, ((enable == 0) ? FALSE : TRUE));
386 return BT_STATUS_SUCCESS;
389 static int set_hal_adapter_request_state(int enable)
392 _bt_hal_set_adapter_request_state(enable);
393 return BT_STATUS_SUCCESS;
396 static int set_hal_le_request_state(int enable)
399 _bt_hal_set_le_request_state(enable);
400 return BT_STATUS_SUCCESS;
403 static int dev_disconnect(const bt_bdaddr_t *bd_addr)
406 return _bt_hal_device_disconnect(bd_addr);
410 static const bt_interface_t bluetooth_if = {
411 .size = sizeof(bt_interface_t),
420 .le_enable = _bt_hal_le_enable,
421 .le_disable = _bt_hal_le_disable,
422 .le_init = _bt_hal_le_init,
423 .le_deinit = _bt_hal_le_deinit,
424 .is_advertising = _bt_hal_is_advertising,
428 .get_adapter_powered_status = get_adapter_powered_status,
430 .get_adapter_properties = get_adapter_properties,
431 .get_adapter_property = get_adapter_property,
432 .set_adapter_property = set_adapter_property,
433 .get_remote_device_properties = get_remote_device_properties,
434 .get_remote_device_property = get_remote_device_property,
435 .set_remote_device_property = set_remote_device_property,
436 .get_remote_service_record = get_remote_service_record,
437 .get_remote_services = get_remote_services,
438 .start_discovery = start_discovery,
440 .start_custom_discovery = start_custom_discovery,
442 .cancel_discovery = cancel_discovery,
443 .create_bond = create_bond,
444 .remove_bond = remove_bond,
445 .cancel_bond = cancel_bond,
446 .pin_reply = pin_reply,
447 .ssp_reply = ssp_reply,
448 .get_profile_interface = get_profile_interface,
449 .dut_mode_configure = dut_mode_configure,
450 .dut_mode_send = dut_mode_send,
451 .le_test_mode = le_test_mode,
452 .config_hci_snoop_log = config_hci_snoop_log,
453 .get_connection_state = get_connection_state,
454 .set_os_callouts = set_os_callouts,
455 .read_energy_info = read_energy_info,
456 /* Tizen Specific API's*/
457 .authorize_response = authorize_response,
458 .set_authorization = set_authorization,
460 .get_service_connection_state = get_service_connection_state,
461 .set_agent_osp_server = set_agent_osp_server,
462 .set_trusted_profile = set_trusted_profile,
463 .get_trusted_profile = get_trusted_profile,
464 .enable_rssi_monitoring = enable_rssi_monitoring,
465 .get_connected_link_rssi_strength = get_connected_link_rssi_strength,
466 .enable_gap_auth_notifications = enable_gap_auth_notifications,
467 .set_le_static_random_address = _bt_hal_set_le_static_random_address,
468 .set_hal_adapter_request_state = set_hal_adapter_request_state,
469 .set_hal_le_request_state = set_hal_le_request_state,
470 .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
471 .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
472 .device_disconnect = dev_disconnect,
476 static const bt_interface_t *get_bluetooth_interface(void)
479 return &bluetooth_if;
482 static int close_bluetooth(struct hw_device_t *device)
490 static int open_bluetooth(const struct hw_module_t *module, char const *name,
491 struct hw_device_t **device)
493 bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t));
497 memset(dev, 0, sizeof(bluetooth_device_t));
498 dev->common.tag = HARDWARE_DEVICE_TAG;
499 dev->common.version = 0;
500 dev->common.module = (struct hw_module_t *) module;
501 dev->common.close = close_bluetooth;
502 dev->get_bluetooth_interface = get_bluetooth_interface;
504 *device = (struct hw_device_t *) dev;
509 static struct hw_module_methods_t bluetooth_module_methods = {
510 .open = open_bluetooth,
513 struct hw_module_t HAL_MODULE_INFO_SYM = {
514 .tag = HARDWARE_MODULE_TAG,
517 .id = BT_HARDWARE_MODULE_ID,
518 .name = "Bluetooth stack",
519 .author = "Intel Corporation",
520 .methods = &bluetooth_module_methods
523 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
525 struct hal_ev_adapter_state_changed *ev = buf;
527 DBG("Adapter State: %d", ev->state);
529 if (bt_hal_cbacks->adapter_state_changed_cb)
530 bt_hal_cbacks->adapter_state_changed_cb(ev->state);
534 static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
536 struct hal_ev_le_state_changed *ev = buf;
538 DBG("Adapter State: %d", ev->state);
540 if (bt_hal_cbacks->le_state_changed_cb)
541 bt_hal_cbacks->le_state_changed_cb(ev->state);
545 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
546 uint8_t num_props, uint16_t len)
551 for (i = 0; i < num_props; i++) {
552 if (sizeof(*prop) + prop->len > len) {
553 ERR("invalid adapter properties(%zu > %u), cant process further properties!!!",
554 sizeof(*prop) + prop->len, len);
558 send_props[i].type = prop->type;
560 switch (prop->type) {
561 /* TODO: Add Adapter Properties */
563 send_props[i].len = prop->len;
564 send_props[i].val = prop->val;
568 DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
570 len -= sizeof(*prop) + prop->len;
571 buf += sizeof(*prop) + prop->len;
579 static void __bt_device_props_to_hal(bt_property_t *send_props,
580 struct hal_property *prop, uint8_t num_props,
588 for (i = 0; i < num_props; i++) {
590 if (sizeof(*prop) + prop->len > len) {
591 ERR("invalid device properties (%zu > %u), cant process further properties!!!",
592 sizeof(*prop) + prop->len, len);
596 send_props[i].type = prop->type;
598 DBG("HAL prop Type [%d]", prop->type);
600 switch (prop->type) {
601 case HAL_PROP_DEVICE_TYPE:
603 DBG("Device property:HAL_PROP_DEVICE_TYPE:");
604 enum_prop_to_hal(send_props[i], prop,
608 case HAL_PROP_DEVICE_VERSION_INFO:
610 DBG("Device property: HAL_PROP_DEVICE_VERSION_INFO");
611 static bt_remote_version_t e;
612 const struct hal_prop_device_info *p;
613 send_props[i].val = &e;
614 send_props[i].len = sizeof(e);
615 p = (struct hal_prop_device_info *) prop->val;
616 e.manufacturer = p->manufacturer;
617 e.sub_ver = p->sub_version;
618 e.version = p->version;
621 case HAL_PROP_DEVICE_SERVICE_REC:
623 DBG("Device property: HAL_PROP_DEVICE_SERVICE_REC");
624 static bt_service_record_t e;
625 const struct hal_prop_device_service_rec *p;
626 send_props[i].val = &e;
627 send_props[i].len = sizeof(e);
628 p = (struct hal_prop_device_service_rec *) prop->val;
629 memset(&e, 0, sizeof(e));
630 memcpy(&e.channel, &p->channel, sizeof(e.channel));
631 memcpy(e.uuid.uu, p->uuid, sizeof(e.uuid.uu));
632 memcpy(e.name, p->name, p->name_len);
636 send_props[i].len = prop->len;
637 send_props[i].val = prop->val;
641 DBG("prop[%d]: %s, len: %d", i, btproperty2str(&send_props[i]), prop->len);
642 len -= sizeof(*prop) + prop->len;
643 buf += sizeof(*prop) + prop->len;
653 ERR("invalid device properties (%u bytes left), ", len);
656 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
658 struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
659 bt_property_t props[ev->num_props];
662 if (!bt_hal_cbacks->adapter_properties_cb)
666 __bt_adapter_props_to_hal(props, ev->props, ev->num_props, len);
668 if (bt_hal_cbacks->adapter_properties_cb)
669 bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
672 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
674 struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
678 if (bt_hal_cbacks->discovery_state_changed_cb)
679 bt_hal_cbacks->discovery_state_changed_cb(ev->state);
682 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len)
684 struct hal_ev_device_found *ev = (struct hal_ev_device_found *) buf;
685 bt_property_t props[ev->num_props];
688 if (!bt_hal_cbacks->device_found_cb)
692 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
694 bt_hal_cbacks->device_found_cb(ev->num_props, props);
697 static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t len)
699 struct hal_ev_remote_device_props *ev = (struct hal_ev_remote_device_props *) buf;
701 bt_property_t props[ev->num_props];
705 if (!bt_hal_cbacks->remote_device_properties_cb)
709 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
710 memcpy(bd_addr.address, ev->bdaddr, 6);
711 bt_hal_cbacks->remote_device_properties_cb(
712 ev->status, &bd_addr, ev->num_props, props);
716 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
719 struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
723 memcpy(bd_addr.address, ev->bdaddr, 6);
725 DBG("[0x%x]", bd_addr.address[0]);
726 DBG("[0x%x]", bd_addr.address[1]);
727 DBG("[0x%x]", bd_addr.address[2]);
728 DBG("[0x%x]", bd_addr.address[3]);
729 DBG("[0x%x]", bd_addr.address[4]);
730 DBG("[0x%x]", bd_addr.address[5]);
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);
744 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
746 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
750 memcpy(bd_addr.address, ev->bdaddr, 6);
752 DBG("[0x%x]", bd_addr.address[0]);
753 DBG("[0x%x]", bd_addr.address[1]);
754 DBG("[0x%x]", bd_addr.address[2]);
755 DBG("[0x%x]", bd_addr.address[3]);
756 DBG("[0x%x]", bd_addr.address[4]);
757 DBG("[0x%x]", bd_addr.address[5]);
759 DBG("ACL Status [0x%x]", ev->status);
760 DBG("ACL State [0x%x]", ev->state);
762 if (!bt_hal_cbacks->acl_state_changed_cb) {
763 ERR("HAL User acl_state_changed_cb is not set!!");
767 bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
771 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
773 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
777 memcpy(bd_addr.address, ev->bdaddr, 6);
779 DBG("Address: [%02X:%02X:%02X:%02X:%02X:%02X]", bd_addr.address[0],
780 bd_addr.address[1], bd_addr.address[2], bd_addr.address[3],
781 bd_addr.address[4], bd_addr.address[5]);
782 DBG("LE conn Status [0x%x]", ev->status);
783 DBG("LE conn State [0x%x]", ev->state);
786 if (!bt_hal_cbacks->le_conn_state_changed_cb) {
787 ERR("HAL User le_conn_state_changed_cb is not set!!");
791 bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
796 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
798 struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
803 memcpy(bd_addr.address, ev->bdaddr, 6);
806 DBG("[0x%x]", bd_addr.address[0]);
807 DBG("[0x%x]", bd_addr.address[1]);
808 DBG("[0x%x]", bd_addr.address[2]);
809 DBG("[0x%x]", bd_addr.address[3]);
810 DBG("[0x%x]", bd_addr.address[4]);
811 DBG("[0x%x]", bd_addr.address[5]);
813 DBG("Service Id: [%u]", ev->service_id);
815 if (!bt_hal_cbacks->authorize_request_cb) {
816 ERR("HAL User authorize_request_cb is not set!!");
820 bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
825 static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
827 struct hal_ev_sock_conn_auth *ev = buf;
833 memcpy(bd_addr.address, ev->bdaddr, 6);
834 memcpy(uuid.uu, ev->uuid, 16);
836 if (!bt_hal_cbacks->socket_authorize_request_cb) {
837 ERR("HAL User socket_authorize_request_cb is not set!!");
841 bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid);
846 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
848 struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
853 memcpy(bd_addr.address, ev->bdaddr, 6);
854 memcpy(bd_name.name, ev->name, 248);
857 DBG("[0x%x]", bd_addr.address[0]);
858 DBG("[0x%x]", bd_addr.address[1]);
859 DBG("[0x%x]", bd_addr.address[2]);
860 DBG("[0x%x]", bd_addr.address[3]);
861 DBG("[0x%x]", bd_addr.address[4]);
862 DBG("[0x%x]", bd_addr.address[5]);
864 DBG("COD [%d]", ev->class_of_dev);
865 DBG("pairing variant [%d]", ev->pairing_variant);
866 DBG("passkey [%d]", ev->passkey);
868 if (!bt_hal_cbacks->ssp_request_cb) {
869 ERR("HAL User ssp_request_cb is not set!!");
873 bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
875 ev->pairing_variant, ev->passkey);
879 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
881 struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
886 memcpy(bd_addr.address, ev->bdaddr, 6);
887 memcpy(bd_name.name, ev->name, 248);
890 DBG("[0x%x]", bd_addr.address[0]);
891 DBG("[0x%x]", bd_addr.address[1]);
892 DBG("[0x%x]", bd_addr.address[2]);
893 DBG("[0x%x]", bd_addr.address[3]);
894 DBG("[0x%x]", bd_addr.address[4]);
895 DBG("[0x%x]", bd_addr.address[5]);
897 DBG("COD [%u]", ev->class_of_dev);
899 if (!bt_hal_cbacks->pin_request_cb) {
900 ERR("HAL User pin_request_cb is not set!!");
904 bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
909 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
911 struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
915 memcpy(bd_addr.address, ev->bdaddr, 6);
917 DBG("[0x%x]", bd_addr.address[0]);
918 DBG("[0x%x]", bd_addr.address[1]);
919 DBG("[0x%x]", bd_addr.address[2]);
920 DBG("[0x%x]", bd_addr.address[3]);
921 DBG("[0x%x]", bd_addr.address[4]);
922 DBG("[0x%x]", bd_addr.address[5]);
924 DBG("Device Trusted? [0x%x]", ev->trust);
926 if (!bt_hal_cbacks->device_trust_state_changed_cb) {
927 ERR("HAL User device_trust_state_changed_cb is not set!!");
931 bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
935 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
937 struct hal_ev_device_trusted_profiles_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->device_trusted_profiles_changed_cb) {
949 ERR("device_trusted_profiles_changed_cb is NULL");
953 bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
958 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
960 struct hal_ev_rssi_monitor_state_changed *ev = buf;
965 memcpy(bd_addr.address, ev->bdaddr, 6);
966 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
967 bd_addr.address[0], bd_addr.address[1],
968 bd_addr.address[2], bd_addr.address[3],
969 bd_addr.address[4], bd_addr.address[5]);
971 if (bt_hal_cbacks->rssi_monitor_state_changed_cb)
972 bt_hal_cbacks->rssi_monitor_state_changed_cb(
973 &bd_addr, ev->link_type, ev->state);
978 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
980 struct hal_ev_rssi_alert_recieved *ev = buf;
985 memcpy(bd_addr.address, ev->bdaddr, 6);
986 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
987 bd_addr.address[0], bd_addr.address[1],
988 bd_addr.address[2], bd_addr.address[3],
989 bd_addr.address[4], bd_addr.address[5]);
991 if (bt_hal_cbacks->rssi_alert_cb)
992 bt_hal_cbacks->rssi_alert_cb(
993 &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
998 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
1000 struct hal_ev_raw_rssi_recieved *ev = buf;
1001 bt_bdaddr_t bd_addr;
1005 memcpy(bd_addr.address, ev->bdaddr, 6);
1006 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
1007 bd_addr.address[0], bd_addr.address[1],
1008 bd_addr.address[2], bd_addr.address[3],
1009 bd_addr.address[4], bd_addr.address[5]);
1011 if (bt_hal_cbacks->raw_rssi_received_cb)
1012 bt_hal_cbacks->raw_rssi_received_cb(
1013 &bd_addr, ev->link_type, ev->rssi);
1018 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
1022 case HAL_EV_ADAPTER_STATE_CHANGED:
1023 DBG("Event: HAL_EV_ADAPTER_STATE_CHANGED");
1024 __bt_hal_handle_adapter_state_changed(buf, len);
1026 case HAL_EV_ADAPTER_PROPS_CHANGED:
1027 DBG("Event: HAL_EV_ADAPTER_PROPS_CHANGED");
1028 __bt_hal_handle_adapter_property_changed(buf, len);
1030 case HAL_EV_DISCOVERY_STATE_CHANGED:
1031 DBG("Event: HAL_EV_DISCOVERY_STATE_CHANGED");
1032 __bt_hal_handle_adapter_discovery_state_changed(buf, len);
1034 case HAL_EV_DEVICE_FOUND:
1035 DBG("Event: HAL_EV_DEVICE_FOUND");
1036 __bt_hal_handle_device_found_event(buf, len);
1038 case HAL_EV_REMOTE_DEVICE_PROPS:
1039 DBG("Event: HAL_EV_REMOTE_DEVICE_PROPS");
1040 __bt_hal_handle_remote_device_properties_event(buf, len);
1042 case HAL_EV_BOND_STATE_CHANGED:
1043 DBG("Event: HAL_EV_BOND_STATE_CHANGED:");
1044 __bt_hal_handle_bond_state_changed_event(buf, len);
1046 case HAL_EV_ACL_STATE_CHANGED:
1047 DBG("Event: HAL_ACL_STATE_CONNECTED or Disconnected");
1048 __bt_hal_handle_device_acl_state_changed_event(buf, len);
1050 case HAL_EV_LE_CONN_STATE_CHANGED:
1051 DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
1052 __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
1054 case HAL_EV_SSP_REQUEST:
1055 DBG("Event: HAL_EV_SSP_REQUEST");
1056 __bt_hal_handle_ssp_request_event(buf, len);
1058 case HAL_EV_PIN_REQUEST:
1059 DBG("Event: HAL_EV_PIN_REQUEST");
1060 __bt_hal_handle_pin_request_event(buf, len);
1062 case HAL_EV_AUTHORIZE_REQUEST:
1063 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1064 __bt_hal_handle_authorize_request_event(buf, len);
1066 case HAL_EV_DEVICE_TRUST_CHANGED:
1067 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1068 __bt_hal_handle_device_trust_state_changed_event(buf, len);
1071 case HAL_EV_SOCK_AUTHORIZE_REQUEST:
1072 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1073 __bt_hal_handle_socket_authorize_request_event(buf, len);
1075 case HAL_EV_LE_STATE_CHANGED:
1076 DBG("Event: HAL_EV_LE_STATE_CHANGED");
1077 __bt_hal_handle_le_state_changed(buf, len);
1080 case HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED:
1081 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1082 __bt_hal_handle_device_trusted_profiles_changed_event(buf, len);
1084 case HAL_EV_RSSI_MONITOR_STATE_CHANGED:
1085 DBG("Event: HAL_EV_RSSI_MONITOR_STATE_CHANGED");
1086 __bt_handle_rssi_monitor_state_changed(buf, len);
1088 case HAL_EV_RSSI_ALERT_RECIEVED:
1089 DBG("Event: HAL_EV_RSSI_ALERT_RECIEVED");
1090 __bt_handle_rssi_alert_recieved(buf, len);
1092 case HAL_EV_RAW_RSSI_RECIEVED:
1093 DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
1094 __bt_handle_raw_rssi_recieved(buf, len);
1097 DBG("Event Currently not handled!!");