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>
48 #include <bt-hal-hf-client.h>
50 #define enum_prop_to_hal(prop, hal_prop, type) do { \
53 prop.len = sizeof(e); \
54 e = *((uint8_t *) (hal_prop->val)); \
57 static const bt_callbacks_t *bt_hal_cbacks = NULL;
60 /* Forward declarations */
61 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop, uint8_t num_props, uint16_t len);
62 static void __bt_device_props_to_hal(bt_property_t *send_props,
63 struct hal_property *prop, uint8_t num_props,
65 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len);
66 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len);
67 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len);
68 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len);
69 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len);
70 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len);
71 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len);
72 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len);
73 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len);
75 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len);
77 static bool interface_ready(void)
79 return bt_hal_cbacks != NULL;
82 static int init(bt_callbacks_t *callbacks)
85 DBG("HAL library Initialization..");
87 if (interface_ready())
88 return BT_STATUS_DONE;
90 bt_hal_cbacks = callbacks;
91 DBG("Store HAL stack msg handler callback");
92 _bt_hal_dbus_store_stack_msg_cb(__bt_hal_handle_stack_messages);
93 ret = _bt_hal_initialize_event_receiver(__bt_hal_handle_stack_messages);
95 if (ret == BT_STATUS_SUCCESS)
96 return BT_STATUS_SUCCESS;
98 return BT_STATUS_FAIL;
101 return BT_STATUS_SUCCESS;
105 static int enable(void)
107 return _bt_hal_dbus_enable_adapter();
110 /* Disable Adapter */
111 static int disable(void)
113 return _bt_hal_dbus_disable_adapter();
117 /* Tizen Specific Reset Adapter */
118 static int reset(void)
120 return _bt_hal_dbus_reset_adapter();
124 static void cleanup(void)
130 /* Tizen Specific Get Powered state */
131 static int get_adapter_powered_status(uint8_t *state)
134 ERR("Invalid param");
135 return BT_STATUS_PARM_INVALID;
138 return _bt_hal_get_adapter_powered_state(state);
142 static int get_adapter_properties(void)
144 return _bt_hal_dbus_get_adapter_properties();
147 static int get_adapter_property(bt_property_type_t type)
149 return _bt_hal_dbus_get_adapter_property(type);
152 static int set_adapter_property(const bt_property_t *property)
155 ERR("Invalid param");
156 return BT_STATUS_PARM_INVALID;
159 return _bt_hal_dbus_set_adapter_property(property);
162 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
165 ERR("Invalid param");
166 return BT_STATUS_PARM_INVALID;
169 return _bt_hal_dbus_get_remote_device_properties(remote_addr);
172 static int get_remote_device_property(bt_bdaddr_t *remote_addr,
173 bt_property_type_t type)
175 return BT_STATUS_UNSUPPORTED;
178 static int set_remote_device_property(bt_bdaddr_t *remote_addr,
179 const bt_property_t *property)
181 return _bt_hal_dbus_set_remote_device_property(remote_addr, property);
184 static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
186 return BT_STATUS_UNSUPPORTED;
189 static int get_remote_services(bt_bdaddr_t *remote_addr)
192 ERR("Invalid param");
193 return BT_STATUS_PARM_INVALID;
195 return _bt_hal_dbus_get_remote_device_services(remote_addr);
198 static int start_discovery(void)
200 return _bt_hal_dbus_start_discovery(false, 0x00);
204 static int start_custom_discovery(bt_disc_role_type_t disc_type)
206 return _bt_hal_dbus_start_discovery(true, disc_type);
210 static int cancel_discovery(void)
212 return _bt_hal_dbus_stop_discovery();
215 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
218 return _bt_hal_device_create_bond(bd_addr, transport);
221 static int cancel_bond(const bt_bdaddr_t *bd_addr)
223 return _bt_hal_device_cancel_bond(bd_addr);
226 static int remove_bond(const bt_bdaddr_t *bd_addr)
229 return _bt_hal_device_remove_bond(bd_addr);
232 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
233 uint8_t pin_len, bt_pin_code_t *pin_code)
235 return _bt_hal_device_legacy_pin_reply(bd_addr, accept, pin_len, (char*)pin_code);
238 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
239 uint8_t accept, uint32_t passkey)
241 return _bt_hal_device_ssp_reply(bd_addr, variant, accept, passkey);
244 static const void *get_profile_interface(const char *profile_id)
246 /*TODO: Profile interfaces to be included later*/
247 DBG("%s", profile_id);
249 if (!interface_ready())
252 if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
253 return bt_get_hidhost_interface();
255 if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
256 return bt_get_socket_interface();
258 if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
261 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
262 return bt_get_av_interface();
264 if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
265 return bt_get_avrcp_tg_interface();
267 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
268 return bt_get_hf_interface();
270 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
271 return bt_get_hf_client_interface();
273 if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
274 return bt_get_gatt_interface();
276 if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
277 return bt_get_hl_interface();
279 if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
280 return bt_get_avrcp_ctrl_interface();
282 if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
285 if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
288 if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
289 return bt_get_a2dp_sink_interface();
294 static int dut_mode_configure(uint8_t enable)
296 return BT_STATUS_UNSUPPORTED;
299 static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
301 return BT_STATUS_UNSUPPORTED;
304 static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
306 return BT_STATUS_UNSUPPORTED;
309 static int config_hci_snoop_log(uint8_t enable)
311 return BT_STATUS_UNSUPPORTED;
314 static int get_connection_state(const bt_bdaddr_t *bd_addr)
317 return _bt_hal_device_get_connection_state(bd_addr);
320 static int set_os_callouts(bt_os_callouts_t *callouts)
322 DBG("callouts: %p", callouts);
324 /* TODO: implement */
326 return BT_STATUS_UNSUPPORTED;
329 static int read_energy_info(void)
331 return BT_STATUS_UNSUPPORTED;
334 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
335 uint8_t authorize, uint8_t save_settings)
338 return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
341 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
344 return _bt_hal_device_set_trust(bd_addr, auth);
348 static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_id_t rem_svc_id)
351 return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
354 static int set_agent_osp_server(uint32_t type, uint8_t enable)
357 return _bt_hal_device_set_osp_server(type, enable);
360 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
363 return _bt_hal_device_set_trusted_profile(bd_addr, profile, trust);
366 static int get_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint32_t *trusted)
369 return _bt_hal_device_get_trusted_profile(bd_addr, profile, trusted);
372 static int get_connected_link_rssi_strength(bt_bdaddr_t *bd_addr, uint32_t conn_link_type)
375 return _bt_hal_device_get_connected_link_rssi_strength(bd_addr, conn_link_type);
378 static int enable_rssi_monitoring(bt_bdaddr_t *bd_addr, uint32_t conn_link_type,
379 int low_threshold, int in_range_threshold, int high_threshold)
382 return _bt_hal_device_enable_rssi_monitoring(bd_addr, conn_link_type,
383 low_threshold, in_range_threshold, high_threshold);
386 static int enable_gap_auth_notifications(uint32_t type, uint8_t enable)
389 _bt_hal_enable_gap_auth_notifications(type, ((enable == 0) ? FALSE : TRUE));
390 return BT_STATUS_SUCCESS;
393 static int set_hal_adapter_request_state(int enable)
396 _bt_hal_set_adapter_request_state(enable);
397 return BT_STATUS_SUCCESS;
400 static int set_hal_le_request_state(int enable)
403 _bt_hal_set_le_request_state(enable);
404 return BT_STATUS_SUCCESS;
407 static int dev_disconnect(const bt_bdaddr_t *bd_addr)
410 return _bt_hal_device_disconnect(bd_addr);
414 static const bt_interface_t bluetooth_if = {
415 .size = sizeof(bt_interface_t),
424 .le_enable = _bt_hal_le_enable,
425 .le_disable = _bt_hal_le_disable,
426 .le_init = _bt_hal_le_init,
427 .le_deinit = _bt_hal_le_deinit,
428 .is_advertising = _bt_hal_is_advertising,
432 .get_adapter_powered_status = get_adapter_powered_status,
434 .get_adapter_properties = get_adapter_properties,
435 .get_adapter_property = get_adapter_property,
436 .set_adapter_property = set_adapter_property,
437 .get_remote_device_properties = get_remote_device_properties,
438 .get_remote_device_property = get_remote_device_property,
439 .set_remote_device_property = set_remote_device_property,
440 .get_remote_service_record = get_remote_service_record,
441 .get_remote_services = get_remote_services,
442 .start_discovery = start_discovery,
444 .start_custom_discovery = start_custom_discovery,
446 .cancel_discovery = cancel_discovery,
447 .create_bond = create_bond,
448 .remove_bond = remove_bond,
449 .cancel_bond = cancel_bond,
450 .pin_reply = pin_reply,
451 .ssp_reply = ssp_reply,
452 .get_profile_interface = get_profile_interface,
453 .dut_mode_configure = dut_mode_configure,
454 .dut_mode_send = dut_mode_send,
455 .le_test_mode = le_test_mode,
456 .config_hci_snoop_log = config_hci_snoop_log,
457 .get_connection_state = get_connection_state,
458 .set_os_callouts = set_os_callouts,
459 .read_energy_info = read_energy_info,
460 /* Tizen Specific API's*/
461 .authorize_response = authorize_response,
462 .set_authorization = set_authorization,
464 .get_service_connection_state = get_service_connection_state,
465 .set_agent_osp_server = set_agent_osp_server,
466 .set_trusted_profile = set_trusted_profile,
467 .get_trusted_profile = get_trusted_profile,
468 .enable_rssi_monitoring = enable_rssi_monitoring,
469 .get_connected_link_rssi_strength = get_connected_link_rssi_strength,
470 .enable_gap_auth_notifications = enable_gap_auth_notifications,
471 .set_le_static_random_address = _bt_hal_set_le_static_random_address,
472 .set_hal_adapter_request_state = set_hal_adapter_request_state,
473 .set_hal_le_request_state = set_hal_le_request_state,
474 .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data,
475 .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
476 .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
477 .device_disconnect = dev_disconnect,
481 static const bt_interface_t *get_bluetooth_interface(void)
484 return &bluetooth_if;
487 static int close_bluetooth(struct hw_device_t *device)
495 static int open_bluetooth(const struct hw_module_t *module, char const *name,
496 struct hw_device_t **device)
498 bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t));
502 memset(dev, 0, sizeof(bluetooth_device_t));
503 dev->common.tag = HARDWARE_DEVICE_TAG;
504 dev->common.version = 0;
505 dev->common.module = (struct hw_module_t *) module;
506 dev->common.close = close_bluetooth;
507 dev->get_bluetooth_interface = get_bluetooth_interface;
509 *device = (struct hw_device_t *) dev;
514 static struct hw_module_methods_t bluetooth_module_methods = {
515 .open = open_bluetooth,
518 struct hw_module_t HAL_MODULE_INFO_SYM = {
519 .tag = HARDWARE_MODULE_TAG,
522 .id = BT_HARDWARE_MODULE_ID,
523 .name = "Bluetooth stack",
524 .author = "Intel Corporation",
525 .methods = &bluetooth_module_methods
528 static void __bt_hal_handle_adapter_state_changed(void *buf, uint16_t len)
530 struct hal_ev_adapter_state_changed *ev = buf;
532 DBG("Adapter State: %d", ev->state);
534 if (bt_hal_cbacks->adapter_state_changed_cb)
535 bt_hal_cbacks->adapter_state_changed_cb(ev->state);
539 static void __bt_hal_handle_le_state_changed(void *buf, uint16_t len)
541 struct hal_ev_le_state_changed *ev = buf;
543 DBG("Adapter State: %d", ev->state);
545 if (bt_hal_cbacks->le_state_changed_cb)
546 bt_hal_cbacks->le_state_changed_cb(ev->state);
550 static void __bt_adapter_props_to_hal(bt_property_t *send_props, struct hal_property *prop,
551 uint8_t num_props, uint16_t len)
556 for (i = 0; i < num_props; i++) {
557 if (sizeof(*prop) + prop->len > len) {
558 ERR("invalid adapter properties(%zu > %u), cant process further properties!!!",
559 sizeof(*prop) + prop->len, len);
563 send_props[i].type = prop->type;
565 switch (prop->type) {
566 /* TODO: Add Adapter Properties */
568 send_props[i].len = prop->len;
569 send_props[i].val = prop->val;
573 DBG("prop[%d]: %s", i, btproperty2str(&send_props[i]));
575 len -= sizeof(*prop) + prop->len;
576 buf += sizeof(*prop) + prop->len;
584 static void __bt_device_props_to_hal(bt_property_t *send_props,
585 struct hal_property *prop, uint8_t num_props,
593 for (i = 0; i < num_props; i++) {
595 if (sizeof(*prop) + prop->len > len) {
596 ERR("invalid device properties (%zu > %u), cant process further properties!!!",
597 sizeof(*prop) + prop->len, len);
601 send_props[i].type = prop->type;
603 DBG("HAL prop Type [%d]", prop->type);
605 switch (prop->type) {
606 case HAL_PROP_DEVICE_TYPE:
608 DBG("Device property:HAL_PROP_DEVICE_TYPE:");
609 enum_prop_to_hal(send_props[i], prop,
613 case HAL_PROP_DEVICE_VERSION_INFO:
615 DBG("Device property: HAL_PROP_DEVICE_VERSION_INFO");
616 static bt_remote_version_t e;
617 const struct hal_prop_device_info *p;
618 send_props[i].val = &e;
619 send_props[i].len = sizeof(e);
620 p = (struct hal_prop_device_info *) prop->val;
621 e.manufacturer = p->manufacturer;
622 e.sub_ver = p->sub_version;
623 e.version = p->version;
626 case HAL_PROP_DEVICE_SERVICE_REC:
628 DBG("Device property: HAL_PROP_DEVICE_SERVICE_REC");
629 static bt_service_record_t e;
630 const struct hal_prop_device_service_rec *p;
631 send_props[i].val = &e;
632 send_props[i].len = sizeof(e);
633 p = (struct hal_prop_device_service_rec *) prop->val;
634 memset(&e, 0, sizeof(e));
635 memcpy(&e.channel, &p->channel, sizeof(e.channel));
636 memcpy(e.uuid.uu, p->uuid, sizeof(e.uuid.uu));
637 memcpy(e.name, p->name, p->name_len);
641 send_props[i].len = prop->len;
642 send_props[i].val = prop->val;
646 DBG("prop[%d]: %s, len: %d", i, btproperty2str(&send_props[i]), prop->len);
647 len -= sizeof(*prop) + prop->len;
648 buf += sizeof(*prop) + prop->len;
658 ERR("invalid device properties (%u bytes left), ", len);
661 static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
663 struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
664 bt_property_t props[ev->num_props];
667 if (!bt_hal_cbacks->adapter_properties_cb)
671 __bt_adapter_props_to_hal(props, ev->props, ev->num_props, len);
673 if (bt_hal_cbacks->adapter_properties_cb)
674 bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
677 static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
679 struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
683 if (bt_hal_cbacks->discovery_state_changed_cb)
684 bt_hal_cbacks->discovery_state_changed_cb(ev->state);
687 static void __bt_hal_handle_device_found_event(void *buf, uint16_t len)
689 struct hal_ev_device_found *ev = (struct hal_ev_device_found *) buf;
690 bt_property_t props[ev->num_props];
693 if (!bt_hal_cbacks->device_found_cb)
697 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
699 bt_hal_cbacks->device_found_cb(ev->num_props, props);
702 static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t len)
704 struct hal_ev_remote_device_props *ev = (struct hal_ev_remote_device_props *) buf;
706 bt_property_t props[ev->num_props];
710 if (!bt_hal_cbacks->remote_device_properties_cb)
714 __bt_device_props_to_hal(props, ev->props, ev->num_props, len);
715 memcpy(bd_addr.address, ev->bdaddr, 6);
716 bt_hal_cbacks->remote_device_properties_cb(
717 ev->status, &bd_addr, ev->num_props, props);
721 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
724 struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
728 memcpy(bd_addr.address, ev->bdaddr, 6);
730 DBG("[0x%x]", bd_addr.address[0]);
731 DBG("[0x%x]", bd_addr.address[1]);
732 DBG("[0x%x]", bd_addr.address[2]);
733 DBG("[0x%x]", bd_addr.address[3]);
734 DBG("[0x%x]", bd_addr.address[4]);
735 DBG("[0x%x]", bd_addr.address[5]);
737 DBG("Bonding State changed Status [0x%x]", ev->status);
738 DBG("Bonding State [0x%x]", ev->state);
740 if (!bt_hal_cbacks->bond_state_changed_cb) {
741 ERR("HAL User bond_state_changed_callback is not set!!");
745 bt_hal_cbacks->bond_state_changed_cb(ev->status, &bd_addr, ev->state);
749 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
751 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
755 memcpy(bd_addr.address, ev->bdaddr, 6);
757 DBG("[0x%x]", bd_addr.address[0]);
758 DBG("[0x%x]", bd_addr.address[1]);
759 DBG("[0x%x]", bd_addr.address[2]);
760 DBG("[0x%x]", bd_addr.address[3]);
761 DBG("[0x%x]", bd_addr.address[4]);
762 DBG("[0x%x]", bd_addr.address[5]);
764 DBG("ACL Status [0x%x]", ev->status);
765 DBG("ACL State [0x%x]", ev->state);
767 if (!bt_hal_cbacks->acl_state_changed_cb) {
768 ERR("HAL User acl_state_changed_cb is not set!!");
772 bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
776 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
778 struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
782 memcpy(bd_addr.address, ev->bdaddr, 6);
784 DBG("Address: [%02X:%02X:%02X:%02X:%02X:%02X]", bd_addr.address[0],
785 bd_addr.address[1], bd_addr.address[2], bd_addr.address[3],
786 bd_addr.address[4], bd_addr.address[5]);
787 DBG("LE conn Status [0x%x]", ev->status);
788 DBG("LE conn State [0x%x]", ev->state);
791 if (!bt_hal_cbacks->le_conn_state_changed_cb) {
792 ERR("HAL User le_conn_state_changed_cb is not set!!");
796 bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
801 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
803 struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
808 memcpy(bd_addr.address, ev->bdaddr, 6);
811 DBG("[0x%x]", bd_addr.address[0]);
812 DBG("[0x%x]", bd_addr.address[1]);
813 DBG("[0x%x]", bd_addr.address[2]);
814 DBG("[0x%x]", bd_addr.address[3]);
815 DBG("[0x%x]", bd_addr.address[4]);
816 DBG("[0x%x]", bd_addr.address[5]);
818 DBG("Service Id: [%u]", ev->service_id);
820 if (!bt_hal_cbacks->authorize_request_cb) {
821 ERR("HAL User authorize_request_cb is not set!!");
825 bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
830 static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t len)
832 struct hal_ev_sock_conn_auth *ev = buf;
838 memcpy(bd_addr.address, ev->bdaddr, 6);
839 memcpy(uuid.uu, ev->uuid, 16);
841 if (!bt_hal_cbacks->socket_authorize_request_cb) {
842 ERR("HAL User socket_authorize_request_cb is not set!!");
846 bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid);
851 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
853 struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
858 memcpy(bd_addr.address, ev->bdaddr, 6);
859 memcpy(bd_name.name, ev->name, 248);
862 DBG("[0x%x]", bd_addr.address[0]);
863 DBG("[0x%x]", bd_addr.address[1]);
864 DBG("[0x%x]", bd_addr.address[2]);
865 DBG("[0x%x]", bd_addr.address[3]);
866 DBG("[0x%x]", bd_addr.address[4]);
867 DBG("[0x%x]", bd_addr.address[5]);
869 DBG("COD [%d]", ev->class_of_dev);
870 DBG("pairing variant [%d]", ev->pairing_variant);
871 DBG("passkey [%d]", ev->passkey);
873 if (!bt_hal_cbacks->ssp_request_cb) {
874 ERR("HAL User ssp_request_cb is not set!!");
878 bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
880 ev->pairing_variant, ev->passkey);
884 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
886 struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
891 memcpy(bd_addr.address, ev->bdaddr, 6);
892 memcpy(bd_name.name, ev->name, 248);
895 DBG("[0x%x]", bd_addr.address[0]);
896 DBG("[0x%x]", bd_addr.address[1]);
897 DBG("[0x%x]", bd_addr.address[2]);
898 DBG("[0x%x]", bd_addr.address[3]);
899 DBG("[0x%x]", bd_addr.address[4]);
900 DBG("[0x%x]", bd_addr.address[5]);
902 DBG("COD [%u]", ev->class_of_dev);
904 if (!bt_hal_cbacks->pin_request_cb) {
905 ERR("HAL User pin_request_cb is not set!!");
909 bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
914 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
916 struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
920 memcpy(bd_addr.address, ev->bdaddr, 6);
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("Device Trusted? [0x%x]", ev->trust);
931 if (!bt_hal_cbacks->device_trust_state_changed_cb) {
932 ERR("HAL User device_trust_state_changed_cb is not set!!");
936 bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
940 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
942 struct hal_ev_device_trusted_profiles_changed *ev = buf;
947 memcpy(bd_addr.address, ev->bdaddr, 6);
948 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
949 bd_addr.address[0], bd_addr.address[1],
950 bd_addr.address[2], bd_addr.address[3],
951 bd_addr.address[4], bd_addr.address[5]);
953 if (!bt_hal_cbacks->device_trusted_profiles_changed_cb) {
954 ERR("device_trusted_profiles_changed_cb is NULL");
958 bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
963 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
965 struct hal_ev_rssi_monitor_state_changed *ev = buf;
970 memcpy(bd_addr.address, ev->bdaddr, 6);
971 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
972 bd_addr.address[0], bd_addr.address[1],
973 bd_addr.address[2], bd_addr.address[3],
974 bd_addr.address[4], bd_addr.address[5]);
976 if (bt_hal_cbacks->rssi_monitor_state_changed_cb)
977 bt_hal_cbacks->rssi_monitor_state_changed_cb(
978 &bd_addr, ev->link_type, ev->state);
983 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
985 struct hal_ev_rssi_alert_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->rssi_alert_cb)
997 bt_hal_cbacks->rssi_alert_cb(
998 &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
1003 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
1005 struct hal_ev_raw_rssi_recieved *ev = buf;
1006 bt_bdaddr_t bd_addr;
1010 memcpy(bd_addr.address, ev->bdaddr, 6);
1011 DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
1012 bd_addr.address[0], bd_addr.address[1],
1013 bd_addr.address[2], bd_addr.address[3],
1014 bd_addr.address[4], bd_addr.address[5]);
1016 if (bt_hal_cbacks->raw_rssi_received_cb)
1017 bt_hal_cbacks->raw_rssi_received_cb(
1018 &bd_addr, ev->link_type, ev->rssi);
1023 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 DBG("Event: HAL_ACL_STATE_CONNECTED or Disconnected");
1053 __bt_hal_handle_device_acl_state_changed_event(buf, len);
1055 case HAL_EV_LE_CONN_STATE_CHANGED:
1056 DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
1057 __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
1059 case HAL_EV_SSP_REQUEST:
1060 DBG("Event: HAL_EV_SSP_REQUEST");
1061 __bt_hal_handle_ssp_request_event(buf, len);
1063 case HAL_EV_PIN_REQUEST:
1064 DBG("Event: HAL_EV_PIN_REQUEST");
1065 __bt_hal_handle_pin_request_event(buf, len);
1067 case HAL_EV_AUTHORIZE_REQUEST:
1068 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1069 __bt_hal_handle_authorize_request_event(buf, len);
1071 case HAL_EV_DEVICE_TRUST_CHANGED:
1072 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1073 __bt_hal_handle_device_trust_state_changed_event(buf, len);
1076 case HAL_EV_SOCK_AUTHORIZE_REQUEST:
1077 DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
1078 __bt_hal_handle_socket_authorize_request_event(buf, len);
1080 case HAL_EV_LE_STATE_CHANGED:
1081 DBG("Event: HAL_EV_LE_STATE_CHANGED");
1082 __bt_hal_handle_le_state_changed(buf, len);
1085 case HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED:
1086 DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
1087 __bt_hal_handle_device_trusted_profiles_changed_event(buf, len);
1089 case HAL_EV_RSSI_MONITOR_STATE_CHANGED:
1090 DBG("Event: HAL_EV_RSSI_MONITOR_STATE_CHANGED");
1091 __bt_handle_rssi_monitor_state_changed(buf, len);
1093 case HAL_EV_RSSI_ALERT_RECIEVED:
1094 DBG("Event: HAL_EV_RSSI_ALERT_RECIEVED");
1095 __bt_handle_rssi_alert_recieved(buf, len);
1097 case HAL_EV_RAW_RSSI_RECIEVED:
1098 DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
1099 __bt_handle_raw_rssi_recieved(buf, len);
1102 DBG("Event Currently not handled!!");